r328: *** 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.22 2000/12/16 06:12:47 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
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35 #ifdef HAVE_FFTW
36 #include <fftw.h>
37 #include <rfftw.h>
38 #endif
39
40
41 // CLASS IDENTIFICATION
42 //    SignalFilter       A filter used to process signals
43 //
44 // CONTAINS
45 //    signal vector
46 //
47 //    Can create either a time/spatial waveform or a frequency signal
48 //    Waveforms can be created either by direct calculation or by inverse fourier transform
49
50 class SignalFilter {
51  public:
52     static const int FILTER_INVALID;
53     static const int FILTER_ABS_BANDLIMIT;      // filter times |x|
54     static const int FILTER_ABS_SINC;
55     static const int FILTER_ABS_G_HAMMING;
56     static const int FILTER_ABS_COSINE;
57     static const int FILTER_SHEPP;
58     static const int FILTER_BANDLIMIT;
59     static const int FILTER_SINC;
60     static const int FILTER_G_HAMMING;
61     static const int FILTER_COSINE;
62     static const int FILTER_TRIANGLE;
63
64     static const int DOMAIN_INVALID;
65     static const int DOMAIN_FREQUENCY;
66     static const int DOMAIN_SPATIAL;
67     
68     SignalFilter (const char* szFilterName, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const char* szDomainName);
69
70     SignalFilter (const int idFilter, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain);
71
72     SignalFilter (const char* szFilterName, const char* szDomainName, double dBandwidth, double dFilterParam);
73
74     ~SignalFilter (void);
75
76     double* getFilter (void) const
77       { return m_adFilter; }
78
79     bool fail(void) const       {return m_fail;}
80     const std::string& failMessage(void) const {return m_failMessage;}
81
82     const std::string& nameFilter(void) const   { return m_nameFilter;}
83     const std::string& nameDomain(void) const   { return m_nameDomain;}
84     const int idFilter(void) const      { return m_idFilter;}
85     const int idDomain(void) const      { return m_idDomain;}
86
87     int getNFilterPoints (void) const  { return m_nFilterPoints; }
88     const double getFilterMin(void) const {return m_dFilterMin;}
89     const double getFilterMax(void) const {return m_dFilterMax;}
90     const double getFilterIncrement(void) const {return m_dFilterInc;}
91     void copyFilterData(double *pdFilter, const int iStart, const int nPoints) const;
92
93     double response (double x);
94
95     static double spatialResponse (int fType, double bw, double x, double param);
96
97     static double frequencyResponse (int fType, double bw, double u, double param);
98
99     static double spatialResponseAnalytic (int fType, double bw, double x, double param);
100
101     static double spatialResponseCalc (int fType, double bw, double x, double param, int nIntegral);
102
103     static void setNumIntegral(int nIntegral) {N_INTEGRAL = nIntegral;}
104
105   static const int getFilterCount() {return s_iFilterCount;}
106   static const char** getFilterNameArray() {return s_aszFilterName;}
107   static const char** getFilterTitleArray() {return s_aszFilterTitle;}
108   static int convertFilterNameToID (const char* const filterName);
109   static const char* convertFilterIDToName (const int idFilter);
110   static const char* convertFilterIDToTitle (const int idFilter);
111
112   static const int getDomainCount() {return s_iDomainCount;}
113   static const char** getDomainNameArray() {return s_aszDomainName;}
114   static const char** getDomainTitleArray() {return s_aszDomainTitle;}
115   static int convertDomainNameToID (const char* const domainName);
116   static const char* convertDomainIDToName (const int idDomain);
117   static const char* convertDomainIDToTitle (const int idDomain);
118
119  private:
120     int m_nFilterPoints;
121     double m_dBandwidth;
122     double m_dFilterParam;
123     double m_dFilterInc;
124     double m_dFilterMin;
125     double m_dFilterMax;
126     double* m_adFilter;
127
128     std::string m_nameFilter;
129     std::string m_nameDomain;
130     int m_idFilter;
131     int m_idDomain;
132
133     bool m_fail;
134     std::string m_failMessage;
135
136     static const char* s_aszFilterName[];
137     static const char* s_aszFilterTitle[];
138     static const int s_iFilterCount;
139     static const char* s_aszDomainName[];
140     static const char* s_aszDomainTitle[];
141     static const int s_iDomainCount;
142     static int N_INTEGRAL;
143
144     static const bool haveAnalyticSpatial (const int filterID);
145
146     void init (const int idFilter, double dFilterMin, double dFilterMax, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain);
147
148     void createFrequencyFilter (double* x) const;
149     void createSpatialFilter (double* x) const;
150
151     double spatialResponseCalc (double x) const;
152     double spatialResponseAnalytic (double x) const;
153     double frequencyResponse (double u) const;
154
155     static double sinc (double x, double mult)
156       { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
157     static double integral_abscos (double u, double w)
158     { return (fabs (u) > F_EPSILON ? (cos (u * w) - 1) / (u * u) + w / u * sin (u * w) : (w * w / 2)); }
159 };
160
161 #endif