📄 normcorr.m
字号:
function [cc,index]=normcorr(a,b)
% Function computes maximum normalized correlation coefficients
% INPUT
% a matrix
% b vector sliding by a (length of b does not exceed number of rows in a)
% OUTPUT
% cc maximum correlation coefficients
% index shift at which this maximum is attained
[la,ba]=size(a);
lb=length(b);
if ba == 1 & la == lb % a and b are vectors with the same number of elements
cc=b(:)'*a/((norm(b)+eps)*(norm(a)+eps));
index=0;
return
else
aa=[zeros(1,size(a,2));cumsum(a.*a)];
bb=b(:)/(norm(b)+eps);
cc=zeros(la-lb+1,ba);
for ii=1:la-lb+1
cc(ii,:)=bb'*a(ii:ii+lb-1,:)./(sqrt(aa(ii+lb,:)-aa(ii,:))+eps);
end
if size(cc,1) > 1
[cc,index]=max(cc);
index=index-1;
else
index(1:ba)=0;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -