Mercurial > hg > qm-dsp
comparison base/KaiserWindow.h @ 349:b247af4c23d2
Add Kaiser window (and some tests for it)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 04 Oct 2013 18:46:32 +0100 |
parents | |
children | 0d3b3c66652b |
comparison
equal
deleted
inserted
replaced
348:50fae18236ee | 349:b247af4c23d2 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 QM DSP library | |
5 Centre for Digital Music, Queen Mary, University of London. | |
6 | |
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. | |
12 */ | |
13 | |
14 #ifndef KAISER_WINDOW_H | |
15 #define KAISER_WINDOW_H | |
16 | |
17 #include <vector> | |
18 #include <cmath> | |
19 | |
20 class KaiserWindow | |
21 { | |
22 public: | |
23 struct Parameters { | |
24 int length; | |
25 double beta; | |
26 }; | |
27 | |
28 /** | |
29 * Construct a Kaiser windower with the given length and beta | |
30 * parameter. | |
31 */ | |
32 KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); } | |
33 | |
34 /** | |
35 * Construct a Kaiser windower with the given attenuation in dB | |
36 * and transition width in samples. | |
37 */ | |
38 static KaiserWindow byTransitionWidth(double attenuation, | |
39 double transition) { | |
40 return KaiserWindow | |
41 (parametersForTransitionWidth(attenuation, transition)); | |
42 } | |
43 | |
44 /** | |
45 * Construct a Kaiser windower with the given attenuation in dB | |
46 * and transition bandwidth in Hz for the given samplerate. | |
47 */ | |
48 static KaiserWindow byBandwidth(double attenuation, | |
49 double bandwidth, | |
50 double samplerate) { | |
51 return KaiserWindow | |
52 (parametersForBandwidth(attenuation, bandwidth, samplerate)); | |
53 } | |
54 | |
55 /** | |
56 * Obtain the parameters necessary for a Kaiser window of the | |
57 * given attenuation in dB and transition width in samples. | |
58 */ | |
59 static Parameters parametersForTransitionWidth(double attenuation, | |
60 double transition); | |
61 | |
62 /** | |
63 * Obtain the parameters necessary for a Kaiser window of the | |
64 * given attenuation in dB and transition bandwidth in Hz for the | |
65 * given samplerate. | |
66 */ | |
67 static Parameters parametersForBandwidth(double attenuation, | |
68 double bandwidth, | |
69 double samplerate) { | |
70 return parametersForTransitionWidth | |
71 (attenuation, (bandwidth * 2 * M_PI) / samplerate); | |
72 } | |
73 | |
74 int getLength() const { | |
75 return m_length; | |
76 } | |
77 | |
78 const double *getWindow() const { | |
79 return m_window.data(); | |
80 } | |
81 | |
82 void cut(double *src) const { | |
83 cut(src, src); | |
84 } | |
85 | |
86 void cut(const double *src, double *dst) const { | |
87 for (int i = 0; i < m_length; ++i) { | |
88 dst[i] = src[i] * m_window[i]; | |
89 } | |
90 } | |
91 | |
92 private: | |
93 int m_length; | |
94 double m_beta; | |
95 std::vector<double> m_window; | |
96 | |
97 void init(); | |
98 }; | |
99 | |
100 #endif |