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: 

Covariance Matrix

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

kgthompson_0-1677885497053.png

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:

kgthompson_1-1677885961763.png

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
(1,011 Views)

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, Mean_STDDEV_5arrays.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
(997 Views)

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
(984 Views)

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

 

altenbach_0-1677891055993.png

 

 

 

Message 4 of 6
(972 Views)

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

0 Kudos
Message 5 of 6
(898 Views)

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

0 Kudos
Message 6 of 6
(896 Views)