Digital Signal Processing Reference
In-Depth Information
function [y] = decx2(h,x,varargin);
%
% decx2 returns the filtered or downsampled (decimated) data
%
using a compacted low-pass filter h. Downsampling factor is 2.
%
%
If h is a compacted half-band low-pass filter and
%
the string 'LPF' is added to the input argument, the
%
procedure implements the standard time domain low-pass
%
filtering operation.
%
%
If h is a compacted half-band band-pass filter and
%
the string 'BPF' is added to the input argument, the
%
procedure implements the standard time domain band-pass
%
filtering operation.
%
%
If h is a compacted half-band band-pass filter and the
%
string 'BPx' is added to the input argument, the
%
procedure implements decimation by 2 operation.
%
%
The final data length is approximately half that of the
%
original length when the decimation option is chosen.
%
% Usage: [y] = decx2(h,x) implements decimation by 2, low-pass filtering
%
[y] = decx2(h,x,'LPF') for low-pass filtering (no decimation)
%
[y] = decx2(h,x,'BPF') for band-pass filtering (no decimation)
%
[y] = decx2(h,x,'BPx') implements decimation by 2, band-pass filtering
%
% Input:
h, compact half-band filter coefficients
%
x, input data
%
% Output: y, data decimated by a factor of 2 or filter output without decimation
%
% Notes: (1) Both h and x should be a single row or column vectors.
%
(2) The output y is a single column vector.
%
(3) Ensure that extraneous frequency components cannot fold back into the
%
pass band when the 'BPx' decimation option is used.
%
N = length(x);
L = length(h)-1;
str = '';
if length(varargin) == 1
str = [varargin{1}(:)]';
end
P = 4*L -1;
if (length(str) == 3)&((str == 'BPF')|(str == 'BPx')) P = 4*L + 1; end
if (length(str) == 3)&((str == 'LPF')|(str == 'BPF')) y(1:N) = 0; else y(1:floor(N/2)) = 0; end
[r,c] = size(h); if (r > 1)&(c == 1) h = h'; end
[r,c] = size(h);
if (r == 1)&(c > 1) Z = zeros(1,P+1);
[r,c] = size(x); if (r > 1)&(c == 1) x = x'; end
[r,c] = size(x);
if (r == 1)&(c > 1) x = [Z x Z];
Figure 2.25 Matlab
function for time domain decimation by 2.
Search WWH ::




Custom Search