r128: *** 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.7 2000/07/03 11:02:06 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 signalIncrement, int n, double param, const char* domainName, const int numIntegral = 0);
87
88     SignalFilter (const FilterID filt_type, FilterMethodID filterMethodID, double bw, double signalIncrement, 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[]) const;
105     void filterSignal (const float input[], double output[]) const;
106
107     static void finiteFourierTransform (const float input[], complex<double> output[], const int n, const int direction);
108
109     void finiteFourierTransform (const float 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     const double getFilterMin(void) const {return m_filterMin;}
119     const double getFilterMax(void) const {return m_filterMax;}
120     const double getFilterIncrement(void) const {return m_filterInc;}
121
122     double response (double x);
123
124     static double spatialResponse (FilterID fType, double bw, double x, double param, int nIntegral = 0);
125
126     static double frequencyResponse (FilterID fType, double bw, double u, double param);
127
128     static double spatialResponseCalc (FilterID fType, double bw, double x, double param, int n);
129
130     static double spatialResponseAnalytic (FilterID fType, double bw, double x, double param);
131
132  private:
133     double m_bw;
134     int m_nFilterPoints;
135     int m_nSignalPoints;
136     double m_signalInc;
137     double m_filterMin;
138     double m_filterMax;
139     double m_filterInc;
140     double* m_vecFilter;
141     double* m_vecFourierCosTable;
142     double* m_vecFourierSinTable;
143
144     bool m_fail;
145     string m_failMessage;
146     string m_nameFilter;
147     string m_nameFilterMethod;
148     string m_nameDomain;
149     FilterID m_idFilter;
150     FilterMethodID m_idFilterMethod;
151     DomainID m_idDomain;
152     double m_filterParam;
153     int m_numIntegral;
154
155     static const FilterID convertFilterNameToID (const char* filterName);
156     static const char* convertFilterIDToName (const FilterID filterID);
157     static const FilterMethodID convertFilterMethodNameToID (const char* filterMethodName);
158     static const char* convertFilterMethodIDToName (const FilterMethodID filterMethodID);
159     static const DomainID convertDomainNameToID (const char* domainName);
160     static const char* convertDomainIDToName (const DomainID domainID);
161
162     void init (const FilterID filt_type, const FilterMethodID filterMethod, double bw, double signalIncrement, int n, double param, const DomainID domain, const int numInt);
163
164 double spatialResponseCalc (double x, double param, int n) const;
165
166     double spatialResponseAnalytic (double x, double param) const;
167
168     double frequencyResponse (double u, double param) const;
169
170     static double sinc (double x, double mult)
171       { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
172
173     static double integral_abscos (double u, double w);
174
175 };
176
177
178 #endif