| 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-2009 Kevin Rosenberg |
| 11 |
** |
| 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. |
| 15 |
** |
| 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. |
| 20 |
** |
| 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 |
******************************************************************************/ |
| 25 |
|
| 26 |
#ifndef FILTER_H |
| 27 |
#define FILTER_H |
| 28 |
|
| 29 |
|
| 30 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include "config.h" |
| 32 |
#endif |
| 33 |
#ifdef HAVE_FFTW |
| 34 |
#include <fftw3.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
|
| 38 |
// CLASS IDENTIFICATION |
| 39 |
// SignalFilter A filter used to process signals |
| 40 |
// |
| 41 |
// CONTAINS |
| 42 |
// signal vector |
| 43 |
// |
| 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 |
| 46 |
|
| 47 |
class SignalFilter { |
| 48 |
public: |
| 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; |
| 62 |
|
| 63 |
static const int DOMAIN_INVALID; |
| 64 |
static const int DOMAIN_FREQUENCY; |
| 65 |
static const int DOMAIN_SPATIAL; |
| 66 |
|
| 67 |
SignalFilter (const char* szFilterName, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const char* szDomainName); |
| 68 |
|
| 69 |
SignalFilter (const int idFilter, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain); |
| 70 |
|
| 71 |
SignalFilter (const char* szFilterName, const char* szDomainName, double dBandwidth, double dFilterParam); |
| 72 |
|
| 73 |
~SignalFilter (void); |
| 74 |
|
| 75 |
double* getFilter (void) const |
| 76 |
{ return m_adFilter; } |
| 77 |
|
| 78 |
bool fail(void) const {return m_fail;} |
| 79 |
const std::string& failMessage(void) const {return m_failMessage;} |
| 80 |
|
| 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;} |
| 85 |
|
| 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; |
| 91 |
|
| 92 |
double response (double x); |
| 93 |
|
| 94 |
static double spatialResponse (int fType, double bw, double x, double param); |
| 95 |
|
| 96 |
static double frequencyResponse (int fType, double bw, double u, double param); |
| 97 |
|
| 98 |
static double spatialResponseAnalytic (int fType, double bw, double x, double param); |
| 99 |
|
| 100 |
static double spatialResponseCalc (int fType, double bw, double x, double param, int nIntegral); |
| 101 |
|
| 102 |
static void setNumIntegral(int nIntegral) {N_INTEGRAL = nIntegral;} |
| 103 |
|
| 104 |
static const int getFilterCount() {return s_iFilterCount;} |
| 105 |
static const int getReconstructFilterCount() { return s_iReconstructFilterCount; } |
| 106 |
|
| 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); |
| 112 |
|
| 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); |
| 119 |
|
| 120 |
static double sinc (double x) |
| 121 |
{ return (fabs(x) > F_EPSILON ? (sin (x) / x) : 1.0); } |
| 122 |
|
| 123 |
static double sinc (double x, double mult) |
| 124 |
{ return (fabs(x) > F_EPSILON ? (sin (x * mult) / x) : 1.0); } |
| 125 |
|
| 126 |
private: |
| 127 |
int m_nFilterPoints; |
| 128 |
double m_dBandwidth; |
| 129 |
double m_dFilterParam; |
| 130 |
double m_dFilterInc; |
| 131 |
double m_dFilterMin; |
| 132 |
double m_dFilterMax; |
| 133 |
double* m_adFilter; |
| 134 |
|
| 135 |
std::string m_nameFilter; |
| 136 |
std::string m_nameDomain; |
| 137 |
int m_idFilter; |
| 138 |
int m_idDomain; |
| 139 |
|
| 140 |
bool m_fail; |
| 141 |
std::string m_failMessage; |
| 142 |
|
| 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; |
| 151 |
|
| 152 |
static const bool haveAnalyticSpatial (const int filterID); |
| 153 |
|
| 154 |
void init (const int idFilter, double dFilterMin, double dFilterMax, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain); |
| 155 |
|
| 156 |
void createFrequencyFilter (double* x) const; |
| 157 |
void createSpatialFilter (double* x) const; |
| 158 |
|
| 159 |
double spatialResponseCalc (double x) const; |
| 160 |
double spatialResponseAnalytic (double x) const; |
| 161 |
double frequencyResponse (double u) const; |
| 162 |
|
| 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)); } |
| 165 |
}; |
| 166 |
|
| 167 |
#endif |