From 4227bfd4471ca3a33e694f5be7ae456ddf70e64a Mon Sep 17 00:00:00 2001 From: efish Date: Wed, 21 Nov 2018 15:38:57 +0100 Subject: [PATCH] =?UTF-8?q?eod=20frequenz=20chirps=20=C3=BCber=20zeit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/eod_frequency_chirp.py | 39 +++++++++++++++++++++++++ code/eod_frequency_normal.py | 56 ++++++++++++++++++++++++++++++++++++ code/read_chirp_data.py | 2 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 code/eod_frequency_chirp.py create mode 100644 code/eod_frequency_normal.py diff --git a/code/eod_frequency_chirp.py b/code/eod_frequency_chirp.py new file mode 100644 index 0000000..a495601 --- /dev/null +++ b/code/eod_frequency_chirp.py @@ -0,0 +1,39 @@ +from read_chirp_data import * +import os +from IPython import embed +import matplotlib.pyplot as plt +import numpy as np + + +data_dir = "../data" +dataset = "2018-11-14-ak-invivo-1" +stim = read_chirp_stimulus(os.path.join(data_dir, dataset)) + +s = stim[(1, 675.0, 100.0)][0] +eod = s[1] +time = s[0] + +eod_norm = eod - np.mean(eod) +# calculate chirp times and indices by zero crossings +threshold = 0 +shift_eod = np.roll(eod_norm, 1) +eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)] + +eod_freq_chirp = 1/np.diff(eod_times) +kernel = np.ones(11)/11 +smooth_eod_freq_chirp = np.convolve(eod_freq_chirp, kernel, mode = 'valid') +time_axis = np.arange(len(smooth_eod_freq_chirp)) + + +fig = plt.plot(time_axis, smooth_eod_freq_chirp) +plt.xlabel("time [ms]", fontsize = 14) +plt.xticks(fontsize = 12) +plt.ylabel("eod frequency [mV]", fontsize = 14) +plt.yticks(fontsize = 12) +plt.axis([0, len(time_axis), 0, 2000]) + +plt.show() + + + + diff --git a/code/eod_frequency_normal.py b/code/eod_frequency_normal.py new file mode 100644 index 0000000..e1a16a9 --- /dev/null +++ b/code/eod_frequency_normal.py @@ -0,0 +1,56 @@ +from read_baseline_data import * +from IPython import embed +import matplotlib.pyplot as plt +import numpy as np + +data_dir = '../data' +dataset = '2018-11-09-ad-invivo-1' + +# read eod and time of baseline +time, eod = read_baseline_eod(os.path.join(data_dir, dataset)) + +eod_norm = eod - np.mean(eod) + +# calculate eod times and indices by zero crossings +threshold = 0 +shift_eod = np.roll(eod_norm, 1) +eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)] + + +## normal +eod_freq_normal = 1/np.diff(eod_times) +kernel = np.ones(7)/7 + +smooth_eod_freq_normal = np.convolve(eod_freq_normal, kernel, mode = 'valid') +time_axis = np.arange(len(smooth_eod_freq_normal)) +#print(eod_freq) +#print(smooth_eod_freq) + +fig = plt.plot(time_axis,smooth_eod_freq_normal, linewidth = 2.0) +plt.xlabel("time [ms]", fontsize = 14) +plt.xticks(fontsize = 12) +plt.ylabel("eod frequency [mV]", fontsize = 14) +plt.yticks(fontsize = 12) +plt.axis([0, len(time_axis), 0, 1000]) + +plt.show() + + + + + + + +## beat +#x = np.arange(0, len(time_axis, 0.000001) # Start, Stop, Step +#y = np.sin(x * 2* np.pi * 600) +#plt.plot(x, y) +#plt.show() + + +#eod_freq_beat = eod_freq_normal + np.sin(x * 2* np.pi * 600) +#smooth_eod_freq_beat = np.convolve(eod_freq_beat, kernel, mode = 'valid') +#fig = plt.plot(time_axis,smooth_eod_freq_beat) +#plt.xlabel("time [ms]") +#plt.ylabel("eod frequency [mV]") +#plt.show() diff --git a/code/read_chirp_data.py b/code/read_chirp_data.py index 4491779..fa64675 100644 --- a/code/read_chirp_data.py +++ b/code/read_chirp_data.py @@ -116,7 +116,7 @@ def read_chirp_stimulus(dataset): if __name__ == "__main__": data_dir = "../data" - dataset = "2018-11-20-ad-invivo-1" + dataset = "2018-11-09-ad-invivo-1" #spikes = load_chirp_spikes(os.path.join(data_dir, dataset)) #chirp_times = load_chirp_times(os.path.join(data_dir, dataset)) #chirp_eod = load_chirp_eod(os.path.join(data_dir, dataset))