How to Match 2 Signals which Are a Shifted and Scaled Version of Each Other I have 2 signals S1 and S2 that contain the same information, but S2 is shifted and scaled compared to S1 by an unknown amount (but small; eg shift would be of the order of 1-10 samples).

What is the best (=most effective yet simple) way to calculate (or estimate) the shift and scaling factor to apply to S2 in order to 'match' with S1.

I have read a few papers referring to using the phase information in FFT, but those were working on signals where scaling was not really an issue (and i must admit not to have understood them completely anyway). I am a bit lost on how to put this in practice when developing that in Matlab (actually I use Octave).

I would love to have an explanation using Matlab/Octave code if possible.

Thanks for any help.

Steve

PS: I add the tag 'image processing' because I suspect that such techniques would be used in automatic stitching of images (in panoramas for example)
Matlab has a function called xcorr() that computes the cross correlation between two vectors.  The cross correlation will be highest when the two signals overlap.  The following code will compute the shift in units of samples:

x = xcorr(s1,s2)
[val,idx] = max(x);
shift = length(s1) - idx

The scaling factor should be given by:

scale = max(s1)/max(s2)