30.06
This commit is contained in:
parent
77534d6e4a
commit
d4ed1e0040
@ -33,7 +33,6 @@ def parse_dataset(dataset_name):
|
|||||||
stimulusfs.append(float(l.split(':')[-1].strip()[:-2]))
|
stimulusfs.append(float(l.split(':')[-1].strip()[:-2]))
|
||||||
|
|
||||||
if '#Key' in l:
|
if '#Key' in l:
|
||||||
#print('KEY')
|
|
||||||
if len(time) != 0: #therefore empty in the first round
|
if len(time) != 0: #therefore empty in the first round
|
||||||
times.append(time) #2nd loop means time != 0, so we put the times/amplitudes/frequencies to
|
times.append(time) #2nd loop means time != 0, so we put the times/amplitudes/frequencies to
|
||||||
amplitudes.append(ampl) #the data of the first loop
|
amplitudes.append(ampl) #the data of the first loop
|
||||||
@ -42,7 +41,6 @@ def parse_dataset(dataset_name):
|
|||||||
time = [] #temporary lists to overwrite the lists with the same name we made before
|
time = [] #temporary lists to overwrite the lists with the same name we made before
|
||||||
ampl = [] #so they are empty again
|
ampl = [] #so they are empty again
|
||||||
freq = []
|
freq = []
|
||||||
print(len(times))
|
|
||||||
|
|
||||||
if len(l) > 0 and l[0] is not '#': #line not empty and doesnt start with #
|
if len(l) > 0 and l[0] is not '#': #line not empty and doesnt start with #
|
||||||
temporary = list(map(float, l.split())) #temporary list where we got 3 index splitted by spacebar, map to find them
|
temporary = list(map(float, l.split())) #temporary list where we got 3 index splitted by spacebar, map to find them
|
||||||
@ -58,7 +56,7 @@ def parse_dataset(dataset_name):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def noise_reduce(dataset_name, n):
|
'''
|
||||||
assert (os.path.exists(dataset_name)) # see if data exists
|
assert (os.path.exists(dataset_name)) # see if data exists
|
||||||
f = open(dataset_name, 'r') # open data we gave in
|
f = open(dataset_name, 'r') # open data we gave in
|
||||||
lines = f.readlines() # read data
|
lines = f.readlines() # read data
|
||||||
@ -74,10 +72,15 @@ def noise_reduce(dataset_name, n):
|
|||||||
if len(l) > 0 and l[0] is not '#':
|
if len(l) > 0 and l[0] is not '#':
|
||||||
temporary = list(map(float, l.split()))
|
temporary = list(map(float, l.split()))
|
||||||
frequencies.append(temporary[1])
|
frequencies.append(temporary[1])
|
||||||
|
'''
|
||||||
|
|
||||||
for k in np.arange(0, len(frequencies), n): # sollte nach k+n weitergehen?
|
def mean_noise_cut(frequencies, time, n):
|
||||||
|
cutf = []
|
||||||
|
cutt = []
|
||||||
|
for k in np.arange(0, len(time), n):
|
||||||
f = frequencies[k:k+n]
|
f = frequencies[k:k+n]
|
||||||
|
t = time[k]
|
||||||
mean = np.mean(f)
|
mean = np.mean(f)
|
||||||
cutf.append(mean)
|
cutf.append(mean)
|
||||||
|
cutt.append(t)
|
||||||
return cutf
|
return cutf, cutt
|
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
from jar_functions import noise_reduce
|
from jar_functions import mean_noise_cut
|
||||||
|
|
||||||
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'))]
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import IPython
|
|||||||
import numpy as np
|
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 noise_reduce
|
from jar_functions import mean_noise_cut
|
||||||
|
|
||||||
|
|
||||||
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'))]
|
||||||
@ -26,7 +26,6 @@ timespan = 210
|
|||||||
for dataset in datasets:
|
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)
|
||||||
cf = noise_reduce(dataset, n = 10)
|
|
||||||
|
|
||||||
'times'
|
'times'
|
||||||
# same for time in both loops
|
# same for time in both loops
|
||||||
@ -46,20 +45,15 @@ for dataset in datasets:
|
|||||||
# interpolation
|
# interpolation
|
||||||
f0new = np.interp(tnew, t0, f0)
|
f0new = np.interp(tnew, t0, f0)
|
||||||
|
|
||||||
f1 = f[1][:minimumf]
|
f1 = f[1] #[:minimumf]
|
||||||
# interpolation
|
# interpolation
|
||||||
f1new = np.interp(tnew, t1, f1)
|
f1new = np.interp(tnew, t1, f1)
|
||||||
|
|
||||||
#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([f0new, f1new])
|
||||||
#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 #.T as transition (1,0) -> (0,1)
|
|
||||||
|
|
||||||
#other variant for transition by reshaping in needed dimension
|
|
||||||
mfreshape = np.reshape(mf, (minimumf, 1)) #as ploting is using the first dimension, number of datapoints has to be in the first
|
|
||||||
treshape = np.reshape(tnew, (minimumf, 1))
|
|
||||||
|
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
#appending data
|
#appending data
|
||||||
eodf.append(e)
|
eodf.append(e)
|
||||||
@ -70,31 +64,39 @@ for dataset in datasets:
|
|||||||
frequency_mean.append(mf)
|
frequency_mean.append(mf)
|
||||||
time.append(tnew)
|
time.append(tnew)
|
||||||
|
|
||||||
|
for i in range(len(frequency_mean)):
|
||||||
|
for n in [10, 50, 100, 1000, 10000, 20000, 30000]:
|
||||||
|
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n)
|
||||||
|
plt.plot(ct, cf, label='n=%d' % n)
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
'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()
|
|
||||||
'''
|
|
||||||
|
|
||||||
'plotting'
|
'plotting'
|
||||||
'''why does append put in a 3rd dimension? plt.plot(time, frequency_mean) '''
|
|
||||||
|
|
||||||
plt.plot(tnew, mf)
|
|
||||||
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('frequency [Hz]')
|
||||||
|
#plt.title('noise_cut_n=100')
|
||||||
|
#plt.savefig('noise_cut_n=100')
|
||||||
|
plt.legend()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def double_exp(t, a1, a2, tau1, tau2):
|
||||||
|
return a1*np.exp(-t/tau1)
|
||||||
|
# plotten mit manual values for a1, ...
|
||||||
|
# auch mal a1 oder a2 auf Null setzen.
|
||||||
|
|
||||||
#evtl. normiert darstellen (frequency / baseline frequency?)?
|
#evtl. normiert darstellen (frequency / baseline frequency?)?
|
||||||
#Zeitkonstante: von sec. 0 bis 63%? relative JAR
|
#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