echo off;
close all; % close all figures
clear;

load data/vmat.mat
load data/nominal.mat

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% weighting function setting for additive uncertainty %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%0 = 0.025;
%1 = 0.85*pi*60;
%2 = 0.88*pi*400;
% = nd2sys(w0*w2*[1, w1], w1*[1, w2]);

W = 1;

W_g = frsp(W, w);
W_Hz = scliv(W_g, 1/(2*pi));

% Gyu = ~Gyu + Delta i.e. Delta = Gyu - ~Gyu
% where ~Gyu is nominal plant for real plant Gyu
delta_Hz = msub(gyu_jw_Hz, Gyu0_Hz);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% verification of weighting function %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(5);
clf;
vplot('liv,lm', delta_Hz, 'bo', W_Hz, 'r');
%axis([10, 2500, 1e-4, 1e2]);
xlabel('Frequency [Hz]', 'FontSize', 18);
ylabel('Magnitude', 'FontSize', 18);
set(findobj('type','text'),'fontsize',18);
set(findobj('type','axes'),'fontsize',18);
set(findobj('type','line'),'linewidth',2);
set(findobj('type','line'),'markersize',3);
title('Uncertainty and weight','fontsize',18);
legend('Uncertainty', 'Weight', 3);
print -djpeg90 -r70 data/uncertain.jpg;

save data/weight.mat W;
