changes to sampling frequency result in wrong answer

1 vue (au cours des 30 derniers jours)
modified covariance
modified covariance le 24 Oct 2012
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 commentaire
modified covariance
modified covariance le 24 Oct 2012
Modifié(e) : modified covariance le 25 Oct 2012
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?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by