LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop to get average

Attached is my vi file and sub-folder contains library functions for A_D card.
Now the table can display only one column of values. I want to break them to a 2-D array.
1st row-> average values when line active button is high
2nd row -> average values when line active is high for the next time
.
.
 
I want to replace the table with 2-D array, as I want to save this as a matrix.
 
Below while loop is similar to my other counter in previous example.
Hope this helps you to understand what exactly I am trying to do.
 
Thanks and regards,
Ravi.
0 Kudos
Message 21 of 28
(1,401 Views)
Hi
Thanks for all the replies. I guess I wasn't very explicit.
I have a data source which generates say 1000 points, which is a noisy spectrum.
and this data set is repeated say 100 times. I need to average each elemeent in the 1000
point array  so I end up with 1000 averaged points. I 'd like to display the spectrum after
each aqusiiton  and be  able to stop it if it is good enough.

In a a normal program this would be trivial
do j=1,100
    do i=1,1000
        new_signal(i)=old_signal(i)+new_signal(i)
    end do
end do
do i=1,1000
    new_signal(i)=new_signal(i)/100.
end do

Many thanks again for any suggestions
Rgds
Terence

0 Kudos
Message 22 of 28
(1,502 Views)
Hello Terence,

in Labview you can do this too, but you need one for loop less: LV can add up arrays with indexing all elements.
So your program reduces to:
do i=1 to 100
 get 1000 datapoints
 add data to old data (yes, you can add one array to a 2nd)
 display data
od

For 'old_data' you don't need an indicator, use a shift register instead.
See the attached picture.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 23 of 28
(1,498 Views)

Hi,

look at the vi attached. What I did is simply look for the falling edge s on line counter.

When line counter = true => add the average to a 1D array

When line counter =  false => do nothing

When line counter change from false to true (rising edge) => do nothing

When line counter change from true to false (falling edge) => add the 1D array to the

2D array and re initialise the 1D array to an empty array.

 

I hope it is what you wanted to do!  Smiley Wink

Dai

LV 7.1 - WIN XP - RT - FP
Message 24 of 28
(1,392 Views)

Thanks a lot. You have implemented such a complex logic in a simple way! It took more than 2 hrs for me to understand it!

Regards,

Ravi.

0 Kudos
Message 25 of 28
(1,385 Views)
Dear Gerd
Many many thnaks for your neet solution it works really well.
Rgds
Terence

0 Kudos
Message 26 of 28
(1,473 Views)
Hi!
 
Was it so complicated? I thaught the comments where sufficient! Sorry!
Next time, I'll try to be even clearer. You should understand that in 2 min!
Dai

LV 7.1 - WIN XP - RT - FP
0 Kudos
Message 27 of 28
(1,374 Views)

No, your comments were really good. It is only the logic in two loops were bit tricky.

Regards,

ravi.

0 Kudos
Message 28 of 28
(1,369 Views)