qm-dsp 1.8
KaiserWindow.h
Go to the documentation of this file.
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
26{
27public:
28 struct Parameters {
29 int length;
30 double beta;
31 };
32
37 KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); }
38
43 static KaiserWindow byTransitionWidth(double attenuation,
44 double transition) {
45 return KaiserWindow
46 (parametersForTransitionWidth(attenuation, transition));
47 }
48
53 static KaiserWindow byBandwidth(double attenuation,
54 double bandwidth,
55 double samplerate) {
56 return KaiserWindow
57 (parametersForBandwidth(attenuation, bandwidth, samplerate));
58 }
59
64 static Parameters parametersForTransitionWidth(double attenuation,
65 double transition);
66
72 static Parameters parametersForBandwidth(double attenuation,
73 double bandwidth,
74 double samplerate) {
76 (attenuation, (bandwidth * 2 * M_PI) / samplerate);
77 }
78
79 int getLength() const {
80 return m_length;
81 }
82
83 const double *getWindow() const {
84 return m_window.data();
85 }
86
87 void cut(double *src) const {
88 cut(src, src);
89 }
90
91 void cut(const double *src, double *dst) const {
92 for (int i = 0; i < m_length; ++i) {
93 dst[i] = src[i] * m_window[i];
94 }
95 }
96
97private:
99 double m_beta;
100 std::vector<double> m_window;
101
102 void init();
103};
104
105#endif
Kaiser window: A windower whose bandwidth and sidelobe height (signal-noise ratio) can be specified.
static Parameters parametersForBandwidth(double attenuation, double bandwidth, double samplerate)
Obtain the parameters necessary for a Kaiser window of the given attenuation in dB and transition ban...
int getLength() const
const double * getWindow() const
std::vector< double > m_window
static KaiserWindow byTransitionWidth(double attenuation, double transition)
Construct a Kaiser windower with the given attenuation in dB and transition width in samples.
static Parameters parametersForTransitionWidth(double attenuation, double transition)
Obtain the parameters necessary for a Kaiser window of the given attenuation in dB and transition wid...
void cut(double *src) const
KaiserWindow(Parameters p)
Construct a Kaiser windower with the given length and beta parameter.
static KaiserWindow byBandwidth(double attenuation, double bandwidth, double samplerate)
Construct a Kaiser windower with the given attenuation in dB and transition bandwidth in Hz for the g...
void cut(const double *src, double *dst) const