Search code examples
matlab2dsimilarity

Matlab 2D function subsequence similarity


If i have 2 functions, let's say f(x) and g(x) and i want to find the longest portion of f that is similar to some portion of g, how can i do that?
For example, consider the figure below: enter image description here

it is pretty evident they are enough similar to each other in the starting position, but what if they where in random position?
That's the point, i need to discover the longest similar portion(s) ... some hints?
In my case the two "functions" are an array rappresentation of two songs, and i want to find the most similar part of them, so they are supposed to be

  1. different in the 99% of the rappresentation ( see the second example below )enter image description here
  2. Just barely similar in a random position : except for the orizontal lines, a perfect matching is never expected to be found

Solution

  • You can do that by using cross-correlation (xcor).

    This method computes the correlation of 2 signals for each "offset" between them. The highest correlated point will be the offset you need to give to signal2 to match signal1. Read the documentation for examples and usage.