MATLAB: Fft of a 2 simple cos functions

fft

Hi Folks,
I need to modify the code so that I am reporting the correct frequencies calculated from the fft
Fs=9827.2*2;
t=0:1/Fs:0.06756;
f=14.8;
f_1=1228.4;
x=cos(2*pi*t*f)+cos(2*pi*t*f_1);
nfft=664;
X=fft(x,nfft);
X = X(1:nfft/2);
mx=abs(X);
f=(0:nfft/2-1)*Fs/nfft/2;
figure(1);
plot(t,x);
title('Cosine wave Signal');
ylabel('Amplitude');
figure(2);
plot(f,mx);
title('Power Spectrum of a sine wave');
xlabel('Frequency(hz)');
ylabel('Power')
I expect to see the 2 fundamental frequencies 14.8Hz and 1228.4Hz (83*14.8) in the frequency window, however, it reports 14.8Hz and 621.9Hz( 14.8*42)instead.
Thanks

Best Answer

Replace the following line:
f=(0:nfft/2-1)*Fs/nfft/2;
with:
f=(0:nfft/2-1)*Fs/nfft;
Related Question