Skip to content

Commit c5145fb

Browse files
committed
Began documenting TestWaveformSource
1 parent 25f8ed4 commit c5145fb

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

scopehal/TestWaveformSource.cpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
@file
3131
@author Andrew D. Zonenberg
3232
@brief Implementation of TestWaveformSource
33+
34+
@ingroup core
3335
*/
3436
#include "scopehal.h"
3537
#include "TestWaveformSource.h"
@@ -40,6 +42,13 @@ using namespace std;
4042
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4143
// Construction / destruction
4244

45+
/**
46+
@brief Initializes a TestWaveformSource
47+
48+
@param rng Random number generator instance that the source should use.
49+
The source maintains a persistent reference to the RNG so it must remain valid
50+
for the entire lifespan of the TestWaveformSource.
51+
*/
4352
TestWaveformSource::TestWaveformSource(minstd_rand& rng)
4453
: m_rng(rng)
4554
, m_cachedBinSize(0)
@@ -69,7 +78,15 @@ TestWaveformSource::~TestWaveformSource()
6978
// Signal generation
7079

7180
/**
72-
@brief Generates a unit step
81+
@brief Generates a step waveform
82+
83+
The waveform starts at vlo for half of the total duration, the instantly transitions to vhi and remains at vhi
84+
for the remainder of the total length.
85+
86+
@param vlo Starting voltage
87+
@param vhi Ending voltage
88+
@param sampleperiod Interval, in femtoseconds, between samples
89+
@param depth Number of points in the waveform
7390
*/
7491
WaveformBase* TestWaveformSource::GenerateStep(
7592
float vlo,
@@ -94,21 +111,28 @@ WaveformBase* TestWaveformSource::GenerateStep(
94111
}
95112

96113
/**
97-
@brief Generates a sinewave with a bit of extra noise added
114+
@brief Generates a sinewave with AWGN added
115+
116+
@param amplitude P-P amplitude of the waveform
117+
@param startphase Starting phase in radians
118+
@param period Period of the sine, in femtoseconds
119+
@param sampleperiod Interval between samples, in femtoseconds
120+
@param depth Total number of samples to generate
121+
@param noise_stdev Standard deviation of the AWGN
98122
*/
99123
WaveformBase* TestWaveformSource::GenerateNoisySinewave(
100124
float amplitude,
101125
float startphase,
102126
float period,
103127
int64_t sampleperiod,
104128
size_t depth,
105-
float noise_amplitude)
129+
float noise_stdev)
106130
{
107131
auto ret = new UniformAnalogWaveform("NoisySine");
108132
ret->m_timescale = sampleperiod;
109133
ret->Resize(depth);
110134

111-
normal_distribution<> noise(0, noise_amplitude);
135+
normal_distribution<> noise(0, noise_stdev);
112136

113137
float samples_per_cycle = period * 1.0 / sampleperiod;
114138
float radians_per_sample = 2 * M_PI / samples_per_cycle;
@@ -133,13 +157,13 @@ WaveformBase* TestWaveformSource::GenerateNoisySinewaveMix(
133157
float period2,
134158
int64_t sampleperiod,
135159
size_t depth,
136-
float noise_amplitude)
160+
float noise_stdev)
137161
{
138162
auto ret = new UniformAnalogWaveform("NoisySineMix");
139163
ret->m_timescale = sampleperiod;
140164
ret->Resize(depth);
141165

142-
normal_distribution<> noise(0, noise_amplitude);
166+
normal_distribution<> noise(0, noise_stdev);
143167

144168
float radians_per_sample1 = 2 * M_PI * sampleperiod / period1;
145169
float radians_per_sample2 = 2 * M_PI * sampleperiod / period2;
@@ -166,7 +190,7 @@ WaveformBase* TestWaveformSource::GeneratePRBS31(
166190
int64_t sampleperiod,
167191
size_t depth,
168192
bool lpf,
169-
float noise_amplitude
193+
float noise_stdev
170194
)
171195
{
172196
auto ret = new UniformAnalogWaveform("PRBS31");
@@ -211,7 +235,7 @@ WaveformBase* TestWaveformSource::GeneratePRBS31(
211235
}
212236
}
213237

214-
DegradeSerialData(ret, sampleperiod, depth, lpf, noise_amplitude, cmdBuf, queue);
238+
DegradeSerialData(ret, sampleperiod, depth, lpf, noise_stdev, cmdBuf, queue);
215239

216240
return ret;
217241
}
@@ -224,7 +248,7 @@ WaveformBase* TestWaveformSource::Generate8b10b(
224248
int64_t sampleperiod,
225249
size_t depth,
226250
bool lpf,
227-
float noise_amplitude)
251+
float noise_stdev)
228252
{
229253
auto ret = new UniformAnalogWaveform("8B10B");
230254
ret->m_timescale = sampleperiod;
@@ -275,7 +299,7 @@ WaveformBase* TestWaveformSource::Generate8b10b(
275299
}
276300
}
277301

278-
DegradeSerialData(ret, sampleperiod, depth, lpf, noise_amplitude, cmdBuf, queue);
302+
DegradeSerialData(ret, sampleperiod, depth, lpf, noise_stdev, cmdBuf, queue);
279303

280304
return ret;
281305
}
@@ -290,15 +314,15 @@ void TestWaveformSource::DegradeSerialData(
290314
int64_t sampleperiod,
291315
size_t depth,
292316
bool lpf,
293-
float noise_amplitude,
317+
float noise_stdev,
294318
vk::raii::CommandBuffer& cmdBuf,
295319
shared_ptr<QueueHandle> queue)
296320
{
297321
//assume input came from CPU
298322
cap->MarkModifiedFromCpu();
299323

300324
//RNGs
301-
normal_distribution<> noise(0, noise_amplitude);
325+
normal_distribution<> noise(0, noise_stdev);
302326

303327
//Prepare for second pass: reallocate FFT buffer if sample depth changed
304328
const size_t npoints = next_pow2(depth);

scopehal/TestWaveformSource.h

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@file
3232
@author Andrew D. Zonenberg
3333
@brief Declaration of TestWaveformSource
34+
@ingroup core
3435
*/
3536

3637
#ifndef TestWaveformSource_h
@@ -42,7 +43,9 @@
4243
/**
4344
@brief Helper class for generating test waveforms
4445
45-
Used by DemoOscilloscope as well as various unit tests etc.
46+
Used by DemoOscilloscope as well as various unit tests
47+
48+
@ingroup core
4649
*/
4750
class TestWaveformSource
4851
{
@@ -59,7 +62,7 @@ class TestWaveformSource
5962
float period,
6063
int64_t sampleperiod,
6164
size_t depth,
62-
float noise_amplitude = 0.01);
65+
float noise_stdev = 0.01);
6366

6467
WaveformBase* GenerateNoisySinewaveMix(
6568
float amplitude,
@@ -69,7 +72,7 @@ class TestWaveformSource
6972
float period2,
7073
int64_t sampleperiod,
7174
size_t depth,
72-
float noise_amplitude = 0.01);
75+
float noise_stdev = 0.01);
7376

7477
WaveformBase* GeneratePRBS31(
7578
vk::raii::CommandBuffer& cmdBuf,
@@ -79,7 +82,7 @@ class TestWaveformSource
7982
int64_t sampleperiod,
8083
size_t depth,
8184
bool lpf = true,
82-
float noise_amplitude = 0.01);
85+
float noise_stdev = 0.01);
8386

8487
WaveformBase* Generate8b10b(
8588
vk::raii::CommandBuffer& cmdBuf,
@@ -89,7 +92,7 @@ class TestWaveformSource
8992
int64_t sampleperiod,
9093
size_t depth,
9194
bool lpf = true,
92-
float noise_amplitude = 0.01);
95+
float noise_stdev = 0.01);
9396

9497
WaveformBase* GenerateStep(
9598
float vlo,
@@ -102,30 +105,52 @@ class TestWaveformSource
102105
int64_t sampleperiod,
103106
size_t depth,
104107
bool lpf,
105-
float noise_amplitude,
108+
float noise_stdev,
106109
vk::raii::CommandBuffer& cmdBuf,
107110
std::shared_ptr<QueueHandle> queue);
108111

109112
protected:
113+
114+
///@brief Random number generator
110115
std::minstd_rand& m_rng;
111116

117+
///@brief Input buffer for FFTs
112118
AcceleratorBuffer<float> m_forwardInBuf;
119+
120+
///@brief Output buffer for FFTs
113121
AcceleratorBuffer<float> m_forwardOutBuf;
122+
123+
///@brief Output buffer for IFFTs
114124
AcceleratorBuffer<float> m_reverseOutBuf;
115125

126+
///@brief FFT plan
116127
std::unique_ptr<VulkanFFTPlan> m_vkForwardPlan;
128+
129+
///@brief Inverse FFT plan
117130
std::unique_ptr<VulkanFFTPlan> m_vkReversePlan;
118131

132+
///@brief FFT bin size, in Hz
119133
double m_cachedBinSize;
134+
135+
///@brief Serial channel S-parameter real part
120136
AcceleratorBuffer<float> m_resampledSparamSines;
137+
138+
///@brief Serial channel S-parameter imaginary part
121139
AcceleratorBuffer<float> m_resampledSparamCosines;
122140

141+
///@brief Compute pipeline for our window function
123142
ComputePipeline m_rectangularComputePipeline;
143+
144+
///@brief Compute pipeline for channel emulation
124145
ComputePipeline m_channelEmulationComputePipeline;
125146

147+
///@brief S-parameters of the channel
126148
SParameters m_sparams;
127149

150+
///@brief FFT point count as of last cache update
128151
size_t m_cachedNumPoints;
152+
153+
///@brief Input size of FFT as of last cache update
129154
size_t m_cachedRawSize;
130155

131156
void InterpolateSparameters(float bin_hz, size_t nouts);

0 commit comments

Comments
 (0)