fft-test.py
from __future__ import division import numpy as np import matplotlib.pyplot as plt sample_freq=44100 sig_freq=int(raw_input("Frequenz des Eingabesignals")) t = np.linspace(0,2*np.pi*sig_freq,sample_freq) print t signal = np.sin(t) + 0.5*np.sin((3/2)*t) #+ 0.75* np.sin(3*t) sp = np.fft.fft(signal)/(0.5*sample_freq) freq = np.fft.fftfreq(t.shape[-1]) #plt.plot(freq, sp.real, freq, sp.imag) plt.plot(signal) plt.plot(abs(sp)) #[<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>] plt.show()
– Erzeugt ein Signal aus 44100 Samples mit der eingegebenen Frequenz und einem Oberton bei 1,5x der Frequenz (≙ Quinte)
Ausgabe
1.
Frequenz des Eingabesignals
2. nach eingabe von 440
[ 0.00000000e+00 6.26907988e-02 1.25381598e-01 ..., 2.76447615e+03 2.76453884e+03 2.76460154e+03]