Rework matlab functions

This commit is contained in:
Thomas Dehaeze 2021-09-01 09:56:11 +02:00
parent c6d715734f
commit e82e86486e
2 changed files with 11 additions and 3 deletions

View File

@ -1,7 +1,7 @@
function [H1, H2] = generateCF(W1, W2, args) function [H1, H2] = generateCF(W1, W2, args)
% createWeight - % createWeight -
% %
% Syntax: [W] = generateCF(args) % Syntax: [H1, H2] = generateCF(W1, W2, args)
% %
% Inputs: % Inputs:
% - W1 - Weighting Function for H1 % - W1 - Weighting Function for H1
@ -14,6 +14,7 @@ function [H1, H2] = generateCF(W1, W2, args)
% - H1 - Generated H1 Filter % - H1 - Generated H1 Filter
% - H2 - Generated H2 Filter % - H2 - Generated H2 Filter
%% Argument validation
arguments arguments
W1 W1
W2 W2
@ -21,10 +22,13 @@ arguments
args.display char {mustBeMember(args.display,{'on', 'off'})} = 'on' args.display char {mustBeMember(args.display,{'on', 'off'})} = 'on'
end end
%% The generalized plant is defined
P = [W1 -W1; P = [W1 -W1;
0 W2; 0 W2;
1 0]; 1 0];
%% The standard H-infinity synthesis is performed
[H2, ~, gamma, ~] = hinfsyn(P, 1, 1,'TOLGAM', 0.001, 'METHOD', args.method, 'DISPLAY', args.display); [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; H1 = 1 - H2;

View File

@ -11,8 +11,9 @@ function [W] = generateWF(args)
% - w0 - Frequency at which |W(j w0)| = Gc [rad/s] % - w0 - Frequency at which |W(j w0)| = Gc [rad/s]
% %
% Outputs: % Outputs:
% - W - Generated Weight % - W - Generated Weighting Function
%% Argument validation
arguments arguments
args.n (1,1) double {mustBeInteger, mustBePositive} = 1 args.n (1,1) double {mustBeInteger, mustBePositive} = 1
args.G0 (1,1) double {mustBeNumeric, mustBePositive} = 0.1 args.G0 (1,1) double {mustBeNumeric, mustBePositive} = 0.1
@ -21,16 +22,19 @@ arguments
args.w0 (1,1) double {mustBeNumeric, mustBePositive} = 1 args.w0 (1,1) double {mustBeNumeric, mustBePositive} = 1
end end
% Verification of correct relation between G0, Gc and Ginf
mustBeBetween(args.G0, args.Gc, args.Ginf); mustBeBetween(args.G0, args.Gc, args.Ginf);
%% Initialize the Laplace variable
s = zpk('s'); 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 + ... 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))/... (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.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; (1/args.Gc)^(1/args.n)))^args.n;
% Custom validation function %% Custom validation function
function mustBeBetween(a,b,c) function mustBeBetween(a,b,c)
if ~((a > b && b > c) || (c > b && b > a)) if ~((a > b && b > c) || (c > b && b > a))
eid = 'createWeight:inputError'; eid = 'createWeight:inputError';