Reputation: 69
i'm using pyplot to show the FFT of the signal 'a', here the code:
myFFT = numpy.fft.fft(a)
x = numpy.arange(len(a))
fig2 = plt.figure(2)
plt.plot(numpy.fft.fftfreq(x.shape[-1]), myFFT)
fig2.show()
There is a line from the begin to the end of the signal in the frequency domain. How i can remove this line? AM I doing something wrong with pyplot?
Upvotes: 2
Views: 1692
Reputation: 190
Instead of sorted
, you might want to use np.fft.fftshift
to center you 0th frequency, this deals properly with odd- and even-size signals. Most importantly, you need to apply the transform on both x and y vectors you are plotting.
plt.plot(np.fft.fftshift(np.fft.fftfreq(x.shape[-1])), np.fft.fftshift(myFFT))
You might also want to display the amplitude or phase of the FFT (np.abs
or np.angle
) - as-is, you are just plotting the real-part.
Upvotes: 3
Reputation: 13218
Have a look at plt.plot(numpy.fft.fftfreq(x.shape[-1])
: the first and last points are the same, hence the graph "makes a loop"
You can do plt.plot(sorted(numpy.fft.fftfreq(x.shape[-1])),myFFT)
or plt.plot(myFFT)
Upvotes: 0