user765269
user765269

Reputation: 423

Matlab: calculate translation between two graphs

consider the following graphs:

enter image description here

All graphs represent measurements of a surface, but taken in different directions.

I would like to compute how much the blue graph(s) are shifted to the right compared to the red graph(s). Is there a built-in function in MATLAB to achieve this? If not, how else could one approximate the "phase" shift?

Upvotes: 2

Views: 882

Answers (1)

nkjt
nkjt

Reputation: 7817

You can use xcorr for a quick and dirty solution, presuming that the shifts are not too large and the sampling is equal:

[c lags] = xcorr(red,blue); 

c is the actual correlations. lags is the shifts made to the blue input before correlating it with red.

Therefore, lags(c==max(c)) should tell you how much to shift blue to get the best match with red.

Upvotes: 3

Related Questions