FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
interpolation_filter.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file interpolation_filter.h
10 * @brief Interpolation filter implementation using Kaiser windowing.
11 */
12
13#pragma once
14
15#include <cstddef>
16#include <expected>
17#include <span>
18#include <vector>
19
20#include "core/config.h"
21
22namespace interp
23{
24 /**
25 * @class InterpFilter
26 * @brief Provides methods to generate interpolation filters using Kaiser windows.
27 */
29 {
30 public:
31 InterpFilter(const InterpFilter&) = delete;
35 ~InterpFilter() = default;
36
37 /**
38 * @brief Computes the sinc function for a given input.
39 *
40 * @param x The input value for which the sinc function is computed.
41 * @return The computed sinc value.
42 */
43 static constexpr RealType sinc(const RealType x) noexcept
44 {
45 return x == 0.0 ? 1.0 : std::sin(x * PI) / (x * PI);
46 }
47
48 /**
49 * @brief Computes the Kaiser window function for a given input.
50 *
51 * @param x The input value for the Kaiser window calculation.
52 * @return The computed window value, or an error message if computation fails.
53 */
54 [[nodiscard]] std::expected<RealType, std::string> kaiserWinCompute(RealType x) const noexcept;
55
56 /**
57 * @brief Computes the interpolation filter value for a given input.
58 *
59 * @param x The input value for which the interpolation filter is computed.
60 * @return The computed filter value, or an error message if computation fails.
61 */
62 [[nodiscard]] std::expected<RealType, std::string> interpFilter(RealType x) const noexcept;
63
64 /**
65 * @brief Retrieves a span of precomputed filter values for a given delay.
66 *
67 * @param delay The delay value for which the filter is retrieved.
68 * @return A span of precomputed filter values.
69 * @throws std::runtime_error If the delay value is out of range.
70 */
71 [[nodiscard]] std::span<const RealType> getFilter(RealType delay) const;
72
73 /**
74 * @brief Retrieves the singleton instance of the `InterpFilter` class.
75 *
76 * @return The singleton instance of the `InterpFilter` class.
77 */
78 static InterpFilter& getInstance() noexcept;
79
80 private:
81 InterpFilter(); ///< Private constructor to prevent instantiation.
82
83 RealType _alpha; ///< The alpha value for the Kaiser window.
84 RealType _beta = 5; ///< The beta value for the Kaiser window.
85 RealType _bessel_beta; ///< The Bessel function value for the Kaiser window.
86 std::size_t _length; ///< The length of the filter.
87 std::size_t _table_filters; ///< The number of filters in the table.
88 std::vector<RealType> _filter_table; ///< The table of precomputed filters.
89 };
90}
Provides methods to generate interpolation filters using Kaiser windows.
static InterpFilter & getInstance() noexcept
Retrieves the singleton instance of the InterpFilter class.
std::span< const RealType > getFilter(RealType delay) const
Retrieves a span of precomputed filter values for a given delay.
InterpFilter & operator=(InterpFilter &&)=delete
InterpFilter(const InterpFilter &)=delete
InterpFilter(InterpFilter &&)=delete
static constexpr RealType sinc(const RealType x) noexcept
Computes the sinc function for a given input.
std::expected< RealType, std::string > kaiserWinCompute(RealType x) const noexcept
Computes the Kaiser window function for a given input.
std::expected< RealType, std::string > interpFilter(RealType x) const noexcept
Computes the interpolation filter value for a given input.
InterpFilter & operator=(const InterpFilter &)=delete
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
constexpr RealType PI
Mathematical constant π (pi).
Definition config.h:43