changes to sampling frequency result in wrong answer
Show older comments
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 Comment
modified covariance
on 24 Oct 2012
Edited: modified covariance
on 25 Oct 2012
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!