Monday, April 23, 2018

image processing - 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)



Answer



In case you specifically want to find a shift and scale you can use the cross correlation function of Matlab. Some additional options for the Matlab xcorr function are the following:


x = xcorr(s1, s2, M, 'unbiased'); 

Here M is the maximum number of lags for calculating the cross correlation function. The input argument unbiased takes care of finite lenght effects of the signals. The biased estimator calculates $$r[k] = \frac{1}{N}\sum_{n=1}^N s_1[n]s_2[n-k]$$ and the unbiased estimator calculates $$r[k] = \frac{1}{N-k}\sum_{n=1}^N s_1[n]s_2[n-k]$$


Another technique that you can in case the relation between $s_1$ and $s_2$ is more complex than an integer delay and a gain is to calculate a Wiener filter wikipedia. If the relation changes over time, then an adaptive filter can be useful, e.g., using the lms algorithm.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...