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 <expected>
16#include <span>
17#include <vector>
18
19#include "core/config.h"
20
21namespace interp
22{
23 /**
24 * @class InterpFilter
25 * @brief Provides methods to generate interpolation filters using Kaiser windows.
26 */
28 {
29 public:
30 InterpFilter(const InterpFilter&) = delete;
34 ~InterpFilter() = default;
35
36 /**
37 * @brief Computes the sinc function for a given input.
38 *
39 * @param x The input value for which the sinc function is computed.
40 * @return The computed sinc value.
41 */
42 static constexpr RealType sinc(const RealType x) noexcept
43 {
44 return x == 0.0 ? 1.0 : std::sin(x * PI) / (x * PI);
45 }
46
47 /**
48 * @brief Computes the Kaiser window function for a given input.
49 *
50 * @param x The input value for the Kaiser window calculation.
51 * @return The computed window value, or an error message if computation fails.
52 */
53 [[nodiscard]] std::expected<RealType, std::string> kaiserWinCompute(RealType x) const noexcept;
54
55 /**
56 * @brief Computes the interpolation filter value for a given input.
57 *
58 * @param x The input value for which the interpolation filter is computed.
59 * @return The computed filter value, or an error message if computation fails.
60 */
61 [[nodiscard]] std::expected<RealType, std::string> interpFilter(RealType x) const noexcept;
62
63 /**
64 * @brief Retrieves a span of precomputed filter values for a given delay.
65 *
66 * @param delay The delay value for which the filter is retrieved.
67 * @return A span of precomputed filter values.
68 * @throws std::runtime_error If the delay value is out of range.
69 */
70 [[nodiscard]] std::span<const RealType> getFilter(RealType delay) const;
71
72 /**
73 * @brief Retrieves the singleton instance of the `InterpFilter` class.
74 *
75 * @return The singleton instance of the `InterpFilter` class.
76 */
77 static InterpFilter& getInstance() noexcept;
78
79 private:
80 InterpFilter(); ///< Private constructor to prevent instantiation.
81
82 RealType _alpha; ///< The alpha value for the Kaiser window.
83 RealType _beta = 5; ///< The beta value for the Kaiser window.
84 RealType _bessel_beta; ///< The Bessel function value for the Kaiser window.
85 int _length; ///< The length of the filter.
86 int _table_filters; ///< The number of filters in the table.
87 std::vector<RealType> _filter_table; ///< The table of precomputed filters.
88 };
89}
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