01.07
This commit is contained in:
parent
d4ed1e0040
commit
b7bc739f37
@ -55,25 +55,6 @@ def parse_dataset(dataset_name):
|
|||||||
return times, frequencies, amplitudes, eodfs, deltafs, stimulusfs #output of the function
|
return times, frequencies, amplitudes, eodfs, deltafs, stimulusfs #output of the function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
assert (os.path.exists(dataset_name)) # see if data exists
|
|
||||||
f = open(dataset_name, 'r') # open data we gave in
|
|
||||||
lines = f.readlines() # read data
|
|
||||||
f.close()
|
|
||||||
#len of frequencies is 10 time shorter than before, so worked?
|
|
||||||
#put in frequencies instead of dataset?
|
|
||||||
#2nd loop cut frequencies by this function?
|
|
||||||
cutf = []
|
|
||||||
frequencies = []
|
|
||||||
for i in range(len(lines)):
|
|
||||||
l = lines[i].strip()
|
|
||||||
|
|
||||||
if len(l) > 0 and l[0] is not '#':
|
|
||||||
temporary = list(map(float, l.split()))
|
|
||||||
frequencies.append(temporary[1])
|
|
||||||
'''
|
|
||||||
|
|
||||||
def mean_noise_cut(frequencies, time, n):
|
def mean_noise_cut(frequencies, time, n):
|
||||||
cutf = []
|
cutf = []
|
||||||
cutt = []
|
cutt = []
|
||||||
@ -84,3 +65,28 @@ def mean_noise_cut(frequencies, time, n):
|
|||||||
cutf.append(mean)
|
cutf.append(mean)
|
||||||
cutt.append(t)
|
cutt.append(t)
|
||||||
return cutf, cutt
|
return cutf, cutt
|
||||||
|
|
||||||
|
def step_response(t, a1, a2, tau1, tau2):
|
||||||
|
r_step = a1*(1 - np.exp(-t/tau1)) + a2*(1- np.exp(-t/tau2))
|
||||||
|
return r_step
|
||||||
|
# plotten mit manual values for a1, ...
|
||||||
|
# auch mal a1 oder a2 auf Null setzen.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def normalized_JAR(frequencies, time, onset=0, offset=100):
|
||||||
|
|
||||||
|
onset_point = onset - 10
|
||||||
|
offset_point = offset - 10
|
||||||
|
embed()
|
||||||
|
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:
|
||||||
|
|
||||||
|
base_eod.append(frequencies[i])
|
||||||
|
|
||||||
|
if time[i] < offset and time[i] > offset_range:
|
||||||
|
step_eod.append(frequencies[i])
|
||||||
|
@ -37,6 +37,9 @@ mean1 = np.mean(z, axis=1)
|
|||||||
print(mean0)
|
print(mean0)
|
||||||
print(mean1)
|
print(mean1)
|
||||||
'''
|
'''
|
||||||
for dataset in datasets:
|
t = [600, 650]
|
||||||
cf = noise_reduce(dataset, 10)
|
|
||||||
embed()
|
x = 1 - np.exp(t / 11)
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
a, b ,c,d = normalized_JAR(fre)
|
@ -6,10 +6,10 @@ import numpy as np
|
|||||||
from IPython import embed
|
from IPython import embed
|
||||||
from jar_functions import parse_dataset
|
from jar_functions import parse_dataset
|
||||||
from jar_functions import mean_noise_cut
|
from jar_functions import mean_noise_cut
|
||||||
|
from jar_functions import step_response
|
||||||
|
|
||||||
|
|
||||||
datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
||||||
# (os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
|
||||||
|
|
||||||
eodf = []
|
eodf = []
|
||||||
deltaf = []
|
deltaf = []
|
||||||
@ -27,76 +27,62 @@ for dataset in datasets:
|
|||||||
#input of the function
|
#input of the function
|
||||||
t, f, a, e, d, s= parse_dataset(dataset)
|
t, f, a, e, d, s= parse_dataset(dataset)
|
||||||
|
|
||||||
'times'
|
|
||||||
# same for time in both loops
|
|
||||||
minimumt = min(len(t[0]), len(t[1]))
|
minimumt = min(len(t[0]), len(t[1]))
|
||||||
t0 = t[0][:minimumt]
|
|
||||||
t1 = t[1][:minimumt]
|
|
||||||
|
|
||||||
# new time with wished timespan because it varies for different loops
|
# new time with wished timespan because it varies for different loops
|
||||||
tnew = np.arange(start, stop, timespan / minimumt) # 3rd input is stepspacing:
|
tnew = np.arange(start, stop, timespan / minimumt) # 3rd input is stepspacing:
|
||||||
# in case complete measuring time devided by total number of datapoints
|
# in case complete measuring time devided by total number of datapoints
|
||||||
|
|
||||||
'frequencies'
|
|
||||||
# minimum datapoint lenght of both loops of frequencies
|
|
||||||
minimumf = min(len(f[0]), len(f[1]))
|
|
||||||
# new frequencies to minimum for both loops
|
|
||||||
f0 = f[0][:minimumf]
|
|
||||||
# interpolation
|
|
||||||
f0new = np.interp(tnew, t0, f0)
|
|
||||||
|
|
||||||
f1 = f[1] #[:minimumf]
|
|
||||||
# interpolation
|
# interpolation
|
||||||
f1new = np.interp(tnew, t1, f1)
|
f0 = np.interp(tnew, t[0], f[0])
|
||||||
|
f1 = np.interp(tnew, t[1], f[1])
|
||||||
|
|
||||||
#new array with frequencies of both loops as two lists put together
|
#new array with frequencies of both loops as two lists put together
|
||||||
frequency = np.array([f0new, f1new])
|
frequency = np.array([f0, f1])
|
||||||
|
|
||||||
#making a mean over both loops with the axis 0 (=averaged in y direction, axis=1 would be over x axis)
|
#making a mean over both loops with the axis 0 (=averaged in y direction, axis=1 would be over x axis)
|
||||||
mf = np.mean(frequency, axis=0) #.T as transition (1,0) -> (0,1)
|
mf = np.mean(frequency, axis=0)
|
||||||
|
|
||||||
#appending data
|
#appending data
|
||||||
eodf.append(e)
|
eodf.append(e)
|
||||||
deltaf.append(d)
|
deltaf.append(d)
|
||||||
stimulusf.append(s)
|
stimulusf.append(s)
|
||||||
amplitude.append(a)
|
amplitude.append(a)
|
||||||
|
|
||||||
frequency_mean.append(mf)
|
frequency_mean.append(mf)
|
||||||
time.append(tnew)
|
time.append(tnew)
|
||||||
|
|
||||||
for i in range(len(frequency_mean)):
|
for i in range(len(frequency_mean)):
|
||||||
for n in [10, 50, 100, 1000, 10000, 20000, 30000]:
|
for n in [10, 50, 100, 1000, 10000, 20000, 30000]:
|
||||||
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n)
|
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n)
|
||||||
plt.plot(ct, cf, label='n=%d' % 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)
|
||||||
|
|
||||||
|
|
||||||
|
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(time[0], frequency_mean[0])
|
||||||
|
plt.show()
|
||||||
|
embed()
|
||||||
|
|
||||||
|
|
||||||
'plotting'
|
'plotting'
|
||||||
plt.xlim([-10,200])
|
plt.xlim([-10,200])
|
||||||
#plt.ylim([400, 1000])
|
#plt.ylim([400, 1000])
|
||||||
plt.xlabel('time [s]')
|
plt.xlabel('time [s]')
|
||||||
plt.ylabel('frequency [Hz]')
|
#plt.ylabel('rel. JAR magnitude')
|
||||||
#plt.title('noise_cut_n=100')
|
#plt.title('fit_function(a1=0)')
|
||||||
#plt.savefig('noise_cut_n=100')
|
#plt.savefig('fit_function(a1=0)')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
def double_exp(t, a1, a2, tau1, tau2):
|
|
||||||
return a1*np.exp(-t/tau1)
|
# normiert darstellen (frequency / mean von baseline frequency?)?
|
||||||
# plotten mit manual values for a1, ...
|
# Zeitkonstante: von sec. 0 bis 63%? relative JAR
|
||||||
# auch mal a1 oder a2 auf Null setzen.
|
|
||||||
|
|
||||||
#evtl. normiert darstellen (frequency / baseline frequency?)?
|
|
||||||
#Zeitkonstante: von sec. 0 bis 63%? relative JAR
|
|
||||||
'''
|
|
||||||
'controll of interpolation'
|
|
||||||
fig=plt.figure()
|
|
||||||
ax=fig.add_subplot(1,1,1)
|
|
||||||
ax.plot(tnew, mf, c = 'r', marker = 'o', ls = 'solid', label = 'new')
|
|
||||||
ax.plot(t0, f0, c = 'b', marker = '+', ls = '-', label = 'loop_0')
|
|
||||||
ax.plot(t1, f1, c= 'g', marker = '+', ls = '-', label = 'loop_1')
|
|
||||||
plt.legend(loc = 'best')
|
|
||||||
#plt.plot(tnew, mf, marker = 'r-o', label = new, t0, f0, marker = 'b-+', label = loop_0, t1, f1, marker = 'g-+', label = loop_1)
|
|
||||||
plt.show()
|
|
||||||
'''
|
|
||||||
|
Loading…
Reference in New Issue
Block a user