1 /*****************************************************************************
5 ** Purpose: Signal filter header file
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: June 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: filter.h,v 1.5 2000/06/30 02:03:27 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
41 FILTER_ABS_BANDLIMIT, // filter times |x|
49 FILTER_METHOD_INVALID,
50 FILTER_METHOD_CONVOLUTION,
51 FILTER_METHOD_FOURIER,
53 FILTER_METHOD_FFT_ZEROPAD_2,
54 FILTER_METHOD_FFT_ZEROPAD_4,
55 FILTER_METHOD_FFT_ZEROPAD_6
64 static const char FILTER_ABS_BANDLIMIT_STR[]= "abs_bandlimit";
65 static const char FILTER_ABS_SINC_STR[]= "abs_sinc";
66 static const char FILTER_ABS_COS_STR[]= "abs_cos";
67 static const char FILTER_ABS_HAMMING_STR[]= "abs_hamming";
68 static const char FILTER_SHEPP_STR[]= "shepp";
69 static const char FILTER_BANDLIMIT_STR[]= "bandlimit";
70 static const char FILTER_SINC_STR[]= "sinc";
71 static const char FILTER_COS_STR[]= "cos";
72 static const char FILTER_HAMMING_STR[]= "hamming";
73 static const char FILTER_TRIANGLE_STR[]= "triangle";
75 static const char FILTER_METHOD_CONVOLUTION_STR[]= "convolution";
76 static const char FILTER_METHOD_FOURIER_STR[]= "fourier";
77 static const char FILTER_METHOD_FFT_STR[]= "fft";
78 static const char FILTER_METHOD_FFT_ZEROPAD_2_STR[]="fft_zeropad2";
79 static const char FILTER_METHOD_FFT_ZEROPAD_4_STR[]="fft_zeropad4";
80 static const char FILTER_METHOD_FFT_ZEROPAD_6_STR[]="fft_zeropad6";
82 static const char DOMAIN_FREQUENCY_STR[]= "frequency";
83 static const char DOMAIN_SPATIAL_STR[]= "spatial";
86 SignalFilter (const char* filterName, double bw, double xmin, double xmax, int n, double param, const char* domainName, const int numIntegral = 0);
88 SignalFilter (const FilterID filt_type, double bw, double xmin, double xmax, int n, double param, const DomainID domain, const int numIntegral = 0);
90 SignalFilter (const char* filterName, const char* domainName, double bw, double param, int numIntegral = 0);
94 double* getFilter (void) const
95 { return m_vecFilter; }
97 double convolve (const double f[], const double dx, const int n, const int np) const;
99 double convolve (const float f[], const double dx, const int n, const int np) const;
101 bool fail(void) const {return m_fail;}
102 const string& failMessage(void) const {return m_failMessage;}
104 const string& nameFilter(void) const { return m_nameFilter;}
105 const string& nameDomain(void) const { return m_nameDomain;}
106 const FilterID idFilter(void) const { return m_idFilter;}
107 const DomainID idDomain(void) const { return m_idDomain;}
109 double response (double x);
111 static double spatialResponse (FilterID fType, double bw, double x, double param, int nIntegral = 0);
113 static double frequencyResponse (FilterID fType, double bw, double u, double param);
115 static double spatialResponseCalc (FilterID fType, double bw, double x, double param, int n);
117 static double spatialResponseAnalytic (FilterID fType, double bw, double x, double param);
126 string m_failMessage;
128 string m_nameFilterMethod;
131 FilterMethodID m_idFilterMethod;
133 double m_filterParam;
136 static FilterID convertFilterNameToID (const char* filterName);
137 static const char* convertFilterIDToName (const FilterID filterID);
138 static const DomainID convertDomainNameToID (const char* domainName);
139 static const char* convertDomainIDToName (const DomainID domainID);
141 void init (const FilterID filt_type, double bw, double xmin, double xmax, int n, double param, const DomainID domain, const int numInt);
143 double spatialResponseCalc (double x, double param, int n) const;
145 double spatialResponseAnalytic (double x, double param) const;
147 double frequencyResponse (double u, double param) const;
149 static double sinc (double x, double mult)
150 { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
152 static double integral_abscos (double u, double w);