lasp/cpp_src/dsp/lasp_window.cpp
J.A. de Jong 41e748c2f5
Some checks failed
Building, testing and releasing LASP if it has a tag / Build-Test-Ubuntu (push) Failing after -4m54s
Building, testing and releasing LASP if it has a tag / Release-Ubuntu (push) Has been skipped
Made code to compile and probably work with 32-bits floating point. This requires quite some testing to be done
2024-06-03 17:28:51 +02:00

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;
}
}