Reputation: 29
I want to find fft of cos(2pi10*n). I wrote this code but it has two problems. First, the estimated frequency is not 10 Hz. Second, from theory I expected that the amplitude of frequency should be pi. I found that the amplitude is dependent to size of fft. I appreciate any help.
n = 0:1:9;
x = cos(2*pi*10*n);
xdft = fft(x);
w=0:2*pi/(10):2*pi-2*pi/(10);
plot(abs(xdft) )
Upvotes: 2
Views: 39
Reputation: 949
You must have overlooked the fact that, since the frequency of your signal is 10 Hz, you must sample it at no less than 20 Hz, lest it appear aliased during spectral analysis:
for i=1:4
if i==1
fs=1; %this is the value originally considered in OP's code
elseif i==2
fs=8;
elseif i==3
fs=20;
else
fs=40;
end
n=0:(1/fs):9;
x=cos(2*pi*10*n);
xdft=fft(x);
f=(0:(numel(x)-1))/numel(x)*fs;
subplot(4,1,i);
stem(f,abs(xdft),'.-');
xlabel('Frequency [Hz]');
end
Upvotes: 3