How to tell if two signals are similar
121 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to compare two periodic signals. Lets say I have 1 period for each of the signals, and I want to know how similar they are. The final target of this is that if they are similar enough (for a given criteria) I can stop calculating some other stuff and save a lot of time. But that doesn't really matter, the question is the same, how to tell if two signals are similar.
I first considered the xcorr(x,y) function, the problem I see with cross correlation is that it gives good info about how to phase one of the signals for it to best match the other one, but it doesn't say how similar they are (or maybe I don't understand it very well, haha). From what I understand and have tested, cross correlation can be really affected by the signals amplitude, for example:
f1 = 1000*sin(x)
f2 = sin(x)
c = xcorr(f2,f2) is the ideal case, where the correlation is perfect c2 = xcoor(f1,f2) is the case I am evaluating, and the peak at c2 is bigger than c, suggesting better correlation? There is a normalization option in MATLAB which I don't really understand (I do understand it when you are doing autocorrelation, like c = xcorr(f2,f2,'coeff'), then you geat the peak correlation to be 1 at zero lag, that is OK, but for crosscorrelation between two functions, I don't understand how this normalization works).
I don't care about the phase since I will compare just one period of each of the signals, so I just need an algorithm to quantify how equal or similar these two signals are. But from what I see the correlation can sometimes be miss leading.
I may add that the signals are discrete, with the same number of elements, same sampling frequency and their frequency is the same, and known, if that helps.
Thanks in advance. JP
0 comentarios
Respuestas (6)
Honglei Chen
el 11 de Jul. de 2012
Perhaps you are looking for a scalar quantity to represent the similarity between two signal as is? If that's the case, you basically only need zero lag, try
xcorr(f1,f2,0,'coeff')
0 comentarios
Wayne King
el 12 de Jul. de 2012
Editada: Wayne King
el 12 de Jul. de 2012
The correlation coefficient is bounded by 1 in absolute value. (Normalized) correlation values always lie between -1 and 1. At either extreme, you are saying that the linear relationship between the two signals is perfect. In other words, one is perfectly linearly predictable from knowledge of the other.
If you use xcorr without the 'coeff' option then you are obtaining the unnormalized cross correlation (at zero lag) in your case. That value absolutely depends on the values of the two waveforms. Just as covariance (not correlation) depends on the values of the quantities you are measuring. Look at the mathematical expression for the (unnormalized) cross correlation at zero lag. You are multiplying the two vectors element by element and summing all the values. If you do that, then as you increase or decrease the amplitude, you increase or decrease the value at zero lag accordingly.
That is precisely why xcorr() with 'coeff' is easier to interpret for your case. You can immediately tell the strength of the linear relationship. It's the same situation with covariance and correlation in inferential statistics. If I tell you the covariance between two random variables is 10,000, then what does that mean? Does it mean the linear relationship is strong or not? The answer is you don't know based on that number alone. But if I tell you the correlation is 0.95, that tells you something. That tells you something about the strength of the linear relationship between the two.
2 comentarios
Honglei Chen
el 12 de Jul. de 2012
What is the similarity you look for? It seems that in your definition, f1, f2, and f3 are not similar. If that's the case, then indeed you are not looking for the correlation between the two.
Joseph
el 25 de Jul. de 2012
Hi Juan, I've got the exact same problem. Xcorr simply gets larger as the amplitude of your comparing signal's multiplier gets larger and if you use the 'coeff' option you get the same value for every multiplier. What I ended up doing is simply dividing one by the other. So.. first do xcorr to find the time shift and then divide to find the amplitude comparison. This makes sense for my situation but mine's a bit different from yours, so maybe it won't work for you. But I thought I'd throw it out there.
0 comentarios
Abhishek Nayak
el 5 de Nov. de 2019
Editada: Abhishek Nayak
el 5 de Nov. de 2019
I want to know the similarity between these two signals. Is there any measures for it?
Here the amplitude of two signals are different and the phase shifting is also present.
Thanks in advance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246822/image.png)
1 comentario
Farrukh Hassan
el 5 de Nov. de 2020
Could you find the answer?? i have two waveform of a signal. each having 2048 samples. the sampling frequency is 1mHz. how can i find similarity between the two using cross-correlation??
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/403540/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/403545/image.jpeg)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!