LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging of each element of array

Solved!
Go to solution

I have a 48 Analog Input Channel DAQ system, I am reading at a rate of 1Khz. (The data has to be datalogged at 1Khz).

The signal received are with noise and to display to user without much fluctuation I am averaging the values using 'Mean Pt by Pt' API.

 

I am attached the VI wherein I have considered only 5 Analog Input which is simulated by a pointer numeric control. In producer loop I am purposely adding noise and storing the data array in a variable named as "data acquisition with noise".

 

In consumer loop I am applying the averaging method to individual analog input by the help of 'mean pt by pt' API. 

 

The VI solves the purpose but for 48 Channel it becomes messy by using 48 'Mean pt by Pt' API.

 

How do I optimize the code so that with a single API I can get averaged values.?

0 Kudos
Message 1 of 33
(2,709 Views)

How about using For-loop

PalanivelThiruvenkadam_0-1654241704850.png

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 33
(2,696 Views)

I have tried with for loop, the results are not matching with the input signal 

0 Kudos
Message 3 of 33
(2,690 Views)

@msabah38 wrote:

I have tried with for loop, the results are not matching with the input signal 


No, that is to be expected.

 

The for loop will average all channel data, as if it was a single channel.

 

You'd have to DIY something...

 

I'd make a 2D circular buffer (search the forum), size Channels X Length. You'd get a history of 10 for all channels, and you'd be able to get an average at any time.

 

Spoiler
As an example circular buffer:
wiebeCARYA_0-1652462535923.png
The data between the sequences (there only for illustration) can 'live' in a DVR, or in private class data or a cluster in a shift register. 

 

Theoretically, you can keep the sum of all data, and subtract the earliest point when you add the newest point. That will save a lot of calculations. However, once you get a NaN, Inf, -Inf, or mixed small and large numbers, the sum is corrupted, and it won't work well. 

Message 4 of 33
(2,674 Views)

wiebe@CARYA wrote:
The for loop will average all channel data, as if it was a single channel.

 


... unless we use a parallel FOR loop with a sufficient number of instances. 😄

 

 

Message 5 of 33
(2,644 Views)

Maybe all you need is something along these lines.

 

(I also remember some other more detailed discussions. Will try to find the link)

0 Kudos
Message 6 of 33
(2,640 Views)

Maybe all you really need is a simple and inexpensive exponential filter.

 

(adapted from my old post here)

 

Note that the filter factor  control could be defined as 1/alpha (where alpha is in the range 0..1)) so a higher number increases the smoothing

 

altenbach_0-1654269702930.png

 

 

 

altenbach_1-1654268880747.png

 

 

 

 

0 Kudos
Message 7 of 33
(2,629 Views)

@altenbach wrote:

wiebe@CARYA wrote:
The for loop will average all channel data, as if it was a single channel.

 


... unless we use a parallel FOR loop with a sufficient number of instances. 😄


should that work?

wiebeCARYA_0-1654269671145.png

It still seems to use 1 instance of the PtPyPt VI?

 

I'd expect 0,1,2,3,4,5,6,7,8,9, but I get 0, .5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5.

0 Kudos
Message 8 of 33
(2,617 Views)

@altenbach wrote:

Note that the filter factor  control could be defined as 1/alpha (where alpha is in the range 0..1)) so a higher number increases the smoothing

 


Here's how that could look like:

 

altenbach_0-1654270956905.png

 

0 Kudos
Message 9 of 33
(2,602 Views)

Could you please downgrade the array averaging_MODCA2.vi ‏15 KB VI to LV.2015

0 Kudos
Message 10 of 33
(2,598 Views)