view m-toolbox/classes/@miir/mkallpass.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line source

% MKALLPASS returns an allpass filter miir(). 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: MKALLPASS returns an allpass filter miir().
%
% CALL:        f = mkallpass(f, pl)
%
% VERSION: $Id: mkallpass.m,v 1.2 2010/10/29 16:09:14 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function f = mkallpass(f, pl)
  
  fs     = find(pl, 'fs');
  method = find(pl, 'method');
  D      = find(pl, 'delay');
  N      = find(pl, 'N');
  
  % Build filter coefficients
  switch method
    case 'thirlen'
      for k=0:N        
        a(k+1) = (-1.0)^k * factorial(N)/(factorial(k)*factorial(N-k));        
        for n=0:N
          a(k+1) = a(k+1) * (D-N+n)/(D-N+k+n);
        end
      end
      
      a = a/sum(a);
      b(1) = 1;
      
    otherwise
      error(['Unrecognised method [' method ']']);
  end
  
  % Set filter properties
  f.name    = 'bandpass';
  f.fs      = fs;
  f.a       = a;
  f.b       = b;
  f.histin  = zeros(1,f.ntaps-1); % initialise input history
  f.histout = zeros(1,f.ntaps-1); % initialise output history
end