r126: *** 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.5 2000/06/30 02:03:27 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, double bw, double xmin, double xmax, int n, double param, const char* domainName, const int numIntegral = 0);
87
88     SignalFilter (const FilterID filt_type, double bw, double xmin, double xmax, 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     double convolve (const double f[], const double dx, const int n, const int np) const;
98
99     double convolve (const float f[], const double dx, const int n, const int np) const;
100
101     bool fail(void) const       {return m_fail;}
102     const string& failMessage(void) const {return m_failMessage;}
103
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;}
108
109     double response (double x);
110
111     static double spatialResponse (FilterID fType, double bw, double x, double param, int nIntegral = 0);
112
113     static double frequencyResponse (FilterID fType, double bw, double u, double param);
114
115     static double spatialResponseCalc (FilterID fType, double bw, double x, double param, int n);
116
117     static double spatialResponseAnalytic (FilterID fType, double bw, double x, double param);
118
119  private:
120     double m_bw;
121     int m_nPoints;
122     double m_xmin;
123     double m_xmax;
124     double* m_vecFilter;
125     bool m_fail;
126     string m_failMessage;
127     string m_nameFilter;
128     string m_nameFilterMethod;
129     string m_nameDomain;
130     FilterID m_idFilter;
131     FilterMethodID m_idFilterMethod;
132     DomainID m_idDomain;
133     double m_filterParam;
134     int m_numIntegral;
135
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);
140
141     void init (const FilterID filt_type, double bw, double xmin, double xmax, int n, double param, const DomainID domain, const int numInt);
142
143 double spatialResponseCalc (double x, double param, int n) const;
144
145     double spatialResponseAnalytic (double x, double param) const;
146
147     double frequencyResponse (double u, double param) const;
148
149     static double sinc (double x, double mult)
150       { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
151
152     static double integral_abscos (double u, double w);
153
154 };
155
156
157 #endif