From 6769872b397e28c6a8023b45bd6766e351fae4a2 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Thu, 3 Jan 2019 19:50:18 +0100 Subject: [PATCH] moved sinc() to utils --- README.md | 1 + resampler.hh | 6 +----- utils.hh | 6 ++++++ window.hh | 6 +----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cb4627f..1e16bdb 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Some everyday helpers: * [signum function](https://en.wikipedia.org/wiki/Sign_function) * [lerp function](https://en.wikipedia.org/wiki/Linear_interpolation) * [probability density function](https://en.wikipedia.org/wiki/Probability_density_function) of the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) +* [sinc function](https://en.wikipedia.org/wiki/Sinc_function) ### [resampler.hh](resampler.hh) diff --git a/resampler.hh b/resampler.hh index 753be93..4353135 100644 --- a/resampler.hh +++ b/resampler.hh @@ -10,6 +10,7 @@ Copyright 2018 Ahmet Inan #include "window.hh" #include "spline.hh" +#include "utils.hh" #include "const.hh" namespace DSP { @@ -19,11 +20,6 @@ class Resampler { typedef DSP::UniformNaturalCubicSpline spline_type; spline_type lpf; - - static TYPE sinc(TYPE x) - { - return TYPE(0) == x ? TYPE(1) : std::sin(DSP::Const::Pi() * x) / (DSP::Const::Pi() * x); - } public: Resampler(TYPE cutoff, TYPE alpha) { diff --git a/utils.hh b/utils.hh index ff987b3..c155ee2 100644 --- a/utils.hh +++ b/utils.hh @@ -29,6 +29,12 @@ TYPE normal_pdf(TYPE x, TYPE m, TYPE s) return std::exp(-std::pow((x - m) / s, TYPE(2)) / TYPE(2)) / (Const::SqrtTwoPi() * s); } +template +TYPE sinc(TYPE x) +{ + return TYPE(0) == x ? TYPE(1) : std::sin(Const::Pi() * x) / (Const::Pi() * x); +} + } #endif diff --git a/window.hh b/window.hh index c01bf88..f8cd512 100644 --- a/window.hh +++ b/window.hh @@ -9,6 +9,7 @@ Copyright 2018 Ahmet Inan #include "const.hh" #include "kahan.hh" +#include "utils.hh" #include "coeffs.hh" namespace DSP { @@ -40,11 +41,6 @@ struct Hamming : public CoeffsFunc template class Lanczos : public CoeffsFunc { - static TYPE sinc(TYPE x) - { - return TYPE(0) == x ? TYPE(1) : std::sin(Const::Pi() * x) / (Const::Pi() * x); - } -public: TYPE operator () (int n, int N) { return sinc(TYPE(2 * n) / TYPE(N - 1) - TYPE(1));