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.cpp
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 #include "dsp/fftwindow.h"
20 
21 void FFTWindow::create(Function function, int n)
22 {
23  Real (*wFunc)(Real n, Real i);
24 
25  m_window.clear();
26 
27  switch(function) {
28  case Flattop:
29  wFunc = flatTop;
30  break;
31 
32  case Bartlett:
33  wFunc = bartlett;
34  break;
35 
36  case BlackmanHarris:
37  wFunc = blackmanHarris;
38  break;
39 
40  case Hamming:
41  wFunc = hamming;
42  break;
43 
44  case Hanning:
45  wFunc = hanning;
46  break;
47 
48  case Rectangle:
49  default:
50  wFunc = rectangle;
51  break;
52  }
53 
54  for(int i = 0; i < n; i++)
55  m_window.push_back(wFunc(n, i));
56 }
57 
58 void FFTWindow::apply(const std::vector<Real>& in, std::vector<Real>* out)
59 {
60  for(size_t i = 0; i < m_window.size(); i++)
61  (*out)[i] = in[i] * m_window[i];
62 }
63 
64 void FFTWindow::apply(const std::vector<Complex>& in, std::vector<Complex>* out)
65 {
66  for(size_t i = 0; i < m_window.size(); i++)
67  (*out)[i] = in[i] * m_window[i];
68 }
69 
70 void FFTWindow::apply(const Complex* in, Complex* out)
71 {
72  for(size_t i = 0; i < m_window.size(); i++)
73  out[i] = in[i] * m_window[i];
74 }
static Real rectangle(Real, Real)
Definition: fftwindow.h:80
void create(Function function, int n)
Definition: fftwindow.cpp:21
void apply(const std::vector< Real > &in, std::vector< Real > *out)
Definition: fftwindow.cpp:58
static Real flatTop(Real n, Real i)
Definition: fftwindow.h:50
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
std::vector< float > m_window
Definition: fftwindow.h:48
std::complex< Real > Complex
Definition: dsptypes.h:43
float Real
Definition: dsptypes.h:42