%% Construct a Decimator Using fdesign Object
% These examples show how to construct decimating filter specification objects.
% First, create a default specifications object without using input arguments except for the decimation factor m.

d = fdesign.decimator(2,'Nyquist',2,0.1,80) %#ok % Set tw=0.1, and ast=80. 

%
% Now create an object by passing a specification type option 'fst1,fp1,fp2,fst2,ast1,ap,ast2' and a design - the resulting object uses default values for the filter specifications. You must provide the design input argument, bandpass in this example, when you include a specification.

d = fdesign.decimator(8,'bandpass',...
'fst1,fp1,fp2,fst2,ast1,ap,ast2'); %#ok

%
% Create another decimating filter specification object, passing the specification values to the object rather than accepting the default values for fp,fst,ap,ast.

d = fdesign.decimator(3,'lowpass',.45,0.55,.1,60); %#ok

%
% Now pass the filter specifications that correspond to the specifications - n,fc,ap,ast.

d = fdesign.decimator(3,'ciccomp',1,2,'n,fc,ap,ast',...
20,0.45,.05,50);

%
% Now design a decimator using the equiripple design method.

equiDecimator = design(d,'equiripple','SystemObject',true);

%
% Pass a new specification type for the filter, specifying the filter order. Note that the inputs must include the differential delay dd with the CIC input argument to design a CIC specification object.

m = 5;
dd = 2;
d = fdesign.decimator(m,'cic',dd,'fp,ast',0.55,55); %#ok

%
% In this example, you specify a sampling frequency as the last input argument. Here is it 1000 Hz. Design an equiripple filter and plot the magnitude response:

d = fdesign.decimator(8,'bandpass','fst1,fp1,fp2,fst2,ast1,ap,ast2',...
100,150,250,300,50,.05,50,1000);
fvtool(design(d,'equiripple','SystemObject',true))

% Copyright 2012 The MathWorks, Inc.