%% Fit D-scale Data
% Use the fitfrd command to fit D-scale data.
% Create D-scale frequency response data from a fifth-order system.

sys = tf([1 2 2],[1 2.5 1.5])*tf(1,[1 0.1]); 
sys = sys*tf([1 3.75 3.5],[1 2.5 13]); 
omeg = logspace(-1,1); 
sysg = frd(sys,omeg); 
bode(sysg,'r-');

%
% You can try to fit the frequency response D-scale data sysg with a first-order system, b1. Similarly, you can fit the D-scale data with a third-order system, b3.

b1 = fitfrd(sysg,1); 
b3 = fitfrd(sysg,3);

%
% Compare the original D-scale data sysg with the frequency responses of the first and third-order models calculated by fitfrd.

b1g = frd(b1,omeg); 
b3g = frd(b3,omeg); 
bode(sysg,'r-',b1g,'k:',b3g,'b-.')
legend('5th order system','1st order fit','3rd order fit','Location','Southwest')

% Copyright 2015 The MathWorks, Inc.