LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous Waveform Averaging

Solved!
Go to solution

I’m new to LabVIEW and am trying to find a way to continuously average a waveform. I’m acquiring the waveforms from an Analog Discovery 2 being used as an oscilloscope. An outer while loop is keeping the data acquisition running continuously. The idea was to average the waveforms similarly to how a traditional oscilloscope does, by summing the last n waveforms and dividing by n. The issue I’m running into is properly storing and accessing the last n waveforms to continuously average them. Right now, I’m trying to store the last n waveforms in an array, sum all the values in the array, then divide by n. This way I could continuously update the array and thus the averaged waveform. 

fdby_0-1689708496610.png

 

 

 

From my understanding, the above code doesn't work because a new array filled with the current waveform is initialized with each pass of the while loop, but I'm unsure how to fix this issue. I tried implementing a case structure to only initialize the starting array with the first pass of the loop but I was unsuccessful it getting it to work. I also understand that I should not be sending the "average waveform" to the shift register but I am confused about what to do instead.

 

I was wondering how I could alter my code to fix this issue or here was an easier way to accomplish the desired outcome.

 

Thanks

0 Kudos
Message 1 of 5
(961 Views)
Solution
Accepted by topic author fdby

I threw this together.  It might work.  Give it a try.

Message 2 of 5
(920 Views)

This seems to be working correctly, thanks.

 

I have a couple questions about how your code works to make sure I'm understanding it correctly:

 

1. The case structure at the beginning will only be true when you change the number of waveforms to average or when you start the program, right?

2. I'm confused about the summing of the array. Why is the "Delete from array" block before the for loop needed?

What elements are being deleted and summed with the elements from the array of waveforms?

Where in the array are they deleted from if no index is specified as an input?

 

I appreciate your help.

0 Kudos
Message 3 of 5
(886 Views)

@fdby wrote:

This seems to be working correctly, thanks.

 

I have a couple questions about how your code works to make sure I'm understanding it correctly:

 

1. The case structure at the beginning will only be true when you change the number of waveforms to average or when you start the program, right?

2. I'm confused about the summing of the array. Why is the "Delete from array" block before the for loop needed?

What elements are being deleted and summed with the elements from the array of waveforms?

Where in the array are they deleted from if no index is specified as an input?

 

I appreciate your help.


1. Correct.  I made it that way to simplify usage; you don't need an "Initialize" input.

2. "Delete from array" removes the last element* which is then used as the initial value to the shift register.  I haven't checked, but I think if you were to use an empty waveform constant feeding into the shift register along with the entire array feeding into the loop, I would expect a blank waveform at the output.

 

* It really doesn't matter which element gets pulled out.

0 Kudos
Message 4 of 5
(840 Views)

That makes sense. Thanks for the help.

0 Kudos
Message 5 of 5
(816 Views)