# Calculating similarity between two signal plots

I have two plots, each having frequency as x-axis and Gain as y-axis. By taking one data set as a reference I have to calculate similarity between them.

The graphs have same values on the x-axis and have same range on the x axis

Can 2D Correlation or Co-variance can do a decent job ? or should I opt for Fréchet distance or DWT as I have read in some other posts ?

The first plot is the reference plot.

Here are the plots:

• Can you show us the plots? Then we might have some idea what "similar" means in this context. – endolith Apr 18 '13 at 13:14
• I have uploaded the plots. The first one is the reference plot! – Animesh Pandey Apr 18 '13 at 13:57
• Those don't look similar at all. Do you think that they are? In what way? – endolith Apr 18 '13 at 14:50
• but there could be some metric by which we can find the degree of difference between the two ? .. just like Peter K. has mentioned below ... – Animesh Pandey Apr 18 '13 at 16:40
• In what way are they similar? That's what you have to answer. – endolith Apr 18 '13 at 19:55

Why not just use something like the relative "error" between the two?

For example, if your frequency magnitude responses are $G_1$ and $G_2$, then calculate:

$$ERR = \sum \left | G_1(n) - G_2(n) \right|^2$$

and then normalize with respect to the reference, $G_1$:

$$NORMALIZED = \sum \left | G_1(n) - G_2(n) \right|^2 / \sum \left | G_1(n) \right|^2$$

Correlation is also a way to go, but it might show some cases where the same shape happens, but at very different frequencies... which might not be what you want.

• I have different Gain values at same frequency points ... I hope I can still apply this concept for Gain values ! – Animesh Pandey Apr 18 '13 at 18:11
• I am not sure what you mean? You should probably apply the above to the actual gain values, rather than to the dB values of your plots; other than that, I can't see a big problem (though I might not get precisely what your question is, feel free to elaborate). – Peter K. Apr 18 '13 at 19:16
• I tested you solution on other data sets as well I am getting satisfactory results ... I think I should mark this as solution – Animesh Pandey Apr 18 '13 at 19:19
• Can I say that the similarity of the graphs is 1.0 - Error , in some way ?? – Animesh Pandey Apr 18 '13 at 19:21
• Yes, that's a way to put it. The error is relative to the $G_1$ energy. It might be true, however, that $ERR > 1.0$, in which case your "similarity" will be negative. If the shape of the curves, rather than the gain is important, then you should normalize them somehow before applying the formulae here. – Peter K. Apr 18 '13 at 19:23

I would use correlation for simple and small data. If your data is large though, I would think about using feature extraction via ICA or PCA analysis, and then compare the features via correlation.

The problem with correlation is scale. Look at the image in the URL below:
Correlation examples

80% is pretty similar in my imagination, but in correlation it really isn't that similar. So, if I were you I would define my own scale of similarity, situated closer to 95-100% on the correlation scale.

And I agree with lxop, in that a correlation between 2 1D signals is enough, given of course that each successive sample index corresponds to the same X-value (frequency) in both signals.

• The data has 400 points. Would it be considered large? – Animesh Pandey Apr 18 '13 at 13:58
• What if I normalize the graphs and then find the Pearson Correlation between the y-axes vectors of the graphs ? – Animesh Pandey Apr 18 '13 at 14:36
• @AnimeshPandey, I would not consider that large at all (hundreds of thousands is more like it). Consider Peter K.'s last recommendation, as it is true. Still, in that case you could measure the phase difference between the two (if they are similar enough) and check for close to zero phase difference. – jhc Apr 18 '13 at 17:48

What's wrong with just normal 1D correlation? That's what it finds - the similarity between two signals ('plots'), at a range of offsets.