Normalized cross-correlation function
이전 댓글 표시
Hello, i am trying to write a normilized cross-correlation method function , but i can't complete it. Here are the details of the formula :

My code is
x=rand(1,1000);
N=length(x); %// length of signal
n1=128; %// length of window
xf=framing(x,n1,n1/2,rectwin(n1)); %this function frames the signal i will get xf(128,14)
win_num=size(xf,2);
for col=1:win_num
for m=1:n1+1
for n=1:n1-m
ccor(m,col)=sum(xf(n+m,col)*(xf(n,col)))/ sqrt(sum(xf(n)^2)*sum(xf(n+m)^2) );
end
end
end
Note that i want to see the correlation values betwen -1 and 1 like in the figure but instead i get

.
댓글 수: 1
devi sowjanya
2021년 3월 6일
Can you please provide the framing function code
채택된 답변
추가 답변 (2개)
Kirby Fears
2015년 9월 18일
편집: Kirby Fears
2015년 9월 18일
0 개 추천
Hi Manolis,
You are looping n and m by starting at 1, but in the formula you posted the sum starts at 0. You will need to correct your calculations to include the 0 terms in the summation. You should also consider pre-allocating "ccor" to save yourself some computational time.
You may have access to the xcorr function which calculates cross correlations. It has several options to control normalization.
Hope this helps.
댓글 수: 2
Manolis Michailidis
2015년 9월 18일
Kirby Fears
2015년 9월 21일
Indeed the loop variables are only used as indices, so you are correct. My mistake. I assumed the loop variables were also used as numeric values in the summand. I'm writing another answer below.
Image Analyst
2015년 9월 29일
0 개 추천
Do you have the Image Processing Toolbox? If so, why not just use the built-in function normxcorr2()?
댓글 수: 1
Manolis Michailidis
2015년 9월 29일
편집: Manolis Michailidis
2015년 9월 29일
카테고리
도움말 센터 및 File Exchange에서 Spectral Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!