diff --git a/jar_functions.py b/jar_functions.py index ec05d44..f5f9506 100644 --- a/jar_functions.py +++ b/jar_functions.py @@ -58,11 +58,10 @@ def parse_dataset(dataset_name): def mean_noise_cut(frequencies, time, n): cutf = [] cutt = [] - for k in np.arange(0, len(time), n): - f = frequencies[k:k+n] + for k in np.arange(0, len(frequencies), n): t = time[k] - mean = np.mean(f) - cutf.append(mean) + f = np.mean(frequencies[k:k+n]) + cutf.append(f) cutt.append(t) return cutf, cutt @@ -74,19 +73,21 @@ def step_response(t, a1, a2, tau1, tau2): -def normalized_JAR(frequencies, time, onset=0, offset=100): - - onset_point = onset - 10 - offset_point = offset - 10 - embed() +def base_eod(frequencies, time, onset_point): base_eod = [] - step_eod = [] - np.mean(f[(time >= onset_point) & time < onset]) - for i in range(len(frequencies)): - if time < onset and time > onset_point: + onset_end = onset_point - 10 + + base = np.mean(frequencies[(time >= onset_end) & (time < onset_point)]) + base_eod.append(base) + return base_eod + +def JAR_eod(frequencies, time, offset_point): + jar_eod = [] + + offset_start = offset_point - 10 - base_eod.append(frequencies[i]) + jar = np.mean(frequencies[(time >= offset_start) & (time < offset_point)]) + jar_eod.append(jar) - if time[i] < offset and time[i] > offset_range: - step_eod.append(frequencies[i]) + return jar_eod \ No newline at end of file diff --git a/second_try.py b/second_try.py index 572e62e..b0590a2 100644 --- a/second_try.py +++ b/second_try.py @@ -7,6 +7,8 @@ from IPython import embed from jar_functions import parse_dataset from jar_functions import mean_noise_cut from jar_functions import step_response +from jar_functions import JAR_eod +from jar_functions import base_eod datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))] @@ -49,40 +51,43 @@ for dataset in datasets: frequency_mean.append(mf) time.append(tnew) +""" + for a in [0, 1, 2]: + for b in [0, 1, 2]: + r_step = step_response(t = ct_arr, a1 = a, a2 = b, tau1 = 30, tau2 = 60) +""" + for i in range(len(frequency_mean)): - for n in [10, 50, 100, 1000, 10000, 20000, 30000]: + for n in [100, 500, 1000]: cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n) - #plt.plot(ct, cf, label='n=%d' % n) - - ct_array = np.array(ct) +10 - r_step = step_response(t=ct_array, a1=0.58, a2=0, tau1=100, tau2=100) - #plt.plot(r_step) + ct_arr = np.array(ct) + cf_arr = np.array(cf) + base = base_eod(cf_arr, ct_arr, onset_point = 0) + ground = cf_arr - base + jar = JAR_eod(ground, ct_arr, offset_point = 100) + norm = ground / jar - for a in [0, 1, 2]: - for b in [0, 1, 2]: - r_step = step_response(t = ct_array, a1 = a, a2 = b, tau1 = 30, tau2 = 60) - + plt.plot(ct_arr, norm, label='n=%d' % n) -plt.plot(time[0], frequency_mean[0]) -plt.show() -embed() +for n in [1480]: + cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n) + ct_arr = np.array(ct) + cf_arr = np.array(cf) + r_step = step_response(t=ct_arr + 10, a1=0.55, a2=0.89, tau1=11.2, tau2= 280) + plt.plot(r_step, label='fit: n=%d' % n) 'plotting' -plt.xlim([-10,200]) +plt.xlim([-10,220]) #plt.ylim([400, 1000]) plt.xlabel('time [s]') -#plt.ylabel('rel. JAR magnitude') +plt.ylabel('rel. JAR magnitude') #plt.title('fit_function(a1=0)') #plt.savefig('fit_function(a1=0)') plt.legend() plt.show() - - - -# normiert darstellen (frequency / mean von baseline frequency?)? -# Zeitkonstante: von sec. 0 bis 63%? relative JAR - +embed() +# Zeitkonstante: von sec. 0 bis 63%? relative JAR \ No newline at end of file