From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cross Correlation in Matlab and Labview. Question.

Hello,

I have the following question.

I have two signals (sem0, sem1; each 131072 samples;) and I need to calculate the cross correlation function between them.

If I use Matlab, I can write  Correl = xcorr(sem0,sem1);
This returns a maximum  with the value  162.77,  and the  index of  the maximum point is  to the  left  of the  middle of the Correlation Function.

If I use Labview, and the CrossCorrelation.vi (the X pin is connected to sem0, the Y pin is connected to sem1);
This returns a maximum with the same value, 162.77,  the index of this maximum value is to the right  of the middle of the Correlation Function.

In other words, for the same signals and the same input order ,  the Correlation functions appear to be mirrored?
If you want  to get the same result, must I switch the input order in Labview?
xcorr(sem0,sem1) in Matlab, is  CrossCorrelation.vi (X=sem1,Y=sem0) in Labview?

Thank you
Download All
0 Kudos
Message 1 of 2
(5,261 Views)
Raul,
 
Yes, it looks like you are correct.  If you reverse the input to that VI so that the X input is sem1 and the Y is sem0, it will give the same maximum, but the index of that maximum will be mirrored around the center of the array.  So it looks like there is just a difference in the way that Matlab calculates the Correlation Function. 
 
You may want to take a look at the detailed help for the Cross Correlation function, which describes how it calculates the value mathematically, and see if this matches up to the function that MatLab uses to calculate the correlation.  I hope this helps.  If you have any other questions, let me know.
Brian Coalson

Software Engineer
National Instruments
Message 2 of 2
(5,232 Views)