%% Uncertain System Bounding an LTI Array
% Consider a third order transfer function with an uncertain gain, filter time constant and a lightly damped flexible mode. This model is used to represent a physical system from which frequency response data is acquired.

gain = ureal('gain',10,'Perc',20); 
tau = ureal('tau',.6,'Range',[.42 .9]); 
wn = 40; 
zeta = 0.1; 
usys = tf(gain,[tau 1])*tf(wn^2,[1 2*zeta*wn wn^2]); 
sysnom = usys.NominalValue; 
parray = usample(usys,30); 
om = logspace(-1,2,80); 
parrayg = frd(parray,om); 
bode(parrayg)

%
% The frequency response data in parray represents 30 experiments performed on the system. The command ltiarray2uss is used to generate an uncertain model, umod, based on the frequency response data. Initially an input multiplicative uncertain model is used to characterize the collection of 30 frequency responses. First and second order input multiplicative uncertainty weight are calculated from the data.

[umodIn1,wtIn1,diffdataIn] = ltiarray2uss(sysnom,parrayg,1); 
[umodIn2,wtIn2,diffdataIn] = ltiarray2uss(sysnom,parrayg,2); 
bodemag(wtIn1,'b-',wtIn2,'g+',diffdataIn,'r.',om) 
title('Input Multiplicative Uncertainty Model Using ltiarray2uss')
legend('1st order','2nd order','difference','Location','SouthEast')

%
% Alternatively, an additive uncertain model is used to characterize the collection of 30 frequency responses.

[umodAdd1,wtAdd1,diffdataAdd] = ltiarray2uss(sysnom,parrayg,1,'Additive'); 
[umodAdd2,wtAdd2,diffdataAdd] = ltiarray2uss(sysnom,parrayg,2,'Additive'); 
bodemag(wtAdd1,'b-',wtAdd2,'g+',diffdataAdd,'r.',om) 
title('Additive Uncertainty Model Using ltiarray2uss')
legend('1st order','2nd order','difference')

% Copyright 2015 The MathWorks, Inc.