FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
falpha_branch.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 falpha_branch.h
10 * @brief Implementation of the FAlphaBranch class for noise generation.
11 */
12
13#pragma once
14
15#include <functional>
16#include <memory>
17#include <random>
18#include <vector>
19
20#include "core/config.h"
21#include "signal/dsp_filters.h"
22
23namespace noise
24{
25 /**
26 * @class FAlphaBranch
27 * @brief Class responsible for generating fractional and integer noise components.
28 *
29 * The FAlphaBranch class generates noise by applying a fractional integrator filter. It uses a series of
30 * filters and upsamplers to process and shape the noise signal.
31 */
33 {
34 public:
35 /**
36 * @brief Constructor for FAlphaBranch.
37 *
38 * @param rngEngine The random number generator engine to use.
39 * @param ffrac Fractional part of the noise generation (e.g., 0.5 for 1/f noise).
40 * @param fint Integer part of the noise generation (e.g., 1 for integration).
41 * @param pre Previous stage of the FAlphaBranch for recursive noise processing.
42 * @param last Specifies if this is the last branch in the chain of processing.
43 */
44 FAlphaBranch(std::mt19937& rngEngine, RealType ffrac, unsigned fint, std::unique_ptr<FAlphaBranch> pre,
45 bool last);
46
47 ~FAlphaBranch() = default;
48
49 FAlphaBranch(const FAlphaBranch&) = delete;
50
52
54
56
57 /**
58 * @brief Retrieves the current noise sample.
59 *
60 * @return The current noise sample.
61 */
62 RealType getSample() noexcept;
63
64 /**
65 * @brief Flushes the branch with a new scaling factor.
66 *
67 * @param scale New scale factor to apply to the previous stage.
68 */
69 void flush(RealType scale);
70
71 /**
72 * @brief Retrieves the previous branch in the chain.
73 *
74 * @return Pointer to the previous FAlphaBranch, or nullptr if none exists.
75 */
76 [[nodiscard]] FAlphaBranch* getPre() const noexcept { return _pre.get(); }
77
78 private:
79 /// Initializes the filters and sets up the initial state of the noise generator.
80 void init();
81
82 /// Refills the sample buffer with new upsampled noise values.
83 void refill() noexcept;
84
85 /// Calculates a new noise sample.
86 RealType calcSample() noexcept;
87
88 std::reference_wrapper<std::mt19937> _rng_engine_ref; ///< Reference to the RNG engine.
89
90 std::normal_distribution<> _normal_dist; ///< Normal distribution for generating white Gaussian noise.
91
92 std::unique_ptr<fers_signal::IirFilter> _shape_filter; ///< Filter used for shaping the noise signal.
93
94 std::unique_ptr<fers_signal::IirFilter> _integ_filter; ///< Filter used for integrating the noise signal.
95
96 std::unique_ptr<fers_signal::IirFilter> _highpass; ///< High-pass filter to remove low-frequency components.
97
98 std::unique_ptr<fers_signal::DecadeUpsampler>
99 _upsampler; ///< Upsampler for generating higher-frequency components.
100
101 std::unique_ptr<FAlphaBranch> _pre; ///< Previous FAlphaBranch in the chain for recursive noise processing.
102
103 RealType _shape_gain{1.0}; ///< Gain factor for shaping filter.
104
105 RealType _integ_gain{1.0}; ///< Gain factor for integration filter.
106
107 RealType _upsample_scale{}; ///< Scaling factor for the upsampled noise.
108
109 std::vector<RealType> _buffer{}; ///< Buffer for storing upsampled noise samples.
110
111 unsigned _buffer_samples{}; ///< Number of samples currently in the buffer.
112
113 RealType _ffrac; ///< Fractional part of the noise generation.
114
115 unsigned _fint; ///< Integer part of the noise generation.
116
117 RealType _offset_sample{}; ///< Offset applied to the final noise sample.
118
119 bool _got_offset{false}; ///< Flag indicating if the offset sample has been retrieved.
120
121 RealType _pre_scale{1.0}; ///< Scale factor for the previous stage's noise output.
122
123 bool _last; ///< Indicates if this is the last branch in the noise processing chain.
124 };
125}
Class responsible for generating fractional and integer noise components.
FAlphaBranch(FAlphaBranch &&)=delete
FAlphaBranch & operator=(const FAlphaBranch &)=delete
FAlphaBranch * getPre() const noexcept
Retrieves the previous branch in the chain.
FAlphaBranch(const FAlphaBranch &)=delete
~FAlphaBranch()=default
void flush(RealType scale)
Flushes the branch with a new scaling factor.
RealType getSample() noexcept
Retrieves the current noise sample.
FAlphaBranch & operator=(FAlphaBranch &&)=delete
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
Header file for Digital Signal Processing (DSP) filters and upsampling/downsampling functionality.