to determine the peak frequency in from the plot of the Fourier transform
4 views (last 30 days)
Show older comments
a continuous-time sinusoid x(t)=10cos(267*pi*t+1.2) is sampled to x[n]=10cos(0.267*pi*n+1.2) with period Ts=0.001 and n is between 0 and 100 (including 0 and 100)
i attempted to determine the peak frequency using the following code.
A=10;
Fs=1000;
w=267*pi*(1/Fs);
p=1.2;
n=0:100;
x = A*cos(w*n+p);
N=500
[freq_response,freq_index] = freqz(x,1,N,Fs); %N is the number of samples
plot(freq_index,abs(freq_response))
abs(freq_response)
the magnitude plot of the Fourier transform for x versus frequency in Hz is seen, and the peak frequency observing the plot is near to 500. but it reuturns in the command window to be a series of numbers, so what's wrong with that?
0 Comments
Accepted Answer
Pedro Villena
on 24 Oct 2012
Edited: Pedro Villena
on 24 Oct 2012
n=0:100; %N=100
N=length(n);
Ts=0.001; %period [s]
Fs=1/Ts; %frequency [Hz]
t=(0:Ts:Ts*n(end));
A=10;
w=0.267*pi*Fs; %oscilation frequency [rad/s]
p=1.2; %phase [rad]
x=A*cos(w*t+p);
[freq_response,freq_index] = freqz(x,1,N,Fs); %N is the number of samples
pM = max(abs(freq_response)); %magnitude
pF = freq_index(abs(freq_response)==pM); %frequency
plot(freq_index,10*log10(abs(freq_response)),'b',pF,10*log10(pM),'r*')
title(sprintf('Peak Frequency = %f Hz (%.1f dB)',pF,10*log10(pM)));
xlabel('Frequency [Hz]')
ylabel('Power [dB]')
2 Comments
More Answers (0)
See Also
Categories
Find more on Spectral Estimation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!