%% Constrain Noise Amplification Evaluated with a Loop Opening
% Create a requirement that constrains the amplification of the variance from the analysis point AP2 to the output y of the following control system, measured with the outer loop open.
%
% Create a model of the system. To do so, specify and connect the numeric plant models G1 and G2, and the tunable controllers C1 and C2. Also specify and connect the AnalysisPoint blocks AP1 and AP2 that mark points of interest for analysis and tuning.

G1 = tf(10,[1 10]);
G2 = tf([1 2],[1 0.2 10]);
C1 = tunablePID('C','pi');
C2 = tunableGain('G',1);
AP1 = AnalysisPoint('AP1');
AP2 = AnalysisPoint('AP2');
T = feedback(G1*feedback(G2*C2,AP2)*C1,AP1);

%
% Create a tuning requirement that constrains the noise amplification from the implicit input associated with the analysis point, AP2, to the output y.

Req = TuningGoal.Variance('AP2','y',0.1);

% This constraint limits the amplification to a factor of 0.1.
%
% Specify that the transfer function from AP2 to y is evaluated with the outer loop open when tuning to this constraint.

Req.Openings = {'AP1'};

% Use systune to tune the free parameters of T to meet the tuning requirement specified by Req. You can then validate the tuned control system against the requirement using viewGoal(Req,T).
% Copyright 2012 The MathWorks, Inc.