Eine schnelle Einfuehrung ohne viel Mathe.
Ich werde immer wieder gefragt, wie die FFT oder das Wasserfalldiagramm z.B. in diversen SDR Anwendungen zu interpretieren ist. Eventuell kann diese kleine Einfuehrung die Basis fuer ein zukuenftiges besseres Verstaendnis bilden.
Du findest hier keine mathematische Herleitung und auch keine mathematischen Grundlagen, wir verwenden keine Fachbegriffe. Aber wenn Du Dich dafuer interessierst, mache ich dazu auch gern einen Workshop :)
Legen wir los.
In [25]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
# diese Funktion macht die FFT, normiert die Amplituden und plottet alles
def do_fft(x):
fft_x = np.fft.fft(x)
n = len(fft_x)
freq = np.fft.fftfreq(n, 1/f_s)
half_n = int(np.ceil(n/2.0))
fft_x_half = (2.0 / n) * fft_x[:half_n]
freq_half = freq[:half_n]
plt.plot(freq_half, np.abs(fft_x_half))
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")
return fft_x
In [26]:
f_s = 50.0 # Samplefrequenz in Hz
time = np.arange(0.0, 3.0, 1/f_s) #Zeitachse
plt.stem(time[1:50],np.ones(50)[1:50]) #Sampelzeitpunkte plotten
Out[26]:
In [27]:
f = 1.0 # 1 Hz
x = 5 * np.sin(2 * np.pi * f * time) # Amplitude 5
plt.plot(time, x)
plt.xlabel("Time (sec)")
plt.ylabel("x")
Out[27]:
In [28]:
fft_x = do_fft(x)
In [29]:
x = x + 2 * np.sin(10 * 2 * np.pi * f * time)
plt.plot(time, x)
plt.xlabel("Time (sec)")
plt.ylabel("x")
Out[29]:
In [30]:
fft_x = do_fft(x)
In [31]:
print(fft_x[1:10])
In [32]:
print(abs(fft_x[1:40]))
In [33]:
plt.plot(abs(fft_x))
Out[33]:
In [34]:
i_x = np.fft.ifft(fft_x)
In [35]:
plt.plot(time,i_x.real) # nur Realteil plotten
plt.xlabel("Time (sec)")
plt.ylabel("x")
Out[35]:
In [36]:
fft_x[30] = 0
fft_x[-30] = 0
In [37]:
i_x = np.fft.ifft(fft_x)
plt.plot(time,i_x)
plt.xlabel("Time (sec)")
plt.ylabel("x")
Out[37]:
In [38]:
x = np.sin(2 * np.pi * f * time) # Sinus 1 Hz, Amplitude 1
x = x + (1/2) * np.sin(2 * 2 * np.pi * f * time) # Sinus 2 Hz, Amplitude 0.5
x = x + (1/3) * np.sin(3 * 2 * np.pi * f * time) # ...
x = x + (1/4) * np.sin(4 * 2 * np.pi * f * time)
x = x + (1/5) * np.sin(5 * 2 * np.pi * f * time)
x = x + (1/6) * np.sin(6 * 2 * np.pi * f * time)
x = x + (1/7) * np.sin(7 * 2 * np.pi * f * time)
x = x + (1/8) * np.sin(8 * 2 * np.pi * f * time)
x = x + (1/9) * np.sin(9 * 2 * np.pi * f * time)
x = x + (1/10) * np.sin(10 * 2 * np.pi * f * time)
plt.plot(time,x)
plt.xlabel("Time (sec)")
plt.ylabel("x")
Out[38]:
In [39]:
tmp = do_fft(x)
In [40]:
x[1:25] = 0.75
x[26:50] = -0.75
x[51:75] = 0.75
x[76:100] = -0.75
x[101:125] = 0.75
x[126:150] = -0.75
x[151:175] = 0.75
x[176:200] = -0.75
x[201:225] = 0.75
x[226:250] = -0.75
x[251:275] = 0.75
x[276:300] = -0.75
plt.plot(time,x)
plt.xlabel("Time (sec)")
plt.ylabel("x")
plt.ylim(-1.2,1.2)
Out[40]:
In [41]:
tmp = do_fft(x)
In [42]:
x = np.sin(1 * 2 * np.pi * f * time) # Sinus 1 Hz, Amplitude 1
x = x + (1/3) * np.sin(3 * 2 * np.pi * f * time) # Sinus 3 Hz, Amplitude 0.333
x = x + (1/5) * np.sin(5 * 2 * np.pi * f * time) # ...
x = x + (1/7) * np.sin(7 * 2 * np.pi * f * time)
x = x + (1/9) * np.sin(9 * 2 * np.pi * f * time)
x = x + (1/11) * np.sin(11 * 2 * np.pi * f * time)
x = x + (1/13) * np.sin(13 * 2 * np.pi * f * time)
x = x + (1/15) * np.sin(15 * 2 * np.pi * f * time)
plt.plot(time,x)
plt.xlabel("Time (sec)")
plt.ylabel("x")
Out[42]:
In [ ]: