%% Spectral Factorization of System
% Consider the following system.

G0 = ss(zpk([-1 -5 1+2i 1-2i],[-100 1+2i 1-2i -10],1e3));
H = G0'*G0;

%
% G0 has a mix of stable and unstable dynamics. H is a self-conjugate system whose dynamics consist of the poles and zeros of G0 and their reflections across the imaginary axis. Use spectral factorization to separate the stable poles and zeros into G and the unstable poles and zeros into G'.

[G,S] = spectralfact(H);

%
% Confirm that G is stable and minimum phase, by checking that all its poles and zeros fall in the left half-plane (Re(s) < 0).

p = pole(G)
z = zero(G)

%
% G also has unit feedthrough.

G.D

%
% Because H is SISO, S is a scalar. If H were MIMO, the dimensions of S would match the I/O dimensions of H.

S

%
% Confirm that G and S satisfy H = G'*S*G by comparing the original system to the difference between the original and factored systems. sigmaplot throws a warning because the difference is very small.

Hf = G'*S*G;
sigmaplot(H,H-Hf)

% Copyright 2012 The MathWorks, Inc.