FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
noise_generators.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 noise_generators.h
10 * @brief Header file for noise generator classes.
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 "falpha_branch.h"
22
23namespace noise
24{
25 /**
26 * @class NoiseGenerator
27 * @brief Abstract base class for noise generators.
28 */
30 {
31 public:
32 NoiseGenerator() = default;
33
34 virtual ~NoiseGenerator() = default;
35
37
39
41
43
44 /**
45 * @brief Pure virtual method to generate a noise sample.
46 *
47 * @return A noise sample of type RealType.
48 */
49 virtual RealType getSample() = 0;
50 };
51
52 /**
53 * @class WgnGenerator
54 * @brief Generates white Gaussian noise.
55 */
56 class WgnGenerator final : public NoiseGenerator
57 {
58 public:
59 /**
60 * @brief Constructor to initialize the WGN generator with a given standard deviation.
61 *
62 * @param rngEngine The random number engine to use for generation.
63 * @param stddev The standard deviation of the generated Gaussian noise. Default is 1.0.
64 */
65 explicit WgnGenerator(std::mt19937& rngEngine, const RealType stddev = 1.0) noexcept :
66 _rng_engine(rngEngine), _dist(0.0, stddev), _stddev(stddev)
67 {
68 }
69
70 /**
71 * @brief Generates a sample of white Gaussian noise.
72 *
73 * @return A noise sample of type RealType.
74 */
75 RealType getSample() noexcept override { return _dist(_rng_engine.get()); }
76
77 private:
78 std::reference_wrapper<std::mt19937> _rng_engine; ///< Reference to the RNG engine.
79 std::normal_distribution<> _dist; ///< Normal distribution for generating Gaussian noise.
80 RealType _stddev; ///< Standard deviation of the generated noise.
81 };
82
83 /**
84 * @class GammaGenerator
85 * @brief Generates Gamma-distributed noise.
86 */
87 class GammaGenerator final : public NoiseGenerator
88 {
89 public:
90 /**
91 * @brief Constructor to initialize the Gamma generator with a shape parameter.
92 *
93 * @param rngEngine The random number engine to use for generation.
94 * @param k The shape parameter of the Gamma distribution.
95 */
96 explicit GammaGenerator(std::mt19937& rngEngine, const RealType k) noexcept :
97 _rng_engine(rngEngine), _dist(k, 1.0)
98 {
99 }
100
101 /**
102 * @brief Generates a sample of Gamma noise.
103 *
104 * @return A noise sample of type RealType.
105 */
106 RealType getSample() noexcept override { return _dist(_rng_engine.get()); }
107
108 private:
109 std::reference_wrapper<std::mt19937> _rng_engine; ///< Reference to the RNG engine.
110 std::gamma_distribution<> _dist; ///< Gamma distribution for generating noise.
111 };
112
113 /**
114 * @class MultirateGenerator
115 * @brief Generates multirate noise using a hierarchical tree structure.
116 */
118 {
119 public:
120 /**
121 * @brief Constructor to initialize the multirate generator.
122 *
123 * @param rngEngine The random number engine to use for generation.
124 * @param alpha The scaling parameter that controls the noise properties.
125 * @param branches The number of branches in the tree structure.
126 */
127 MultirateGenerator(std::mt19937& rngEngine, RealType alpha, unsigned branches);
128
129 /**
130 * @brief Generates a multirate noise sample.
131 *
132 * @return A noise sample of type RealType.
133 */
134 RealType getSample() override { return _topbranch->getSample() * _scale; }
135
136 /**
137 * @brief Skips a number of samples in the noise sequence.
138 *
139 * @param samples The number of samples to skip.
140 */
141 void skipSamples(long long samples) noexcept;
142
143 /**
144 * @brief Resets the noise generator state.
145 */
146 void reset() noexcept;
147
148 private:
149 RealType _scale; ///< Scaling factor for the noise.
150 std::unique_ptr<FAlphaBranch> _topbranch; ///< Pointer to the top branch in the tree structure.
151 std::reference_wrapper<std::mt19937> _rng_engine; ///< Reference to the RNG engine.
152
153 /**
154 * @brief Helper method to create the hierarchical tree structure.
155 *
156 * @param fAlpha Fractional alpha value.
157 * @param fInt Integer part of the scaling factor.
158 * @param branches The number of branches in the tree.
159 */
160 void createTree(RealType fAlpha, int fInt, unsigned branches);
161 };
162
163 /**
164 * @class ClockModelGenerator
165 * @brief Generates noise using a clock model with multiple rates.
166 *
167 * This is useful for simulating clock jitter or other similar phenomena.
168 */
170 {
171 public:
172 /**
173 * @brief Constructor to initialize the clock model generator.
174 *
175 * @param rngEngine The random number engine to use for generation.
176 * @param alpha Vector of scaling parameters for the noise.
177 * @param inWeights Vector of weights for each rate process.
178 * @param frequency The base frequency of the clock model.
179 * @param phaseOffset The phase offset of the generated noise.
180 * @param freqOffset The frequency offset of the generated noise.
181 * @param branches The number of branches in each rate process.
182 */
183 ClockModelGenerator(std::mt19937& rngEngine, const std::vector<RealType>& alpha,
184 const std::vector<RealType>& inWeights, RealType frequency, RealType phaseOffset,
185 RealType freqOffset, int branches) noexcept;
186
187 /**
188 * @brief Generates a clock model noise sample.
189 *
190 * @return A noise sample of type RealType.
191 */
192 RealType getSample() override;
193
194 /**
195 * @brief Skips a number of samples in the noise sequence.
196 *
197 * @param samples The number of samples to skip.
198 */
199 void skipSamples(long long samples);
200
201 /**
202 * @brief Resets the noise generator state.
203 */
204 void reset();
205
206 /**
207 * @brief Checks if the noise generator is enabled.
208 *
209 * @return True if the generator is enabled, false otherwise.
210 */
211 [[nodiscard]] bool enabled() const;
212
213 private:
214 std::reference_wrapper<std::mt19937> _rng_engine; ///< Reference to the RNG engine.
215 std::vector<std::unique_ptr<MultirateGenerator>> _generators; ///< Multirate noise generators.
216 std::vector<RealType> _weights; ///< Weights for each rate process.
217 RealType _phase_offset; ///< Phase offset for the noise.
218 RealType _freq_offset; ///< Frequency offset for the noise.
219 RealType _frequency; ///< Base frequency of the clock model.
220 unsigned long _count = 0; ///< Sample counter.
221 };
222}
Generates noise using a clock model with multiple rates.
Class responsible for generating fractional and integer noise components.
Generates Gamma-distributed noise.
RealType getSample() noexcept override
Generates a sample of Gamma noise.
GammaGenerator(std::mt19937 &rngEngine, const RealType k) noexcept
Constructor to initialize the Gamma generator with a shape parameter.
Generates multirate noise using a hierarchical tree structure.
void reset() noexcept
Resets the noise generator state.
void skipSamples(long long samples) noexcept
Skips a number of samples in the noise sequence.
RealType getSample() override
Generates a multirate noise sample.
Abstract base class for noise generators.
NoiseGenerator(NoiseGenerator &&)=delete
NoiseGenerator & operator=(const NoiseGenerator &)=delete
NoiseGenerator & operator=(NoiseGenerator &&)=delete
NoiseGenerator(const NoiseGenerator &)=delete
virtual ~NoiseGenerator()=default
virtual RealType getSample()=0
Pure virtual method to generate a noise sample.
Generates white Gaussian noise.
WgnGenerator(std::mt19937 &rngEngine, const RealType stddev=1.0) noexcept
Constructor to initialize the WGN generator with a given standard deviation.
RealType getSample() noexcept override
Generates a sample of white Gaussian noise.
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
Implementation of the FAlphaBranch class for noise generation.