%% Construct a Nyquist Filter Using fdesign Object
% These examples show how to construct a Nyquist filter specification object.
% First, create a default specifications object without using input arguments.

d = fdesign.nyquist; %#ok

%
% Now create an object by passing a specification type 'n,ast' - the resulting object uses default values for n and ast.

d = fdesign.nyquist(2,'n,ast'); %#ok

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

d = fdesign.nyquist(3,'n,ast',42,80) %#ok

%
% Finally, pass the filter specifications that correspond to the default Specification - tw,ast. When you pass only the values, fdesign.nyquist assumes the default Specification option.

d = fdesign.nyquist(4,.01,80)

%
% Now design a Nyquist filter using the kaiserwin design method.

hd = design(d,'kaiserwin','SystemObject',true);

%
% Create two equiripple Nyquist 4th-band filters with and without a nonnegative zero phase response:

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

%
% Equiripple Nyquist 4th-band filter with nonnegative zero phase response

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

%
% Equiripple Nyquist 4th-band filter with 'ZeroPhase' set to 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 Nyquist designs with the 'N,TW' specification. You cannot specify 'MinPhase' and 'ZeroPhase' to be simultaneously 'true'.
% Copyright 2012 The MathWorks, Inc.