Best way to compare two signals in Matlab

toozie21 picture toozie21 · Jan 17, 2013 · Viewed 20.8k times · Source

I have a signal I made in matlab that I want to compare to another signal (call them y and z). What I am looking for is a way to assign a value or percentage of how similar two signals are.

I was trying to use corrcoef, but I get very poor values (corrcoef(y,z) = -0.1141), yet when I look at the FFT of the two plots superimposed on each other, I would have visually said that they are very similar. Taking a look at the corrcoef of the FFT of the magnitude of the two signals looks a lot more promising: corrcoef(abs(fft(y)),abs(fft(z))) = 0.9955, but I am not sure if that is the best way to go about it since the two signals in their pure form appear to not be correlated.

Does anyone have a recommendation of how to compare two signals in Matlab as described?

Thanks!

Answer

Pete picture Pete · Jan 17, 2013

The question is impossible to answer without a clearer definition of what you mean by "similar".

If by "similar" you mean "correlated frequency responses", then, well, you're one step ahead of the game!

In general, defining the proper metric is highly application specific; you need to answer why you want to know how similar these two signals are to know how to measure how similar they are. Will they be input to the same system? Do they need to be detected by the same algorithm?

In the meantime, your idea to use the freq-domain correlation is not bad. But you might also consider

http://en.wikipedia.org/wiki/Dynamic_time_warping

Or the likelihood of the time-series under various statistical models:

http://en.wikipedia.org/wiki/Hidden_Markov_model http://en.wikipedia.org/wiki/Autoregressive_model http://en.wikipedia.org/wiki/Autoregressive%E2%80%93moving-average_model

Or any number of other models...

I should add: In general, the correlation coefficient between two time-series is a very poor metric of the time-series' similarity, except under very specific circumstances (e.g., no shifts in phase)