Cross Correlation Demo using Matlabs xcorr function

  Рет қаралды 148,398

David Dorran

David Dorran

Күн бұрын

Пікірлер: 100
@nichoyeah
@nichoyeah 2 жыл бұрын
8 years later, this video still helps people out!
@mahmoudlouati7700
@mahmoudlouati7700 Жыл бұрын
this is by far the best explanation of corrlation
@cyrus9893
@cyrus9893 Жыл бұрын
I don't know how to thank you, you are my one the best KZbinrs that explains these concepts clearly. Thanks a lot
@蔡文翔蔡文翔
@蔡文翔蔡文翔 4 жыл бұрын
This video is the one i found most usefull for understanding how matlab is doing in this func.!!
@melihcanyldz368
@melihcanyldz368 Жыл бұрын
finally , I found useful video to understand cross correlation , thank you David
@williamsalloom7331
@williamsalloom7331 4 жыл бұрын
I find your videos, explanations, and your channel of so much use. It mixes theory and application. Thank you for the explanations!
@GuruPrasanna
@GuruPrasanna 5 жыл бұрын
Finally found a simple explanation that made me understand it! Thanks.
@bernsbuenaobra473
@bernsbuenaobra473 5 жыл бұрын
Great understanding equals great teacher truly illuminating this is now I can go back to my agricultural cycle use case
@puzzlepencilholder
@puzzlepencilholder 10 жыл бұрын
Best explanation for cross correlation! Thanks David
@MrKarnn
@MrKarnn 7 ай бұрын
Thank you so much, why do people overcomplicate the explenation of this topic when you can explain it as simply as this
@laurameusel9300
@laurameusel9300 5 жыл бұрын
Thank you so much, i was looking for a video like that, 2hrs minimum... now i finally get xcorr !
@martuskaipawcio666
@martuskaipawcio666 7 жыл бұрын
Thanks a lot.. I did not expected it to be so simple. Directly going to look for other of your tutorials. Maybe I really have a chance to understand the math I did not have an opportunity to learn until now... and how to use it in Matlab. Once more great thanks for your affords of providing such a nice (and dummies-friendly) explanation.
@ddorran
@ddorran 7 жыл бұрын
You're welcome. Good luck with your studies.
@bobby2636
@bobby2636 3 жыл бұрын
Exactly what I'm searching for, great respect!
@fitrahramadhan8416
@fitrahramadhan8416 3 жыл бұрын
Thank you for your great explanation. I use this to find a similarity between countries economic cycle.
@ddorran
@ddorran Жыл бұрын
nice to see it being applied in different disciplines!
@TobiasTepper
@TobiasTepper 5 жыл бұрын
A really nice and helpful video! I'm just reading through the books about digital signal processing but mostly there are formulas with integrals. But I want to cross-correlate two signals in an FPGA (looking for a barker code in a stochastic signal) and it doesn't understand integrals. This video gives me an idea of how to do it - thank you!
@michelleelizabeth9956
@michelleelizabeth9956 Жыл бұрын
Thanks for making it so clear
@janiobachmann5029
@janiobachmann5029 5 жыл бұрын
Best explanation on cross correlation!! Thanks for sharing!
@apppurchaser2268
@apppurchaser2268 Жыл бұрын
Amazing explanation, thanks a lot
@laurentthowai3359
@laurentthowai3359 5 ай бұрын
Simple and efficient Thanks !
@ddorran
@ddorran 5 ай бұрын
Glad it was helpful!
@rap7123
@rap7123 2 жыл бұрын
made this so clear ,thank you
@ddorran
@ddorran Жыл бұрын
Glad it helped!
@SoLaR27
@SoLaR27 4 жыл бұрын
Thanks for the great video, David. It was very helpful!
@DieselBoulder
@DieselBoulder 3 жыл бұрын
Great explanation, but I'm curious why Matlab's xcorr function uses FFT to calculate the correlation, instead of shifted and trunctates Hadamard products of the signals?
@benblumberg9266
@benblumberg9266 8 жыл бұрын
Great, simple explanations. Thank you
@劉晏誠-g4o
@劉晏誠-g4o 4 жыл бұрын
Thanks David, help me alot. Easily understand.
@劉晏誠-g4o
@劉晏誠-g4o 4 жыл бұрын
But hmmm.. I have issue about the lag is 2 Cuz I thought data2 shall be source and data1 shall be a time-lag series It make sense in real. So lag is 2 shall be a negative time (-2) in real. Btw its opposite. Wonder this right or not, please explain it for me. Thanks alot.
@phakawatlamchuan
@phakawatlamchuan 4 жыл бұрын
Thanks a million. That’s very kind of you.
@sugandhigopal8539
@sugandhigopal8539 6 жыл бұрын
Even me as a non mathematics non engineer understood this 😊
@shalipse
@shalipse 10 жыл бұрын
Millions of thank you
@juanfdez96
@juanfdez96 7 жыл бұрын
I have a doubt with some homework I have to do. The thing is that I have a .wav signal and I have to compute its autocorrelation. I wrote this code in a script: [xt,fs]=wavread('signal8.wav'); Nt=length(xt); t1=0; t2=Nt/fs; t0=(t2-t1)/Nt; t=t1:t0:t2-t0; %Compute the autocorrelation, phitau and the shift tau using the xcorr function [phitau,tau]=xcorr('signal8.wav'); close all; plot(t,xt); xlabel('t sek'); ylabel('x(t)'); figure; plot(t0*tau,t0*phitau); xlabel('tau sek'); ylabel('phi(tau)'); and at the end in the command window I try to execute my script but I have an error like this: Undefined function 'fft' for input arguments of type 'char'. Error in xcorr>vectorXcorr (line 105) X = fft(x,2^nextpow2(2*M-1)); Error in xcorr (line 53) [c,M,N] = vectorXcorr(x,autoFlag,varargin{:}); Error in lab4b (line 8) [phitau,tau]=xcorr('signal8.wav'); Could you help me with there problem?
@kirasan
@kirasan 9 жыл бұрын
+Axel Thieffry This is not a normalized correlation
@shubhamdang8506
@shubhamdang8506 9 жыл бұрын
Hi, Nice tutorial. Thanks. I have a small query. I am supposed to calculate the "average of cross correlation" of over 20 series at zero lag. If i do it pair wise, i am assuming there would be 20C2 (20 Choose 2 ) coefficients which is a very high number and then i will have to calculate the average. Is there an easier way to do it ? perhaps something that can be implemented on excel ? Many thanks.
@praveensomesh2551
@praveensomesh2551 7 жыл бұрын
It is very clear.thank you so much david.. can you please suggest me how to implement the same in c language
@Tigres14
@Tigres14 3 жыл бұрын
Hi! Why correlation looks different when we use digital samples like [.... 1 0 1 1 1 0 ..... ]? In this case, final plot shows when correlation occurs (which is ok), but the rest values seems to form an triangular shape along the "lag" values
@muhammadusman-pc3on
@muhammadusman-pc3on 6 жыл бұрын
Thank you for such a beautiful explanation.
@ajnikhil
@ajnikhil 9 жыл бұрын
thanks a lot for simple explanation..Can you give link to next video?
@zoma93
@zoma93 9 жыл бұрын
Great tutorial and great code. Many thanks..
@darkdante2k4
@darkdante2k4 10 жыл бұрын
Thanks for your explanation and demo, it really helped!
@alanvelazquez8758
@alanvelazquez8758 3 жыл бұрын
Really thanks a lot!
@Jdonovanford
@Jdonovanford 7 жыл бұрын
Actually, when I plot lags against xcorr I get on the Y axes values up to 150. How to make sense of this? More generally, how to know if two signals are crosscorrelated? Is there an objective measure?
@dmosabel07
@dmosabel07 10 жыл бұрын
Thank you so much. This is of great help. All the best!
@tajiknomi
@tajiknomi 10 жыл бұрын
Thanks for your effort...It really helped me understand.
@girafepourpre6914
@girafepourpre6914 5 жыл бұрын
Priceless, thank you so much sir !
@muhammad.anas.8006
@muhammad.anas.8006 8 жыл бұрын
Thank you for the video. Simple explanation
@alainsteve6381
@alainsteve6381 7 жыл бұрын
I like your explanation. Thanks
@axisgraf
@axisgraf 10 жыл бұрын
Excellent explanation--thank you so much!
@v1rus412
@v1rus412 7 жыл бұрын
Is it possible to correlate two dataset (financial asset) even though their probability density function is not normally distributed?
@ymt36awq480k
@ymt36awq480k 3 жыл бұрын
Ah yes, how handy! - Got some earthquakes to check. ;-)
@raghunathn
@raghunathn 9 жыл бұрын
Hello David. Great tutorials. I have one question, I want to derive approaches for the signals are not aligned vertically. In normalized correlation also the data points are vertically aligned. How can we derive correlation , normalized correlation for non vertical aligned signals.
@ddorran
@ddorran 9 жыл бұрын
raghunath n My initial approach would be to interpolate the data so that it is vertically aligned and see how that works.
@raghunathn
@raghunathn 9 жыл бұрын
Thank you David. Your message confirmed my solution. Thank you.
@PierreBYT
@PierreBYT 9 жыл бұрын
Thank you for that useful demo !
@volcempire2540
@volcempire2540 9 жыл бұрын
Great explanation. I have one problem with this approach, maybe you can clear things up. I have two signals which look like peaks correlate where one peak is towards the beginning of signal 'A', and the other peak is towards the end of signal 'B'. Using cross correlation, the lag (which is large) to allign these samples doesn't provide the largest correlation value purely because there are less points involved in calculating the the correlation at this lag i.e. because many of the data points on one signal don't have an associated point on the other signal to be multiplied by because the two signals now have only a small region of overlap. I hope I have explained that comprehendably. Do you know of a solution for this/is this a known problem of cross-correlation, or am I missing something major in my understanding. Thanks in advance.
@ddorran
@ddorran 9 жыл бұрын
+volcEmpire In matlab there is an unbiased version of the xcorr (cross correlation) function. I think this just divides each correlation measure by the 'overlapping' vertically aligned samples which gives more weight to the correlations associated with larger lags. You should be careful when using this technique as sometimes the correlation measures at large lags can be excessively scaled.
@magma169
@magma169 9 жыл бұрын
For the cross-correlation to be valid, do you absolutely need to have the same number of elements between the two signals ?
@ddorran
@ddorran 9 жыл бұрын
yes. In the event that you have two sequences of numbers that do not have the same number of elements you can either zero-pad the shorter one or truncate the longer one.
@andyyyyy
@andyyyyy 9 жыл бұрын
David Dorran magma169 No they do not. Correct your intuition in Matlab if you can. The resultant of xcorr(a,b) will be of length a.length + b.length - 1 and the 'zero index' will be the (b.length -1)th entry.
@ddorran
@ddorran 9 жыл бұрын
Andrew Gallasch Perhaps we have different versions of matlab - I have 7.11 (R2010b) and it always returns 2N-1 correlation value, where N is the length of the longest input sequence. There is also a note in the help on xcorr that the shorter sequence is zero padded by the function.
@andyyyyy
@andyyyyy 9 жыл бұрын
so it does. That will only result in extra zeros appearing at the end of the xcorr result. They can be ignored. There is no mathematical limitation that inputs have to be equal length however.
@Yeajin84
@Yeajin84 8 жыл бұрын
so if we have the largest number in correlation sequence (in this vide, it is 23.18 with lag 2) means that there is highest similarity but at the end of video, you said that between 0 to 2 the signals are most similar which means the highest similarity at at lag1. It is disconnected story. What is the criteria to select the correlation sequence with highest similarity?
@ddorran
@ddorran 8 жыл бұрын
I'm not sure where I said "said that between 0 to 2 the signals are most similar which means the highest similarity at at lag1". If I did then I was incorrect. The lag at which the signals are most similar is at a lag of 2 samples.
@MrSak87
@MrSak87 9 жыл бұрын
Hi David, excellent video. I'm using excel 2003 but with a vast set of data (over 40,000 rows) is there a formula to calculate the correlation sequence value without having to individually multiply each numerical value associated with each sample? This is killing me!
@ddorran
@ddorran 9 жыл бұрын
You could downsample your data before correlating. Or you could cross correlate over a smaller range of lags. Both of these approaches would require a good understanding of the data you are working with to avoid missing useful info. Alternative you could use octave to process your data (an online version is available at octave-online.net/)
@khashablanca
@khashablanca 8 жыл бұрын
i have a query that i was hoping you would be able to help me with, for my final year project i have been researching into calculating distance using sound on an iphone 6. I have been playing short frequency sweeps on one iphone and recording the data on another phone sitting on top of the other. What i'm planning to do is calculate the delay between the initial sound and the reflected sound and combining that with the speed of sound to give me the distance between a wall and the iphone. however i'm struggling to do so. I know you are a wizard on MatLab and was wondering if there was any techniques or methods to approach in calculating that time delay within MatLab or Audacity.
@stargazer7644
@stargazer7644 8 жыл бұрын
+Khash Ghalam This should be doable, though I'm not sure what kind of resolution you'll get. The key is to send a very short but high amplitude, high frequency impulse (a click) and record it on the second phone. Ideally, the second phone should record two clicks, one directly from the first phone, and one (much weaker) from the reflected surface. Auto-correlate the signal to determine the delay between the two pulses. That delay is the distance. Complicating factors will be the limited bandwidth of the audio circuits at high frequency distorting your pulse (that's why this is usually done with ultrasonic transducers) and the multipath and smearing of the return signals since it isn't going to bounce off of just one point on the wall, but off of multiple points with slightly different times.
@lifeboost2030
@lifeboost2030 6 жыл бұрын
Great!! simple and understandable
@vibhorrastogi6711
@vibhorrastogi6711 9 жыл бұрын
Thanks. This was very helpful!
@zecheng3771
@zecheng3771 6 жыл бұрын
The video up to 6:05 is unfortunately wrong. You are calculating the convolution of two signals, not cross correlation.
@bernardmathias2017
@bernardmathias2017 5 жыл бұрын
I think you're right
@hajerjomaa3855
@hajerjomaa3855 4 жыл бұрын
thanks a lot
@darmowecukierki
@darmowecukierki 10 жыл бұрын
Great stuff !
@hannapamelaanino468
@hannapamelaanino468 10 жыл бұрын
Thanks for uploading...😄
@oren12311
@oren12311 7 жыл бұрын
very helpful, thank you
@TheBjjninja
@TheBjjninja 5 жыл бұрын
Does the data have to be stationary?
@ddorran
@ddorran 5 жыл бұрын
The data can be any sequence of numerical values
@relaxidermist9502
@relaxidermist9502 10 жыл бұрын
Thanks, very helpful
@qzorn4440
@qzorn4440 9 жыл бұрын
Supercalifragilisticexpialidocious. thanks.
@17joren
@17joren 9 жыл бұрын
So what is the resulting number actually mean? 7.52 what? %?
@ddorran
@ddorran 9 жыл бұрын
The meaning of the number is dependent upon the signals involved. A value of 7.52 might mean signals are identical for one pair of signals but extremely dissimilar for another pair of signals. The reason for this is because the number returned by a standard correlation function are dependent upon the energy in the signals. Normalised correlation attempts to resolve this by normalising to the energy of both signals so that the result lies within +- 1. A value of 1 in this case means that the signals are identical, -1 means the signals are an inverted form of each other and 0 means that they are orthogonal to each other. So you are probably wondering what 0.5 means versus say 0.9 - the simple answer is to say that a result of 0.9 means that the signals are more similar than signals that have a normalised correlation of 0.5. A more complete answer could be obtained by looking at the equations - I was trying to come up with a verbal description but couldn't come up with something that was easy to interpret - this question did get me thinking about it though so I'll get back to this at some stage.
@17joren
@17joren 9 жыл бұрын
So using your number system, what number result would indicate 100% identical, in phase, etc?
@ddorran
@ddorran 9 жыл бұрын
Using normalised correlation a value of 1. For standard correlation sum(x.^2) where x is one of the signals
@17joren
@17joren 9 жыл бұрын
I guess I meant standard, if that is what you're using in this video. You have 7.52 and -12.48 and so on so I am curious as to what 100% identical signals would yield.
@ddorran
@ddorran 9 жыл бұрын
17joren As an example say you had a signal [ -2 3 4 -10] then a standard correlation measure if you correlated this signal with itself would be 4+9+16+100 = 129.
@barunbasnet
@barunbasnet 6 жыл бұрын
Thank you very very very very much
@athief
@athief 9 жыл бұрын
"At Lag zero we have a correlation value of 7.52"..... really??? A correlation of 7+ ??? What the..
@charmerhue
@charmerhue 7 жыл бұрын
thank you so much!!!
@shulhi55
@shulhi55 10 жыл бұрын
Thank you!
@Roiogaruz
@Roiogaruz 5 жыл бұрын
Thank you so much omg
@mcnimi
@mcnimi 10 жыл бұрын
Thanks a lot!
@alibade4921
@alibade4921 7 жыл бұрын
thanks dude
@youmah25
@youmah25 10 жыл бұрын
thank you
@a-bm9ux
@a-bm9ux 4 ай бұрын
10 years later, this video still helps people out!
@xxvampxxify
@xxvampxxify 2 жыл бұрын
Thanks for this!
@楊鎮宇-h4i
@楊鎮宇-h4i 3 жыл бұрын
thank you so much!!!!
@simhadivya237
@simhadivya237 4 жыл бұрын
is lag the time delay?
@ddorran
@ddorran 4 жыл бұрын
Yes
@armitosmt5753
@armitosmt5753 5 жыл бұрын
Thank you
How to Measure a Time Delay Using Cross Correlation?
16:14
Virtins Technology
Рет қаралды 109 М.
Part 2: Convolution and Cross-Correlation - G. Jensen
15:06
caltech
Рет қаралды 195 М.
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 275 #shorts
00:29
2 MAGIC SECRETS @denismagicshow @roman_magic
00:32
MasomkaMagic
Рет қаралды 29 МЛН
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 21 МЛН
Using matlabs fft function 2 - zero padding and windowing
23:06
David Dorran
Рет қаралды 97 М.
Introduction to Meshgrid Function and 3D Plotting in MATLAB
9:17
Aleksandar Haber PhD
Рет қаралды 22 М.
Normalised Correlation  Explanation with Demo
10:15
David Dorran
Рет қаралды 69 М.
3.8 - Auto correlation and cross correlation
10:33
LaintalAy
Рет қаралды 67 М.
pitch period tracking using correlation
21:05
David Dorran
Рет қаралды 45 М.
Using Matlab's fft function
17:40
David Dorran
Рет қаралды 433 М.
What Is Correlation?
6:56
Melanie Maggard
Рет қаралды 478 М.
Covariance, Clearly Explained!!!
22:23
StatQuest with Josh Starmer
Рет қаралды 564 М.
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 275 #shorts
00:29