Contents

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

State-space representation (MATLAB)

[A,B,C,D]= tf2ss(b,a);

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_3 : 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')