%% Convert Transfer Function to State-Space Model
% Compute the state-space model of the following transfer function:
% H\left( s \right) = \left[ {\begin{array}{*{20}{c}}
% {\frac{{s + 1}}{{{s^3} + 3{s^2} + 3s + 2}}}\\
% {\frac{{{s^2} + 3}}{{{s^2} + s + 1}}}
% \end{array}} \right]
% Create the transfer function model.

H = [tf([1 1],[1 3 3 2]) ; tf([1 0 3],[1 1 1])];

%
% Convert this model to a state-space model.

sys = ss(H);

%
% Examine the size of the state-space model.

size(sys)

% The number of states is equal to the cumulative order of the SISO entries in H(s).
%
% To obtain a minimal realization of H(s), enter

sys = ss(H,'minimal');
size(sys)

% The resulting model has an order of three, which is the minimum number of states needed to represent H(s). To see this number of states, refactor H(s) as the product of a first-order system and a second-order system.
% H(s) = \left[ {\begin{array}{*{20}{c}}
% {\frac{1}{{s + 2}}}&0\\
% 0&1
% \end{array}} \right]\left[ {\begin{array}{*{20}{c}}
% {\frac{{s + 1}}{{{s^2} + s + 1}}}\\
% {\frac{{{s^2} + 3}}{{{s^2} + s + 1}}}
% \end{array}} \right]
% Copyright 2012 The MathWorks, Inc.