FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
noise::ClockModelGenerator Class Referencefinal

Generates noise using a clock model with multiple rates. More...

#include "noise_generators.h"

+ Inheritance diagram for noise::ClockModelGenerator:
+ Collaboration diagram for noise::ClockModelGenerator:

Public Member Functions

 ClockModelGenerator (std::mt19937 &rngEngine, const std::vector< RealType > &alpha, const std::vector< RealType > &inWeights, RealType frequency, RealType phaseOffset, RealType freqOffset, int branches) noexcept
 Constructor to initialize the clock model generator.
 
RealType getSample () override
 Generates a clock model noise sample.
 
void skipSamples (std::size_t samples)
 Skips a number of samples in the noise sequence.
 
void reset ()
 Resets the noise generator state.
 
bool enabled () const
 Checks if the noise generator is enabled.
 

Detailed Description

Generates noise using a clock model with multiple rates.

This is useful for simulating clock jitter or other similar phenomena.

Definition at line 170 of file noise_generators.h.

Constructor & Destructor Documentation

◆ ClockModelGenerator()

noise::ClockModelGenerator::ClockModelGenerator ( std::mt19937 &  rngEngine,
const std::vector< RealType > &  alpha,
const std::vector< RealType > &  inWeights,
RealType  frequency,
RealType  phaseOffset,
RealType  freqOffset,
int  branches 
)
noexcept

Constructor to initialize the clock model generator.

Parameters
rngEngineThe random number engine to use for generation.
alphaVector of scaling parameters for the noise.
inWeightsVector of weights for each rate process.
frequencyThe base frequency of the clock model.
phaseOffsetThe phase offset of the generated noise.
freqOffsetThe frequency offset of the generated noise.
branchesThe number of branches in each rate process.

Definition at line 108 of file noise_generators.cpp.

111 :
112 _rng_engine(rngEngine), _weights(inWeights), _phase_offset(phaseOffset), _freq_offset(freqOffset),
113 _frequency(frequency)
114 {
115 for (size_t i = 0; i < alpha.size(); ++i)
116 {
117 auto mgen = std::make_unique<MultirateGenerator>(_rng_engine.get(), alpha[i], branches);
118 _generators.push_back(std::move(mgen));
119
120 switch (static_cast<int>(alpha[i]))
121 {
122 case 2:
123 _weights[i] *= std::pow(10.0, 1.225);
124 break;
125 case 1:
126 _weights[i] *= std::pow(10.0, 0.25);
127 break;
128 case 0:
129 _weights[i] *= std::pow(10.0, -0.25);
130 break;
131 case -1:
132 _weights[i] *= std::pow(10.0, -0.5);
133 break;
134 case -2:
135 _weights[i] *= std::pow(10.0, -1.0);
136 break;
137 default:
138 break;
139 }
140 }
141 }

Member Function Documentation

◆ enabled()

bool noise::ClockModelGenerator::enabled ( ) const

Checks if the noise generator is enabled.

Returns
True if the generator is enabled, false otherwise.

Definition at line 178 of file noise_generators.cpp.

179 {
180 return !_generators.empty() || _freq_offset != 0 || _phase_offset != 0;
181 }

◆ getSample()

RealType noise::ClockModelGenerator::getSample ( )
overridevirtual

Generates a clock model noise sample.

Returns
A noise sample of type RealType.

Implements noise::NoiseGenerator.

Definition at line 143 of file noise_generators.cpp.

144 {
145 RealType sample = 0;
146 for (size_t i = 0; i < _generators.size(); ++i)
147 {
148 sample += _generators[i]->getSample() * _weights[i];
149 }
150
151 sample += _phase_offset;
152 sample += 2 * PI * _freq_offset * static_cast<double>(_count) / params::rate();
153 ++_count;
154
155 return sample;
156 }
double RealType
Type for real numbers.
Definition config.h:27
constexpr RealType PI
Mathematical constant π (pi).
Definition config.h:43
RealType rate() noexcept
Get the rendering sample rate.
Definition parameters.h:121

References PI, and params::rate().

+ Here is the call graph for this function:

◆ reset()

void noise::ClockModelGenerator::reset ( )

Resets the noise generator state.

Definition at line 167 of file noise_generators.cpp.

168 {
169 // reset() call chain is only called if sync on pulse is enabled,
170 // otherwise the all generators and counts remain as-is
171 for (const auto& generator : _generators)
172 {
173 generator->reset();
174 }
175 _count = 0;
176 }

◆ skipSamples()

void noise::ClockModelGenerator::skipSamples ( std::size_t  samples)

Skips a number of samples in the noise sequence.

Parameters
samplesThe number of samples to skip.

Definition at line 158 of file noise_generators.cpp.

159 {
160 for (const auto& generator : _generators)
161 {
162 generator->skipSamples(samples);
163 }
164 _count += samples;
165 }

The documentation for this class was generated from the following files: