%% Impulse and Frequency Response of Halfband Decimation Filter
% Create a lowpass halfband decimation filter for data sampled at 44.1 kHz. The output data rate is 1/2 the input sampling rate, or 22.05 kHz. Specify the filter order to be 52 with a transition width of 4.1 kHz.

Fs = 44.1e3; 
filterspec = 'Filter order and transition width';
Order = 52;
TW = 4.1e3; 
firhalfbanddecim =dsp.FIRHalfbandDecimator('Specification',filterspec, ...
                                              'FilterOrder',Order, ...
                                              'TransitionWidth',TW, ...
                                              'SampleRate',Fs);

%
% Plot the impulse response. The zeroth-order coefficient is delayed 26 samples, which is equal to the group delay of the filter. This yields a causal halfband filter.

fvtool(firhalfbanddecim,'Analysis','impulse')

%
% Plot the magnitude and phase response.

fvtool(firhalfbanddecim,'Analysis','freq')

% Copyright 2015 The MathWorks, Inc.