% SVD2  Laguerre approximation
% Question: finding the MSE in time is the same as finding the
% MSE for the adjustable parameters????

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

X = [u1 u2 u3 u4]';

%System we want to match
thetat=[3.2 1.19 0.4 0.21];
yt=(thetat * X);    % yt in time

%systems test A
theta1=[1 .25 .2 .1];
y1=(theta1 * X);

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

y_hat_a=2*y1+3*y2;    

error_a_t=norm(yt-y_hat_a)
error_a_g=norm(thetat-(2*theta1+3*theta2))

%systems test B
theta1=[1 .25 .2 -.1];
y1=(theta1 * X);

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

y_hat_b=2*y1+3*y2;    

error_b_t=norm(yt-y_hat_b)
error_b_g=norm(thetat-(2*theta1+3*theta2))

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