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.color_i (1,1) double {mustBeInteger, mustBePositive} = 1 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 G_ang = 180/pi*angle(squeeze(freqresp(args.G, freqs, 'Hz'))); p = patch([freqs flip(freqs)], [G_ang+Dphi; flip(G_ang-Dphi)], 'w', ... 'DisplayName', args.DisplayName); p.FaceColor = colors(args.color_i, :); p.EdgeColor = 'none'; p.FaceAlpha = args.opacity; end