changes to sampling frequency result in wrong answer

4 次查看(过去 30 天)
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