I am very surprised not to find a version of normxcorr2 for 1D signals in Matlab ! I implemented something like that by hand (with 2 for loops, and normalizing the template as well as the window under the template (in the 1D signal in which the template is searched).

Did I just not find it or does it not exist? (A normalized cross correlation (NCC) for 1D signals, i.e., like normxcorr2 but for vectors)

(cf. https://ch.mathworks.com/help/images/ref/normxcorr2.html for the 2D version )


template=[1 2 3]

signal=[0 1 4 8 9 3 7 7 1 2 3 0 5 5 0]

the NCC should find the max at a lag of 9 (because you can see that the pattern [1 2 3] starts at pos 9). I consider here sliding the template starting at the template positioned over the window [0 1 4] of the signal and finishes at [5 5 0] , like that I obtain an output signal of length:


P.S. and it seems clearly that corr or xcorr does not do the same thing even with the 'normalization' argument because what I am looking for is something that normalized the kernel and the window in the signal at each step, which is quite cumbersome but needed for the NCC as mentioned in : http://www.cse.psu.edu/~rtc12/CSE486/lecture07.pdf for example)

  • $\begingroup$ Is the option coeff to function xcorr() doing what you want? or what about the function corrcoef() ? $\endgroup$ – Fat32 Nov 29 '19 at 0:47
  • $\begingroup$ @Fat32 thanks for your answer! No these functions are not the ones I m looking for since i m really looking for the cross-correlation between a template (by definition a smaller signal) with a longer signal $\endgroup$ – Machupicchu Nov 29 '19 at 9:44
  • $\begingroup$ corrcoef and xcorr with 'coef' or 'normalization' require to have both signal of same size $\endgroup$ – Machupicchu Nov 29 '19 at 9:45
  • $\begingroup$ what do you think? It seems strange not to have the equivalent of normxcorr2 for 1D signals ?! $\endgroup$ – Machupicchu Nov 29 '19 at 9:45
  • $\begingroup$ I updated my question to be more precise; it is a 1D template matching problem by Normalized Cross-Correlation (NCC). $\endgroup$ – Machupicchu Nov 29 '19 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.