%% Mode Selection at the Command Line
% To reduce the order of a model by mode selection at the command line, use freqsep. This command separates a dynamic system model into slow and fast components around a specified frequency.
% For this example, load the model Gms and examine its frequency response.

load modeselect Gms
bodeplot(Gms)

% Gms has two sets of resonances, one at relatively low frequency and the other at relatively high frequency. Suppose that you want to tune a controller for Gms, but the actuator in your system is limited to a bandwidth of about 3 rad/s, in between the two groups of resonances. To simplify calculation and tuning using Gms, you can use mode selection to eliminate the high-frequency dynamics.
%

[Gms_s,Gms_f] = freqsep(Gms,30);

%
% freqsep decomposes Gms into slow and fast components such that Gms = Gms_s + Gms_f. All modes (poles) with natural frequency less than 30 are in Gms_s, and the higher-frequency poles are in Gms_f.

bodeplot(Gms,Gms_s,Gms_f)
legend('original','slow','fast')

%
% The slow component, Gms_s, contains only the lower-frequency resonances and matches the DC gain of the original model. Examine the orders of both models.

order(Gms)
order(Gms_s)

% When the high-frequency dynamics are unimportant for your application, you can use the 10th-order Gms_s instead of the original 18th-order model. If neglecting low-frequency dynamics is appropriate for your application, you can use Gms_f. To select modes that fall between a low-frequency and a high-frequency cutoff, use additional calls to freqsep.
% Copyright 2012 The MathWorks, Inc.