MATLAB: FFT and sin wave

digital signal processing

A small doubt in signal processing. When you take fft of a signal — k=fft(y,512); and plot it, we get 512 points. I want to represent the 'x' axis in Hz . How would you do that? For eg: if k=40 what is the the corresponding frequency in Hz for a 512 point FFT?

Best Answer

If the signal is real-valued:
t = 0:.001:1-0.001;
Fs = 1e3;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
freq = 0:Fs/length(x):Fs/2;
plot(freq,abs(xdft));
xlabel('Hz');