05-15-2017 10:15 AM
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 !!
05-15-2017 10:24 AM
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.
05-15-2017 10:41 AM
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?
Thank you
05-15-2017 11:04 AM
@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?
Thank you
This thread has a running average.
Ben
05-15-2017 11:33 AM
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.
05-15-2017 11:40 AM
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
05-15-2017 05:04 PM - edited 05-15-2017 05:05 PM
@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.
05-15-2017 06:41 PM - edited 05-15-2017 06:42 PM
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.
Please advise.
Thank you once more.
05-15-2017 08:16 PM - edited 05-15-2017 08:19 PM
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.
05-15-2017 08:46 PM
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.
Thank you