04-14-2022 11:21 AM
Hello,
I'm trying to find the average output of the amplitude over a period of time. So the formula is the (Sum of amplitude/ΔT). Where for each time interval, the average amplitude is shown on the graph. I tried using the add array elements and dividing by the time, but from the waveform, this does not look correct. Would the MeanPtByPt vi work? Or is there any other way I could go about this? The amplitude should be around 5V. Thank you.
04-14-2022 11:42 AM
I think that you have your formula wrong. To get an average you take the sum of the array elements divided by the number of elements in the array (assuming that the array only contains data over the period of time of interest). Even better is to use the Mean primitive from the Math/Probability and Statistics palette.
04-14-2022 11:58 AM
Is the data spit out at a set rate? If so, then remove the wait from your loop and hardcode the number of bytes to read. Then you can just use the Mean.vi on the data and write that directly to your chart. I say to remove the wait because the VISA Read will wait for the number of bytes you told it to wait for, up to the timeout. Also, make sure the Termination Character is OFF during this transaction otherwise, if a byte just happens to match the termination character, you will not get all of the data you expected.
04-14-2022 12:18 PM
I would use "Mean ptbypt" and just reset after each time interval (or set a fixed length if that works).
04-14-2022 01:52 PM
@DailonDonley wrote:
Hello,
I'm trying to find the average output of the amplitude over a period of time. So the formula is the (Sum of amplitude/ΔT). Where for each time interval, the average amplitude is shown on the graph. I tried using the add array elements and dividing by the time, but from the waveform, this does not look correct. Would the MeanPtByPt vi work? Or is there any other way I could go about this? The amplitude should be around 5V. Thank you
Which answer do you want?
Average or Sigma per Delta Tau?
Despite the oddest typecast string to array of int16 I've seen lately and the completely superfluous build Array you have implemented the latter ALMOST! since the number of readings seams inconsistent for each second interval.
crossrulz is exactly right! Remove the bytes at port an simply read a reasonable even number of bytes. The to from flattened strings could likely be replaced with a typecast. (You didn't show the received data format). And we really don't know what the device measurement timing is.
With that information we can by more helpful to you.
04-14-2022 02:24 PM
@JÞB wrote:Despite the oddest typecast string to array of int16 I've seen lately..
The only odd part about it is the first Flatten To String. You already have a binary string, so you do not need to "flatten" it. But the Unflatten From String to convert to I16 or U16 is fine. Notice the "Little Endian" option is being used. So if you used Type Cast instead, you would need to add a "Swap Bytes".