Got an extra line on python plot
<p>i'm using pyplot to show the FFT of the signal 'a', here the code:</p>

<pre><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()
</code></pre>

<p>and i get this figure
<a href="http://i.stack.imgur.com/21CFm.png" rel="nofollow"><img src="http://i.stack.imgur.com/21CFm.png" alt="enter image description here"></a></p>

<p>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?</p>

<p>Instead of <code>sorted</code>, you might want to use <code>np.fft.fftshift</code> 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.</p>

<pre><code>plt.plot(np.fft.fftshift(np.fft.fftfreq(x.shape[-1])), np.fft.fftshift(myFFT))
</code></pre>

<p>You might also want to display the amplitude or phase of the FFT (<code>np.abs</code> or <code>np.angle</code>) - as-is, you are just plotting the real-part.</p>

python numpy matplotlib fft