Why would I get two consecutive values the same when executing the loop below?

1 view (last 30 days)
I am trying to calculate the sample cross correlation function in matlab using this code:
fs=4000;
Ts=1/fs;
tb=.055;
te=.115;
Ta=.060;
T=.050;
A=10.0;
fc=1000;
theta=0;
idx3=1;
R=0;
for TAUk=(kb*Ts):Ts:(ke*Ts)
for ti=(ib*Ts):Ts:((TAUk/Ts+N2-1)*Ts)
if (ti-TAUk)>=0 && (ti-TAUk)<=T && ((ti-TAUk)/Ts)>0 && ((ti-TAUk)/Ts)<(N2-1)
g2b=A*cos(2*pi*fc*(ti-TAUk)+theta);
else
g2b=0;
end
if Ta<=ti && ti<=(T+Ta) && (ti/Ts)<ie
g1b=A*cos(2*pi*fc*(ti-Ta)+theta);
else
g1b=0;
end
R=R+g1b*g2b;
end
Rxyb(idx3)=2*(1/N2)*R;
idx3=idx3+1;
end
My problem is that the data I get back should by symmetric about its max value and it is off by like a tenth. Also, I get back the same value for two consecutive indicies of Rxyb which I also don't think should be the case. If anyone has any pointers I could really use some help. I have been staring at this for several days now and can't figure it out.
Terrell

Answers (0)

Community Treasure Hunt

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

Start Hunting!