changes to sampling frequency result in wrong answer

조회 수: 4 (최근 30일)
modified covariance
modified covariance 2012년 10월 24일
given the following code to determine frequency, Ts=0.001,hence fs=1000
t = 0:0.001:0.1-0.001;
x = 10*cos(267*pi*t+1.2);
N=max(size(x));
t1=0;
t2=0;
for n=3:N
t1=t1+x(n-1)*(x(n)+x(n-2));
t2=t2+2*(x(n-1))^2;
end
r = t1/t2;
if (r>1)
r=1;
end
if (r<-1)
r=-1;
end
w=acos(r)
now i want to replace x = 10*cos(267*pi*t+1.2) by the third column imported from a text file.
Fs becomes 1, the code is now changed into
ssn = spot_num(:,3);
ssn = ssn-mean(ssn);
x=ssn;
N=max(size(x));
t1=0;
t2=0;
for n=3:N
t1=t1+x(n-1)*(x(n)+x(n-2));
t2=t2+2*(x(n-1))^2;
end
r = t1/t2;
if (r>1)
r=1;
end
if (r<-1)
r=-1;
end
w=acos(r)
the output is not what i expected, i guess the problem lies in the unit needed to be further changed, but have no idea of doing so.
  댓글 수: 1
modified covariance
modified covariance 2012년 10월 24일
편집: modified covariance 2012년 10월 25일
same problem lies here where fs=1000
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);
now i want to replace x = 10*cos(267*pi*t+1.2) by the third column imported from a text file as shown above.
Fs now Fs becomes 1.the code now is changed into
ssn = spot_num(:,3);
ssn = ssn-mean(ssn);
x=ssn;
N=max(size(x));
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);
once again the output is not consistent to model answer. so what happens then?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by