function varargout = dspblkfirdn2(action,varargin)
% DSPBLKFIRDN Mask dynamic dialog function for FIR decimation block

% Copyright 1995-2000 The MathWorks, Inc.
% $Date: 2000/04/29 22:54:38 $ $Revision: 1.4 $

blk = gcb;   % Cache handle to block

switch action

case 'setup'
   % Input arguments for setup case:
   % dspblkfirdn('setup',h,D,framing)
   
   h = varargin{1};
   D = varargin{2};

   if(isempty(D))
      str = '???';  % Default display
   else
      str=['x[' num2str(D) 'n]'];      
   end
   
   if(~isempty(h) & ~isempty(D))
 
      [M,N] = size(h);
      if (M ~= 1 & N ~= 1)
          error('The filter coefficients must be a non-empty vector');
      end
      if (isempty(D) | D < 1 | fix(D) ~= D)
          error('Decimation factor must be a positive integer');
      end
 
      % Need to reshuffle the coefficients into phase order   
      len = length(h);
      h = flipud(h(:));
      if (rem(len, D) ~= 0)
         nzeros = D - rem(len, D);
         h = [zeros(nzeros,1); h];
      end
      len = length(h);
      nrows = len / D;
      % Re-arrange the coefficients
      h = flipud(reshape(h, D, nrows).');
   end
   
   % Gather up outputs
   varargout = {h,str};
   
otherwise
   error('unhandled case');
end

% end of dspblkfirdn2.m
