Digital filtering - first order vs. second order

nyanpasu

Member
Join Date
Aug 2018
Location
Canada
Posts
79
I've become interested in code for digital filtering. I have read this excellent (and old) thread : http://www.plctalk.net/qanda/showthread.php?t=43380 and decided to try my luck with a Butterworth filter (zipped AOI attached).


I very briefly learned about digital filtering in school, where we learned about first order filters. I programmed one of these on the fly as well to compare. It seems that for equivalent lag time, the Butterworth filter follows more closely the original, non-distorted sine wave (see trend and sim ladder - I could have been more aggressive but eh, those are just tests). Now, the problem I'm having is that I don't really know how any of it works. I have a few questions :


- does the AOI code looks right?



- are those result representative of the performance differences between this implementation of the Butterworth and a "standard" (I used Rockwell's formula) low pass first order filter? From the tread, it seems a second order filter attenuates more aggressively undesired frequencies.



- in school I was told that sample time ought to be at least period/20 (ie. 20 samples or so) to ensure a realistic representation of the filtered signal. Does that still hold in second order filters, and/or is there a better way of choosing the value? I do sample at the same rate as my filter's sample time, right?



- how do I choose the cutoff frequency? In the thread it does say it should be about 10 times lower than the sample time. I vaguely remember the term from electronics, but what about when I'm just filtering a number? Do I just wing it until I find something tolerable (in this case I winged it)? What would be a better, more precise way?


Sorry if those are dummy questions, I'm still in school and still learning (and I expect I'll always be).


Thanks!

sim.png trend.png
 

Attachments

  • FILTRE_BUTTERWORTH.zip
    1.8 KB · Views: 10
They aren't dummy questions.

Much depends on the frequency you want to filter out and what frequency you want to keep. I usually set the cut off frequency to roughly the geometric mean between these two values.

If trying to reduce 60 Hz noise and the frequency you are trying to keep is at 10 Hz then put the filter roughly at the sqrt(10*60) = 24.5 but 30 will do. Since the Butterworth filter reduces noise at 6 db per octave per pole you would reduce the noise by about a factor of about 12 db

https://deltamotion.com/peter/Mathcad/Mathcad - Butterworth PLC.pdf
https://deltamotion.com/peter/Mathcad/Mathcad - Butterworth NG.pdf

We use 2 and 4 pole Butterworth filters in a motion controllers
 
Thanks a lot for the reply. Setting the cutoff as a mean of the frequencies you want to keep and filter makes sense.

Playing with my AOI I noticed that as I increased the cutoff frequency, B0 would eventually get to 1. The coefficients seem to act like weights for the past filtered and present raw measures in order to balance the amount of past and present in the new filtered value. So at a high cutoff, that B0 would = 1 makes sense since there comes a point where you aren't filtering anything, so it's just the raw value coming through. I would have another question if you don't mind, why is it that sometimes one of the other coefficients is negative? How come there are times where we want to take a negatively weighted measure into account in the filtering?
 
Playing with my AOI I noticed that as I increased the cutoff frequency, B0 would eventually get to 1. The coefficients seem to act like weights for the past filtered and present raw measures in order to balance the amount of past and present in the new filtered value. So at a high cutoff, that B0 would = 1 makes sense since there comes a point where you aren't filtering anything, so it's just the raw value coming through.
Yes

I would have another question if you don't mind, why is it that sometimes one of the other coefficients is negative? How come there are times where we want to take a negatively weighted measure into account in the filtering?
First, look at page 3/4 half way down in
https://deltamotion.com/peter/Mathcad/Mathcad - Butterworth PLC.pdf
where it say the sum of coefficients must add up to 1.
This is a good check to make sure your coefficient calculations are correct.
The real answer requires knowledge of pole location in the z-domain. The Butterworth filter has two complex poles in the Z domain. Poles inside the unit circle will cause the response to decay, these are negative poles. Positive poles are outside unit circle are positive and cause the response to "blow up". Negative poles result in exponential terms like exp(-αt). This will decay to 0. Positive poles will result in terms like exp(αt). This will "blow up". The negative poles result in negative coefficients.
In the case of the 2 pole Butterworth filter there are two poles. -α+iβ and -α-iβ. The imaginary part is what adds the sine or cosine terms to any response.
 

Similar Topics

Question to anyone with ideas about my thoughts on upgrading a very vintage timer, which is being used to switch between 2 5hp domestic water...
Replies
14
Views
425
I have a PLC type PM856 from ABB with some I/O modules and I get an error from the Digital Inputs model type DI801. The unit status shows error...
Replies
0
Views
260
I am monitoring two BMXDDO3202K digital outputs for their behaviour, they are each for opening and closing, and so the on time affects how far the...
Replies
1
Views
277
On the laser displacement sensor now connected to my PLC, the manual says 4mA=643 and 20mA=64,877. However, I checked with a Fluke, injecting...
Replies
5
Views
881
I'm new to S7/TIA. There's no devices connected to the PLC yet. I've got a laser measurement sensor (Micro-Epsilon optoNCDT 1220). From the...
Replies
18
Views
2,927
Back
Top Bottom