From 8b97b8f3044483003d3a07d400fc7ab338054b42 Mon Sep 17 00:00:00 2001 From: xaver Date: Wed, 24 Jun 2020 17:18:33 +0200 Subject: [PATCH] 4.backup --- jar_functions.py | 24 ++++++++++++++++++++++++ second_try.py | 36 ++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 jar_functions.py 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()