annotate base/KaiserWindow.cpp @ 378:f5b5f64835b9

Some docs; remove FiltFiltConfig as it's the same as FilterConfig
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 21 Oct 2013 11:59:57 +0100
parents 5ff562f5b521
children fdaa63607c15
rev   line source
c@349 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@349 2
c@349 3 /*
c@349 4 QM DSP library
c@349 5 Centre for Digital Music, Queen Mary, University of London.
c@349 6
c@349 7 This program is free software; you can redistribute it and/or
c@349 8 modify it under the terms of the GNU General Public License as
c@349 9 published by the Free Software Foundation; either version 2 of the
c@349 10 License, or (at your option) any later version. See the file
c@349 11 COPYING included with this distribution for more information.
c@349 12 */
c@349 13
c@349 14 #include "KaiserWindow.h"
c@349 15
c@349 16 #include "maths/MathUtilities.h"
c@349 17
c@349 18 KaiserWindow::Parameters
c@349 19 KaiserWindow::parametersForTransitionWidth(double attenuation,
c@349 20 double transition)
c@349 21 {
c@349 22 Parameters p;
c@349 23 p.length = 1 + (attenuation > 21.0 ?
c@349 24 ceil((attenuation - 7.95) / (2.285 * transition)) :
c@349 25 ceil(5.79 / transition));
c@349 26 p.beta = (attenuation > 50.0 ?
c@349 27 0.1102 * (attenuation - 8.7) :
c@349 28 attenuation > 21.0 ?
c@349 29 0.5842 * pow(attenuation - 21.0, 0.4) + 0.07886 * (attenuation - 21.0) :
c@349 30 0);
c@349 31 return p;
c@349 32 }
c@349 33
c@349 34 static double besselTerm(double x, int i)
c@349 35 {
c@349 36 if (i == 0) {
c@349 37 return 1;
c@349 38 } else {
c@349 39 double f = MathUtilities::factorial(i);
c@349 40 return pow(x/2, i*2) / (f*f);
c@349 41 }
c@349 42 }
c@349 43
c@349 44 static double bessel0(double x)
c@349 45 {
c@349 46 double b = 0.0;
c@349 47 for (int i = 0; i < 20; ++i) {
c@349 48 b += besselTerm(x, i);
c@349 49 }
c@349 50 return b;
c@349 51 }
c@349 52
c@349 53 void
c@349 54 KaiserWindow::init()
c@349 55 {
c@349 56 double denominator = bessel0(m_beta);
c@352 57 bool even = (m_length % 2 == 0);
c@352 58 for (int i = 0; i < (even ? m_length/2 : (m_length+1)/2); ++i) {
c@349 59 double k = double(2*i) / double(m_length-1) - 1.0;
c@349 60 m_window.push_back(bessel0(m_beta * sqrt(1.0 - k*k)) / denominator);
c@349 61 }
c@352 62 for (int i = 0; i < (even ? m_length/2 : (m_length-1)/2); ++i) {
c@352 63 m_window.push_back(m_window[int(m_length/2) - i - 1]);
c@352 64 }
c@349 65 }