Contents

% 2nd order filter in state-space representation in
% transposed direct formm II - impulse response
% lab1_1.m * mw * 01/06/2007
b = [1 2 1]; a = [1 -1.4 .74]; % numerator and denominator

State-space representation in transposed direct form II

A = [-a(2) 1; -a(3) 0];               % matrix A
B = [b(2)-a(2)*b(1); b(3)-a(3)*b(1)]; % vector b
C = [1 0];                            % vector cT
D = b(1);                             % scalar d

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) = C*S + D*x(n); % compute output signal
     S    = A*S + B*x(n); % update state space variables
end

Graphics - Impulse response

FIG = figure('Name','lab1_1 : Impulse response',...
    'NumberTitle','off','Units','normalized','Position',[.3 .5 .4 .32]);
stem(0:50,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')