Plotting Fourier Transform Of A Sinusoid In Python
The following python program plots a sinusoid: import matplotlib.pyplot as plt import numpy as np # Canvas plt.style.use('ggplot') # Frequency, Oscillations & Range f = int(i
Solution 1:
By correctly applying FFT on your signal you should be just fine:
# FFT# number of samples
N = len(t)
# time step
dt = t[1]-t[0]
# max number of harmonic to display
H_max = 5
xf = np.linspace(0.0, 1.0/(2.0*dt), N//2)
yf = np.fft.fft(y_sin)
axs[1].plot(xf, (2/N)*np.abs(yf[:N//2]))
axs[1].set_xlim([0, H_max*f])
axs[1].set_xlabel('f (Hz)')
axs[1].set_ylabel('$||H_i||_2$')
which gives for inputs f=100
and n_o=3
:
Hope this helps.
Post a Comment for "Plotting Fourier Transform Of A Sinusoid In Python"