02-16-2023 03:07 PM
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.
02-16-2023 04:09 PM
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
02-16-2023 06:31 PM
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.
02-16-2023 08:17 PM - edited 02-16-2023 08:25 PM
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
02-16-2023 11:51 PM
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
02-17-2023 02:23 PM
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)
02-18-2023 11:54 AM
02-20-2023 11:35 AM
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.
02-20-2023 01:17 PM
Hi Steven,
@StevenD wrote:
I did use some of your simplifications, added a few of my own,
Well:
02-20-2023 01:29 PM
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.