%% Reorder Biquadratic Filter
% Being able to rearrange the order of the sections in a filter can be a powerful tool for controlling the filter design process. This example uses reorder to change the sections of a df2sos filter. Let reorder do the reordering automatically in the first filter. In the second, use reorder to specify the new order for the sections.
% First use the automatic reordering option on a lowpass filter.

d = fdesign.lowpass('n,f3db',15,0.75);
biquad = design(d,'butter','SystemObject',true);
biquadreorder = reorder(biquad,'auto');

%
% Then, create an SOS filter in the direct form II implementation.

biquad2sos = design(d,'butter', 'FilterStructure', 'df2sos',...
    'SystemObject',true);
biquad2sosreorder = reorder(biquad2sos,[1 3:7 2 8]);
fvt = fvtool(biquad2sos,biquad2sosreorder,'analysis','coefficients');

%
% Remove the third, fourth, and seventh sections.

biquad2sosclone1 = clone(biquad2sos);
reorder(biquad2sosclone1, logical([1 1 0 0 1 1 0 1]));
setfilter(fvt, biquad2sosclone1);

%
% Move the first filter to the end and remove the eighth section.

biquad2sosclone2 = clone(biquad2sos);
reorder(biquad2sosclone2, [2:7 1]);
setfilter(fvt, biquad2sosclone2);

%
% Move the numerator and denominator independently.

biquad2sosclone3 = clone(biquad2sos);
reorder(biquad2sosclone3, [1 3:8 2], (1:8));
setfilter(fvt, biquad2sosclone3);

% Copyright 2012 The MathWorks, Inc.