# Impulse and step response of a system that contains cascaded second order sections

I have to design an 8th-order IIR filter with the following transfer function magnitude response as a specification: I use "ellip" function from matlab to calculate the unquantised coefficient set: Then i implement the filter using a cascade of second-order sections using "tf2sos" matlab function: And then i quantize these coefficients: After all these steps i take the two matrices below: I choose the filter representation for every second-order instance to be like below (Direct Form 2): • 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
function[y,state,pointer]=Second_Order(x,a,b,state,pointer)

%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
y=b(1)*x+state(pointer+1);
pointer=rem(pointer+1,2); %update pointer in modulo form

%Update states
state(pointer+1)=b(2)*x-a(2)*y+state(pointer+1);
pointer=rem(pointer+1,2);

%Overwrite oldest sum with b(N-1).x
state(pointer+1)=b(3)*x-a(3)*y;
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?

%Initialization
[b,a]=ellip(4,1.3,60,2*[0.2,0.3]);
[sos,q]=tf2sos(b,a);
sosq=Quantize('round',sos,2^6);

bf=sosq(1,1:3);
af=sosq(1,4:6);

%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
impp=0;
stpp=0;

% Simulation of filter operation

x=1;
for k=1:len
[impy(k),impsv,impp]=Second_Order(x,af,bf,impsv,impp);
[stpy(k),stpsv,stpp]=Second_Order(1,af,bf,stpsv,stpp);
x=0;
end

• You should use zpk2sos instead of tf2sos. tf is not good for high order filters – endolith Jul 1 '13 at 1:35

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.