SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
fftwindow.h
Go to the documentation of this file.
1 // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
3 // written by Christian Daniel //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef INCLUDE_FFTWINDOW_H
20 #define INCLUDE_FFTWINDOW_H
21 
22 #include <vector>
23 #define _USE_MATH_DEFINES
24 #include <math.h>
25 #include "dsp/dsptypes.h"
26 #include "export.h"
27 
28 #undef M_PI
29 #define M_PI 3.14159265358979323846
30 
32 public:
33  enum Function {
39  Rectangle
40  };
41 
42  void create(Function function, int n);
43  void apply(const std::vector<Real>& in, std::vector<Real>* out);
44  void apply(const std::vector<Complex>& in, std::vector<Complex>* out);
45  void apply(const Complex* in, Complex* out);
46 
47 private:
48  std::vector<float> m_window;
49 
50  static inline Real flatTop(Real n, Real i)
51  {
52  // correction ?
53  return 1.0 - 1.93 * cos((2.0 * M_PI * i) / n) + 1.29 * cos((4.0 * M_PI * i) / n) - 0.388 * cos((6.0 * M_PI * i) / n) + 0.03222 * cos((8.0 * M_PI * i) / n);
54  }
55 
56  static inline Real bartlett(Real n, Real i)
57  {
58  // amplitude correction = 2.0
59  return (2.0 / (n - 1.0)) * ( (n - 1.0) / 2.0 - fabs(i - (n - 1.0) / 2.0)) * 2.0;
60  }
61 
62  static inline Real blackmanHarris(Real n, Real i)
63  {
64  // amplitude correction = 2.79
65  return (0.35875 - 0.48829 * cos((2.0 * M_PI * i) / n) + 0.14128 * cos((4.0 * M_PI * i) / n) - 0.01168 * cos((6.0 * M_PI * i) / n)) * 2.79;
66  }
67 
68  static inline Real hamming(Real n, Real i)
69  {
70  // amplitude correction = 1.855, energy correction = 1.586
71  return (0.54 - 0.46 * cos((2.0 * M_PI * i) / n)) * 1.855;
72  }
73 
74  static inline Real hanning(Real n, Real i)
75  {
76  // amplitude correction = 2.0, energy correction = 1.633
77  return (0.5 - 0.5 * cos((2.0 * M_PI * i) / n)) * 2.0;
78  }
79 
80  static inline Real rectangle(Real, Real)
81  {
82  return 1.0;
83  }
84 };
85 
86 #endif // INCLUDE_FFTWINDOWS_H
static Real rectangle(Real, Real)
Definition: fftwindow.h:80
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
static Real flatTop(Real n, Real i)
Definition: fftwindow.h:50
void * create(QString type)
int32_t i
Definition: decimators.h:244
static Real blackmanHarris(Real n, Real i)
Definition: fftwindow.h:62
static Real hamming(Real n, Real i)
Definition: fftwindow.h:68
static Real bartlett(Real n, Real i)
Definition: fftwindow.h:56
static Real hanning(Real n, Real i)
Definition: fftwindow.h:74
#define M_PI
Definition: fftwindow.h:29
std::vector< float > m_window
Definition: fftwindow.h:48
#define SDRBASE_API
Definition: export.h:40
std::complex< Real > Complex
Definition: dsptypes.h:43
float Real
Definition: dsptypes.h:42