zsiciarz / aquila

Aquila is a digital signal processing library for C++11.
http://aquila-dsp.org
MIT License
459 stars 112 forks source link

Kaiser Window #52

Open ulikoehler opened 8 years ago

ulikoehler commented 8 years ago

In some of my projects I'm using the Kaiser Window as a DPSS window approximation. In some cases I was able to improve the SNR by using Kaiser windows instead of .

In https://github.com/zsiciarz/aquila/pull/51 I added some extra window functions. However, I couldn't add the Kaiser function because the formula depends on the modified Bessel function of the first kind.

My implementation (which is hereby released under CC0 1.0 Universal) depends on boost::math which provides Bessel functions:

template<typename T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr>
void kaiserWindow(T* out, size_t n, T alpha = 2.0) {
    using namespace boost::math;
    const T denom = (T)n - 1.0;
    const T piAlpha = boost::math::constants::pi<T>() * alpha;
    for (size_t i = 0; i < n; ++i) {
        T term1 = (2.0 * i / denom) - 1.0;
        out[i] = cyl_bessel_i(0, piAlpha * std::sqrt(1.0 - term1 * term1)) / cyl_bessel_i(0, piAlpha);
    }
}

However, boost::math is a huge template library. I'd like to avoid introducing it as a aquila dependency just because of a single window function.

Do you see any alternative to using boost::math for this?

pfeatherstone commented 3 years ago

C++17 now has bessel functions in the standard library