I did a step function FFT on matlab but only getti

2019-08-23 07:20发布

问题:

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])



标签: matlab fft