LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continously Averaging and shifting values in arrays (FIFO)

Calculating the Average with this logic!

 

 

  1. Create 1-D Array with 10 elements with AI voltage, DAQ, a0,a1,,,,a9
  2. Select the sampling time with t0,t1, t2…..t10
  3. t0  t1  t2  t3  t4  t5  t6  t7  t8  t9  sample time

a0  a1  a2 a3 a4  a5  a6  a7  a8  a9 values

  1. Average

A9^=Summation (a0 to a9)/10

 

  1. Delete the a9 value and shift next
  2. Shifting the values

t0  t1      t2  t3  t4  t5  t6  t7  t8  t9

a0*  a0 -> a1->  a2 a3  a4  a5  a6  a7  a8

  1. Calculating the average

A9^=Summation(a0* to a9)/10

 Please let me know how can I create it.

0 Kudos
Message 1 of 13
(3,251 Views)

Your description is a bit unclear and has lots of duplicate or missing information, but maybe you can use mean ptbypt or make your own. This should give you some ideas.

Message 2 of 13
(3,245 Views)

Hi,

 

What you need is a Moving Average Filter. It's pretty simple and easy to be done.

 

Take a look in the attachment.

 

Paul

Message 3 of 13
(3,235 Views)

Thank you for sharing the info.

I tried to develop the VI based on the logic but unable to attain all conditions.

In my VI attached:

1.How can I introduce time factor like 1, 2, 3, 4....ms as an array?? I need counting generator to be attached to the sample time, t0,t1, t2...t9

2. Array received from AI is giving only value per channel?

3. The case structure is not considering other cases just averaging simply, how can I give the condition.

Finally I will save all data as a file.

Please give your comments, sugestions & modifications.

0 Kudos
Message 4 of 13
(3,228 Views)

Hi,

 

I'm not sure that I understand exactly what you want to achieve.


1.How can I introduce time factor like 1, 2, 3, 4....ms as an array?? I need counting generator to be attached to the sample time, t0,t1, t2...t9

You want different sampling times for each read? For example first read after 1ms, second after 2ms, third after 3ms and so on?

 

2. Array received from AI is giving only value per channel?

I've noticed that you read 2 channels in parallel (AI2 and AI3) but only one sample (from each channel) at a time. Do you want to read more than one/channel? This is what you meant? You can use N Channels / N Sample 2DBL. You have to specify the number of samples and at output you will have a 2D Array (Channels x Samples/Read).

 

3. The case structure is not considering other cases just averaging simply, how can I give the condition.

I see no reason for having the second (inner) While loop. If you want to change from Average to Average New get rid of the second loop (as I said in this configuration has absolutely no function) and Change the Enumeration Constant (Average,..) in Control Element.

 

Please make it more clear what you really want to do with the values read from the Analog Input? First I thought that you want to filter (using average) the voltage from one channel, but you make you filter the voltage from two different channels.

 

I've attached a modify version of your VI of what I think I understood that must be done. (PS: It's draft, there are many things that must be improved - like sampling rate. It's not recommendable to be done as delay in the while loop).

 

Paul

Message 5 of 13
(3,223 Views)

Thank you so much Paul. Yes I need to use AI values and N channel, single sample.

I have modified my VI with more concepts and adding your concept.

In my VI:

1. I have 2 stops. How can I control my VI?

2. How can I add the sample time from 0, 1, 2,...10ms?

Please see the attached.

 

0 Kudos
Message 6 of 13
(3,217 Views)

Hi,

 

In the vi you can see that after each read the Loop Delay increases with one step. There is also a block that limits maximum delay time. You can modify it.

 

If you want to use one stop for both loops you simply have to delete one and to connect the outer while loop stop to the inner one.

 

Rgds,

Paul

Message 7 of 13
(3,212 Views)

Thank you Paul!

Saturation concept is new for me, it seems good for adding a delay.

But I wish to connect some simple counter or a short VI function which automatically generates the simple counting 1, 2, 3, 4....as a control to the timer,

0 Kudos
Message 8 of 13
(3,202 Views)

I have introduced the simple counting for the sample time in my VI but the loop doesnt move again, it iterates only time but I want iterate till the count of 10.Please see the attached.

0 Kudos
Message 9 of 13
(3,181 Views)

 

Hey KRAZE4LV, 
Have you tried using the iterator of the while loop (the i box, in the upper left corner) as your counting? You could feed in a condition to the stop button for i>10, stop to iterate until the count of 10. Hope this helps!
~kgarrett

 

District Sales Engineer
0 Kudos
Message 10 of 13
(3,142 Views)