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-2001 Kevin Rosenberg
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.
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.
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 ******************************************************************************/
40 // CLASS IDENTIFICATION
41 // SignalFilter A filter used to process signals
46 // Can create either a time/spatial waveform or a frequency signal
47 // Waveforms can be created either by direct calculation or by inverse fourier transform
51 static const int FILTER_INVALID;
52 static const int FILTER_ABS_BANDLIMIT; // filter times |x|
53 static const int FILTER_ABS_SINC;
54 static const int FILTER_ABS_G_HAMMING;
55 static const int FILTER_ABS_HANNING;
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_HANNING;
62 static const int FILTER_COSINE;
63 static const int FILTER_TRIANGLE;
65 static const int DOMAIN_INVALID;
66 static const int DOMAIN_FREQUENCY;
67 static const int DOMAIN_SPATIAL;
69 SignalFilter (const char* szFilterName, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const char* szDomainName);
71 SignalFilter (const int idFilter, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain);
73 SignalFilter (const char* szFilterName, const char* szDomainName, double dBandwidth, double dFilterParam);
77 double* getFilter (void) const
78 { return m_adFilter; }
80 bool fail(void) const {return m_fail;}
81 const std::string& failMessage(void) const {return m_failMessage;}
83 const std::string& nameFilter(void) const { return m_nameFilter;}
84 const std::string& nameDomain(void) const { return m_nameDomain;}
85 const int idFilter(void) const { return m_idFilter;}
86 const int idDomain(void) const { return m_idDomain;}
88 int getNFilterPoints (void) const { return m_nFilterPoints; }
89 const double getFilterMin(void) const {return m_dFilterMin;}
90 const double getFilterMax(void) const {return m_dFilterMax;}
91 const double getFilterIncrement(void) const {return m_dFilterInc;}
92 void copyFilterData(double *pdFilter, const int iStart, const int nPoints) const;
94 double response (double x);
96 static double spatialResponse (int fType, double bw, double x, double param);
98 static double frequencyResponse (int fType, double bw, double u, double param);
100 static double spatialResponseAnalytic (int fType, double bw, double x, double param);
102 static double spatialResponseCalc (int fType, double bw, double x, double param, int nIntegral);
104 static void setNumIntegral(int nIntegral) {N_INTEGRAL = nIntegral;}
106 static const int getFilterCount() {return s_iFilterCount;}
107 static const int getReconstructFilterCount() { return s_iReconstructFilterCount; }
109 static const char* const* getFilterNameArray() {return s_aszFilterName;}
110 static const char* const* getFilterTitleArray() {return s_aszFilterTitle;}
111 static int convertFilterNameToID (const char* const filterName);
112 static const char* convertFilterIDToName (const int idFilter);
113 static const char* convertFilterIDToTitle (const int idFilter);
115 static const int getDomainCount() {return s_iDomainCount;}
116 static const char* const* getDomainNameArray() {return s_aszDomainName;}
117 static const char* const* getDomainTitleArray() {return s_aszDomainTitle;}
118 static int convertDomainNameToID (const char* const domainName);
119 static const char* convertDomainIDToName (const int idDomain);
120 static const char* convertDomainIDToTitle (const int idDomain);
122 static double sinc (double x)
123 { return (fabs(x) > F_EPSILON ? (sin (x) / x) : 1.0); }
125 static double sinc (double x, double mult)
126 { return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); }
131 double m_dFilterParam;
137 std::string m_nameFilter;
138 std::string m_nameDomain;
143 std::string m_failMessage;
145 static const char* const s_aszFilterName[];
146 static const char* const s_aszFilterTitle[];
147 static const int s_iFilterCount;
148 static const int s_iReconstructFilterCount;
149 static const char* const s_aszDomainName[];
150 static const char* const s_aszDomainTitle[];
151 static const int s_iDomainCount;
152 static int N_INTEGRAL;
154 static const bool haveAnalyticSpatial (const int filterID);
156 void init (const int idFilter, double dFilterMin, double dFilterMax, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain);
158 void createFrequencyFilter (double* x) const;
159 void createSpatialFilter (double* x) const;
161 double spatialResponseCalc (double x) const;
162 double spatialResponseAnalytic (double x) const;
163 double frequencyResponse (double u) const;
165 static double integral_abscos (double u, double w)
166 { return (fabs (u) > F_EPSILON ? (cos (u * w) - 1) / (u * u) + w / u * sin (u * w) : (w * w / 2)); }