开发者

Samples by samples cross-correlation(Xcorr) matlab

I am using the xcorr function for identifying the similarity of the signals. the following is the code,

r1 = max(abs(xcorr(S1, shat1,'coeff')));
r2 = max(abs(xcorr(S1,shat2,'coeff')));
if r1>r2
dn=shat2; 
else
dn=shat1; 
end

It worked perfectly. But the problem is the signals are having 40,000 samples each. Practically I do get a lot of delay. I have to send bunch of samples (like 250samples)into the xcorr for getting rid of the delay. But how do I do that? I know that I have to use a for loop, but found d开发者_运维百科ifficult in doing that. Can some one suggest me how do I do that.I tried something like this

for i=1:250:40000
r1 = max(abs(xcorr(S1(:,i), shat1(:,i),'coeff')));

but totally lost. Someone suggest something please....


If I understand you correctly, you want to cross-correlate block of 250 samples, one after the other. Adapting from your attempt, try

for i=1:250:40000
 r1 = max(abs(xcorr(S1(i:i+249), shat1(i:i+249),'coeff')));
end

As a side note, do you know anything about the maximum lag between your signals? If you can safely assume that the temporal shift between your signals is below 250 (which the idea of splitting it into intervals suggests), you could save calculation time by modifying your original code with using maxlags, a parameter for xcorr:

maxlags=250; %# or some other reasonable value, maybe even 100? 50?
r1 = max(abs(xcorr(S1, shat1,maxlags, 'coeff')));
r2 = max(abs(xcorr(S1, shat2,maxlags, 'coeff')));
...

I haven't tested how fast that would be, but my guess is you might be able to avoid your loop altogether with this...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜