diff options
author | Jacob Gilbert <mrjacobagilbert@gmail.com> | 2020-04-24 12:33:15 -0600 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-04-26 11:17:00 -0400 |
commit | 44c0882682f2c9110f3a880b86faf2c9252a7c58 (patch) | |
tree | 734445a155aef0bf5afd9189bee3a2948118c274 | |
parent | cfdf6546024944b8cbbf2bd24b01c5efa5a6c237 (diff) |
gr-fft: added tukey window generation
-rw-r--r-- | gr-fft/include/gnuradio/fft/window.h | 10 | ||||
-rw-r--r-- | gr-fft/lib/window.cc | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/gr-fft/include/gnuradio/fft/window.h b/gr-fft/include/gnuradio/fft/window.h index 8daeacaf9a..6b44113936 100644 --- a/gr-fft/include/gnuradio/fft/window.h +++ b/gr-fft/include/gnuradio/fft/window.h @@ -288,6 +288,16 @@ public: static std::vector<float> riemann(int ntaps); /*! + * \brief Build a Tukey window. + * + * \param ntaps Number of coefficients in the window. + * \param alpha Shaping parameter for the Tukey window, an + * alpha of zero is equivalent to a rectangular + * window, an alpha of 1 is equivalent to Hann. + */ + static std::vector<float> tukey(int ntaps, float alpha); + + /*! * \brief Build a window using gr::fft::win_type to index the * type of window desired. * diff --git a/gr-fft/lib/window.cc b/gr-fft/lib/window.cc index 8638d3738f..8b0a07f430 100644 --- a/gr-fft/lib/window.cc +++ b/gr-fft/lib/window.cc @@ -316,6 +316,29 @@ std::vector<float> window::riemann(int ntaps) return taps; } +std::vector<float> window::tukey(int ntaps, float a) +{ + if ((a < 0) || (a > 1)) + throw std::out_of_range("window::tukey: alpha must be between 0 and 1"); + + float N = static_cast<float>(ntaps - 1); + + float aN = a * N; + float p1 = aN / 2.0; + float mid = midn(ntaps); + std::vector<float> taps(ntaps); + for (int i = 0; i < mid; i++) { + if (abs(i) < p1) { + taps[i] = 0.5 * (1.0 - cos((2 * GR_M_PI * i) / (aN))); + taps[ntaps - 1 - i] = taps[i]; + } else { + taps[i] = 1.0; + taps[ntaps - i - 1] = 1.0; + } + } + return taps; +} + std::vector<float> window::build(win_type type, int ntaps, double beta) { switch (type) { |