function v=vwts(z,n)
%function v=vwts(z,n)
% Calculates n   v (impulse weights) for input (u) output(y)
% Uses Yule Walker Equations .Differences u and y to improve conditioning
% z=[y u]

%Arthur Jutan 
%Dept of Chemical and Biochemical Enginering
%Univ of Western Ontario
%London Ontario Canada, N6A 5B9

y=z(:,1);u=z(:,2);
y=diff(y); u=diff(u);
G=toeplitz(xcovn(u,u,n)); % calc Gamma(u,u) cross cov function(Mac Notes 2-26)
v=G\xcovn(u,y,n);
l=length(u);i=(0:n-1);o=ones(1,n);s=2/sqrt(l);
plot(i,v,'+c5',i,zeros(1:n),i,o*s,'--w',i,-o*s,'--w');
xlabel('LAG NUMBER');
ylabel('IMPULSE WTS with 95% CL');
grid;
