%% Higher Order Weighting Functions
% By default, makeweight creates first-order weighting functions. If you want a sharper transition between the low-frequency and high-frequency gains, you can specify the order with the last input argument. For instance, suppose you want to create a weighting function with a sample time of 0.1 s. The function has a gain of –10 dB at low frequency, rising to 40 dB at high frequency. Additionally, the gain passes through 6 dB at 1 rad/s. For comparison, create both a third-order and a first-order function with these specifications.

W3 = makeweight(0.316,[1 2],100,0.1,3);
W1 = makeweight(0.316,[1 2],100,0.1);
bodemag(W3,W1)
legend('location','northwest')
grid on

% For the first-order function, the high-frequency leveling is distorted due to the proximity of its crossover frequency to the Nyquist frequency. Using a sharper, higher-order transition ensures that the function has leveled out before reaching the Nyquist frequency.
%
% To create continuous-time weighting functions of higher order, set Ts = 0. For instance, create continuous-time weighting functions with the same gain specifications as W1 and W3.

W3c = makeweight(0.316,[1 2],100,0,3);
W1c = makeweight(0.316,[1 2],100);
bodemag(W3c,W1c)
legend('location','northwest')
grid on

%
% Copyright 2019 The MathWorks, Inc.