% Laguerre approximation
% system with 4 adjustable parameters
% show that one system yt is the linear combination 
% of two systems yt=2y1+3y2, and this is valid for 
% time the time domain and the zeros (gains) of the laguerre
% polynomial

clear
hold off
T=.1; a = .8; K = sqrt((1-a^2)*T);

n1 = [0 K];               %find the outputs of the 4 laguerre polynomial
d1 = [1 -1*a];
u1 = dimpulse(n1,d1,100); 
n2 = [-a 1];
d2 = [1 -a];
u2 = dlsim(n2,d2,u1); 
n3 = [-a 1];
d3 = [1 -a];
u3 = dlsim(n3,d3,u2); 
n4 = [-a 1];
d4 = [1 -a];
u4 = dlsim(n4,d4,u3); 


x=[1:100];
plot(x,u1,'g',x,u2,'r',x,u3,'w',x,u4,'b')

pause
X = [u1 u2 u3 u4]';

%sum of systems yt=2y1+3y2
thetat=[3.2 1.19 0.4 0.21];
yt=(thetat * X);    % yt in time

%subsystems
theta1=[1 .25 .2 0];
y1=(theta1 * X);

theta2=[.4 .23 0 .07];
y2=(theta2 * X);

y_hat=2*y1+3*y2;    % y1 and y2 are in time

x=[1:100];
plot(x,yt,'g',x,y_hat,'r')         

T=[theta1' theta2'];
gain=inv(T'*T)*T'*thetat'  % the two adjustable gains are 2 and 3

thetat=thetat';
theta1=theta1';
theta2=theta2';
