64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
// lasp_window.cpp
|
|
//
|
|
// Author: J.A. de Jong - ASCEE
|
|
//
|
|
/* #define DEBUGTRACE_ENABLED */
|
|
#include "debugtrace.hpp"
|
|
#include "lasp_window.h"
|
|
|
|
using rte = std::runtime_error;
|
|
using std::cerr;
|
|
using std::endl;
|
|
|
|
// Safe some typing. Linspace form 0 up to (and NOT including N).
|
|
#define lin0N arma::linspace<vd>(0, N - 1, N)
|
|
|
|
vd Window::hann(const us N) {
|
|
return arma::pow(arma::sin((arma::datum::pi/N) * lin0N), 2);
|
|
}
|
|
vd Window::hamming(const us N) {
|
|
d alpha = 25.0 / 46.0;
|
|
return alpha - (1 - alpha) * arma::cos(2 * number_pi * lin0N / N);
|
|
}
|
|
vd Window::blackman(const us N) {
|
|
d a0 = 7938. / 18608.;
|
|
d a1 = 9240. / 18608.;
|
|
d a2 = 1430. / 18608.;
|
|
return a0 - a1 * arma::cos((2 * number_pi/N) * lin0N) +
|
|
a2 * arma::cos((4 * number_pi / N)* lin0N );
|
|
}
|
|
|
|
vd Window::rectangular(const us N) { return arma::ones(N); }
|
|
|
|
vd Window::bartlett(const us N) {
|
|
return 1 - arma::abs(2 * (lin0N - (N - 1) / 2.) / N);
|
|
}
|
|
vd Window::create(const WindowType w, const us N) {
|
|
|
|
switch (w) {
|
|
case WindowType::Hann: {
|
|
return hann(N);
|
|
break;
|
|
}
|
|
case WindowType::Hamming: {
|
|
return hamming(N);
|
|
break;
|
|
}
|
|
case WindowType::Rectangular: {
|
|
return rectangular(N);
|
|
break;
|
|
}
|
|
case WindowType::Bartlett: {
|
|
return bartlett(N);
|
|
break;
|
|
}
|
|
case WindowType::Blackman: {
|
|
return blackman(N);
|
|
break;
|
|
}
|
|
default:
|
|
abort();
|
|
break;
|
|
}
|
|
}
|