add all files
This commit is contained in:
34
B3-control/src/generateCF.m
Normal file
34
B3-control/src/generateCF.m
Normal file
@@ -0,0 +1,34 @@
|
||||
function [H1, H2] = generateCF(W1, W2, args)
|
||||
% generateCF -
|
||||
%
|
||||
% Syntax: [H1, H2] = generateCF(W1, W2, args)
|
||||
%
|
||||
% Inputs:
|
||||
% - W1 - Weighting Function for H1
|
||||
% - W2 - Weighting Function for H2
|
||||
% - args:
|
||||
% - method - H-Infinity solver ('lmi' or 'ric')
|
||||
% - display - Display synthesis results ('on' or 'off')
|
||||
%
|
||||
% Outputs:
|
||||
% - H1 - Generated H1 Filter
|
||||
% - H2 - Generated H2 Filter
|
||||
|
||||
%% Argument validation
|
||||
arguments
|
||||
W1
|
||||
W2
|
||||
args.method char {mustBeMember(args.method,{'lmi', 'ric'})} = 'ric'
|
||||
args.display char {mustBeMember(args.display,{'on', 'off'})} = 'on'
|
||||
end
|
||||
|
||||
%% The generalized plant is defined
|
||||
P = [W1 -W1;
|
||||
0 W2;
|
||||
1 0];
|
||||
|
||||
%% The standard H-infinity synthesis is performed
|
||||
[H2, ~, gamma, ~] = hinfsyn(P, 1, 1,'TOLGAM', 0.001, 'METHOD', args.method, 'DISPLAY', args.display);
|
||||
|
||||
%% H1 is defined as the complementary of H2
|
||||
H1 = 1 - H2;
|
43
B3-control/src/generateWF.m
Normal file
43
B3-control/src/generateWF.m
Normal file
@@ -0,0 +1,43 @@
|
||||
function [W] = generateWF(args)
|
||||
% generateWF -
|
||||
%
|
||||
% Syntax: [W] = generateWeight(args)
|
||||
%
|
||||
% Inputs:
|
||||
% - n - Weight Order (integer)
|
||||
% - G0 - Low frequency Gain
|
||||
% - G1 - High frequency Gain
|
||||
% - Gc - Gain of the weight at frequency w0
|
||||
% - w0 - Frequency at which |W(j w0)| = Gc [rad/s]
|
||||
%
|
||||
% Outputs:
|
||||
% - W - Generated Weighting Function
|
||||
|
||||
%% Argument validation
|
||||
arguments
|
||||
args.n (1,1) double {mustBeInteger, mustBePositive} = 1
|
||||
args.G0 (1,1) double {mustBeNumeric, mustBePositive} = 0.1
|
||||
args.Ginf (1,1) double {mustBeNumeric, mustBePositive} = 10
|
||||
args.Gc (1,1) double {mustBeNumeric, mustBePositive} = 1
|
||||
args.w0 (1,1) double {mustBeNumeric, mustBePositive} = 1
|
||||
end
|
||||
|
||||
% Verification of correct relation between G0, Gc and Ginf
|
||||
mustBeBetween(args.G0, args.Gc, args.Ginf);
|
||||
|
||||
%% Initialize the Laplace variable
|
||||
s = zpk('s');
|
||||
|
||||
%% Create the weighting function according to formula
|
||||
W = (((1/args.w0)*sqrt((1-(args.G0/args.Gc)^(2/args.n))/(1-(args.Gc/args.Ginf)^(2/args.n)))*s + ...
|
||||
(args.G0/args.Gc)^(1/args.n))/...
|
||||
((1/args.Ginf)^(1/args.n)*(1/args.w0)*sqrt((1-(args.G0/args.Gc)^(2/args.n))/(1-(args.Gc/args.Ginf)^(2/args.n)))*s + ...
|
||||
(1/args.Gc)^(1/args.n)))^args.n;
|
||||
|
||||
%% Custom validation function
|
||||
function mustBeBetween(a,b,c)
|
||||
if ~((a > b && b > c) || (c > b && b > a))
|
||||
eid = 'createWeight:inputError';
|
||||
msg = 'Gc should be between G0 and Ginf.';
|
||||
throwAsCaller(MException(eid,msg))
|
||||
end
|
42
B3-control/src/plotMagUncertainty.m
Normal file
42
B3-control/src/plotMagUncertainty.m
Normal file
@@ -0,0 +1,42 @@
|
||||
function [p] = plotMagUncertainty(W, freqs, args)
|
||||
% plotMagUncertainty -
|
||||
%
|
||||
% Syntax: [p] = plotMagUncertainty(W, freqs, args)
|
||||
%
|
||||
% Inputs:
|
||||
% - W - Multiplicative Uncertainty Weight
|
||||
% - freqs - Frequency Vector [Hz]
|
||||
% - args - Optional Arguments:
|
||||
% - G
|
||||
% - color_i
|
||||
% - opacity
|
||||
%
|
||||
% Outputs:
|
||||
% - p - Plot Handle
|
||||
|
||||
arguments
|
||||
W
|
||||
freqs double {mustBeNumeric, mustBeNonnegative}
|
||||
args.G = tf(1)
|
||||
args.color_i (1,1) double {mustBeInteger, mustBeNonnegative} = 0
|
||||
args.opacity (1,1) double {mustBeNumeric, mustBeNonnegative} = 0.3
|
||||
args.DisplayName char = ''
|
||||
end
|
||||
|
||||
% Get defaults colors
|
||||
colors = get(groot, 'defaultAxesColorOrder');
|
||||
|
||||
p = patch([freqs flip(freqs)], ...
|
||||
[abs(squeeze(freqresp(args.G, freqs, 'Hz'))).*(1 + abs(squeeze(freqresp(W, freqs, 'Hz')))); ...
|
||||
flip(abs(squeeze(freqresp(args.G, freqs, 'Hz'))).*max(1 - abs(squeeze(freqresp(W, freqs, 'Hz'))), 1e-6))], 'w', ...
|
||||
'DisplayName', args.DisplayName);
|
||||
|
||||
if args.color_i == 0
|
||||
p.FaceColor = [0; 0; 0];
|
||||
else
|
||||
p.FaceColor = colors(args.color_i, :);
|
||||
end
|
||||
p.EdgeColor = 'none';
|
||||
p.FaceAlpha = args.opacity;
|
||||
|
||||
end
|
52
B3-control/src/plotPhaseUncertainty.m
Normal file
52
B3-control/src/plotPhaseUncertainty.m
Normal file
@@ -0,0 +1,52 @@
|
||||
function [p] = plotPhaseUncertainty(W, freqs, args)
|
||||
% plotPhaseUncertainty -
|
||||
%
|
||||
% Syntax: [p] = plotPhaseUncertainty(W, freqs, args)
|
||||
%
|
||||
% Inputs:
|
||||
% - W - Multiplicative Uncertainty Weight
|
||||
% - freqs - Frequency Vector [Hz]
|
||||
% - args - Optional Arguments:
|
||||
% - G
|
||||
% - color_i
|
||||
% - opacity
|
||||
%
|
||||
% Outputs:
|
||||
% - p - Plot Handle
|
||||
|
||||
arguments
|
||||
W
|
||||
freqs double {mustBeNumeric, mustBeNonnegative}
|
||||
args.G = tf(1)
|
||||
args.unwrap logical {mustBeNumericOrLogical} = false
|
||||
args.color_i (1,1) double {mustBeInteger, mustBeNonnegative} = 0
|
||||
args.opacity (1,1) double {mustBeNumeric, mustBePositive} = 0.3
|
||||
args.DisplayName char = ''
|
||||
end
|
||||
|
||||
% Get defaults colors
|
||||
colors = get(groot, 'defaultAxesColorOrder');
|
||||
|
||||
% Compute Phase Uncertainty
|
||||
Dphi = 180/pi*asin(abs(squeeze(freqresp(W, freqs, 'Hz'))));
|
||||
Dphi(abs(squeeze(freqresp(W, freqs, 'Hz'))) > 1) = 360;
|
||||
|
||||
% Compute Plant Phase
|
||||
if args.unwrap
|
||||
G_ang = 180/pi*unwrap(angle(squeeze(freqresp(args.G, freqs, 'Hz'))));
|
||||
else
|
||||
G_ang = 180/pi*angle(squeeze(freqresp(args.G, freqs, 'Hz')));
|
||||
end
|
||||
|
||||
p = patch([freqs flip(freqs)], [G_ang+Dphi; flip(G_ang-Dphi)], 'w', ...
|
||||
'DisplayName', args.DisplayName);
|
||||
|
||||
if args.color_i == 0
|
||||
p.FaceColor = [0; 0; 0];
|
||||
else
|
||||
p.FaceColor = colors(args.color_i, :);
|
||||
end
|
||||
p.EdgeColor = 'none';
|
||||
p.FaceAlpha = args.opacity;
|
||||
|
||||
end
|
Reference in New Issue
Block a user