# fft of a 2 simple cos functions

5 views (last 30 days)
deltanabla on 8 Jan 2015
Answered: Rick Rosson on 9 Jan 2015
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

Rick Rosson on 9 Jan 2015
Replace the following line:
f=(0:nfft/2-1)*Fs/nfft/2;
with:
f=(0:nfft/2-1)*Fs/nfft;

### Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!