LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone know how I can average several waveforms?

I am trying to filter a nasty square wave,without affecting the rise or fall times of it. I have tried standard filtering, which helps with the noise, but is destructive to the rise and fall times. I have also tried taking the median of the signal, which is effective to a point, but I would like to try taking several single cycle or multiple cycles and averaging the the group of captured cycles. Just so its clear, I don't want the rolling average of each of the cycles, I want the point by point average of the group of averaged signals, as if they were laid on top of each other and each point is then averaged. Can anyone help me with this? I will attach a waveform example below, 3 captured cycles in wdt form,
just in case anyone has any has any good ideas about filtering without affecting rise or fall times.
0 Kudos
Message 1 of 8
(3,956 Views)
Averaging is a good way to clean up noisy signals, provided (IMPORTANT) that you can accurately sychronize the cycles. If you know precisely where each cycle starts, it should be easy to do. If all you have are the noisy waveforms and the signal frequency is not synchronous with the sampling clock, you will lose some information. Also if some of the noise is synchronized with the signal or sampling frequencies, that noise will not average out.

In one loop separate individual cycles. Make an array of those. Add the waveforms of the cycles and divide by the number of cycles to get an average. If you have large numbers of cycles, consider round-off and truncation errors.

If you do not have any way of accurately synchronizing the cycles, then the problem
may be much tougher.

Lynn
0 Kudos
Message 2 of 8
(3,956 Views)
Thank you for your suggestion. I can see from the graph of the combined signals that software triggering is not going to allow me to capture perfectly synchronized signals, they are too noisy. I was thinking of using an external vertical synch signal to trigger the signal capture. The only problem is that it sends out a pulse at 60Hz, and I need a trigger at about once a second, is there a way to only take every 60th pulse as the trigger. Maybe there is a way to generate some output from the DAQ that can be fed back into the trigger input to trigger the signal. Do you have any ideas?
0 Kudos
Message 3 of 8
(3,956 Views)
If the square wave is synchronized with the 60 Hz, that is, a new pulse is generated on the rising zero crossing of every 60th cycle of the 60 Hz reference, then you can do the same thing. Even if you don't have any way of knowing exactly which of the 60 reference pulses trigger the square wave, you would always get exactly one cycle. If it is important to display the signal at a particular phase, it gets messier. I would consider putting your averaged (cleaned up) waveform into a circular buffer and shifting it until you get the alignment you want. For continuous data acquisition you could keep track of that phase shift and adjust the "phase" of the 1 Hz segment to be averaged. Each time you make an adjustment, the averaged output would be c
orrupted until a new average appears.

Lynn
0 Kudos
Message 4 of 8
(3,956 Views)
This does sound messy, as I would need for the waveforms to be in phase. The fist reply that you gave, just gave me an idea. I have been getting fairly good results by using the median function, but it isn't good enough, and increasing the width of the median (rank) would take too much of a tole on the rise and fall times, which are very important to my application. I was thinking, however, that if there was a way that I could seperate signals at a specific point in the cycle after the wave has been captured and sent through the median function, I could then take several of those seperated waves and average them, as they would all be in phase. The median filter does a great job in the transition, and not as great in the peaks and v
alleys. Is there a way that I could do this? I will post my vi to give you a better idea of where I am at now with filtering. I am now capturing several cycles, each time median filtering, then taking the rise and fall times, then averaging the rise and fall times. All of this while flickering a picture box between grey levels.
0 Kudos
Message 5 of 8
(3,956 Views)
Median filters are good at removing extreme values but are not necessarily very good for noise. The sample selected for the median in some cases will be very far from the desired signal.

A different approach: Is your signal in the absense of noise a square wave with finite rise and fall times (a trapezoid) or does it have overshoot or ripple or some other complication in addition to the noise. If you can define the desired waveform with straightforward mathematical functions (like straight lines), perhaps curve fitting using regression would give you the result you want.

If you found the mean values of, say, the middle 0.4 seconds of the high part of each square wave (easier said than done, I know) and extracted a simila
r portion of the low parts, those two values would define tha amplitude of the signal. Then if you connected these values with lines whose slope can be varied (the rise and fall times) and fitted this to the data you could get amplitude and rise and fall times. I haven't thought through exactly how to do this but it might be workable.

How many cycles are available for processing? Does the proecessing need to be done while the the experiment is running (pseudo real time) or can it be analyzed after all the data is collected?

Lynn
0 Kudos
Message 6 of 8
(3,956 Views)
The signal is a square wave with finite rise and fall times that vary depending on grey level. The rise time also is not the same as the fall time. There is little overshoot or ringing to deal with, but there is some 60 Hz. noise associated with the refresh rate. I had an idea similar to yours. Instead of actually capturing a full signal,what about capturing just a single transition. If I were to start capturing a little before I caused a grey level change (which corresponds to a signal level change from high to low or the reverse) and continue the capture for a little after the transition, there would be a high point to average, and a low point to average, and if a straight slope could be attached between the
two time points that matched these everaged values, then a rise or fall time could be determined. For that matter, it might even be easier to just quatify that time in between thoses two averaged values. I looked around the functions library quite a bit and could figure out no way to do this. If you have any ideas, they would be appreciated. I am including a print screen copy of the waveform, see what you think.
0 Kudos
Message 7 of 8
(3,956 Views)
I have not had any time to work on this, but I think you are on the right track. If you can trigger an acquisition on each gray level change and then average the transitions, that should take care of the synchronization problems. Use a hardware signal from your gray scale changes, if available, as it is more precise than software triggering. Take readings about 0.4 seconds long and keep the rising and falling edges in different shift registers or arrays.

I have some other ideas about half baked in the back of my mind. If they develop into anything, I will post them.

Lynn
0 Kudos
Message 8 of 8
(3,956 Views)