kwave  18.07.70
WindowFunction.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  WindowFunction.cpp - Windows functions for signal processing
3  -------------------
4  begin : Feb 05 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include <KLocalizedString>
20 #include <math.h>
21 
22 #include "libkwave/String.h"
23 #include "libkwave/Utils.h"
25 
26 //***************************************************************************
27 //***************************************************************************
28 
30 {
32  _("none"), _(I18N_NOOP("None")));
34  _("hamming"), _(I18N_NOOP("Hamming")));
36  _("hanning"), _(I18N_NOOP("Hanning")));
38  _("blackman"), _(I18N_NOOP("Blackman")));
40  _("triangular"), _(I18N_NOOP("Triangular")));
41 }
42 
43 //***************************************************************************
44 // static initializer
46 
47 //***************************************************************************
48 //***************************************************************************
50  :m_type(type)
51 {
52 }
53 
54 //***************************************************************************
56 {
57 }
58 
59 //***************************************************************************
60 QVector<double> Kwave::WindowFunction::points(unsigned int len) const
61 {
62  QVector<double> out(len);
63  Q_ASSERT(out.count() == Kwave::toInt(len));
64  if (out.count() != Kwave::toInt(len)) {
65  out.resize(0);
66  return out;
67  }
68 
69  // Hanning, Hamming, Blackman window functions as proposed
70  // in Oppenheim, Schafer, p.241 ff
71  switch (m_type) {
72  case WINDOW_FUNC_NONE: //rectangular window
73  for (unsigned int i = 0; i < len; i++)
74  out[i] = 1;
75  break;
77  for (unsigned int i = 0; i < len; i++)
78  out[i] = 0.5 * (1 - cos(i * 2 * M_PI / (len - 1)));
79  break;
81  for (unsigned int i = 0; i < len; i++)
82  out[i] = 0.54-(0.46 * cos(static_cast<double>(i) * 2 * M_PI /
83  (len - 1)));
84  break;
86  for (unsigned int i = 0; i < len; i++)
87  out[i] = 0.42-(0.50 * cos(static_cast<double>(i) * 2 * M_PI /
88  (len - 1))) +
89  (0.08 * cos(static_cast<double>(i) * 4 * M_PI /
90  (len - 1)));
91  break;
93  for (unsigned int i = 0; i < len / 2; i++)
94  out[i] = static_cast<double>(i) / (len / 2 - 1);
95 
96  for (unsigned int i = len / 2; i < len; i++)
97  out[i] = 1 - (static_cast<double>(i) - len / 2) / (len / 2 - 1);
98  break;
99  }
100 
101  return out;
102 }
103 
104 //***************************************************************************
105 //***************************************************************************
static InitializedTypesMap m_types_map
window_function_t
window_function_t m_type
int toInt(T x)
Definition: Utils.h:127
virtual void append(window_function_t index, unsigned int data, const QString &name, const QString &description)
Definition: TypesMap.h:72
QVector< double > points(unsigned int len) const
WindowFunction(window_function_t type)
#define _(m)
Definition: memcpy.c:66
virtual void fill() Q_DECL_OVERRIDE