Showing results for 
Search instead for 
Did you mean: 

Covariance Matrix

Hello, I am brand-new to LabView and I'm trying to implement the following:


The inputs are five features extracted from an ultrasonic echo. The features are represented by 1D arrays with 64 elements each. I'll refer to the features as x1, x2, x3, x4, and x5. The vector v referenced in the equation is v = [x1, x2, x3, x4, x5].


Each feature has a mean value, which I've already calculated. To get (vi - u), I am looping through each of the 64 elements of the features, building the vi vector, then subtracting the associated mean from each value. So, if u1 is the mean of feature x1, then vector vi = [x1i - u1, x2i - u2, x3i - u3, x4i - u4, x5i - u5].


I'm then putting the vector vi into another for loop twice, with one auto-indexed tunnel and the other tunnel with no indexing. I think this is achieving the vector multiplication correctly. The result of this should be a 2D array containing the covariance values for that individual element. But this is where I get stuck. Here's what I have so far:


The next part (assuming what I've done so far is correct) is summing the values of the 2D arrays and dividing each by 64. I thought about trying to use a shift register, but I'm not sure how I'd implement that. The other thought I had was to output the 3D array (5x5x64) and use another for loop to sum each of the 64 2D arrays. Am I approaching this correctly, and how would I finish the computation?

0 Kudos
Message 1 of 6

Do you know about LabVIEW Projects (and Project files, .lvproj)?  It is a way to organize your LabVIEW code so that when you want someone to look at your code, and you send them a compressed (zipped) version of the Project Folder, they get even the missing sub-VI,


I don't remember when Matrices were added to the LabVIEW Array palette, but they might be there in LabVIEW 2016.  They might simplify the math a little in dealing with Covariances.


Bob Schor

Message 2 of 6

Please make our life easier and attach a VI that has reasonable defaults for all inputs so we can run it (fill the controls, the do a make current values default). Having all empty arrays is not useful. You also have a missing subVI that we need to run things.


All that said, I don't think your code is even close. 😄 We can help.


(And please (please!) don't maximize the front panel and diagram to the monitor, that just annoying!)


(Can you explain your terminology: Is "vector" v a 1D array (vector!) with 5x64 elements, or a 64x5 2D array, i.e. a "matrix!")

0 Kudos
Message 3 of 6

If you prep your data correctly, all you might needs is this tool. You can even look inside what it does.






Message 4 of 6

I did not know about Labview projects, I will look into that. Thank you!

0 Kudos
Message 5 of 6

Great, I will try to implement this, thank you!

0 Kudos
Message 6 of 6