Contents

% 2nd order filter in state-space representation - impulse response
% lab1_2.m * mw * 06/0^6/2007
b = [1 2 1]; a = [1 -1.4 .74]; % numerator and denominator

State-space representation in transposed direct form II

A2t = [-a(2) 1; -a(3) 0];               % matrix A
B2t = [b(2)-a(2)*b(1); b(3)-a(3)*b(1)]; % vector b
C2t = [1 0];                            % vector cT
D2t = b(1);                             % scalar d

Transformation of transposed direct form II to non-transposed

A2 = [0 1;1 0]*A2t'*[0 1;1 0];
B2 = [0 1;1 0]*C2t';
C2 = B2t'*[0 1;1 0];
D2 = D2t;

Filtering

x = [1 zeros(1,50)]; % input signal (impulse)
S = [0;0];           % state variables
y = zeros(size(x));  % output signal
for n=1:length(x)
     y(n) = C2*S + D2*x(n); % compute output signal
     S    = A2*S + B2*x(n); % update state variables
end

Graphics - Impulse response

FIG = figure('Name','lab1_2 : Impulse response',...
    'NumberTitle','off','Units','normalized','Position',[.3 .5 .4 .32]);
stem(0:length(x)-1,y/max(abs(y)),'filled')
axis([0 50 -.5 1]); grid;
xlabel('n \rightarrow'), ylabel('h[n] / MAX \rightarrow')
text(.82*50,.86,['MAX = ',num2str(max(abs(y)))])
title('Impulse response')