I have created a 3rd order Butterworth lowpass filter, and from that, a discrete version.

rate = 120.;
dt = 1/rate;
corner = 12;
tf = ButterworthFilterModel[{3, corner 2 Pi}];
tfd = ToDiscreteTimeModel[tf, dt];

I would like to transform tdf into the coefficients of the recurrence equation, so that I can implement my own recursive filter as a set of gains and delays. Is there a simple way to do this?


1 Answer 1


To get numerical values, you will need to set rate to something, I set it to 1. If you look at the internal structure of tdf, you will see that the numerator polynomial is contained in

num=tfd[[1, 1, 1, 1]]

and the denominator polynomial is in

den=tfd[[1, 2, 1, 1]]

Then you can get the list of coefficients from these using:

cnum = CoefficientList[Expand[num], \[FormalZ] ]
{428631., 1.28589*10^6, 1.28589*10^6, 428631.}

dnum = CoefficientList[Chop[Expand[den // N]], \[FormalZ] ]
{406486., 1.26257*10^6, 1.308*10^6, 451982.}

These will be the coefficients of the filter which you can implement using RecurrenceFilter, for instance:

RecurrenceFilter[{Reverse[cden], Reverse[cnum]}, in]

where in is the input to the filter.

Alternatively, if you prefer to implement the filyter in state space form, you can find the value of the a,b,c matrices using:

Normal[StateSpaceModel[tfd]] // N
  • $\begingroup$ Thanks! I did actually set a rate=120. However, when I then attempt:cnum = CoefficientList[Expand[num], [FormalZ]] cden = CoefficientList[Chop[Expand[den // N]], [FormalZ]] in = Join[{1}, ConstantArray[0, n - 1]]; out = RecurrenceFilter[{cden, cnum}, in]; I get something that does not look correct. $\endgroup$
    – abwatson
    Commented Feb 23, 2017 at 0:33
  • 1
    $\begingroup$ Well -- look at cnum and look at cden and see if they make sense. Saying only that "it does not look correct" is not particularly helpful. $\endgroup$
    – bill s
    Commented Feb 23, 2017 at 1:17
  • $\begingroup$ num = tfd[[1, 1, 1, 1]]; den = tfd[[1, 2, 1, 1]]; cnum = CoefficientList[Expand[num], [FormalZ]]; cden = CoefficientList[Chop[Expand[den // N]], [FormalZ]]; n = 120; in = Join[{1}, ConstantArray[0, n - 1]]; out1 = RecurrenceFilter[tfd, in]; out2 = RecurrenceFilter[{cden, cnum}, in]; The two results are completely different. Not sure how to show a plot or output in a comment. $\endgroup$
    – abwatson
    Commented Feb 23, 2017 at 2:50
  • $\begingroup$ If you look at cnum and cden, then you will see why your answers do not align. Coefficient list is pulling the coefficients out from the tfd in the opposite order from that which you seem to expect. In other words: use RecurrenceFilter[{Reverse[cden], Reverse[cnum]}, in] $\endgroup$
    – bill s
    Commented Feb 23, 2017 at 4:25
  • $\begingroup$ Aha! I actually had this thought as I was waking this morning. Clearly just a good nights sleep was required. $\endgroup$
    – abwatson
    Commented Feb 23, 2017 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.