jar_project/sin_response_fit.py
2020-08-05 17:16:49 +02:00

28 lines
764 B
Python

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
from IPython import embed
from scipy.optimize import curve_fit
from jar_functions import sin_response
data = np.load('files.npy')
for d in data:
dd = list(d)
jar = np.load('%s.npy' %dd)
time = np.load('time: %s.npy' %dd)
b, a = signal.butter(4, (float(d[1]) / 2) / 10000, 'high', analog=True)
y = signal.filtfilt(b, a, jar - np.mean(jar))
plt.plot(time, y)
#plt.plot(time, jar)
sinv, sinc = curve_fit(sin_response, time, y, [float(d[1]), 2, 0.5])
print('frequency, phaseshift, amplitude:', sinv)
plt.plot(time, sin_response(time, *sinv), label='fit: f=%f, p=%.2f, A=%.2f' % tuple(sinv))
# plt.legend()
plt.show()
embed()
#betrag von A