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 ******************************************************************************/
42 typedef std::complex<double> CTSimComplex;
47 static const int FILTER_METHOD_INVALID;
48 static const int FILTER_METHOD_CONVOLUTION;
49 static const int FILTER_METHOD_FOURIER;
50 static const int FILTER_METHOD_FOURIER_TABLE;
51 static const int FILTER_METHOD_FFT;
53 static const int FILTER_METHOD_FFTW;
54 static const int FILTER_METHOD_RFFTW;
57 static const int FILTER_GENERATION_INVALID;
58 static const int FILTER_GENERATION_DIRECT;
59 static const int FILTER_GENERATION_INVERSE_FOURIER;
66 ProcessSignal (const char* szFilterName, const char* szFilterMethodName,double bw, double signalIncrement,
67 int n, double param, const char* szDomainName, const char* szFilterGenerationName,
68 const int zeropad, const int preinterpolationFactor, const int iTraceLevel, int iGeometry,
69 double dFocalLength, double dSourceDetectorLength, SGP* pSGP = NULL);
73 void filterSignal (const float input[], double output[]) const;
75 bool fail(void) const {return m_fail;}
76 const std::string& failMessage(void) const {return m_failMessage;}
78 void setTraceLevel (int traceLevel) {m_traceLevel = traceLevel; }
80 int getNFilterPoints (void) const { return m_nFilterPoints; }
81 const double getFilterMin(void) const {return m_dFilterMin;}
82 const double getFilterMax(void) const {return m_dFilterMax;}
83 const double getFilterIncrement(void) const {return m_dFilterInc;}
84 double* getFilter(void) {return m_adFilter;}
85 const double* getFilter(void) const {return m_adFilter;}
87 const int idFilterGeneration() const { return m_idFilterGeneration;}
89 static const int getFilterGenerationCount() {return s_iFilterGenerationCount;}
90 static const char* const* getFilterGenerationNameArray() {return s_aszFilterGenerationName;}
91 static const char* const* getFilterGenerationTitleArray() {return s_aszFilterGenerationTitle;}
92 static int convertFilterGenerationNameToID (const char* const fgName);
93 static const char* convertFilterGenerationIDToName (const int idFG);
94 static const char* convertFilterGenerationIDToTitle (const int idFG);
96 static const int getFilterMethodCount() {return s_iFilterMethodCount;}
97 static const char* const* getFilterMethodNameArray() {return s_aszFilterMethodName;}
98 static const char* const* getFilterMethodTitleArray() {return s_aszFilterMethodTitle;}
99 static int convertFilterMethodNameToID (const char* const filterMethodName);
100 static const char* convertFilterMethodIDToName (const int idFilterMethod);
101 static const char* convertFilterMethodIDToTitle (const int idFilterMethod);
103 // transforms using direct trigometric calculation
104 static void finiteFourierTransform (const double input[], double output[], const int n, const int direction);
105 static void finiteFourierTransform (const double input[], std::complex<double> output[], const int n, const int direction);
106 static void finiteFourierTransform (const std::complex<double> input[], std::complex<double> output[], const int n, const int direction);
107 static void finiteFourierTransform (const std::complex<double> input[], double output[], const int n, const int direction);
109 static int addZeropadFactor (int n, int iZeropad);
112 std::string m_nameFilterMethod;
113 std::string m_nameFilterGeneration;
114 int m_idFilterMethod;
115 int m_idFilterGeneration;
117 double* m_adFourierCosTable;
118 double* m_adFourierSinTable;
125 bool m_bFrequencyFiltering;
127 // Variables also kept in SignalFilter class
133 double m_dFilterParam;
136 int m_iPreinterpolationFactor;
138 double m_dFocalLength;
139 double m_dSourceDetectorLength;
142 std::string m_failMessage;
144 static const char* const s_aszFilterMethodName[];
145 static const char* const s_aszFilterMethodTitle[];
146 static const int s_iFilterMethodCount;
147 static const char* const s_aszFilterGenerationName[];
148 static const char* const s_aszFilterGenerationTitle[];
149 static const int s_iFilterGenerationCount;
152 double *m_adRealFftInput, *m_adRealFftOutput, *m_adRealFftSignal, *m_adRealFftBackwardOutput;
153 fftw_plan m_realPlanForward, m_realPlanBackward;
154 fftw_complex *m_adComplexFftInput, *m_adComplexFftOutput, *m_adComplexFftSignal, *m_adComplexFftBackwardOutput;
155 fftw_plan m_complexPlanForward, m_complexPlanBackward;
158 void init (const int idFilter, int idFilterMethod, double dBandwidth, double dSignalIncrement,
159 int nSignalPoints, double dFilterParam, const int idDomain, int idFilterGeneration, const int iZeropad,
160 const int iPreinterpolationFactor, const int iTraceLevel, const int iGeometry, double dFocalLength,
161 double dSourceDetectorLength, SGP* pSGP);
163 // transforms that use precalculated trig tables, therefore don't
164 // require number of data points (n) as an argument
165 void finiteFourierTransform (const double input[], std::complex<double> output[], const int direction) const;
166 void finiteFourierTransform (const std::complex<double> input[], std::complex<double> output[], const int direction) const;
167 void finiteFourierTransform (const std::complex<double> input[], double output[], const int direction) const;
169 double convolve (const double func[], const double filter[], const double dx, const int n, const int np) const;
170 double convolve (const double f[], const double dx, const int n, const int np) const;
171 double convolve (const float f[], const double dx, const int n, const int np) const;