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-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
38 // CLASS IDENTIFICATION
39 // SignalFilter A filter used to process signals
44 // Can create either a time/spatial waveform or a frequency signal
45 // Waveforms can be created either by direct calculation or by inverse fourier transform
49 static const int FILTER_INVALID;
50 static const int FILTER_ABS_BANDLIMIT; // filter times |x|
51 static const int FILTER_ABS_SINC;
52 static const int FILTER_ABS_G_HAMMING;
53 static const int FILTER_ABS_HANNING;
54 static const int FILTER_ABS_COSINE;
55 static const int FILTER_SHEPP;
56 static const int FILTER_BANDLIMIT;
57 static const int FILTER_SINC;
58 static const int FILTER_G_HAMMING;
59 static const int FILTER_HANNING;
60 static const int FILTER_COSINE;
61 static const int FILTER_TRIANGLE;
63 static const int DOMAIN_INVALID;
64 static const int DOMAIN_FREQUENCY;
65 static const int DOMAIN_SPATIAL;
67 SignalFilter (const char* szFilterName, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const char* szDomainName);
69 SignalFilter (const int idFilter, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain);
71 SignalFilter (const char* szFilterName, const char* szDomainName, double dBandwidth, double dFilterParam);
75 double* getFilter (void) const
76 { return m_adFilter; }
78 bool fail(void) const {return m_fail;}
79 const std::string& failMessage(void) const {return m_failMessage;}
81 const std::string& nameFilter(void) const { return m_nameFilter;}
82 const std::string& nameDomain(void) const { return m_nameDomain;}
83 const int idFilter(void) const { return m_idFilter;}
84 const int idDomain(void) const { return m_idDomain;}
86 int getNFilterPoints (void) const { return m_nFilterPoints; }
87 const double getFilterMin(void) const {return m_dFilterMin;}
88 const double getFilterMax(void) const {return m_dFilterMax;}
89 const double getFilterIncrement(void) const {return m_dFilterInc;}
90 void copyFilterData(double *pdFilter, const int iStart, const int nPoints) const;
92 double response (double x);
94 static double spatialResponse (int fType, double bw, double x, double param);
96 static double frequencyResponse (int fType, double bw, double u, double param);
98 static double spatialResponseAnalytic (int fType, double bw, double x, double param);
100 static double spatialResponseCalc (int fType, double bw, double x, double param, int nIntegral);
102 static void setNumIntegral(int nIntegral) {N_INTEGRAL = nIntegral;}
104 static const int getFilterCount() {return s_iFilterCount;}
105 static const int getReconstructFilterCount() { return s_iReconstructFilterCount; }
107 static const char* const* getFilterNameArray() {return s_aszFilterName;}
108 static const char* const* getFilterTitleArray() {return s_aszFilterTitle;}
109 static int convertFilterNameToID (const char* const filterName);
110 static const char* convertFilterIDToName (const int idFilter);
111 static const char* convertFilterIDToTitle (const int idFilter);
113 static const int getDomainCount() {return s_iDomainCount;}
114 static const char* const* getDomainNameArray() {return s_aszDomainName;}
115 static const char* const* getDomainTitleArray() {return s_aszDomainTitle;}
116 static int convertDomainNameToID (const char* const domainName);
117 static const char* convertDomainIDToName (const int idDomain);
118 static const char* convertDomainIDToTitle (const int idDomain);
120 static double sinc (double x)
121 { return (fabs(x) > F_EPSILON ? (sin (x) / x) : 1.0); }
123 static double sinc (double x, double mult)
124 { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
129 double m_dFilterParam;
135 std::string m_nameFilter;
136 std::string m_nameDomain;
141 std::string m_failMessage;
143 static const char* const s_aszFilterName[];
144 static const char* const s_aszFilterTitle[];
145 static const int s_iFilterCount;
146 static const int s_iReconstructFilterCount;
147 static const char* const s_aszDomainName[];
148 static const char* const s_aszDomainTitle[];
149 static const int s_iDomainCount;
150 static int N_INTEGRAL;
152 static const bool haveAnalyticSpatial (const int filterID);
154 void init (const int idFilter, double dFilterMin, double dFilterMax, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain);
156 void createFrequencyFilter (double* x) const;
157 void createSpatialFilter (double* x) const;
159 double spatialResponseCalc (double x) const;
160 double spatialResponseAnalytic (double x) const;
161 double frequencyResponse (double u) const;
163 static double integral_abscos (double u, double w)
164 { return (fabs (u) > F_EPSILON ? (cos (u * w) - 1) / (u * u) + w / u * sin (u * w) : (w * w / 2)); }