%% Minimum Phase Filters
% Design a sixth-order lowpass Butterworth IIR filter using second order sections. Specify a normalized 3-dB frequency of 0.15. Check if the filter has minimum phase.

[z,p,k] = butter(6,0.15);
SOS = zp2sos(z,p,k);            
min_flag = isminphase(SOS)

%
% Redesign the filter using designfilt. Check that the zeros and poles of the transfer function are on or within the unit circle.

d = designfilt('lowpassiir','DesignMethod','butter','FilterOrder',6, ...
               'HalfPowerFrequency',0.25);
d_flag = isminphase(d)
zplane(d)

%
% Given a filter defined with a set of single-precision numerator and denominator coefficients, check if it has minimum phase for different tolerance values.

b = single([1 1.00001]);  
a = single([1 0.45]);               
min_flag1 = isminphase(b,a)        
min_flag2 = isminphase(b,a,1e-3)

% Copyright 2015 The MathWorks, Inc.