use matlab to represent equations

2 ビュー (過去 30 日間)
modified covariance
modified covariance 2012 年 10 月 23 日
i am now trying to use use matlab to represent equations
come up with:
t1=0;
t2=0;
for n=1:N-2
r1=(1/(N-1))*x(n)*x(n+1);
r2=(1/(N-2))*x(n)*x(n+2);
t1=t1+r2+((r2)^2+8*(r1)^2)^(1/2);
end
for n=1:N-1
r1=(1/(N-1))*x(n)*x(n+1);
t2=t2+4*r1;
end
r = t1/t2;
if (r>1)
r=1;
end
if (r<-1)
r=-1;
end
w=acos(r);
it does not seem to work, could anyone help to correct? thank you!
  2 件のコメント
modified covariance
modified covariance 2012 年 10 月 23 日
N=max(size(x));
Jan
Jan 2012 年 10 月 23 日
"It does not seem to work" is not a helpful description of the occurring problems. Please be so kind and explain the difference between the results and your expectations.

サインインしてコメントする。

採用された回答

Pedro Villena
Pedro Villena 2012 年 10 月 23 日
fs = 1000; % samplig frequency [Hz]
t = 0:1/fs:0.1-1/fs; % time vector
w = 267*pi; % oscilation frequency [rad/s] (133.5 Hz)
p = 1.2; % phase [rad] (68.7549 deg)
x = 10*cos(w*t+p); % wave vector
N=length(x); % N:number of values
r=zeros(1,3); % r={r0,r1,r2}
for k=0:2, % k=0,1,2
n=(0:N-1-k);
r(k+1) = sum(x(n+1).*x(n+1+k))/(N-k);
end
w0 = fs*acos((r(3)+sqrt(r(3)^2+8*r(2)^2))/(4*r(2))); % [rad/s]
fprintf('w0 = %f rad/s = %f Hz\n',w0,w0/2/pi);
  1 件のコメント
modified covariance
modified covariance 2012 年 10 月 23 日
i have to express my sincere gratitude to you. it works!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by