%% Reduction with Focus on Particular Frequency Band
% Reduce a 4th-order system to a second-order approximation with emphasis on the frequency band 10 rad/s - 100 rad/s. Consider the following system.

sys = tf(1,[1 0.5 1]) + tf(100*[1/10 1],[1 10 1000]); 
bode(sys)

%
% To focus the model-reduction algorithm on the higher-frequency dynamics, specify a function with a bandpass profile.

s = tf('s'); 
w1 = (s+1)/(s/10+1)/(s/60+1)*(s/600+1); 
bodemag(w1)

%
% The plot confirms that the weighting function w1 has the desired profile, peaking between 10 rad/s and 100 rad/s. To perform the reduction, specify the inverse of this profile as the output weight, using the 'Weights' option of balancmr.

weight = {1/w1,1}; 
wrsys = balancmr(sys,2,'Weights',weight);

%
% Compare the result with a second-order model obtained without the weighting.

rsys = balancmr(sys,2);
bode(sys,rsys,wrsys) 
legend('Original','Unweighted','Weighted')

% The model obtained with the weighting function provides a better match for the dynamics in the frequency band 10 rad/s - 100 rad/s.
% Copyright 2012 The MathWorks, Inc.