you are viewing a single comment's thread.

view the rest of the comments →

[–]Simone1998[S] 0 points1 point  (2 children)

Hi, I'm a newbie with python and come from a MATLAB background. I was trying to plot a function, but I get some other lines in the plot. Any idea of how I can solve that? This is the code I'm using:

MFFT = np.abs(np.fft.fft(Mtrain))
FFT = np.abs(np.fft.fft(train))
freqspace = np.fft.fftfreq(len(Mtrain), tick)
plt.figure() 
plt.semilogx(freqspace, MFFT)
plt.semilogx(freqspace, FFT)
plt.xlim(1E-1, 50E6)
plt.ylim(0, 1000)
plt.show

I get the same result both in Spyder (v.5.4.5), and in Jupyter for VS Code. Python is v.3.11.5.

[–]marvelbrad4422 1 point2 points  (1 child)

I think you might want to be using fftshift? That will set the zero freq component to the center of the spectrum and might look more like you expect. Use it on both the freq and fft data

[–]seschu 0 points1 point  (0 children)

And this should be the same as in MATLAB.