1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
5 Centre for Digital Music, Queen Mary, University of London.
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version. See the file
11 COPYING included with this distribution for more information.
14 #include "KaiserWindow.h"
16 #include "maths/MathUtilities.h"
18 KaiserWindow::Parameters
19 KaiserWindow::parametersForTransitionWidth(double attenuation,
23 p.length = 1 + (attenuation > 21.0 ?
24 ceil((attenuation - 7.95) / (2.285 * transition)) :
25 ceil(5.79 / transition));
26 p.beta = (attenuation > 50.0 ?
27 0.1102 * (attenuation - 8.7) :
29 0.5842 * pow(attenuation - 21.0, 0.4) + 0.07886 * (attenuation - 21.0) :
34 static double besselTerm(double x, int i)
39 double f = MathUtilities::factorial(i);
40 return pow(x/2, i*2) / (f*f);
44 static double bessel0(double x)
47 for (int i = 0; i < 20; ++i) {
48 b += besselTerm(x, i);
56 double denominator = bessel0(m_beta);
57 bool even = (m_length % 2 == 0);
58 for (int i = 0; i < (even ? m_length/2 : (m_length+1)/2); ++i) {
59 double k = double(2*i) / double(m_length-1) - 1.0;
60 m_window.push_back(bessel0(m_beta * sqrt(1.0 - k*k)) / denominator);
62 for (int i = 0; i < (even ? m_length/2 : (m_length-1)/2); ++i) {
63 m_window.push_back(m_window[int(m_length/2) - i - 1]);