LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting and averaging of arrays

Solved!
Go to solution

I have a dequeue operation within a while loop where I extract an array which should consist of 100 samples of 12 signals (waveforms).

 

-I want to compress this signal by a factor of 100, i.e. average all the samples,while preserving the waveform timestamp. Is there a method of applying this to the array as a whole or do I have to split the array at first? How can I achieve this yet maintain my (compressed/ average) time (dt) consistent to the data?

 

-Then I'd like to split the array into each individual signal/ waveform and perform calculations/ scaling of the signal. Do I simply have to use loops and index or is there a way of separating all the signals?

 

My predecessor used "signal compression" and "split signals" express VIs which I don't trust and it appears these only output the shady "dynamic signal" which everyone in this forum recommend to avoid

0 Kudos
Message 1 of 12
(5,389 Views)

I am considering using a for loop containing a case structure, running through each index of the array, averaging each waveform/ 100 samples at a time, then performing the calculations and exporting. Would this be an appropriate method or am I completely lost here?

 

I still need to know how to perform the compression/ averaging while maintaining the waveform timestamp

0 Kudos
Message 2 of 12
(5,380 Views)

Get the waveform components, average data by 100 and change dT by x100.

If you stay with waveforms instead of Dynamic data, you should simply have an array of waveforms to splitting them should be easy enough.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 12
(5,355 Views)

Thanks Yamaeda, seems like a neat way of preserving my time data.

 

Only problem I have now is that the output of the "get waveform components" gives me the wonderful (dbl) data type which doesn't work with the point-by-point mean function and the general mean function provides only single value output which I can not use to reconstruct my waveform (and I would also like not to limit the routine to always reducing the sample batch to single values).

 

Any suggestions on how to solve this issue?

0 Kudos
Message 4 of 12
(5,326 Views)

@KRICLA wrote:

Any suggestions on how to solve this issue?


Use a FOR loop around the Mean PtByPt.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 12
(5,320 Views)
Solution
Accepted by KRICLA

You start with a Waveform, and want to replace it with a Waveform that results from averaging over 100 points, resulting in a Waveform 1/100th the size (or at least that's what I assume you are doing).  To have this work seamlessly, you'd want the size of the Waveform Y data chunk to be a multiple of 100, such as 1000 points.  Then you'd simply peal off 100 points at a time, average them, and build a new waveform.  There is no need for point-by-point averaging, since you (a) need to get the Waveform before you can process it, (b) this requires that all its points be available, so (c) there's no problem in "resizing" the array.

 

The processing is simple.  Assume your waveform has size 100*m.  Reshape the 1D Array into a 2D m-by-100 2D Array, pass this through a For Loop with a "Mean" function inside to convert it to an Array of size m consisting of the average of each sub-array of size 100.  Use this to build a new Waveform, also (as Yamaeda noted) multiplying dt by 100.  This example, based on a 1000 samples of a generated Waveform of N(0, 1) random numbers gives an Waveform where the resulting Waveform is now N(0, 0.1), as expected.Average WaveformAverage Waveform

Bob Schor

 

 

Message 6 of 12
(5,308 Views)

@crossrulz wrote:

@KRICLA wrote:

Any suggestions on how to solve this issue?


Use a FOR loop around the Mean PtByPt.


Only if you use a parallel FOR loop with N parallel instances. Else all iterations will use the same instance of mean ptbypt, mixing all channels.

0 Kudos
Message 7 of 12
(5,278 Views)

@KRICLA wrote:

-I want to compress this signal by a factor of 100, i.e. average all the samples,while preserving the waveform timestamp.


Well, each sample has it's own time, so you should probably calculate the timestamp of the central element instead of keeping the one of the first element.

0 Kudos
Message 8 of 12
(5,273 Views)

@Bob_Schor wrote:

You start with a Waveform, and want to replace it with a Waveform that results from averaging over 100 points, resulting in a Waveform 1/100th the size (or at least that's what I assume you are doing).  To have this work seamlessly, you'd want the size of the Waveform Y data chunk to be a multiple of 100, such as 1000 points.  Then you'd simply peal off 100 points at a time, average them, and build a new waveform.  There is no need for point-by-point averaging, since you (a) need to get the Waveform before you can process it, (b) this requires that all its points be available, so (c) there's no problem in "resizing" the array.

 

The processing is simple.  Assume your waveform has size 100*m.  Reshape the 1D Array into a 2D m-by-100 2D Array, pass this through a For Loop with a "Mean" function inside to convert it to an Array of size m consisting of the average of each sub-array of size 100.  Use this to build a new Waveform, also (as Yamaeda noted) multiplying dt by 100.  This example, based on a 1000 samples of a generated Waveform of N(0, 1) random numbers gives an Waveform where the resulting Waveform is now N(0, 0.1), as expected.Average WaveformAverage Waveform

Bob Schor

 

 


Thanks a lot Bob! I'll try to implement your suggestion, haven't got it to run yet.

 

To clarify; I read a DAQ using DAQmx with the "Analog 1D Wfm, NChan NSamp" setting, where I have 13 channels at the moment and I pick 100 samples at a time. So what I want to do then is to compress each of the signals/ channels 100 times from 1000Hz to 10Hz. (I could of course pick 1000 samples as well but would prefer to run my "consumer loop" at 10Hz to have a decent rate of updates on the data, charts etc.

 

The problem I discovered now is that I was not extracting my 1 signal x 100 samples from my "main array". I don't even know what the array that DAQmx spits out actually looks like so I have bit of a hard time coming up with how to split it. The array size function tells me it's "13" so it seems my size is my channels. Where are the 100 samples? Hidden in each array element like a struct?

0 Kudos
Message 9 of 12
(5,244 Views)

@KRICLA wrote:

@Bob_Schor wrote:

You start with a Waveform, and want to replace it with a Waveform that results from averaging over 100 points, resulting in a Waveform 1/100th the size (or at least that's what I assume you are doing).  To have this work seamlessly, you'd want the size of the Waveform Y data chunk to be a multiple of 100, such as 1000 points.  Then you'd simply peal off 100 points at a time, average them, and build a new waveform.  There is no need for point-by-point averaging, since you (a) need to get the Waveform before you can process it, (b) this requires that all its points be available, so (c) there's no problem in "resizing" the array.

 

The processing is simple.  Assume your waveform has size 100*m.  Reshape the 1D Array into a 2D m-by-100 2D Array, pass this through a For Loop with a "Mean" function inside to convert it to an Array of size m consisting of the average of each sub-array of size 100.  Use this to build a new Waveform, also (as Yamaeda noted) multiplying dt by 100.  This example, based on a 1000 samples of a generated Waveform of N(0, 1) random numbers gives an Waveform where the resulting Waveform is now N(0, 0.1), as expected.Average WaveformAverage Waveform

Bob Schor

 

 


Thanks a lot Bob! I'll try to implement your suggestion, haven't got it to run yet.

 

To clarify; I read a DAQ using DAQmx with the "Analog 1D Wfm, NChan NSamp" setting, where I have 13 channels at the moment and I pick 100 samples at a time. So what I want to do then is to compress each of the signals/ channels 100 times from 1000Hz to 10Hz. (I could of course pick 1000 samples as well but would prefer to run my "consumer loop" at 10Hz to have a decent rate of updates on the data, charts etc.

 

The problem I discovered now is that I was not extracting my 1 signal x 100 samples from my "main array". I don't even know what the array that DAQmx spits out actually looks like so I have bit of a hard time coming up with how to split it. The array size function tells me it's "13" so it seems my size is my channels. Where are the 100 samples? Hidden in each array element like a struct?


Yes, a Waveform is a Cluster (struct) with a t0, dT and an array of samples, that in your case should be 100 elements long. In Bobs picture above you can see the "Get waveform components" (or what it's called) as the 2nd block where you can access the different parts.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 12
(5,230 Views)