Changeset 185
- Timestamp:
- 07/24/08 17:23:32 (4 months ago)
- Files:
-
- trunk/src/analysis.py (modified) (1 diff)
- trunk/src/signals.py (modified) (5 diffs)
- trunk/test/test_analysis.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/analysis.py
r180 r185 96 96 if D[k] == max_val: 97 97 return k 98 99 def simple_frequency_spectrum(x): 100 """ 101 Very simple calculation of frequency spectrum with no detrending, 102 windowing, etc. Just the first half (positive frequency components) of 103 abs(fft(x)) 104 """ 105 spec = numpy.absolute(numpy.fft.fft(x)) 106 spec = spec[:len(x)/2] # take positive frequency components 107 spec /= len(x) # normalize 108 spec *= 2.0 # to get amplitudes of sine components, need to multiply by 2 109 spec[0] /= 2.0 # except for the dc component 110 return spec 98 111 99 112 class TuningCurve(object): trunk/src/signals.py
r184 r185 10 10 except Exception: 11 11 print "Warning: pylab not present" 12 from NeuroTools import analysis 12 13 13 14 … … 120 121 return len(self.spike_times) 121 122 123 def duration(self): 124 return self.t_stop - self.t_start 125 122 126 def format(self, relative=False, quantized=False): 123 127 """ … … 308 312 return tuning_curve 309 313 314 def frequency_spectrum(self, time_bin): 315 """ 316 Returns the frequency spectrum of the time histogram together with the 317 frequency axis. 318 """ 319 hist = self.time_histogram(time_bin, normalized=False) 320 freq_spect = analysis.simple_frequency_spectrum(hist) 321 freq_bin = 1000.0/self.duration() # Hz 322 freq_axis = numpy.arange(len(freq_spect)) * freq_bin 323 return freq_spect, freq_axis 324 325 def f1f0_ratio(self, time_bin, f_stim): 326 """ 327 Returns the F1/F0 amplitude ratio where the input stimulus frequency is 328 f_stim. 329 """ 330 freq_spect = self.frequency_spectrum(time_bin)[0] 331 F0 = freq_spect[0] 332 freq_bin = 1000.0/self.duration() 333 try: 334 F1 = freq_spect[int(round(f_stim/freq_bin))] 335 except IndexError: 336 errmsg = "time_bin (%f) too large to estimate F1/F0 ratio for an input frequency of %f" % (time_bin, f_stim) 337 errmsg += "\nFrequency_spectrum: %s" % freq_spect 338 raise Exception(errmsg) 339 return F1/F0 340 310 341 311 342 class SpikeList(object): … … 412 443 self.spiketrains[id] = spiketrain 413 444 self.id_list.append(id) 414 self.N += 1415 445 self.__calc_startstop() 416 446 … … 915 945 def as_pyNN_SpikeArray(self): 916 946 """ 917 to use in conj onction with SpikeSourceArray neurons947 to use in conjunction with SpikeSourceArray neurons 918 948 919 949 >>> pop = Population((10,),SpikeSourceArray, {'spike_times': sl.as_pyNN_SpikeArray() })

