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(10e-3 * fs)) ) ### Run model rates = cochlea.run_zilany2014_rate( s, fs, anf_types=['msr'], cf=(125, 20000, 100), powerlaw='approximate', species='human' ) ### Plot rates fig, ax = plt.subplots() img = ax.imshow( rates.T, aspect='auto' ) plt.colorbar(img) 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 main(): fs = 100e3 cf = 8e3 ### Make sound t = np.arange(0, 0.1, 1/fs) tone = np.sin(2*np.pi*t*cf) tone = cochlea.set_dbspl(tone, 20) pad = np.zeros(50e-3 * fs) sound = np.concatenate( (tone, pad) ) ### Run model anf = cochlea.run_zilany2014( sound, fs, anf_num=(200,0,0), cf=cf, seed=0, powerlaw='approximate', species='human' ) print(anf.head(20)) ### Plot PSTH all_spikes = np.concatenate(anf.spikes) tmax = anf.duration.max() bin_size = 1e-3 fig,ax = plt.subplots() ax.hist( all_spikes, bins=int(tmax/bin_size), range=(0,tmax), weights=np.ones_like(all_spikes)/bin_size/len(anf) ) ax.set_xlabel("Time [s]") ax.set_ylabel("Rate [spikes/s]") ax.set_title("PSTH") 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(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 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()
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 rates = cochlea.run_zilany2014_rate(s, fs, anf_types=['msr'], cf=(125, 20000, 100), powerlaw='approximate', species='human') ### Plot rates fig, ax = plt.subplots() img = ax.imshow(rates.T, aspect='auto') plt.colorbar(img) plt.show()
def run_exp(c_freq, itd, str_e, str_i): # br.globalprefs.set_global_preferences(useweave=True, openmp=True, usecodegen=True, # usecodegenweave=True ) br.defaultclock.dt = 20E-6 * second #Basic Parameters fs_coch = 100e3 # s/second duration = 100E-3 # seconds## pad = 20E-3 # second n_neuron = 300 dbspl = 50 n_neuron = 500 dt_coch = 1 / fs_coch n_pad = int(pad / dt_coch) n_itd = int(itd / dt_coch) const_dt = 100e-6 sound = audio.generate_tone(c_freq, duration, fs_coch) sound = sound * audio.cosine_fade_window(sound, 20e-3, fs_coch) sound = coch.set_dbspl(sound, dbspl) sound = np.concatenate((np.zeros(n_pad), sound, np.zeros(n_pad))) sound = audio.delay_signal(sound, np.abs(itd), fs_coch) if itd < 0: sound = sound[:, ::-1] duration = len(sound) / fs_coch # construct ipsi and contra-lateral ANF trains and convert them to # neuron groups cochlea_train_left = coch.run_zilany2014(sound=sound[:, 0], fs=fs_coch, anf_num=(n_neuron, 0, 0), cf=c_freq, species='human', seed=0) cochlea_train_right = coch.run_zilany2014(sound=sound[:, 1], fs=fs_coch, anf_num=(n_neuron, 0, 0), cf=c_freq, species='human', seed=0) anf_group_left = coch.make_brian_group(cochlea_train_left) anf_group_right = coch.make_brian_group(cochlea_train_right) # Setup a new mso group and new gbc groups mso_group_left = make_mso_group(n_neuron) mso_group_right = make_mso_group(n_neuron) gbc_group_left = cochlea_to_gbc(anf_group_left, n_neuron) gbc_group_right = cochlea_to_gbc(anf_group_right, n_neuron) # Synaptic connections for the groups syn_mso_l_in_ipsi, syn_mso_l_in_contra = inhibitory_to_mso( mso_group=mso_group_left, ipsi_group=gbc_group_left['neuron_groups'][0], contra_group=gbc_group_right['neuron_groups'][0], strength=str_i, ipsi_delay=0, contra_delay=-0.6e-3 + const_dt) syn_mso_r_in_ipsi, syn_mso_r_in_contra = inhibitory_to_mso( mso_group=mso_group_right, ipsi_group=gbc_group_right['neuron_groups'][0], contra_group=gbc_group_left['neuron_groups'][0], strength=str_i, ipsi_delay=0, contra_delay=-0.6e-3 + const_dt) syn_mso_l_ex_ipsi, syn_mso_l_ex_contra = excitatory_to_mso( mso_group=mso_group_left, ipsi_group=anf_group_left, contra_group=anf_group_right, strength=str_e, contra_delay=const_dt) syn_mso_r_ex_ipsi, syn_mso_r_ex_contra = excitatory_to_mso( mso_group=mso_group_right, ipsi_group=anf_group_right, contra_group=anf_group_left, strength=str_e, contra_delay=const_dt) sp_mon_left = br.SpikeMonitor(mso_group_left, record=True) sp_mon_right = br.SpikeMonitor(mso_group_right, record=True) network = ([ mso_group_left, mso_group_right, anf_group_left, anf_group_right, syn_mso_l_ex_ipsi, syn_mso_l_ex_contra, syn_mso_l_in_ipsi, syn_mso_l_in_contra, syn_mso_r_ex_ipsi, syn_mso_r_ex_contra, syn_mso_r_in_ipsi, syn_mso_r_in_contra, sp_mon_left, sp_mon_right ] + gbc_group_left['neuron_groups'] + gbc_group_right['neuron_groups']) run(duration, network) mso_train_left = thorns.make_trains(sp_mon_left) mso_train_right = thorns.make_trains(sp_mon_right) return {'spikes_left': mso_train_left, 'spikes_right': mso_train_right}