Bode Plot mittels gesampleter Daten

mit matplotlib, NumPy, pandas, SciPy, SymPy und weiteren mathematischen Programmbibliotheken.
Antworten
Squipy
User
Beiträge: 39
Registriert: Sonntag 30. Juni 2019, 16:42

Hallo Zusammen,

hat jemand Erfahrung wie man mit zwei gesampleten Datensätzen ein Bodediagramm erstellt? Es gibt zwar die Funktion signal.bode() aber ich verstehe leider überhaupt nicht wie das funktionieren soll... Mein Versuch war der Folgende, allerdings ohne erfolg...

Code: Alles auswählen

from scipy import signal

exc = np.random.random_sample(3000,)
resp = np.random.random_sample(3000,)


sys = signal.lti(exc, [1/(3000*pi),resp])
f = logspace(0,1500,3000)
w = 2*pi*f
w, mag, phase = signal.bode(sys,w)

plt.plot(w,mag)
Mein nächster Versuch war, fir frf funktion von pyFRF zu verwenden, was auch gut klappt. Hier habe ich allerdings das Problem dass ich die Antwort noch gerne "curve fitten" möchte.
Dafür muss ich eine Näherungsfunktion definieren... Googlen hat mir bisher nicht dabei geholfen, welche für ein bode plot sinnvoll ist...

Code: Alles auswählen

frf = FRF(sampling_freq=5000, exc=exc, resp=resp, exc_window='None', resp_type='d', resp_window='None')

x = frf.get_f_axis()
y = np.abs(frf.get_FRF())


def test(x, a, b,c): 
    return a * np.sin(b * x) + c
 
y_tofit = np.linspace(min(y),max(y),len(y))

init_vals = [1, 0, 1]  # for [amp, cen, wid]
param, param_cov = curve_fit(test, y, y_tofit)
ans = (param[1]*(np.sin(param[2]*y)))
plt.plot(x, y, 'o', color ='red', label ="data") 
plt.plot(x, ans, '--', color ='blue', label ="optimized data")
plt.title('FRF H1')
plt.legend()
Hat hier evtl. schon jemand Erfahrung damit gemacht?

Besten Dank!
.
Antworten