please help correct fft command used to compute equation

조회 수: 1 (최근 30일)
modified covariance
modified covariance 2012년 10월 23일
given a discrete-time sinusoid x[n]=10cos(200*pi*t+1.2) where n is between 0 and 100 (including 0 and 100)
With the use of the fft command, i attempted to develop the MATLAB function to compute the follwing equation. Also use the command max in the peak search to determine the peak freqency.
t = 0:0.001:0.1-0.001;
x = 10*cos(200*pi*t+1.2);
function X = dtft(x, 200*pi)
[L1, L] = size(x);
z = exp(-j*w); X = 0;
for n = L-1:-1:0,
X = x(n+1) + z .* X;
end
Y=(X^2)/N
p = max(X)
no outputs return at all. please help correct. thank u!

채택된 답변

Wayne King
Wayne King 2012년 10월 23일
편집: Wayne King 2012년 10월 23일
"With the use of the fft command..."
where have you used the fft() command?
Fs = 1000;
t = 0:0.001:0.1-0.001;
x = 10*cos(2*pi*100*t+1.2);
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
freq = 0:Fs/length(x):Fs/2;
[maxval,idx] = max(abs(xdft));
freq(idx)
As you see freq(idx) produces the frequency corresponding to the maximum absolute value in the DFT of x.

추가 답변 (1개)

Matt J
Matt J 2012년 10월 23일
편집: Matt J 2012년 10월 23일
Stop reposting your question in the hopes that somebody will do your homework for you. Thankfully, Wayne's code isn't the complete solution.
Your code doesn't fail to return outputs. It completely fails to run, because it contains absurd syntax errors, like
function X = dtft(x, 200*pi)
When defining a function, it makes no sense to use expressions like 200*pi in the argument list.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by