diff --git a/jar_functions.py b/jar_functions.py new file mode 100644 index 0000000..a8edc79 --- /dev/null +++ b/jar_functions.py @@ -0,0 +1,24 @@ +import os + + +def parse_dataset(dataset_name): + assert(os.path.exists(dataset_name)) + f = open(dataset_name, 'r') + lines = f.readlines() + f.close() + + time = [] + frequency = [] + amplitude = [] + + for i in range(len(lines)): + l = lines[i].strip() + + if len(l) > 0 and l[0] is not '#': + temp = list(map(float, l.split())) + + time.append(temp[0]) + frequency.append(temp[1]) + amplitude.append(temp[2]) + + return time, frequency, amplitude \ No newline at end of file diff --git a/second_try.py b/second_try.py index a134737..0c33d39 100644 --- a/second_try.py +++ b/second_try.py @@ -2,35 +2,31 @@ import matplotlib.pyplot as plt import os import glob import IPython +import numpy as np from IPython import embed +from jar_functions import parse_dataset + + +dataset = os.path.join('D:\\', 'jar_project', 'JAR', '2020-06-22-ac', 'beats-eod.dat') + +t, f, a = parse_dataset(dataset) + +avg_frequency = np.mean(f) +print(avg_frequency) -def parse_dataset(dataset_name): - assert(os.path.exists(dataset_name)) - f = open(dataset_name, 'r') - lines = f.readlines() - f.close() - time = [] - frequency = [] - amplitude = [] - for i in range(len(lines)): - print(lines[i]) - l = lines[i].strip() - if len(l) > 0 and l[0] is not '#': - temp = list(map(float, l.split())) - time.append(temp[0]) - frequency.append(temp[1]) - amplitude.append(temp[2]) - return time, frequency, amplitude -dataset = os.path.join('D:\\', 'jar_project', 'JAR', '2020-06-22-ac', 'beats-eod.dat') -t, f, a = parse_dataset(dataset) plt.plot(t, f) -plt.show() \ No newline at end of file + +plt.xlabel('time [s]') +plt.ylabel('frequency [Hz]') +plt.xlim([-10,200]) +plt.title('second try because first try was sold out') +plt.show()