LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Moving average VI

Hi

 

I am new to LabVIEW . I have some noisy data coming in. I would like to filter the data by taking  moving average of the samples. For that I have made the VI which is attached with this mail.

This VI is an example VI, in the sense that the incoming signal is an artificial signal.

However, I am not able to get the averaged data (which should be a sine curve), from the noisy signal.

 

For your convenience, I have attached a snapshot of both the front panel and the block diagram. As you can see, the averaged signal is almost a straight line. 

 

The problem might be as simple as changing the scale of X, for all we know. Right now, the x coordinate is auto scaled. I tried to make the scale of x on both the plots same but was met with only limited success. 

 

Please help !!FrontPanel.PNG

BlockDiagram.PNG

0 Kudos
Message 1 of 15
(9,232 Views)

You are not moving the start of the average.  I recommend you just use the Mean PtByPt VI inside of the FOR loop instead of your current implementation.


GCentral
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
Message 2 of 15
(9,219 Views)

Thank you.

 

That really did help.

 

The averaged signal is no longer a straight line but is behaving as it should.

 

To improve the VI further, we need to accomplish the following:

 

1. Plot the average and original on the same chart.

 

Could you please help me here as well?

 

 

FrontPanel.PNG

BlockDiagram.PNG

 

Thank you

 

 

0 Kudos
Message 3 of 15
(9,203 Views)

@anand32 wrote:

Thank you.

 

That really did help.

 

The averaged signal is no longer a straight line but is behaving as it should.

 

To improve the VI further, we need to accomplish the following:

 

1. Plot the average and original on the same chart.

 

Could you please help me here as well?

 

 

FrontPanel.PNG

BlockDiagram.PNG

 

Thank you

 

 


This thread has a running average.

 

 

Ben

 

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 15
(9,186 Views)

1.  You should use the autoindexing tunnel inside of the FOR loop.  You are just averaging the same value repeatedly.

 

2.  No need for the To DDT.

 

3. Use Build Array to make an array of waveforms.  That will be wired to the graph.


GCentral
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 15
(9,166 Views)

Thank you

 

Regarding the autoindexing tunnel for "FOR" loop, am I not already doing that?

I mean, if you look at the left wall of the "FOR " Loop, one of the tunnels is auto-indexed, is it not?

 

Please advise.

 

Vishal Anand 

0 Kudos
Message 6 of 15
(9,163 Views)

@anand32 wrote:

I mean, if you look at the left wall of the "FOR " Loop, one of the tunnels is auto-indexed, is it not?


But you need the indexed data inside of the loop, not the ENTIRE array.  The Mean PtByPt takes a single element and calculates the moving average.  In your current setup, you are just averaging the first (or possibly last, depending on how the To DDT works) element over and over again.  You need to use the indexing loop to process all of the data in order.


GCentral
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 7 of 15
(9,124 Views)

Okay. Thank again.

 

I incorporated your suggestion and it seems to work fine for the simulated signal. But when I sample a real (physical) channel, the average signal graph remains blank.

 

Please see the pictures below.

 

 

FrontPanel.PNG

BlockDiagram.PNG

 

Please advise. 

 

Thank you once more.

 

 

0 Kudos
Message 8 of 15
(9,118 Views)

That is because you are losing your T0 (start time) for your waveform.  To make your life easier, only extract the Y from the first waveform and only update the Y for the moving average waveform.  Now just wire the original waveform to the top of the Set Waveform Components, just like a Bundle By Name.  This will reuse the T0 and dt from the original waveform.

 

And as a side note, the Time Loop is mostly a waste in a Windows application.  Just replace it with a normal While loop.  To set the loop rate, tell the DAQmx Read to read 1 second's worth of data.


GCentral
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
Message 9 of 15
(9,105 Views)

Thank you so much.

As always, you were spot on with your advice. I am learning a lot from you.

 

Moving on, I would like to take average of many signals

 

I have made a VI which takes 2 signals and averages them individually, by invoking a separate for loop for each.

 

However, I think it can be improved. Using this method for more  signals will make the file  very large. 

 

Can you Help me write a VI which can

 

1.  average multiple signals a little more efficiently (if possible)

2. Plot the multiple signals on the same chart.

 

 

FrontPanel.PNGBlockDiagram.PNGThank you

 

0 Kudos
Message 10 of 15
(9,101 Views)