ngscopeclient v0.2.2
Loading...
Searching...
No Matches
CouplerDeEmbedFilter.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopeprotocols *
4* *
5* Copyright (c) 2012-2026 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
35#ifndef CouplerDeEmbedFilter_h
36#define CouplerDeEmbedFilter_h
37
38#include "DeEmbedFilter.h"
39
41{
42public:
44 : m_cachedBinSize(0)
45 , m_groupDelayFs(0)
46 , m_groupDelaySamples(0)
47 {
48 m_resampledSparamSines.SetName("CouplerSParameters.m_resampledSparamSines");
49 m_resampledSparamCosines.SetName("CouplerSParameters.m_resampledSparamCosines");
50 }
51
56 {
57 //Check if bin size changed
58 if(fabs(m_cachedBinSize - bin_hz) > FLT_EPSILON)
59 return true;
60
61 if( (m_magKey != wmag) || (m_angleKey != wang) )
62 return true;
63 return false;
64 }
65
69 void Refresh(
71 WaveformBase* wang,
72 double bin_hz,
73 bool invert,
74 size_t nouts,
75 float maxGain,
76 int64_t timescale,
77 size_t npoints)
78 {
79 //Update cache keys to reflect the current waveforms we're processing
80 m_magKey = wmag;
81 m_angleKey = wang;
82
83 m_resampledSparamCosines.clear();
84 m_resampledSparamSines.clear();
86
87 m_groupDelayFs = GetGroupDelay();
88 m_groupDelaySamples = ceil( m_groupDelayFs / timescale );
89
90 //Sanity check: if we have noisy or poor quality S-parameter data, group delay might not make sense.
91 //Skip this correction pass in that case.
92 if(static_cast<size_t>(llabs(m_groupDelaySamples)) >= npoints)
93 {
94 m_groupDelayFs = 0;
95 m_groupDelaySamples = 0;
96 }
97 }
98
101 WaveformBase* wang,
102 float bin_hz,
103 bool invert,
104 size_t nouts,
105 float maxGain);
106
107 virtual int64_t GetGroupDelay();
108
109 AcceleratorBuffer<float> m_resampledSparamSines;
110 AcceleratorBuffer<float> m_resampledSparamCosines;
111
112 WaveformCacheKey m_magKey;
113 WaveformCacheKey m_angleKey;
114
115 SParameterVector m_cachedSparams;
116
117 double m_cachedBinSize;
118
119 int64_t m_groupDelayFs;
120 int64_t m_groupDelaySamples;
121};
122
124{
125public:
126 CouplerDeEmbedFilter(const std::string& color);
127 virtual ~CouplerDeEmbedFilter();
128
129 virtual void Refresh(vk::raii::CommandBuffer& cmdBuf, std::shared_ptr<QueueHandle> queue) override;
130 virtual uint32_t GetExecutionCapabilitiesMask() override;
131
132 static std::string GetProtocolName();
133
134 PROTOCOL_DECODER_INITPROC(CouplerDeEmbedFilter)
135
136protected:
137
138 void ForwardPath(
139 vk::raii::CommandBuffer& cmdBuf,
146 size_t npoints,
147 size_t nouts);
148
150 vk::raii::CommandBuffer& cmdBuf,
151 std::unique_ptr<VulkanFFTPlan>& plan,
152 size_t istart,
153 size_t iend,
155 size_t stream,
156 size_t npoints,
160
163 size_t& istart,
164 size_t& iend,
166 bool invert);
167
168 std::string m_maxGainName;
169
170 enum TruncationMode
171 {
172 TRUNC_AUTO,
173 TRUNC_MANUAL
174 };
175
176 float m_cachedMaxGain;
177
178 size_t m_cachedNumPoints;
179
180 CouplerSParameters m_forwardCoupledParams;
181 CouplerSParameters m_reverseCoupledParams;
182 CouplerSParameters m_forwardLeakageParams;
183 CouplerSParameters m_reverseLeakageParams;
184
185 AcceleratorBuffer<float> m_scalarTempBuf1;
186
187 ComputePipeline m_normalizeComputePipeline;
188 ComputePipeline m_forwardPathComputePipeline;
189
190 std::unique_ptr<VulkanFFTPlan> m_vkForwardPlan;
191 std::unique_ptr<VulkanFFTPlan> m_vkForwardPlan2;
192
193 std::unique_ptr<VulkanFFTPlan> m_vkReversePlan;
194};
195
196#endif
Declaration of DeEmbedFilter.
Definition AcceleratorBuffer.h:204
void clear()
Resize the container to be empty (but don't free memory)
Definition AcceleratorBuffer.h:703
Encapsulates a Vulkan compute pipeline and all necessary resources to use it.
Definition ComputePipeline.h:55
Definition CouplerDeEmbedFilter.h:124
void GroupDelayCorrection(CouplerSParameters &params, size_t &istart, size_t &iend, int64_t &phaseshift, bool invert)
Calculate bounds for the meaningful output data. Since we're phase shifting, there's gonna be some ga...
Definition CouplerDeEmbedFilter.cpp:361
virtual uint32_t GetExecutionCapabilitiesMask() override
Returns a bitmask of ExecutionCapabilities fields.
Definition CouplerDeEmbedFilter.cpp:141
void GenerateScalarOutput(vk::raii::CommandBuffer &cmdBuf, std::unique_ptr< VulkanFFTPlan > &plan, size_t istart, size_t iend, WaveformBase *refin, size_t stream, size_t npoints, int64_t phaseshift, AcceleratorBuffer< float > &samplesIn, AcceleratorBuffer< float > &samplesOut)
Generates a scalar output from a complex input.
Definition CouplerDeEmbedFilter.cpp:383
void ForwardPath(vk::raii::CommandBuffer &cmdBuf, AcceleratorBuffer< float > &samplesInP, AcceleratorBuffer< float > &samplesInN, AcceleratorBuffer< float > &samplesOut, CouplerSParameters &paramsA, CouplerSParameters &paramsB, CouplerSParameters &paramsC, size_t npoints, size_t nouts)
Forward de-embedding path.
Definition CouplerDeEmbedFilter.cpp:437
Definition CouplerDeEmbedFilter.h:41
void Refresh(WaveformBase *wmag, WaveformBase *wang, double bin_hz, bool invert, size_t nouts, float maxGain, int64_t timescale, size_t npoints)
Refresh the cached data.
Definition CouplerDeEmbedFilter.h:69
virtual int64_t GetGroupDelay()
Returns the max mid-band group delay of the channel.
Definition CouplerDeEmbedFilter.cpp:474
bool NeedUpdate(WaveformBase *wmag, WaveformBase *wang, double bin_hz)
Check to see if we need to refresh our cache.
Definition CouplerDeEmbedFilter.h:55
void InterpolateSparameters(WaveformBase *wmag, WaveformBase *wang, float bin_hz, bool invert, size_t nouts, float maxGain)
Recalculate the cached S-parameters (and clamp gain if requested)
Definition CouplerDeEmbedFilter.cpp:492
Abstract base class for all filter graph blocks which are not physical instrument channels.
Definition Filter.h:105
A single S-parameter array.
Definition SParameters.h:75
Base class for all Waveform specializations.
Definition Waveform.h:59
Describes a particular revision of a waveform.
Definition Filter.h:62