07-18-2023 02:34 PM
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.
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
Solved! Go to Solution.
07-18-2023 09:15 PM
I threw this together. It might work. Give it a try.
07-19-2023 11:03 AM
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.
07-20-2023 09:22 AM
@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.
07-21-2023 01:37 PM
That makes sense. Thanks for the help.