EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
Loading...
Searching...
No Matches
WindowFunctions.cpp
Go to the documentation of this file.
1
9
10
#include "
WindowFunctions.hpp
"
11
12
#include <
cmath
>
13
#include <numbers>
14
15
namespace
echomap
16
{
17
18
float
WindowFunctions::Hann::operator()
(
19
const
std::size_t
index,
20
const
std::size_t
size
21
)
noexcept
22
{
23
if
(size <= 1)
24
return
1.0f;
25
26
const
auto
sine =
std::sin
(std::numbers::pi_v<float> *
static_cast<
float
>
(index) /
static_cast<
float
>
(size - 1));
27
return
sine * sine;
28
}
29
30
float
WindowFunctions::Hamming::operator()
(
31
const
std::size_t
index,
32
const
std::size_t
size
33
)
noexcept
34
{
35
if
(size <= 1)
36
return
1.0f;
37
38
constexpr
float
hamming_ratio = 25.0f / 46;
39
return
hamming_ratio - (1.0f - hamming_ratio) *
std::cos
(
40
2.0f * std::numbers::pi_v<float> *
41
static_cast<
float
>
(index) /
static_cast<
float
>
(size - 1)
42
);
43
}
44
45
float
WindowFunctions::Constant::operator()
(
46
std::size_t
/*index*/
,
47
std::size_t
/*size*/
48
)
noexcept
49
{
50
return
1.0f;
51
}
52
53
float
WindowFunctions::Bartlett::operator()
(
54
const
std::size_t
index,
55
const
std::size_t
size
56
)
noexcept
57
{
58
if
(size <= 1)
59
return
1.0f;
60
61
const
auto
centre =
static_cast<
float
>
(size - 1) / 2.0f;
62
return
(2.0f /
static_cast<
float
>
(size - 1)) * (centre - std::abs(
static_cast<
float
>
(index) - centre));
63
}
64
65
float
WindowFunctions::Blackman::operator()
(
66
const
std::size_t
index,
67
const
std::size_t
size
68
)
noexcept
69
{
70
if
(size <= 1)
71
return
1.0f;
72
73
const
auto
phase = 2.0f * std::numbers::pi_v<float> *
static_cast<
float
>
(index) /
static_cast<
float
>
(size - 1);
74
return
0.42f - 0.5f *
std::cos
(phase) + 0.08f *
std::cos
(2.0f * phase);
75
}
76
77
float
WindowFunctions::BlackmanHarris::operator()
(
78
const
std::size_t
index,
79
const
std::size_t
size
80
)
noexcept
81
{
82
if
(size <= 1)
83
return
1.0f;
84
85
// Disabled warnings: a{0,1,2,3} are standard names in the literature describing Blackman-Harris.
86
87
constexpr
auto
a0 = 0.35875f;
// NOLINT(*-identifier-length)
88
constexpr
auto
a1 = 0.48829f;
// NOLINT(*-identifier-length)
89
constexpr
auto
a2 = 0.14128f;
// NOLINT(*-identifier-length)
90
constexpr
auto
a3 = 0.01168f;
// NOLINT(*-identifier-length)
91
92
const
auto
phase = 2.0f * std::numbers::pi_v<float> *
static_cast<
float
>
(index) /
static_cast<
float
>
(size - 1);
93
return
a0 - a1 *
std::cos
(phase) + a2 *
std::cos
(2.0f * phase) - a3 *
std::cos
(3.0f * phase);
94
}
95
96
float
WindowFunctions::Welch::operator()
(
97
const
std::size_t
index,
98
const
std::size_t
size
99
)
noexcept
100
{
101
if
(size <= 1)
102
return
1.0f;
103
104
const
auto
centre =
static_cast<
float
>
(size - 1) / 2.0f;
105
const
auto
x = (
static_cast<
float
>
(index) - centre) / centre;
106
return
1.0f - x * x;
107
}
108
109
}
// namespace echomap
WindowFunctions.hpp
WindowFunctions specification.
cmath
std::cos
T cos(T... args)
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::sin
T sin(T... args)
std::size_t
echomap::WindowFunctions::Bartlett::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Bartlett function.
Definition
WindowFunctions.cpp:53
echomap::WindowFunctions::BlackmanHarris::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman-Harris function.
Definition
WindowFunctions.cpp:77
echomap::WindowFunctions::Blackman::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman function.
Definition
WindowFunctions.cpp:65
echomap::WindowFunctions::Constant::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index to the constant 1.0.
Definition
WindowFunctions.cpp:45
echomap::WindowFunctions::Hamming::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hamming function.
Definition
WindowFunctions.cpp:30
echomap::WindowFunctions::Hann::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hann function.
Definition
WindowFunctions.cpp:18
echomap::WindowFunctions::Welch::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Welch function.
Definition
WindowFunctions.cpp:96
src
objects
factories
WindowFunctions.cpp
Generated by
1.17.0