-
Notifications
You must be signed in to change notification settings - Fork 2
/
filters.h
105 lines (81 loc) · 2.6 KB
/
filters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef _FILTERS_H_
#define _FILTERS_H_
class CGenericFilter
{
public:
CGenericFilter (double dWidth) : m_dWidth (dWidth) {}
virtual ~CGenericFilter() {}
double GetWidth() { return m_dWidth; }
void SetWidth (double dWidth) { m_dWidth = dWidth; }
virtual double Filter (double dVal) = 0;
protected:
#define FILTER_PI double (3.1415926535897932384626433832795)
#define FILTER_2PI double (2.0 * 3.1415926535897932384626433832795)
#define FILTER_4PI double (4.0 * 3.1415926535897932384626433832795)
double m_dWidth;
};
class CBoxFilter : public CGenericFilter
{
public:
CBoxFilter (double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
virtual ~CBoxFilter() {}
double Filter (double dVal) { return (fabs((double)dVal) <= m_dWidth ? 1.0 : 0.0); }
};
class CBilinearFilter : public CGenericFilter
{
public:
CBilinearFilter (double dWidth = double(1.0)) : CGenericFilter(dWidth) {}
virtual ~CBilinearFilter() {}
double Filter (double dVal)
{
dVal = fabs((double)dVal);
return (dVal < m_dWidth ? m_dWidth - dVal : 0.0);
}
};
class CGaussianFilter : public CGenericFilter
{
public:
CGaussianFilter (double dWidth = double(3.0)) : CGenericFilter(dWidth) {}
virtual ~CGaussianFilter() {}
double Filter (double dVal)
{
if (fabs ((double)dVal) > m_dWidth)
{
return 0.0;
}
return exp (-dVal * dVal / 2.0) / sqrt ((double)FILTER_2PI);
}
};
class CHammingFilter : public CGenericFilter
{
public:
CHammingFilter (double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
virtual ~CHammingFilter() {}
double Filter (double dVal)
{
if (fabs ((double)dVal) > m_dWidth)
{
return 0.0;
}
double dWindow = 0.54 + 0.46 * cos ((double)FILTER_2PI * dVal);
double dSinc = (dVal == 0) ? 1.0 : sin ((double)FILTER_PI * dVal) / (FILTER_PI * dVal);
return dWindow * dSinc;
}
};
class CBlackmanFilter : public CGenericFilter
{
public:
CBlackmanFilter (double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
virtual ~CBlackmanFilter() {}
double Filter (double dVal)
{
if (fabs ((double)dVal) > m_dWidth)
{
return 0.0;
}
double dN = 2.0 * m_dWidth + 1.0;
return 0.42 + 0.5 * cos (FILTER_2PI * dVal / ( dN - 1.0 )) +
0.08 * cos (FILTER_4PI * dVal / ( dN - 1.0 ));
}
};
#endif // _FILTERS_H_