title: Matlab: xcorr 1d cross-correlation normalisation issue
body: <p>I have a reference signal (s1) of length = 5 and another signal (s2) of length = 25 samples (containing a shifted version of the same 5 sample signal s1).</p>
  
  <p>I want to find the normalised cross correlation between the two signals to calculate the sample distance (delay / lag) between signals s1 and s2.</p>
  
  <p>I pad s1 with zeros (so it is the same length as s2 as required for xcorr 'coeff' option):</p>
  
  <pre><code>s1(numel(s2)) = 0;
  </code></pre>
  
  <p>and then do:</p>
  
  <pre><code>[R lags]=xcorr(s2,s1,'coeff');
  
  [vm im]=max(R); %max. correlation and index
  s1_lag=lags(im);
  </code></pre>
  
  <p>to find the normalised cross-correlation for lags of -24 to 24 samples.</p>
  
  <p>Since s2 contains a shifted version of s1 I would expect to obtain a maximum correlation value of 1 but maximum correlation is 0.4776 at a lag of 19 samples. I don't understand this? </p>
  
  <p>If I let s1 = s2 and repeat xcorr (now s1 and s2 are identical) I get a maximum correlation value of 1.0 at 0 sample lag as expected.</p>