%% Create Halfband Filters Using fdesign Object
% Create a default halfband filter specifications object.

d=fdesign.halfband;

%
% Create another halfband filter object, passing the specification values to the object rather than accepting the default values for n and ast.

d2 = fdesign.halfband('n,ast', 42, 80);

%
% For another example, pass the filter values that correspond to the default Specification - n,ast.

d3 = fdesign.halfband(.01, 80);

%
% This example designs an equiripple FIR filter, starting by passing a new specification type and specification values to fdesign.halfband.

hs = fdesign.halfband('n,ast',80,70);
hd =design(hs,'equiripple','SystemObject',true);

%
% In this example, pass the specifications for the filter, and then design a least-squares FIR filter from the object, using firls as the design method.

hs = fdesign.halfband('n,tw', 42, .04);
hd2 = design(hs,'firls','SystemObject',true);

%
% Create two equiripple halfband filters with and without a nonnegative zero phase response:

f=fdesign.halfband('N,TW',12,0.2);

%
% Equiripple halfband filter with nonnegative zero phase response

Hd1 = design(f,'equiripple','ZeroPhase',true,'SystemObject',true);

%
% Equiripple halfband filter with zero phase false 'zerophase',false is the default

Hd2=design(f,'equiripple','ZeroPhase',false,'SystemObject',true);

%
% Obtain real-valued amplitudes (not magnitudes)

[Hr_zerophase,~]=zerophase(Hd1);
[Hr,W]=zerophase(Hd2);

%
% Plot and compare response

plot(W,Hr_zerophase,'k','linewidth',2);
xlabel('Radians/sample'); ylabel('Amplitude');
hold on;
plot(W,Hr,'r');
axis tight; grid on;
legend('with ''ZeroPhase'', true','with ''ZeroPhase'' false');

% Note that the amplitude of the zero phase response (black line) is nonnegative for all frequencies. The 'ZeroPhase' option is valid only for equiripple halfband designs with the 'N,TW' specification. You cannot specify 'MinPhase' and 'ZeroPhase' to be simultaneously 'true'.
% Copyright 2012 The MathWorks, Inc.