ngscopeclient 0.1-dev+51fbda87c
TestWaveformSource.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
37#ifndef TestWaveformSource_h
38#define TestWaveformSource_h
39
40#include "VulkanFFTPlan.h"
41#include <random>
42
51{
52public:
53 TestWaveformSource(std::minstd_rand& rng);
54 virtual ~TestWaveformSource();
55
57 TestWaveformSource& operator=(const TestWaveformSource&) =delete;
58
60 float amplitude,
61 float startphase,
62 float period,
63 int64_t sampleperiod,
64 size_t depth,
65 float noise_stdev = 0.01,
66 std::function<void(float)> downloadCallback = nullptr);
67
69 float amplitude,
70 float startphase1,
71 float startphase2,
72 float period1,
73 float period2,
74 int64_t sampleperiod,
75 size_t depth,
76 float noise_stdev = 0.01,
77 std::function<void(float)> downloadCallback = nullptr);
78
80 vk::raii::CommandBuffer& cmdBuf,
81 std::shared_ptr<QueueHandle> queue,
82 float amplitude,
83 float period,
84 int64_t sampleperiod,
85 size_t depth,
86 bool lpf = true,
87 float noise_stdev = 0.01,
88 std::function<void(float)> downloadCallback = nullptr);
89
91 vk::raii::CommandBuffer& cmdBuf,
92 std::shared_ptr<QueueHandle> queue,
93 float amplitude,
94 float period,
95 int64_t sampleperiod,
96 size_t depth,
97 bool lpf = true,
98 float noise_stdev = 0.01,
99 std::function<void(float)> downloadCallback = nullptr);
100
102 float vlo,
103 float vhi,
104 int64_t sampleperiod,
105 size_t depth);
106
109 int64_t sampleperiod,
110 size_t depth,
111 bool lpf,
112 float noise_stdev,
113 vk::raii::CommandBuffer& cmdBuf,
114 std::shared_ptr<QueueHandle> queue);
115
116protected:
117
119 std::minstd_rand& m_rng;
120
123
126
129
131 std::unique_ptr<VulkanFFTPlan> m_vkForwardPlan;
132
134 std::unique_ptr<VulkanFFTPlan> m_vkReversePlan;
135
138
141
144
147
150
153
156
159
160 void InterpolateSparameters(float bin_hz, size_t nouts);
161};
162
163#endif
Declaration of VulkanFFTPlan.
Encapsulates a Vulkan compute pipeline and all necessary resources to use it.
Definition: ComputePipeline.h:55
A set of S-parameters.
Definition: SParameters.h:201
Helper class for generating test waveforms.
Definition: TestWaveformSource.h:51
WaveformBase * GenerateStep(float vlo, float vhi, int64_t sampleperiod, size_t depth)
Generates a step waveform.
Definition: TestWaveformSource.cpp:92
WaveformBase * Generate8b10b(vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue, float amplitude, float period, int64_t sampleperiod, size_t depth, bool lpf=true, float noise_stdev=0.01, std::function< void(float)> downloadCallback=nullptr)
Generates a K28.5 D16.2 (1000base-X / SGMII idle) waveform through a lossy channel with AWGN.
Definition: TestWaveformSource.cpp:294
ComputePipeline m_channelEmulationComputePipeline
Compute pipeline for channel emulation.
Definition: TestWaveformSource.h:149
SParameters m_sparams
S-parameters of the channel.
Definition: TestWaveformSource.h:152
std::unique_ptr< VulkanFFTPlan > m_vkForwardPlan
FFT plan.
Definition: TestWaveformSource.h:131
AcceleratorBuffer< float > m_resampledSparamCosines
Serial channel S-parameter imaginary part.
Definition: TestWaveformSource.h:143
AcceleratorBuffer< float > m_reverseOutBuf
Output buffer for IFFTs.
Definition: TestWaveformSource.h:128
double m_cachedBinSize
FFT bin size, in Hz.
Definition: TestWaveformSource.h:137
size_t m_cachedRawSize
Input size of FFT as of last cache update.
Definition: TestWaveformSource.h:158
std::unique_ptr< VulkanFFTPlan > m_vkReversePlan
Inverse FFT plan.
Definition: TestWaveformSource.h:134
AcceleratorBuffer< float > m_forwardOutBuf
Output buffer for FFTs.
Definition: TestWaveformSource.h:125
ComputePipeline m_rectangularComputePipeline
Compute pipeline for our window function.
Definition: TestWaveformSource.h:146
void InterpolateSparameters(float bin_hz, size_t nouts)
Recalculate the cached S-parameters used for channel emulation.
Definition: TestWaveformSource.cpp:510
WaveformBase * GenerateNoisySinewave(float amplitude, float startphase, float period, int64_t sampleperiod, size_t depth, float noise_stdev=0.01, std::function< void(float)> downloadCallback=nullptr)
Generates a sinewave with AWGN added.
Definition: TestWaveformSource.cpp:125
AcceleratorBuffer< float > m_forwardInBuf
Input buffer for FFTs.
Definition: TestWaveformSource.h:122
WaveformBase * GeneratePRBS31(vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue, float amplitude, float period, int64_t sampleperiod, size_t depth, bool lpf=true, float noise_stdev=0.01, std::function< void(float)> downloadCallback=nullptr)
Generates a PRBS-31 waveform through a lossy channel with AWGN.
Definition: TestWaveformSource.cpp:219
WaveformBase * GenerateNoisySinewaveSum(float amplitude, float startphase1, float startphase2, float period1, float period2, int64_t sampleperiod, size_t depth, float noise_stdev=0.01, std::function< void(float)> downloadCallback=nullptr)
Generates a sum of two sinewaves with AWGN added.
Definition: TestWaveformSource.cpp:170
std::minstd_rand & m_rng
Random number generator.
Definition: TestWaveformSource.h:119
void DegradeSerialData(UniformAnalogWaveform *cap, int64_t sampleperiod, size_t depth, bool lpf, float noise_stdev, vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue)
Takes an idealized serial data stream and turns it into something less pretty.
Definition: TestWaveformSource.cpp:376
size_t m_cachedNumPoints
FFT point count as of last cache update.
Definition: TestWaveformSource.h:155
AcceleratorBuffer< float > m_resampledSparamSines
Serial channel S-parameter real part.
Definition: TestWaveformSource.h:140
A waveform sampled at uniform intervals.
Definition: Waveform.h:365
Base class for all Waveform specializations.
Definition: Waveform.h:59