06-02-2017 04:30 PM
Hi,
I have a very basic data acquisition program. The program reads a sine wave for 1 second and stores the read values as an array containing 102400 elements.
The frequency of the wave is 50 Hz so 1 cycle is contained within 2048 elements. I want to write a program that evaluates the average value over 1 second or 50 cycles. Any idea how to do that?
I tried using for loop but it's now working for me. can any one help me out?
Best Regards,
Mubeen Haadi.
06-02-2017 04:56 PM
The problem comes when you are summing the arrays. Look at the very first sum, and ask yourself what two things are being added.
LabVIEW is very particular about how it handles arrays. If I add an array of size 5 to an array of size 10, how big do you thing the resulting sum will be? If you are not sure, write a little LabVIEW program that does exactly that. Once you see the answer to this second question, you can probably figure out why your sum is not working, and maybe even how to fix it.
Note -- I am deliberately not telling you the (relatively simple) fix. Since you are trying to learn LabVIEW, finding and fixing the problem yourself will be much better for you in terms of learning. However, if you are still having trouble, and especially if you did the simple "Add two arrays of known and different sizes" exercise, come back and explain what puzzles you ...
Bob Schor
06-02-2017 04:59 PM
You might want to rethink the average, and replace with RMS. The average of a sine wave will be zero or whatever its offset is, the RMS value is probably more enlightening.
mcduff
06-02-2017 07:54 PM
I figured it out. needed to initialize the shift register with first.
06-02-2017 07:57 PM
@mcduff
I was not interested in finding average of on cycle. that is obviously zero. I wanted to add the 50 cycles up and than find average such that at the end I have one cycle left.
06-02-2017 08:06 PM
Yep. By not specifying an input, you effectively used the "default" value, which is an empty array. As you've discovered, adding two arrays of different lengths gives you a "sum array" whose length is the shorter of the two addends. If one is an empty array, then the sum will also be an empty (length 0) array.
Bob Schor
06-03-2017 12:28 PM
That makes more sense. Sorry I misunderstood.
Here's another way, shift registers not required.
mcduff