I have to design an 8th-order IIR filter with the following transfer function magnitude response as a specification:

enter image description here

I use "ellip" function from matlab to calculate the unquantised coefficient set:

enter image description here

Then i implement the filter using a cascade of second-order sections using "tf2sos" matlab function:

enter image description here

And then i quantize these coefficients:

enter image description here

After all these steps i take the two matrices below:

enter image description here

I choose the filter representation for every second-order instance to be like below (Direct Form 2):

enter image description here

  • circle with "X" is a multiplication
  • circle with "Σ" is an addition
  • and the triangle is a delay element

After that i have done all of these i write some matlab code to model the structure above:

%Implementation of a second-order filter structure

%The filter routine when fed with an input sample produce one output
%sample each time it is called

%x=input value
%a=array containing feedback coefficients[1,a1,a2]
%b=array containing feed forward coefficients[b0,b1,b2]
%state=array(of length 2) containing old input values
%y=output value

%compute output value
pointer=rem(pointer+1,2); %update pointer in modulo form

%Update states 

%Overwrite oldest sum with b(N-1).x
pointer=rem(pointer+1,2);%Increment pointer modulo-(N-1)

At the end, and the point that i don't know how to do it properly is how i can display the impulse and step response of the whole filter and not for every second order section.

For example if i write something like that, i think i take the impulse response of the first second order section. How i can take the impulse resonse of the whole system?



%impulse invariant design
impsv=zeros([1,2]);%impulse response state variable
stpsv=zeros([1,2]);%step response state variable
len=20; % run length
impy=zeros([1,len]);%impulse response result
stpy=zeros([1,len]);% step response result

% Simulation of filter operation

for k=1:len
  • $\begingroup$ You should use zpk2sos instead of tf2sos. tf is not good for high order filters $\endgroup$
    – endolith
    Jul 1, 2013 at 1:35

1 Answer 1


Not sure I follow completely, but is this the question: how to obtain the impulse and step response of a filter that is realized as a cascade of second or sections? or are you asking for working code that implements this?

Your 8th order filter is decomposed into 4 second order sections. The ordering is not really important here. For any input $x$ to your 8th order filter you compute the output $y$ by first filtering the input with the first second order section $SOS_1$ to get output $s_1$, that is $s_1 = SOS_1*x$ (the $*$ means processing the $x$ with a second order difference equation with coefs from $SOS$). Then that output is made input to the second SOS, that is $s_2 = SOS_2*s_1$. So now you have $s_2 = SOS_2*(SOS_1*x)$. And then continue this pattern (output from one section is input to the next) through all sections.

If you understand this, then it should also be rather obvious that you obtain the impulse response or the step response by letting an impulse or a step waveform be input to your filter and the output $y$ contains the response.

I have not looked at your code. But try to start with a simpler case first just to verify your code and your understanding of the concept.


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.