1 ## Copyright (C) 1999 Paul Kienzle <pkienzle@users.sf.net>
2 ## Copyright (C) 2003 Doug Stewart <dastew@sympatico.ca>
3 ## Copyright (C) 2009 Thomas Sailer <t.sailer@alumni.ethz.ch>
5 ## This program is free software; you can redistribute it and/or modify it under
6 ## the terms of the GNU General Public License as published by the Free Software
7 ## Foundation; either version 3 of the License, or (at your option) any later
10 ## This program is distributed in the hope that it will be useful, but WITHOUT
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 ## You should have received a copy of the GNU General Public License along with
16 ## this program; if not, see <http://www.gnu.org/licenses/>.
18 ## Generate a bessel filter.
19 ## Default is a Laplace space (s) filter.
21 ## [b,a] = besself(n, Wc)
22 ## low pass filter with cutoff pi*Wc radians
24 ## [b,a] = besself(n, Wc, 'high')
25 ## high pass filter with cutoff pi*Wc radians
27 ## [b,a] = besself(n, [Wl, Wh])
28 ## band pass filter with edges pi*Wl and pi*Wh radians
30 ## [b,a] = besself(n, [Wl, Wh], 'stop')
31 ## band reject filter with edges pi*Wl and pi*Wh radians
33 ## [z,p,g] = besself(...)
34 ## return filter as zero-pole-gain rather than coefficients of the
35 ## numerator and denominator polynomials.
37 ## [...] = besself(...,'z')
38 ## return a discrete space (Z) filter, W must be less than 1.
40 ## [a,b,c,d] = besself(...)
41 ## return state-space matrices
45 ## Proakis & Manolakis (1992). Digital Signal Processing. New York:
46 ## Macmillan Publishing Company.
48 function [a, b, c, d] = besself (n, W, varargin)
50 if (nargin>4 || nargin<2) || (nargout>4 || nargout<2)
54 ## interpret the input parameters
55 if (!(length(n)==1 && n == round(n) && n > 0))
56 error ("besself: filter order n must be a positive integer");
61 for i=1:length(varargin)
63 case 's', digital = 0;
64 case 'z', digital = 1;
65 case { 'high', 'stop' }, stop = 1;
66 case { 'low', 'pass' }, stop = 0;
67 otherwise, error ("besself: expected [high|stop] or [s|z]");
73 if (!(length(W)<=2 && (r==1 || c==1)))
74 error ("besself: frequency must be given as w0 or [w0, w1]");
75 elseif (!(length(W)==1 || length(W) == 2))
76 error ("besself: only one filter band allowed");
77 elseif (length(W)==2 && !(W(1) < W(2)))
78 error ("besself: first band edge must be smaller than second");
81 if ( digital && !all(W >= 0 & W <= 1))
82 error ("besself: critical frequencies must be in (0 1)");
83 elseif ( !digital && !all(W >= 0 ))
84 error ("besself: critical frequencies must be in (0 inf)");
87 ## Prewarp to the band edges to s plane
89 T = 2; # sampling frequency of 2 Hz
93 ## Generate splane poles for the prototype bessel filter
94 [zero, pole, gain] = besselap(n);
96 ## splane frequency transform
97 [zero, pole, gain] = sftrans(zero, pole, gain, W, stop);
99 ## Use bilinear transform to convert poles to the z plane
101 [zero, pole, gain] = bilinear(zero, pole, gain, T);
104 ## convert to the correct output form
106 a = real(gain*poly(zero));
107 b = real(poly(pole));
114 [a, b, c, d] = zp2ss (zero, pole, gain);