I have used the cheby2 routine in Matlab to design a simple low-pass filter of order 2. However, the cutoff frequency is very low at 0.001. This filter works on my input signal as a second-order filter, but when I try to increase the order of the filter for better stop-band attenuation, it goes unstable. Besides down-sampling the input signal in order to raise the cutoff frequency of the LP filter, does anyone know of a trick to make my filter stable with a very low cutoff frequency?
Low Pass Digital Filter Stability Question
Started by ●January 31, 2011
Reply by ●January 31, 20112011-01-31
On 1/31/2011 3:50 PM, j26 wrote:> I have used the cheby2 routine in Matlab to design a simple low-pass filter > of order 2. However, the cutoff frequency is very low at 0.001. This > filter works on my input signal as a second-order filter, but when I try to > increase the order of the filter for better stop-band attenuation, it goes > unstable. Besides down-sampling the input signal in order to raise the > cutoff frequency of the LP filter, does anyone know of a trick to make my > filter stable with a very low cutoff frequency?Yeah, don't go any farther than second order or it'll go unstable. Less sarcastically, what you want to do is break your filter up into second-order sections, each one representing either a pair of real poles or (more likely) a complex pole-pair. Under Octave there are some functions beginning with "sos" that work on those sorts of things; there's probably something similar in Matlab. By the way, by the time you've got your coefficients out in transfer function [b, a] format, floating point errors have already killed you. Stick to zeros and poles until you've got the order down. -- Rob Gaddi, Highland Technology Email address is currently out of order
Reply by ●January 31, 20112011-01-31
On 01/31/2011 03:54 PM, Rob Gaddi wrote:> On 1/31/2011 3:50 PM, j26 wrote: >> I have used the cheby2 routine in Matlab to design a simple low-pass >> filter >> of order 2. However, the cutoff frequency is very low at 0.001. This >> filter works on my input signal as a second-order filter, but when I >> try to >> increase the order of the filter for better stop-band attenuation, it >> goes >> unstable. Besides down-sampling the input signal in order to raise the >> cutoff frequency of the LP filter, does anyone know of a trick to make my >> filter stable with a very low cutoff frequency? > > Yeah, don't go any farther than second order or it'll go unstable. > > Less sarcastically, what you want to do is break your filter up into > second-order sections, each one representing either a pair of real poles > or (more likely) a complex pole-pair. Under Octave there are some > functions beginning with "sos" that work on those sorts of things; > there's probably something similar in Matlab.Really, you should keep the real poles as 1st order. But you'll generally only ever have one, and then only if your filter has odd order.> By the way, by the time you've got your coefficients out in transfer > function [b, a] format, floating point errors have already killed you. > Stick to zeros and poles until you've got the order down. >Yup. The underlying problem is the representation of the transfer function as a ratio of polynomials -- polynomial roots can be _very_ sensitive to coefficient variation as the order goes up, which is _not_ what you need in a case like this. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●January 31, 20112011-01-31
>On 1/31/2011 3:50 PM, j26 wrote: >> I have used the cheby2 routine in Matlab to design a simple low-passfilter>> of order 2. However, the cutoff frequency is very low at 0.001. This >> filter works on my input signal as a second-order filter, but when I tryto>> increase the order of the filter for better stop-band attenuation, itgoes>> unstable. Besides down-sampling the input signal in order to raise the >> cutoff frequency of the LP filter, does anyone know of a trick to makemy>> filter stable with a very low cutoff frequency? > >Yeah, don't go any farther than second order or it'll go unstable. > >Less sarcastically, what you want to do is break your filter up into >second-order sections, each one representing either a pair of real poles >or (more likely) a complex pole-pair. Under Octave there are some >functions beginning with "sos" that work on those sorts of things; >there's probably something similar in Matlab. > >By the way, by the time you've got your coefficients out in transfer >function [b, a] format, floating point errors have already killed you. >Stick to zeros and poles until you've got the order down. > >-- >Rob Gaddi, Highland Technology >Email address is currently out of order >So basically, I want to feed the signal through a series of 1st and 2nd order filters or would I get the same result by leaving everything in pole-zero form? How do I process a signal using poles and zeros without using the filter coefficients? As I recall, the coefficients come from the poles and zeros. I apologize if this is a dumb question, I'm just a bit rusty. I did suspect that rounding errors were my problem. Also, is a 4th order cheby filter the same as 2 second order cheby filters in series?
Reply by ●January 31, 20112011-01-31
On 01/31/2011 04:59 PM, j26 wrote:>> On 1/31/2011 3:50 PM, j26 wrote: >>> I have used the cheby2 routine in Matlab to design a simple low-pass > filter >>> of order 2. However, the cutoff frequency is very low at 0.001. This >>> filter works on my input signal as a second-order filter, but when I try > to >>> increase the order of the filter for better stop-band attenuation, it > goes >>> unstable. Besides down-sampling the input signal in order to raise the >>> cutoff frequency of the LP filter, does anyone know of a trick to make > my >>> filter stable with a very low cutoff frequency? >> >> Yeah, don't go any farther than second order or it'll go unstable. >> >> Less sarcastically, what you want to do is break your filter up into >> second-order sections, each one representing either a pair of real poles >> or (more likely) a complex pole-pair. Under Octave there are some >> functions beginning with "sos" that work on those sorts of things; >> there's probably something similar in Matlab. >> >> By the way, by the time you've got your coefficients out in transfer >> function [b, a] format, floating point errors have already killed you. >> Stick to zeros and poles until you've got the order down. >> >> -- >> Rob Gaddi, Highland Technology >> Email address is currently out of order >> > > So basically, I want to feed the signal through a series of 1st and 2nd > order filters or would I get the same result by leaving everything in > pole-zero form? How do I process a signal using poles and zeros without > using the filter coefficients? As I recall, the coefficients come from the > poles and zeros.You make a bunch of 2nd-order filters and you cascade them, by feeding the output of filter1 into the input of filter2, etc. In Scilab you can make one filter in state-space form, that takes care of this for you (at least when you run the filter). I don't know if Matlab has the equivalent, and if so if you can get it without buying some $$$$ toolbox.> I apologize if this is a dumb question, I'm just a bit > rusty. I did suspect that rounding errors were my problem.No problem -- that's why we're here.> Also, is a 4th > order cheby filter the same as 2 second order cheby filters in series?No -- in general the "named" filters have poles that do not lie atop one another. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●January 31, 20112011-01-31
Ok, so it sounds like the approach for filtering is to use state-space form in order to avoid having to filter in the time domain via filter coefficients (and associated rounding errors)? I still want to design the filter experimentally (via genetic algorithm - differential evolution) using the approach outlined in this paper: http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBMQFjAA&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.33.5676&rct=j&q=Differential%20Evolution%20Design%20of%20an%20IIR-Filter%20with%20Requirements%20for%20Magnitude%20and%20Group%20Delay&ei=dGdHTY7QLI-osAPx86nWAg&usg=AFQjCNHRt09_T7ze5lsHe3J5w-RPwhfDDA&cad=rja (sorry for the long link). So the algorithm described there will give me a set of poles and zeros to use. What's the best ways to take those poles/zeros and use them to filter, preferably in Java.>On 01/31/2011 04:59 PM, j26 wrote: >>> On 1/31/2011 3:50 PM, j26 wrote: >>>> I have used the cheby2 routine in Matlab to design a simple low-pass >> filter >>>> of order 2. However, the cutoff frequency is very low at 0.001.This>>>> filter works on my input signal as a second-order filter, but when Itry>> to >>>> increase the order of the filter for better stop-band attenuation, it >> goes >>>> unstable. Besides down-sampling the input signal in order to raisethe>>>> cutoff frequency of the LP filter, does anyone know of a trick tomake>> my >>>> filter stable with a very low cutoff frequency? >>> >>> Yeah, don't go any farther than second order or it'll go unstable. >>> >>> Less sarcastically, what you want to do is break your filter up into >>> second-order sections, each one representing either a pair of realpoles>>> or (more likely) a complex pole-pair. Under Octave there are some >>> functions beginning with "sos" that work on those sorts of things; >>> there's probably something similar in Matlab. >>> >>> By the way, by the time you've got your coefficients out in transfer >>> function [b, a] format, floating point errors have already killed you. >>> Stick to zeros and poles until you've got the order down. >>> >>> -- >>> Rob Gaddi, Highland Technology >>> Email address is currently out of order >>> >> >> So basically, I want to feed the signal through a series of 1st and 2nd >> order filters or would I get the same result by leaving everything in >> pole-zero form? How do I process a signal using poles and zeroswithout>> using the filter coefficients? As I recall, the coefficients come fromthe>> poles and zeros. > >You make a bunch of 2nd-order filters and you cascade them, by feeding >the output of filter1 into the input of filter2, etc. > >In Scilab you can make one filter in state-space form, that takes care >of this for you (at least when you run the filter). I don't know if >Matlab has the equivalent, and if so if you can get it without buying >some $$$$ toolbox. > >> I apologize if this is a dumb question, I'm just a bit >> rusty. I did suspect that rounding errors were my problem. > >No problem -- that's why we're here. > >> Also, is a 4th >> order cheby filter the same as 2 second order cheby filters in series? > >No -- in general the "named" filters have poles that do not lie atop one >another. > >-- > >Tim Wescott >Wescott Design Services >http://www.wescottdesign.com > >Do you need to implement control loops in software? >"Applied Control Theory for Embedded Systems" was written for you. >See details at http://www.wescottdesign.com/actfes/actfes.html >
Reply by ●January 31, 20112011-01-31
On 1/31/2011 5:58 PM, j26 wrote:> Ok, so it sounds like the approach for filtering is to use state-space form > in order to avoid having to filter in the time domain via filter > coefficients (and associated rounding errors)? I still want to design the > filter experimentally (via genetic algorithm - differential evolution) > using the approach outlined in this paper: > > http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBMQFjAA&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.33.5676&rct=j&q=Differential%20Evolution%20Design%20of%20an%20IIR-Filter%20with%20Requirements%20for%20Magnitude%20and%20Group%20Delay&ei=dGdHTY7QLI-osAPx86nWAg&usg=AFQjCNHRt09_T7ze5lsHe3J5w-RPwhfDDA&cad=rja > > (sorry for the long link). So the algorithm described there will give me a > set of poles and zeros to use. What's the best ways to take those > poles/zeros and use them to filter, preferably in Java. > >> On 01/31/2011 04:59 PM, j26 wrote: >>>> On 1/31/2011 3:50 PM, j26 wrote: >>>>> I have used the cheby2 routine in Matlab to design a simple low-pass >>> filter >>>>> of order 2. However, the cutoff frequency is very low at 0.001. > This >>>>> filter works on my input signal as a second-order filter, but when I > try >>> to >>>>> increase the order of the filter for better stop-band attenuation, it >>> goes >>>>> unstable. Besides down-sampling the input signal in order to raise > the >>>>> cutoff frequency of the LP filter, does anyone know of a trick to > make >>> my >>>>> filter stable with a very low cutoff frequency? >>>> >>>> Yeah, don't go any farther than second order or it'll go unstable. >>>> >>>> Less sarcastically, what you want to do is break your filter up into >>>> second-order sections, each one representing either a pair of real > poles >>>> or (more likely) a complex pole-pair. Under Octave there are some >>>> functions beginning with "sos" that work on those sorts of things; >>>> there's probably something similar in Matlab. >>>> >>>> By the way, by the time you've got your coefficients out in transfer >>>> function [b, a] format, floating point errors have already killed you. >>>> Stick to zeros and poles until you've got the order down. >>>> >>>> -- >>>> Rob Gaddi, Highland Technology >>>> Email address is currently out of order >>>> >>> >>> So basically, I want to feed the signal through a series of 1st and 2nd >>> order filters or would I get the same result by leaving everything in >>> pole-zero form? How do I process a signal using poles and zeros > without >>> using the filter coefficients? As I recall, the coefficients come from > the >>> poles and zeros. >> >> You make a bunch of 2nd-order filters and you cascade them, by feeding >> the output of filter1 into the input of filter2, etc. >> >> In Scilab you can make one filter in state-space form, that takes care >> of this for you (at least when you run the filter). I don't know if >> Matlab has the equivalent, and if so if you can get it without buying >> some $$$$ toolbox. >> >>> I apologize if this is a dumb question, I'm just a bit >>> rusty. I did suspect that rounding errors were my problem. >> >> No problem -- that's why we're here. >> >>> Also, is a 4th >>> order cheby filter the same as 2 second order cheby filters in series? >> >> No -- in general the "named" filters have poles that do not lie atop one >> another. >> >> -- >> >> Tim Wescott >> Wescott Design Services >> http://www.wescottdesign.com >> >> Do you need to implement control loops in software? >> "Applied Control Theory for Embedded Systems" was written for you. >> See details at http://www.wescottdesign.com/actfes/actfes.html >>You're still not quite getting it. At the end of the day, yes, you're going to filter in the time domain, which will mean turning your poles and zeros back into time domain coefficients. What you don't want to do, however, is turn them all into one giant polynomial. You want to turn them into a cascade of polynomials, none of them more than second order. Start by going through your poles and pairing them off into complex conjugate pairs. Each of those pole pairs represents one second order section, which can be turned into a difference equation. Then you chain the output of each of those second order sections into the input of the next. If you sit down and do the math by hand of actually trying to turn all of those poles into one giant difference equation instead, what you'll find is that you're doing a whole lot of "small difference of large numbers". The inability of the computer to express that with infinite resolution is why you get an unstable result; the result you get is wrong and not a perfect match for the poles you put in. -- Rob Gaddi, Highland Technology Email address is currently out of order
Reply by ●January 31, 20112011-01-31
On Feb 1, 12:50�am, "j26" <ptd26@n_o_s_p_a_m.live.com> wrote:> I have used the cheby2 routine in Matlab to design a simple low-pass filter > of order 2. �However, the cutoff frequency is very low at 0.001. �This > filter works on my input signal as a second-order filter, but when I try to > increase the order of the filter for better stop-band attenuation, it goes > unstable. �Besides down-sampling the input signal in order to raise the > cutoff frequency of the LP filter, does anyone know of a trick to make my > filter stable with a very low cutoff frequency?You need to do a full design of your filter. If you have access to the cheb2 function of matlab, you have access to either the signal processig toolbox or the filter design tollbox from matlab. In that case you have access to more elaborate design tools (I *think* one is caled FDATOOL), that allows the novice user to do thse kinds of things without having to worry too much about the technicalities. Rune
Reply by ●February 1, 20112011-02-01
On 01/31/2011 05:58 PM, j26 wrote: (Top posting fixed)>> On 01/31/2011 04:59 PM, j26 wrote: >>>> On 1/31/2011 3:50 PM, j26 wrote: >>>>> I have used the cheby2 routine in Matlab to design a simple low-pass >>> filter >>>>> of order 2. However, the cutoff frequency is very low at 0.001. > This >>>>> filter works on my input signal as a second-order filter, but when I > try >>> to >>>>> increase the order of the filter for better stop-band attenuation, it >>> goes >>>>> unstable. Besides down-sampling the input signal in order to raise > the >>>>> cutoff frequency of the LP filter, does anyone know of a trick to > make >>> my >>>>> filter stable with a very low cutoff frequency? >>>> >>>> Yeah, don't go any farther than second order or it'll go unstable. >>>> >>>> Less sarcastically, what you want to do is break your filter up into >>>> second-order sections, each one representing either a pair of real > poles >>>> or (more likely) a complex pole-pair. Under Octave there are some >>>> functions beginning with "sos" that work on those sorts of things; >>>> there's probably something similar in Matlab. >>>> >>>> By the way, by the time you've got your coefficients out in transfer >>>> function [b, a] format, floating point errors have already killed you. >>>> Stick to zeros and poles until you've got the order down. >>>> >>>> -- >>>> Rob Gaddi, Highland Technology >>>> Email address is currently out of order >>>> >>> >>> So basically, I want to feed the signal through a series of 1st and 2nd >>> order filters or would I get the same result by leaving everything in >>> pole-zero form? How do I process a signal using poles and zeros > without >>> using the filter coefficients? As I recall, the coefficients come from > the >>> poles and zeros. >> >> You make a bunch of 2nd-order filters and you cascade them, by feeding >> the output of filter1 into the input of filter2, etc. >> >> In Scilab you can make one filter in state-space form, that takes care >> of this for you (at least when you run the filter). I don't know if >> Matlab has the equivalent, and if so if you can get it without buying >> some $$$$ toolbox. >> >>> I apologize if this is a dumb question, I'm just a bit >>> rusty. I did suspect that rounding errors were my problem. >> >> No problem -- that's why we're here. >> >>> Also, is a 4th >>> order cheby filter the same as 2 second order cheby filters in series? >> >> No -- in general the "named" filters have poles that do not lie atop one >> another.> > Ok, so it sounds like the approach for filtering is to use > state-space form > in order to avoid having to filter in the time domain via filter > coefficients (and associated rounding errors)? Slow down there -- you have to filter in the time domain, that's the domain that we live in. The state-space representation is just a convenient one if your tools conveniently support it. Scilab does. It's an easier way to get high-order filters that don't run into numerical problems that execute all in one thump -- but that's not necessarily best. > I still want to > design the > filter experimentally (via genetic algorithm - differential evolution) > using the approach outlined in this paper: > > http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBMQFjAA&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.33.5676&rct=j&q=Differential%20Evolution%20Design%20of%20an%20IIR-Filter%20with%20Requirements%20for%20Magnitude%20and%20Group%20Delay&ei=dGdHTY7QLI-osAPx86nWAg&usg=AFQjCNHRt09_T7ze5lsHe3J5w-RPwhfDDA&cad=rja > > (sorry for the long link). So the algorithm described there will give me a > set of poles and zeros to use. What's the best ways to take those > poles/zeros and use them to filter, preferably in Java. > Java? You were talking about Matlab! Java's different -- while it does have built-in functions that are faster than what you get from coding your own, none of them support filtering. So you may as well go for readable and standard. Probably a cascade of 2nd-order filters, in whichever one of the direct forms is supposed to be best for floating point math. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●February 1, 20112011-02-01
First of all, I really appreciate all the help here! Definitely! Thanks!!! Here's what I now understand. Please let me know if I got it: I want to design a low-pass filter that meets certain requirements which can be characterized / specified as frequency response and group lag constraints. Assume that I can follow the approach of the paper linked above to find the poles and zeros of the complex filter which meets these requirements. This, I envision, would be done in Java (I'd use Octave / Matlab to double-check my setup). So I end up with a collection of poles and zeros that describe my filter. Now I need to implement this filter in Java to be used in a real-time application (yes, otherwise, I could have just done everything in Octave / Matlab). The suggestion from the posts above lead me towards pairing up the poles / zeros into groups of no greater than second order such that I have a cascade of second-order filters. I then find the coefficients of these second-order filters and process the signal in the time-domain by running it through one filter at a time. If all that is true, then I think I now know how to design my filter. Although, I might ask well ask, does anyone know of an open-source / free software implementation of the algorithm described in the paper above -- some software that can output filter coefficients based upon frequency response as well as group delay constraints?






