MATLAB: Sampling rate and fft

fft

Do I need to specify the sampling rate when using FFT? I am wanting to look at frequency response of a signal, and am getting crazy frequency response, way above sampling rate. Sorry for a very basic question, trying to get up to speed.

Best Answer

No, you don't need to specify the sampling rate, but if you wish to create a meaning frequency vector, then you need to know the sampling rate.
For example:
Fs = 1000; % sampling rate of 1000 Hz
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
DF = Fs/length(x); % frequency increment
freqvec = 0:DF:Fs/2;
plot(freqvec,abs(xdft))
so the output of fft() is agnostic about frequency, but if you want to interpret that output in physical frequencies, then you need to know the sampling rate.
Related Question