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 QM_DSP_KAISER_WINDOW_H
15 #define QM_DSP_KAISER_WINDOW_H
16 
17 #include <vector>
18 #include <cmath>
19 
26 {
27 public:
28  struct Parameters {
29  int length;
30  double beta;
31  };
32 
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 
97 private:
98  int m_length;
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...
Definition: KaiserWindow.h:25
int getLength() const
Definition: KaiserWindow.h:79
std::vector< double > m_window
Definition: KaiserWindow.h:100
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...
Definition: KaiserWindow.h:53
static Parameters parametersForTransitionWidth(double attenuation, double transition)
Obtain the parameters necessary for a Kaiser window of the given attenuation in dB and transition wid...
double m_beta
Definition: KaiserWindow.h:99
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...
Definition: KaiserWindow.h:72
void cut(const double *src, double *dst) const
Definition: KaiserWindow.h:91
const double * getWindow() const
Definition: KaiserWindow.h:83
static KaiserWindow byTransitionWidth(double attenuation, double transition)
Construct a Kaiser windower with the given attenuation in dB and transition width in samples...
Definition: KaiserWindow.h:43
void cut(double *src) const
Definition: KaiserWindow.h:87
KaiserWindow(Parameters p)
Construct a Kaiser windower with the given length and beta parameter.
Definition: KaiserWindow.h:37