diff --git a/filter.hh b/filter.hh index cb7d8ec..006aacd 100644 --- a/filter.hh +++ b/filter.hh @@ -18,7 +18,7 @@ class LowPass TYPE f; public: LowPass(TYPE cutoff) : f(TYPE(2) * cutoff) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1); return f * sinc(f * x); @@ -32,7 +32,7 @@ class LowPass2 TYPE fac; public: LowPass2(int num, int den) : num(num), den(den), fac(TYPE(2*num)/TYPE(den)) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { int twox = 2 * n - (N - 1); return !twox ? fac : fac * @@ -47,7 +47,7 @@ class HighPass TYPE f; public: HighPass(TYPE cutoff) : f(TYPE(2) * cutoff) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1); // if (N%1) return delta(x) - f * sinc(f * x); @@ -63,7 +63,7 @@ class HighPass2 TYPE fac; public: HighPass2(int num, int den) : num(num), den(den), fac(TYPE(2*num)/TYPE(den)) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { int twox = 2 * n - (N - 1); return !twox ? TYPE(1) - fac : @@ -80,7 +80,7 @@ class BandPass public: BandPass(TYPE cutoff0, TYPE cutoff1) : f0(TYPE(2) * cutoff0), f1(TYPE(2) * cutoff1) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1); return f1 * sinc(f1 * x) - f0 * sinc(f0 * x); @@ -90,7 +90,7 @@ public: template struct HilbertTransform { - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { if (N&1) { int x = n - (N - 1) / 2; diff --git a/window.hh b/window.hh index 17fd00c..8eac7ee 100644 --- a/window.hh +++ b/window.hh @@ -16,13 +16,13 @@ namespace DSP { template struct Rect { - TYPE operator () (int n, int N) { return n >= 0 && n < N ? 1 : 0; } + TYPE operator () (int n, int N) const { return n >= 0 && n < N ? 1 : 0; } }; template struct Hann { - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { return TYPE(0.5) * (TYPE(1) - UnitCircle::cos(n, N - 1)); } @@ -31,7 +31,7 @@ struct Hann template struct Hamming { - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { return TYPE(0.54) - TYPE(0.46) * UnitCircle::cos(n, N - 1); } @@ -40,7 +40,7 @@ struct Hamming template struct Lanczos { - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { #if 0 return sinc(TYPE(2 * n) / TYPE(N - 1) - TYPE(1)); @@ -60,7 +60,7 @@ public: Blackman(TYPE a) : Blackman((TYPE(1) - a) / TYPE(2), TYPE(0.5), a / TYPE(2)) {} // "exact Blackman" Blackman() : Blackman(TYPE(7938) / TYPE(18608), TYPE(9240) / TYPE(18608), TYPE(1430) / TYPE(18608)) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { return a0 - a1 * UnitCircle::cos(n, N-1) + a2 * UnitCircle::cos((2*n)%(N-1), N-1); } @@ -72,7 +72,7 @@ class Gauss TYPE o; public: Gauss(TYPE o) : o(o) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { return exp(- TYPE(0.5) * pow((TYPE(n) - TYPE(N - 1) / TYPE(2)) / (o * TYPE(N - 1) / TYPE(2)), TYPE(2))); } @@ -110,7 +110,7 @@ class Kaiser } public: Kaiser(TYPE a) : a(a) {} - TYPE operator () (int n, int N) + TYPE operator () (int n, int N) const { return i0(Const::Pi() * a * sqrt(TYPE(1) - sqr(TYPE(2 * n) / TYPE(N - 1) - TYPE(1)))) / i0(Const::Pi() * a); }