def main(): fs = 48e3 ### Make sound tmax = 0.03 t = np.arange(0, tmax, 1 / fs) s = dsp.chirp(t, 80, t[-1], 16000) sound = cochlea.set_dbspl(s, 50) ### Run model anf = run_matlab_auditory_periphery( sound, fs, anf_num=(100, 50, 20), cf=(125, 16000, 80), seed=0, ) ### Accumulate spike trains anf_acc = th.accumulate(anf, keep=['cf', 'duration']) anf_acc.sort('cf', ascending=False, inplace=True) ### Plot auditory nerve response fig, ax = plt.subplots(2, 1, sharex=True) th.plot_signal(signal=sound, fs=fs, ax=ax[0]) th.plot_neurogram(anf_acc, fs, ax=ax[1]) plt.show()
def main(): fs = 100e3 ### Make sound t = np.arange(0, 0.1, 1 / fs) s = dsp.chirp(t, 80, t[-1], 20000) s = cochlea.set_dbspl(s, 50) pad = np.zeros(10e-3 * fs) sound = np.concatenate((s, pad)) ### Run model anf = cochlea.run_zilany2014( sound, fs, anf_num=(100, 0, 0), cf=(125, 20000, 100), seed=0, powerlaw="approximate", species="human" ) ### Accumulate spike trains anf_acc = th.accumulate(anf, keep=["cf", "duration"]) anf_acc.sort("cf", ascending=False, inplace=True) ### Plot auditory nerve response fig, ax = plt.subplots(2, 1) th.plot_signal(signal=sound, fs=fs, ax=ax[0]) th.plot_neurogram(anf_acc, fs, ax=ax[1]) plt.show()
def main(): fs = 48e3 ### Make sound t = np.arange(0, 0.1, 1 / fs) s = dsp.chirp(t, 80, t[-1], 20000) s = cochlea.set_dbspl(s, 50) s = np.concatenate((s, np.zeros(int(10e-3 * fs)))) ### Run model anf_trains = cochlea.run_holmberg2007( s, fs, anf_num=(100, 0, 0), seed=0, ) ### Plot auditory nerve response anf_acc = th.accumulate(anf_trains, keep=['cf', 'duration']) anf_acc.sort('cf', ascending=False, inplace=True) fig, ax = plt.subplots(2, 1) th.plot_signal(signal=s, fs=fs, ax=ax[0]) th.plot_neurogram(anf_acc, fs, ax=ax[1]) plt.show()
def test_accumulate(): trains = th.make_trains([[1], [2], [3], []], cfs=[2, 1, 2, 3]) accumulated = th.accumulate(trains) expected = th.make_trains([[2], [1, 3], []], cfs=[1, 2, 3]) assert_frame_equal(accumulated, expected)
def main(): fs = 100e3 ### Make sound t = np.arange(0, 0.1, 1/fs) s = dsp.chirp(t, 80, t[-1], 20000) s = cochlea.set_dbspl(s, 50) s = np.concatenate( (s, np.zeros(10e-3 * fs)) ) ### Run model anf = cochlea.run_zilany2009( s, fs, anf_num=(100,0,0), cf=(80, 20000, 100), seed=0, powerlaw='approximate' ) ### Plot auditory nerve response anf_acc = th.accumulate(anf, keep=['cf', 'duration']) anf_acc.sort('cf', ascending=False, inplace=True) cfs = anf.cf.unique() fig, ax = plt.subplots(2,1, sharex=True) th.plot_neurogram( anf_acc, fs, ax=ax[0] ) th.plot_raster( anf[anf.cf==cfs[30]], ax=ax[1] ) ax[1].set_title("CF = {}".format(cfs[30])) plt.show()
def test_accumulate(): trains = th.make_trains( [[1], [2], [3], []], cfs=[2,1,2,3] ) accumulated = th.accumulate(trains) expected = th.make_trains( [[2], [1,3], []], cfs=[1,2,3] ) assert_frame_equal( accumulated, expected, check_like=True, )
def main(): fs = 48e3 ### Make sound tmax = 0.03 t = np.arange(0, tmax, 1/fs) s = dsp.chirp(t, 80, t[-1], 16000) sound = cochlea.set_dbspl(s, 50) ### Run model anf = run_matlab_auditory_periphery( sound, fs, anf_num=(100,50,20), cf=(125, 16000, 80), seed=0, ) ### Accumulate spike trains anf_acc = th.accumulate(anf, keep=['cf', 'duration']) anf_acc.sort('cf', ascending=False, inplace=True) ### Plot auditory nerve response fig, ax = plt.subplots(2, 1, sharex=True) th.plot_signal( signal=sound, fs=fs, ax=ax[0] ) th.plot_neurogram( anf_acc, fs, ax=ax[1] ) plt.show()
def main(): fs = 100e3 # Make sound t = np.arange(0, 0.1, 1/fs) s = dsp.chirp(t, 80, t[-1], 20000) s = cochlea.set_dbspl(s, 50) s = np.concatenate((s, np.zeros(int(10e-3*fs)))) # Run model anf = cochlea.run_zilany2009( s, fs, anf_num=(100,0,0), cf=(80, 20000, 100), seed=0, powerlaw='approximate' ) # Plot auditory nerve response anf_acc = th.accumulate(anf, keep=['cf', 'duration']) anf_acc.sort_values('cf', ascending=False, inplace=True) cfs = anf.cf.unique() fig, ax = plt.subplots(2,1, sharex=True) th.plot_neurogram( anf_acc, fs, ax=ax[0] ) th.plot_raster( anf[anf.cf==cfs[30]], ax=ax[1] ) ax[1].set_title("CF = {}".format(cfs[30])) plt.show()
def main(): fs = 100e3 # Make sound t = np.arange(0, 0.1, 1/fs) s = dsp.chirp(t, 80, t[-1], 20000) s = cochlea.set_dbspl(s, 50) pad = np.zeros(int(10e-3 * fs)) sound = np.concatenate( (s, pad) ) # Run model anf = cochlea.run_zilany2014( sound, fs, anf_num=(100,0,0), cf=(125, 20000, 100), seed=0, powerlaw='approximate', species='human', ) # Accumulate spike trains anf_acc = th.accumulate(anf, keep=['cf', 'duration']) anf_acc.sort_values('cf', ascending=False, inplace=True) # Plot auditory nerve response fig, ax = plt.subplots(2,1) th.plot_signal( signal=sound, fs=fs, ax=ax[0] ) th.plot_neurogram( anf_acc, fs, ax=ax[1] ) plt.show()
def main(): fs = 48e3 ### Make sound t = np.arange(0, 0.1, 1/fs) s = dsp.chirp(t, 80, t[-1], 20000) s = cochlea.set_dbspl(s, 50) s = np.concatenate( (s, np.zeros(10e-3 * fs)) ) ### Run model anf_trains = cochlea.run_holmberg2007( s, fs, anf_num=(100,0,0), seed=0, ) ### Plot auditory nerve response anf_acc = th.accumulate(anf_trains, keep=['cf', 'duration']) anf_acc.sort('cf', ascending=False, inplace=True) fig, ax = plt.subplots(2,1) th.plot_signal( signal=s, fs=fs, ax=ax[0] ) th.plot_neurogram( anf_acc, fs, ax=ax[1] ) plt.show()
rate = f.getframerate() duration = frames / float(rate) spf = wave.open(fname, "r") # Extract Raw Audio from Wav File signal = spf.readframes(-1) signal = np.frombuffer(signal, dtype=np.int16) number_lv = np.ceil(np.log10(np.max(signal))) spf.close() signal = signal / 10.**number_lv signal = dsp.resample(signal, int(fs * duration)) plt.figure(1) plt.title("Signal Wave...") wv.plot_signal(signal, int(fs)) plt.show() anf_trains = cochlea.run_zilany2014(signal, int(fs), anf_num=(0, 0, 50), cf=(125, 10e3, 100), seed=0, species='human') th.plot_raster(th.accumulate(anf_trains)) plt.show()