LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_window.cpp
Go to the documentation of this file.
1// lasp_window.cpp
2//
3// Author: J.A. de Jong - ASCEE
4//
5/* #define DEBUGTRACE_ENABLED */
6#include "debugtrace.hpp"
7#include "lasp_window.h"
8
9using rte = std::runtime_error;
10using std::cerr;
11using std::endl;
12
13// Safe some typing. Linspace form 0 up to (and NOT including N).
14#define lin0N arma::linspace(0, N - 1, N)
15
16vd Window::hann(const us N) {
17 return arma::pow(arma::sin((arma::datum::pi/N) * lin0N), 2);
18}
20 d alpha = 25.0 / 46.0;
21 return alpha - (1 - alpha) * arma::cos(2 * number_pi * lin0N / N);
22}
24 d a0 = 7938. / 18608.;
25 d a1 = 9240. / 18608.;
26 d a2 = 1430. / 18608.;
27 return a0 - a1 * d_cos((2 * number_pi/N) * lin0N) +
28 a2 * d_cos((4 * number_pi / N)* lin0N );
29}
30
31vd Window::rectangular(const us N) { return arma::ones(N); }
32
34 return 1 - arma::abs(2 * (lin0N - (N - 1) / 2.) / N);
35}
36vd Window::create(const WindowType w, const us N) {
37
38 switch (w) {
39 case WindowType::Hann: {
40 return hann(N);
41 break;
42 }
44 return hamming(N);
45 break;
46 }
48 return rectangular(N);
49 break;
50 }
52 return bartlett(N);
53 break;
54 }
56 return blackman(N);
57 break;
58 }
59 default:
60 abort();
61 break;
62 }
63}
static vd create(const WindowType w, const us len)
Dispatcher: create a window based on enum type and len.
static vd bartlett(const us len)
Bartlett window.
static vd hamming(const us len)
Hamming window.
static vd hann(const us len)
Hann window.
static vd blackman(const us len)
Blackman window.
static vd rectangular(const us len)
Rectangular (boxcar) window.
std::runtime_error rte
Definition lasp_daq.cpp:16
arma::Col< d > vd
#define d_cos
const d number_pi
size_t us
We often use boolean values.
Definition lasp_types.h:29
#define lin0N