LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Software filter for signal with spike

I've got a project that reads several pressure signals (analog 0-10 vdc). Two of my signals come from solenoid operated pressure regulators. In a static situation, these signals are pretty steady. However when given a set point they can spike by large numbers (I've seen over 1 volt spike in the signal). I would like to filter out these spikes, but am not sure which filter would best be suited for this. I believe I want a FIR filter or average since the spike can be so large, I don't want remnants of it hanging around. My DAQ rate is pretty low, 4S/sec. I was thinking of making my own, something along the line of keeping an array of 10 values and ignoring the high and the low, but there is a better built in filter I would be interested in using that. I am just not familiar enough with the different filters to know which one would be appropriate. 

0 Kudos
Message 1 of 13
(1,660 Views)

You might want to consider a median filter, which is especially useful for eliminating "spikes" and single outliers.  

 

First you should better characterize the duration of the "spike" you get from energizing / de-energizing the solenoid.  Then make sure you set the median filter width to be bigger.

 

For example, let's suppose the spike duration can be 80 msec.  You could sample at 20 Hz which would give you samples every 50 msec.  The spike lasts for 1.6 samples worth of time, so you set the median filter width to 2 samples to be bigger.   A width of 2 means that the output value will be the median of 5 samples -- 2 samples prior, 1 center sample, and 2 samples after. 

 

You'll get either 1 or 2 samples of spike data.  So as the 5-sample median filter window slides over the outlier spike samples, the output of the filter will always be one of the other 3 or 4 "normal" samples.  After the median filter eliminates the spikes, you could also "decimate by averaging" in 5 sample blocks to get back to your original 4 Hz rate.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 13
(1,647 Views)

Hi Kevin,

 

How did you get 50 msec? Do you have an example code of what you are explaining? I'm also interested in this.

0 Kudos
Message 3 of 13
(1,624 Views)

Kevin said "You could sample at 20 Hz", or 20 samples/second.  The reciprocal of sampling frequency gives you sampling interval, 0.05 seconds/sample = 50 msec/sample.  The Median Filter can be found in the Signal Processing, Filters Palette.  

 

Bob Schor

0 Kudos
Message 4 of 13
(1,601 Views)

Hi Bob,


wow you simplified what Kevin said in 3 sentences. I’m pretty sure you are very good at simplification in Algebra. 😛 

 

Thanks a lot,

 

GRCK5000

0 Kudos
Message 5 of 13
(1,585 Views)

Unfortunately I do not have the hardware to characterize the signal better, but I did have some time today and made a rough simulation of what I remembered seeing and making a custom filter. The general idea is keep an array of signal inputs, sort the array and assume the points in the middle have more weight than the extremes. That worked pretty well, but the large spikes I had seen would drive the filtered signal up until that point was removed from the array so I also added the ability to reject points on the outsides of the range. It was a pretty fun little project and I am happy with the simulation data I ran through it. I will need to see how it actually works with the hardware. 

 

I call it middle biased filter.

(LV 2016)

 

middle-biased-with-cutoff.pngmiddle-biased-with-cutoff-2.png

0 Kudos
Message 6 of 13
(1,559 Views)

Hi Steven,

 

you might think about simplifying your filter, like removing unneeded FOR loops!

 

See attachment…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 13
(1,512 Views)

Thanks Gerd. I did use some of your simplifications, added a few of my own, added a few checks to re-init if the user changes parameters, added a custom warning message, and added an unexposed variable to change the weight distribution. 

 

 

0 Kudos
Message 8 of 13
(1,465 Views)

Hi Steven,

 


@StevenD wrote:

I did use some of your simplifications, added a few of my own,


Well:

  • InRangeAndCoerce with limits 1...+Inf is the same as taking the max of input und 1. There's a MinMax function…
  • The FOR loop inside the TRUE case only should contain "i" and ToDBL. All other operations can be applied to the resulting array outside the loop.
  • When you want to generate an error then you should set the status of the error cluster to TRUE…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 13
(1,452 Views)

Is there any benefit to using min max as opposed to in range and coerce?

 

The for loop CAN only include the I, but I did some tests and it runs faster as is. It is slightly less obfuscated and runs faster, so that is how I am going to leave it.

 

I specifically am using the WARNING feature of the error cluster, not an error.

0 Kudos
Message 10 of 13
(1,448 Views)