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

Generates multirate noise using a hierarchical tree structure. More...

#include "noise_generators.h"

+ Inheritance diagram for noise::MultirateGenerator:
+ Collaboration diagram for noise::MultirateGenerator:

Public Member Functions

 MultirateGenerator (std::mt19937 &rngEngine, RealType alpha, unsigned branches)
 Constructor to initialize the multirate generator.
 
RealType getSample () override
 Generates a multirate noise sample.
 
void skipSamples (long long samples) noexcept
 Skips a number of samples in the noise sequence.
 
void reset () noexcept
 Resets the noise generator state.
 

Detailed Description

Generates multirate noise using a hierarchical tree structure.

Definition at line 117 of file noise_generators.h.

Constructor & Destructor Documentation

◆ MultirateGenerator()

noise::MultirateGenerator::MultirateGenerator ( std::mt19937 &  rngEngine,
RealType  alpha,
unsigned  branches 
)

Constructor to initialize the multirate generator.

Parameters
rngEngineThe random number engine to use for generation.
alphaThe scaling parameter that controls the noise properties.
branchesThe number of branches in the tree structure.

Definition at line 24 of file noise_generators.cpp.

24 :
25 _rng_engine(rngEngine)
26 {
27 const RealType beta = -(alpha - 2) / 2.0;
28 const int fint = static_cast<int>(std::floor(beta));
29 const RealType ffrac = std::fmod(beta, 1.0);
30
31 createTree(ffrac, fint, branches);
32 // TODO: verify scale factor calculation (* 2.0 appears to be a bug)
33 _scale = 1.0 / std::pow(10.0, (-alpha + 2.0) * 2.0);
34 }
double RealType
Type for real numbers.
Definition config.h:27

Member Function Documentation

◆ getSample()

RealType noise::MultirateGenerator::getSample ( )
overridevirtual

Generates a multirate noise sample.

Returns
A noise sample of type RealType.

Implements noise::NoiseGenerator.

Definition at line 134 of file noise_generators.h.

134{ return _topbranch->getSample() * _scale; }

◆ reset()

void noise::MultirateGenerator::reset ( )
noexcept

Resets the noise generator state.

Definition at line 85 of file noise_generators.cpp.

86 {
87 std::vector<FAlphaBranch*> branches;
88 FAlphaBranch* branch = _topbranch.get();
89
90 while (branch)
91 {
92 branches.push_back(branch);
93 branch = branch->getPre();
94 }
95
96 for (const auto& b : std::ranges::reverse_view(branches))
97 {
98 b->flush(1.0);
99 }
100 }

References noise::FAlphaBranch::flush(), and noise::FAlphaBranch::getPre().

+ Here is the call graph for this function:

◆ skipSamples()

void noise::MultirateGenerator::skipSamples ( long long  samples)
noexcept

Skips a number of samples in the noise sequence.

Parameters
samplesThe number of samples to skip.

Definition at line 37 of file noise_generators.cpp.

38 {
39 if (const int skip_branches = static_cast<int>(std::log10(samples)) - 1; skip_branches > 0)
40 {
41 std::vector<FAlphaBranch*> flushbranches;
42 FAlphaBranch* branch = _topbranch.get();
43
44 for (int i = 0; i < skip_branches && branch; ++i)
45 {
46 flushbranches.push_back(branch);
47 branch = branch->getPre();
48 }
49
50 if (branch)
51 {
52 const auto reduced_samples = samples / static_cast<long long>(std::pow(10.0, skip_branches));
53 for (long long i = 0; i < reduced_samples; ++i)
54 {
55 branch->getSample();
56 }
57 }
58
59 for (const auto& fb : std::ranges::reverse_view(flushbranches))
60 {
61 fb->flush(1.0);
62 }
63 }
64 else
65 {
66 for (long long i = 0; i < samples; ++i)
67 {
68 _topbranch->getSample();
69 }
70 }
71 }

References noise::FAlphaBranch::getPre(), and noise::FAlphaBranch::getSample().

+ Here is the call graph for this function:

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