I did a step function FFT on matlab but only getting one side of the spectrum (0 to infinity)

女生的网名这么多〃 提交于 2019-12-11 20:11:37

问题


with this code i am only getting half og the fft spectrum from 0 to positive infinity . i am trying to mirror this along the y axis to get the other half which is symmetric to this one from 0 to negative infinity.

    Fs = 1000;   %sampling rate
    Ts = 1/Fs; %sampling time interval
    t = -10:Ts:10-Ts; %sampling period
    n = length(t); %number of samples
    y = heaviside(t)-heaviside(t-4); %the step curve

    matlabFFT = figure;  %create a new figure
    YfreqDomain = fft(y); %take the fft of our step funcion, y(t)
    y=abs(YfreqDomain);
    plot(y)
    xlabel('Sample Number')
    ylabel('Amplitude')
    title('Using the Matlab fft command')
    grid
    axis([-100,100,0,5000])

回答1:


That's normal behaviour. The FFT returns the spectrum in positive frequencies only (between 0 and Fs). You can use fftshift to correct that. The zero frequency will then be at the center of the x axis. So you should use

plot(fftshift(y))
axis([-100+1e4,100+1e4,0,5000])



来源:https://stackoverflow.com/questions/19717779/i-did-a-step-function-fft-on-matlab-but-only-getting-one-side-of-the-spectrum-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!