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 (long long 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 169 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 102 of file noise_generators.cpp.

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

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 172 of file noise_generators.cpp.

173 {
174 return !_generators.empty() || _freq_offset != 0 || _phase_offset != 0;
175 }

◆ 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 137 of file noise_generators.cpp.

138 {
139 RealType sample = 0;
140 for (size_t i = 0; i < _generators.size(); ++i)
141 {
142 sample += _generators[i]->getSample() * _weights[i];
143 }
144
145 sample += _phase_offset;
146 sample += 2 * PI * _freq_offset * static_cast<double>(_count) / params::rate();
147 ++_count;
148
149 return sample;
150 }
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:109

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 161 of file noise_generators.cpp.

162 {
163 // reset() call chain is only called if sync on pulse is enabled,
164 // otherwise the all generators and counts remain as-is
165 for (const auto& generator : _generators)
166 {
167 generator->reset();
168 }
169 _count = 0;
170 }

◆ skipSamples()

void noise::ClockModelGenerator::skipSamples ( long long  samples)

Skips a number of samples in the noise sequence.

Parameters
samplesThe number of samples to skip.

Definition at line 152 of file noise_generators.cpp.

153 {
154 for (const auto& generator : _generators)
155 {
156 generator->skipSamples(samples);
157 }
158 _count += samples;
159 }

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