Contents

% partial impulse responses f and g
% lab4_1b.m * mw * 02/20/2007

2nd order system

b = [1 2 1]; a = [1 -1.4 .74];    % numerator and denominator
h = filter(b,a,[1 zeros(1,100)]); % impulse response
b = b / sqrt(sum(h.^2));          % l2 scaling
ssr = ssr_ABCD(b,a,'NF2');        % direct form II - > normal form

Simulation

N1 = 100; N2 = 31;
f = zeros(2,N1); f(:,2) = ssr.B;
g = zeros(2,N1); g(:,2) = ssr.C';
Ap = eye(2);
for n = 3:N1
    Ap = Ap*ssr.A;
    f(:,n) = Ap*ssr.B;
    g(:,n) = (ssr.C*Ap)';
end
% system impulse response
hf = zeros(1,N1);
hg = zeros(1,N1);
for n=1:N1
    hf(n) = ssr.C*f(:,n);
    hg(n) = g(:,n)'*ssr.B;
end
hf(1) = hf(1) + ssr.D;
hg(1) = hg(1) + ssr.D;
h = hf;  % = hg
% energies
Ef1 = sum(f(1,:).^2); Ef2 = sum(f(2,:).^2);
Eg1 = sum(g(1,:).^2); Eg2 = sum(g(2,:).^2);
Eh  = sum(h.^2);
fprintf('\nlab4_1 - %s\n',ssr.form)
fprintf('Ef1 = %g ,  Eg1 = %g \n',Ef1,Eg1)
fprintf('Ef2 = %g ,  Eg2 = %g \n',Ef2,Eg2)
fprintf('Eh = %g \n',Eh)
lab4_1 - NF2
Ef1 = 1.56714 ,  Eg1 = 0.843915 
Ef2 = 2.27902 ,  Eg2 = 0.987923 
Eh = 1 

Graphics - Partial impulse responses f and g, and impulse response h

FIG1 = figure('Name',['lab4_1 : f and g - ',ssr.form],...
    'NumberTitle','off');
subplot(2,2,1),stem(0:N2-1,f(1,1:N2),'filled')
axis([0 N2 -2 2]); grid;
xlabel('n \rightarrow'), ylabel('f_1[n] \rightarrow')
title('Partial impulse response')
subplot(2,2,3),stem(0:N2-1,f(2,1:N2),'filled')
axis([0 N2 -2 2]); grid;
xlabel('n \rightarrow'), ylabel('f_2[n] \rightarrow')
title('Partial impulse response')
subplot(2,2,2),stem(0:N2-1,g(1,1:N2),'filled')
axis([0 N2 -2 2]); grid;
xlabel('n \rightarrow'), ylabel('g_1[n] \rightarrow')
title('Partial impulse response')
subplot(2,2,4),stem(0:N2-1,g(2,1:N2),'filled')
axis([0 N2 -2 2]); grid;
xlabel('n \rightarrow'), ylabel('g_2[n] \rightarrow')
title('Partial impulse response')
FIG2 = figure('Name',['lab4_1 : Impulse response - ',ssr.form],...
    'NumberTitle','off');
stem(0:N2-1,hf(1:N2),'filled')
axis([0 N2 -1 1]); grid;
xlabel('n \rightarrow'), ylabel('h[n] \rightarrow')
title('Impulse response')