First Order Filter

Originally posted by Peter Nachtwey:

The noise above the cut off frequency is attenuated at -40 db per decade instead of -20 db per decade for a first order filter...

All second order filter will roll off at -40dB per decade, even two first order filters in series...sooner or later.

Originally posted by Peter Nachtwey:

...and the cut off between between the high and low frequencies is much sharper. Some people call the cut off frequency the corner frequency.

This is where the Butterworth design (or any other two-pole filter that allows placement of imaginary poles) excels over the two first order filters in series, at least the way I calculate filter constants. I don't know how to calculate coefficients for imaginary poles. You can adjust the sharpness of the roll-off by locating the poles differently.

Keith
 
kamenges said:
I don't know how to calculate coefficients for imaginary poles. You can adjust the sharpness of the roll-off by locating the poles differently.
Keith
Yes, changing the pole locations will affect both the magnitude and phase of the response. The PID tuning technique I use is called pole placement. I can place the poles anywhere to get the response I want but normally I place the poles on the negative real axis so there is no overshoot.

If you took a digital signal processing class you would need to learn all about this. However, I am just trying raise the high bar a little by showing how a second order filter can be implemented on a PLC. Note, I have never taken a digital signal processing class. I learned from the school of hard knocks.

Back to the Butterworth filter.

The first two pages just compares the frequency response of the 2 pole Butterworth filter, the low pass filter present above, and a two pole low pass filter which can be implemented as cascaded simple low pass filters. Perhaps two cascade low pass filters is good enough. However, the Butterworth filter doesn't affect the signal as much below the corner or cut off frequency as the two pole low pass filter does.

ftp://ftp.deltacompsys.com/public/NG/Mathcad - Butterworth PLC.pdf

The equations for B0, A1 and A2 can easily be computed in a compute block or in ST. The run time part is easy but now one must keep track of the last two outputs instead of the the last output.
 
Peter Nachtwey said:
I learned from the school of hard knocks.

I hate that school. The dean is a real jerk. And I never seem to get good grades there - I usually have to repeat a course several times before I get it.
 
Thanks, Peter. I'll probably start using that as I go along. It's easy enough to calculate and definitely provides better performance.

So now the next step. I believe what makes a Butterworth filter a Butterworth filter is that the poles are place equidistant around a circle centered on 0 with a radius equal to wc in radians per second. The damping ratio you show in your PDF needs to be what it is because that will place the poles as stated. If I want a 4-pole Butterworth filter I suspect I can do that with two cascaded 2-pole Butterworth filters but will use damping ratio of 0.9238 for one stage and a damping ratio of 0.3827 for the other.

Correct or way off?
Keith
 
Hmm,

something I don't understand here. Continuous transfer function of two pole Butterworth filter is (with data given in the .pdf file):
H = 1/(0.02533s^2+0.2251s+1). Now I cannot figure out which z-transform rule will give discrete transfer function of this filter in form y(n)=A1*y(n-1)+A2*y(n-2)+B0*x(n)? Can you explain this more?
 
Alaric said:
I hate that school. The dean is a real jerk. And I never seem to get good grades there - I usually have to repeat a course several times before I get it.
And you never graduate or at least hope not to.



Keith said:
Thanks, Peter. I'll probably start using that as I go along. It's easy enough to calculate and definitely provides better performance.

So now the next step. I believe what makes a Butterworth filter a Butterworth filter is that the poles are place equidistant around a circle centered on 0 with a radius equal to wc in radians per second. The damping ratio you show in your PDF needs to be what it is because that will place the poles as stated. If I want a 4-pole Butterworth filter I suspect I can do that with two cascaded 2-pole Butterworth filters but will use damping ratio of 0.9238 for one stage and a damping ratio of 0.3827 for the other.

Correct or way off?
Keith
See this. I used the Tustin approximation for this one.
ftp://ftp.deltacompsys.com/public/PDF/Mathcad - Butterworth.pdf

Pandiani said:
Now I cannot figure out which z-transform rule will give discrete transfer function of this filter in form y(n)=A1*y(n-1)+A2*y(n-2)+B0*x(n)? Can you explain this more?
Using Tustin's approxmaition will introduce a zero in the z domain and the form wil be:
y(n)=A1*y(n-1)+A2*y(n-2)+B0*x(n)+B1*x(n-1)?

I used MZT ( matched Z transforms ). MZT does not introduce the zero in the z domain. Where did it come from? Should the zero in the z-domain be there when there isn't a zero in the s domain? Most people use the Tustin approximation but it is just an approximation. There isn't much on the web about MZT. I can post more if you want but it will 'reek of geek'.

The MZT version has one less multiply and add and one less value to keep track of. I am trying to KISS as much as I can.
 
Well I can't even try to follow the maths and theories behind these equations; I would need to invest alot of time to catch up on 30 years of inactivity in this department!

However, by using the examples given and doing some of my own examples in excel, I can see how a 2 pole and 4 pole butterwotrh filters can knock the spots off a simple first order filter.

The only drawback I can see with the butterworth filter is for the need to properly calculate the ceofficients: an incorrect coefficient in a first order filter will simply result in either no noise attenuation or overdamping of the signal whereas incorrect coefficients in a butterworth filter can actually accentuate the effect of noise. This will require careful selection of the required cutoff frequency and the sample time.
 
burnerman said:
Well I can't even try to follow the maths and theories behind these equations; I would need to invest alot of time to catch up on 30 years of inactivity in this department!
30 years ago this was done using OP-AMPs, capacitors and resistors. They didn't have DSPs back then.

All you need to do is calculate B0, A1, A2 and then use 1 row for each time period that implements y(row)=A1*y(row-1)+A2*y(row-2)+B0*x(row)

You don't need to understand how I came up with the formula. Just plug and chug.

However, by using the examples given and doing some of my own examples in excel, I can see how a 2 pole and 4 pole butterwotrh filters can knock the spots off a simple first order filter.
Good, so can you take your excel code and translate it to PLC code?

The only drawback I can see with the butterworth filter is for the need to properly calculate the ceofficients: an incorrect coefficient in a first order filter will simply result in either no noise attenuation or overdamping of the signal whereas incorrect coefficients in a butterworth filter can actually accentuate the effect of noise.
Ah but as you pointed out there is an easy check. The sum of B0,A1, and A2 must be 1. Notice that I included that for you to prove you right. Also, once you get the formulas right for calculating the coefficients right in you spread sheet then you can use them to very the calculations in the PLC program.

When in doubt you can always use two low pass filters and use the output of the first one as the input to the second filter.

This will require careful selection of the required cutoff frequency and the sample time.

Usually one is trying to get rid of 50-60Hz hum. Most other noise is much higher. Temperature system have 'frequencies' that are on the order of 0.01 Hz which is why people prefer to use time constants. A corner frequency at 1 Hz will do fine if the sample rate is much higher. A motion control application usually tops out at about 5 to 10 Hz. If I am sampling at 1000Hz then I know the filter corner frequency must be in between what I need and what I must filter. I usually use a geometric mean or sqrt(10Hz*1000Hz)=100Hz. If 50Hz is a problem and my system must move at 5 Hz then I would move the filter down to sqrt(5*50)=22 Hz.

For most PLC work just start with 1 Hz like I did and adjust from there. All you need to do is recalculate omega which should be easy to do one the PLC program is working.
 
Peter, I've found more on Matched Z transform. Never really heard of it before. I used Butterworth filter on my DSP classes. As you might guess, we use Matlab to create it.
Syntax is very simple and powerful:
Code:
 [B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital
 	Butterworth filter and returns the filter coefficients in length 
 	N+1 vectors B (numerator) and A (denominator). The coefficients 
 	are listed in descending powers of z. The cutoff frequency 
 	Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to 
 	half the sample rate.

So, for this particular example (T = 0.01 and w = 2*pi)
result would be:
Code:
 0.0009447 z^2 + 0.001889 z + 0.0009447
 --------------------------------------
 		z^2 - 1.911 z + 0.915

which is same as if Tustin approximation Z transform is used on continuous transfer function.
At the first glance, Matched Z transform looks better to be used, every zero and pole in "s" domain is mapped to correcponding zero and pole in "z" domain. No new zeros or poles are introduced in the discrete transfer function. Also very handy property of sum of coefficients equals 1 is very helpful for checking.

However, since there is so little about it comparing with "zoh" or "tustin", I must conclude that there must be some drawbacks.
First I notice, it will change the gain, but that can be compensated. So, what's the trick here? Is the frequency response of Matched Butterworth filter worse than Butterworth's with Tustin?
There must be something here, otherwise Matched "z" transform would be general knowledge... :)
 
Pandiani said:
Code:
0.0009447 z^2 + 0.001889 z + 0.0009447
--------------------------------------
		z^2 - 1.911 z + 0.915
which is same as if Tustin approximation Z transform is used on continuous transfer function.
You can see there are zeros.
Matlab makes calculating the coefficients so easy but there is no understanding of the math used to create them.

However, since there is so little about it comparing with "zoh" or "tustin", I must conclude that there must be some drawbacks.
First I notice, it will change the gain, but that can be compensated.
Obviously I have done that. The draw back it that one must understand how to do the substitution. One must understand Euler's identity. However, once the formula for the coefficients are worked out it easier to implement. The approximate solution requires keeping track of the last two inputs.

So, what's the trick here? Is the frequency response of Matched Butterworth filter worse than Butterworth's with Tustin?
That is a good question. The MZT should be exact whereas Tustin is just an approximation. This will make a difference when the frequency approaches half the sample frequency. The approximation methods require frequency warping.

There must be something here, otherwise Matched "z" transform would be general knowledge... :)
Doing the calculations to compute the coefficients takes a little effort, much more than Tustin's approximation requires.
 
Peter Nachtwey said:
All you need to do is calculate B0, A1, A2 and then use 1 row for each time period that implements y(row)=A1*y(row-1)+A2*y(row-2)+B0*x(row)

You don't need to understand how I came up with the formula. Just plug and chug.


Good, so can you take your excel code and translate it to PLC code?


Ah but as you pointed out there is an easy check. The sum of B0,A1, and A2 must be 1. Notice that I included that for you to prove you right. Also, once you get the formulas right for calculating the coefficients right in you spread sheet then you can use them to very the calculations in the PLC program.

When in doubt you can always use two low pass filters and use the output of the first one as the input to the second filter.



Usually one is trying to get rid of 50-60Hz hum. Most other noise is much higher. Temperature system have 'frequencies' that are on the order of 0.01 Hz which is why people prefer to use time constants. A corner frequency at 1 Hz will do fine if the sample rate is much higher. A motion control application usually tops out at about 5 to 10 Hz. If I am sampling at 1000Hz then I know the filter corner frequency must be in between what I need and what I must filter. I usually use a geometric mean or sqrt(10Hz*1000Hz)=100Hz. If 50Hz is a problem and my system must move at 5 Hz then I would move the filter down to sqrt(5*50)=22 Hz.

For most PLC work just start with 1 Hz like I did and adjust from there. All you need to do is recalculate omega which should be easy to do one the PLC program is working.



Yeah, no problem implementing this in a plc, although I always prefer to know why I'm doing something not just how I'm doing it.

I will take the time to try and re-learn the maths, I think that there may be fragments left somewhere in the grey matter that just need joining together again. It would be useful because I know now that alot of this area of maths can be used for optimising PID control as well; after 30 years of trial and error (and your old favourite Zeiger Nicholls!) maybe it's time I adopted a more scientific approach.

The partcular area I'm interested in at the moment is for the pressure control loop in incinerators and cremators to filter out small incursions in pressure caused by sporadic combustion events and pulses occuring when burners are ignited. I haven't collected any data yet but I would guess that these are in the area of 1 - 0.5 Hz.

I've yet to see a plant with a well set up pressure control loop and I am aiming to succeed where others have failed.
 
It isn't part of the language or specification so y'all ( I don't want to be mistaken for Prince Charles ) can't count on it being available in all implementations of ST. It is so easy to roll your own. The responses to this question are good. Is anybody ready for the next step?

How about a two pole Butterworth filter? Implementing a Butterworth filter is just a little more work but the filtering is so much better.


+1!
I would be very interested in learning more. Where do I go?

OOPS! I just realized how old this thread is. Sorry.
 
Last edited:
http://deltamotion.com/peter/Mathcad/Mathcad - Butterworth NG.pdf
I probably made this second example just for this thread
http://deltamotion.com/peter/Mathcad/Mathcad - Butterworth PLC.pdf

This following is smoothing, not filtering' because it is done after the data is collected and the smoothing uses points in the future as well as the past. You can see it works well.
The Savitsky-Golay filter results in coefficients for a formula that will best fit a set of data points. This is more sophisticate than the linear least squares fit. This can generated coefficients for second, third, forth etc order polynomials but it is best kept to second or 3rd order.
http://deltamotion.com/peter/Mathcad/Mathcad - holoborodko.pdf




This is a little more advanced.
This is an alpha-beta-gamma filter which is basically like a static Kalman filter but you get 95% of the benefit with 5% of the effort.
http://deltamotion.com/peter/Maxima/ABG.html

I have a lot of examples that simply occupy space on a web server some where. These examples are lonely and often times feel unwanted. :(
 

Similar Topics

Afternoon all, I'm working on setting up a large excel recipe table for porting updates through the Linx Gateway RTD/DDE function into my recipe...
Replies
2
Views
110
We are trying to poll data coming from a PLC for remote monitoring we have the IP address of the PLC and the default port number and the path is...
Replies
25
Views
578
Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,362
Hello, I have been looking for a reference for the order that a UDT is copied in the COP instruction. More specifically - I have a set of code...
Replies
5
Views
548
Hello all, I got a session with the network guys that never deals with Profinet before. One of a comment to me was "can you make it not scan the...
Replies
5
Views
1,023
Back
Top Bottom