r127: *** empty log message ***
[ctsim.git] / include / filter.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **      Name:         filter.h
5 **      Purpose:      Signal filter header file
6 **      Programmer:   Kevin Rosenberg
7 **      Date Started: June 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: filter.h,v 1.6 2000/07/02 18:21:39 kevin Exp $
13 **
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.
17 **
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.
22 **
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 ******************************************************************************/
27
28 #ifndef FILTER_H
29 #define FILTER_H
30
31 class SignalFilter {
32  public:
33
34     typedef enum {         
35         FILTER_INVALID,
36         FILTER_BANDLIMIT, 
37         FILTER_SINC,
38         FILTER_G_HAMMING,
39         FILTER_COSINE,
40         FILTER_TRIANGLE,
41         FILTER_ABS_BANDLIMIT,   // filter times |x| 
42         FILTER_ABS_SINC, 
43         FILTER_ABS_G_HAMMING,
44         FILTER_ABS_COSINE,
45         FILTER_SHEPP
46     } FilterID;
47
48     typedef enum {
49         FILTER_METHOD_INVALID,
50         FILTER_METHOD_CONVOLUTION,
51         FILTER_METHOD_FOURIER,
52         FILTER_METHOD_FFT,
53         FILTER_METHOD_FFT_ZEROPAD_2,
54         FILTER_METHOD_FFT_ZEROPAD_4,
55         FILTER_METHOD_FFT_ZEROPAD_6
56     } FilterMethodID;
57
58     typedef enum {
59         DOMAIN_INVALID,
60         DOMAIN_FREQUENCY,
61         DOMAIN_SPATIAL 
62     } DomainID;
63     
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";
74     
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";
81
82     static const char DOMAIN_FREQUENCY_STR[]=    "frequency";
83     static const char DOMAIN_SPATIAL_STR[]= "spatial";
84
85
86     SignalFilter (const char* filterName, const char* filterMethodName,double bw, double signalLength, int n, double param, const char* domainName, const int numIntegral = 0);
87
88     SignalFilter (const FilterID filt_type, FilterMethodID filterMethodID, double bw, double signalLength, int n, double param, const DomainID domain, const int numIntegral = 0);
89
90     SignalFilter (const char* filterName, const char* domainName, double bw, double param, int numIntegral = 0);
91
92     ~SignalFilter (void);
93
94     double* getFilter (void) const
95       { return m_vecFilter; }
96
97     int getNFilterPoints (void) const
98         { return m_nFilterPoints; }
99
100     double convolve (const double f[], const double dx, const int n, const int np) const;
101
102     double convolve (const float f[], const double dx, const int n, const int np) const;
103
104     void filterSignal (const double input[], double output[], double dx, const int n) const;
105     void filterSignal (const float input[], double output[], double dx, const int n) const;
106
107     static void finiteFourierTransform (const double input[], complex<double> output[], const int n, const int direction);
108
109     void finiteFourierTransform (const double input[], complex<double> output[], const int direction) const;
110
111     bool fail(void) const       {return m_fail;}
112     const string& failMessage(void) const {return m_failMessage;}
113
114     const string& nameFilter(void) const        { return m_nameFilter;}
115     const string& nameDomain(void) const        { return m_nameDomain;}
116     const FilterID idFilter(void) const         { return m_idFilter;}
117     const DomainID idDomain(void) const         { return m_idDomain;}
118
119     double response (double x);
120
121     static double spatialResponse (FilterID fType, double bw, double x, double param, int nIntegral = 0);
122
123     static double frequencyResponse (FilterID fType, double bw, double u, double param);
124
125     static double spatialResponseCalc (FilterID fType, double bw, double x, double param, int n);
126
127     static double spatialResponseAnalytic (FilterID fType, double bw, double x, double param);
128
129  private:
130     double m_bw;
131     int m_nFilterPoints;
132     int m_nSignalPoints;
133     double m_signalLength;
134     double m_xmin;
135     double m_xmax;
136     double* m_vecFilter;
137     double* m_vecFourierCosTable;
138     double* m_vecFourierSinTable;
139
140     bool m_fail;
141     string m_failMessage;
142     string m_nameFilter;
143     string m_nameFilterMethod;
144     string m_nameDomain;
145     FilterID m_idFilter;
146     FilterMethodID m_idFilterMethod;
147     DomainID m_idDomain;
148     double m_filterParam;
149     int m_numIntegral;
150
151     static const FilterID convertFilterNameToID (const char* filterName);
152     static const char* convertFilterIDToName (const FilterID filterID);
153     static const FilterMethodID convertFilterMethodNameToID (const char* filterMethodName);
154     static const char* convertFilterMethodIDToName (const FilterMethodID filterMethodID);
155     static const DomainID convertDomainNameToID (const char* domainName);
156     static const char* convertDomainIDToName (const DomainID domainID);
157
158     void init (const FilterID filt_type, const FilterMethodID filterMethod, double bw, double xmin, double xmax, int n, double param, const DomainID domain, const int numInt);
159
160 double spatialResponseCalc (double x, double param, int n) const;
161
162     double spatialResponseAnalytic (double x, double param) const;
163
164     double frequencyResponse (double u, double param) const;
165
166     static double sinc (double x, double mult)
167       { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
168
169     static double integral_abscos (double u, double w);
170
171 };
172
173
174 #endif