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 (std::size_t 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 118 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 135 of file noise_generators.h.

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

◆ reset()

void noise::MultirateGenerator::reset ( )
noexcept

Resets the noise generator state.

Definition at line 91 of file noise_generators.cpp.

92 {
93 std::vector<FAlphaBranch*> branches;
94 FAlphaBranch* branch = _topbranch.get();
95
96 while (branch != nullptr)
97 {
98 branches.push_back(branch);
99 branch = branch->getPre();
100 }
101
102 for (const auto& b : std::ranges::reverse_view(branches))
103 {
104 b->flush(1.0);
105 }
106 }

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

+ Here is the call graph for this function:

◆ skipSamples()

void noise::MultirateGenerator::skipSamples ( std::size_t  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 (samples == 0)
40 {
41 return;
42 }
43
44 if (const int skip_branches = static_cast<int>(std::log10(static_cast<double>(samples))) - 1; skip_branches > 0)
45 {
46 std::vector<FAlphaBranch*> flushbranches;
47 FAlphaBranch* branch = _topbranch.get();
48
49 for (int i = 0; i < skip_branches && (branch != nullptr); ++i)
50 {
51 flushbranches.push_back(branch);
52 branch = branch->getPre();
53 }
54
55 if (branch != nullptr)
56 {
57 const auto reduced_samples =
58 samples / static_cast<std::size_t>(std::pow(10.0, static_cast<double>(skip_branches)));
59 for (std::size_t i = 0; i < reduced_samples; ++i)
60 {
61 branch->getSample();
62 }
63 }
64
65 for (const auto& fb : std::ranges::reverse_view(flushbranches))
66 {
67 fb->flush(1.0);
68 }
69 }
70 else
71 {
72 for (std::size_t i = 0; i < samples; ++i)
73 {
74 _topbranch->getSample();
75 }
76 }
77 }

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: