问题
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