EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
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
15namespace echomap
16{
17
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
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
46 std::size_t /*index*/,
47 std::size_t /*size*/
48) noexcept
49{
50 return 1.0f;
51}
52
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
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
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
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 specification.
T cos(T... args)
The main EchoMap outermost namespace for all non-exported symbols.
T sin(T... args)
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Bartlett function.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman-Harris function.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman function.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index to the constant 1.0.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hamming function.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hann function.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Welch function.