Skip to content

Commit af70d79

Browse files
committed
Tweaks
1 parent 384ca67 commit af70d79

2 files changed

Lines changed: 156 additions & 39 deletions

File tree

source/TS.NET.Sequences/Sequences/NoiseVerificationSequence.cs

Lines changed: 143 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -119,47 +119,154 @@ private void AddSteps(ModalUiContext modalUiContext)
119119
Bandwidth = ThunderscopeBandwidth.BwFull,
120120
SampleRateHz = 1_000_000_000,
121121
},
122-
new CombineChartsStep("Combined - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0", this),
122+
new CombinedSeriesStep("Combined - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0", this)
123+
{
124+
ChartTitle = "Noise spectral density",
125+
ChartXAxis = new ResultMetadataXYChartAxis
126+
{
127+
Label = "Frequency (Hz)",
128+
Scale = XYChartScaleType.Log10,
129+
AdditionalRangeValues = [10e3, 1e9]
130+
},
131+
ChartYAxis = new ResultMetadataXYChartAxis
132+
{
133+
Label = "Noise (V/rHz)",
134+
Scale = XYChartScaleType.Log10,
135+
AdditionalRangeValues = [100e-9, 100e-12],
136+
},
137+
ChartSeries = [
138+
new SeriesReference { StepName = "Channel 1 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0" },
139+
new SeriesReference { StepName = "Channel 2 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0" },
140+
new SeriesReference { StepName = "Channel 3 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0" },
141+
new SeriesReference { StepName = "Channel 4 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0" }
142+
],
143+
ChartLegendLocation = ResultMetadataXYChartLegendLocation.BottomLeft,
144+
},
145+
146+
new NsdStep("Channel 1 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0", Variables)
147+
{
148+
ChannelIndex = 0,
149+
Termination = ThunderscopeTermination.FiftyOhm,
150+
PgaPreampGain = PgaPreampGain.High,
151+
PgaLadder = 0,
152+
Bandwidth = ThunderscopeBandwidth.Bw200M,
153+
SampleRateHz = 1_000_000_000,
154+
},
155+
new NsdStep("Channel 2 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0", Variables)
156+
{
157+
ChannelIndex = 1,
158+
Termination = ThunderscopeTermination.FiftyOhm,
159+
PgaPreampGain = PgaPreampGain.High,
160+
PgaLadder = 0,
161+
Bandwidth = ThunderscopeBandwidth.Bw200M,
162+
SampleRateHz = 1_000_000_000,
163+
},
164+
new NsdStep("Channel 3 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0", Variables)
165+
{
166+
ChannelIndex = 2,
167+
Termination = ThunderscopeTermination.FiftyOhm,
168+
PgaPreampGain = PgaPreampGain.High,
169+
PgaLadder = 0,
170+
Bandwidth = ThunderscopeBandwidth.Bw200M,
171+
SampleRateHz = 1_000_000_000,
172+
},
173+
new NsdStep("Channel 4 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0", Variables)
174+
{
175+
ChannelIndex = 3,
176+
Termination = ThunderscopeTermination.FiftyOhm,
177+
PgaPreampGain = PgaPreampGain.High,
178+
PgaLadder = 0,
179+
Bandwidth = ThunderscopeBandwidth.Bw200M,
180+
SampleRateHz = 1_000_000_000,
181+
},
182+
new CombinedSeriesStep("Combined - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0", this)
183+
{
184+
ChartTitle = "Noise spectral density",
185+
ChartXAxis = new ResultMetadataXYChartAxis
186+
{
187+
Label = "Frequency (Hz)",
188+
Scale = XYChartScaleType.Log10,
189+
AdditionalRangeValues = [10e3, 1e9]
190+
},
191+
ChartYAxis = new ResultMetadataXYChartAxis
192+
{
193+
Label = "Noise (V/rHz)",
194+
Scale = XYChartScaleType.Log10,
195+
AdditionalRangeValues = [100e-9, 100e-12],
196+
},
197+
ChartSeries = [
198+
new SeriesReference { StepName = "Channel 1 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0" },
199+
new SeriesReference { StepName = "Channel 2 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0" },
200+
new SeriesReference { StepName = "Channel 3 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0" },
201+
new SeriesReference { StepName = "Channel 4 - NSD - 50R, 8-bit, 1 GSPS, BW 200M, PGA HG L0" }
202+
],
203+
ChartLegendLocation = ResultMetadataXYChartLegendLocation.BottomLeft,
204+
},
205+
206+
new NsdStep("Channel 1 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", Variables)
207+
{
208+
ChannelIndex = 0,
209+
Termination = ThunderscopeTermination.FiftyOhm,
210+
PgaPreampGain = PgaPreampGain.High,
211+
PgaLadder = 0,
212+
Bandwidth = ThunderscopeBandwidth.Bw20M,
213+
SampleRateHz = 1_000_000_000,
214+
},
215+
new NsdStep("Channel 2 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", Variables)
216+
{
217+
ChannelIndex = 1,
218+
Termination = ThunderscopeTermination.FiftyOhm,
219+
PgaPreampGain = PgaPreampGain.High,
220+
PgaLadder = 0,
221+
Bandwidth = ThunderscopeBandwidth.Bw20M,
222+
SampleRateHz = 1_000_000_000,
223+
},
224+
new NsdStep("Channel 3 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", Variables)
225+
{
226+
ChannelIndex = 2,
227+
Termination = ThunderscopeTermination.FiftyOhm,
228+
PgaPreampGain = PgaPreampGain.High,
229+
PgaLadder = 0,
230+
Bandwidth = ThunderscopeBandwidth.Bw20M,
231+
SampleRateHz = 1_000_000_000,
232+
},
233+
new NsdStep("Channel 4 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", Variables)
234+
{
235+
ChannelIndex = 3,
236+
Termination = ThunderscopeTermination.FiftyOhm,
237+
PgaPreampGain = PgaPreampGain.High,
238+
PgaLadder = 0,
239+
Bandwidth = ThunderscopeBandwidth.Bw20M,
240+
SampleRateHz = 1_000_000_000,
241+
},
242+
new CombinedSeriesStep("Combined - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0", this)
243+
{
244+
ChartTitle = "Noise spectral density",
245+
ChartXAxis = new ResultMetadataXYChartAxis
246+
{
247+
Label = "Frequency (Hz)",
248+
Scale = XYChartScaleType.Log10,
249+
AdditionalRangeValues = [10e3, 1e9]
250+
},
251+
ChartYAxis = new ResultMetadataXYChartAxis
252+
{
253+
Label = "Noise (V/rHz)",
254+
Scale = XYChartScaleType.Log10,
255+
AdditionalRangeValues = [100e-9, 100e-12],
256+
},
257+
ChartSeries = [
258+
new SeriesReference { StepName = "Channel 1 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0" },
259+
new SeriesReference { StepName = "Channel 2 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0" },
260+
new SeriesReference { StepName = "Channel 3 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0" },
261+
new SeriesReference { StepName = "Channel 4 - NSD - 50R, 8-bit, 1 GSPS, BW 20M, PGA HG L0" }
262+
],
263+
ChartLegendLocation = ResultMetadataXYChartLegendLocation.BottomLeft,
264+
},
123265

124266
new Step("Cleanup"){ Action = (CancellationToken cancellationToken) => {
125267
Instruments.Instance.Close();
126268
return Sequencer.Status.Done;
127269
}},
128270
];
129271
}
130-
131-
private class CombineChartsStep : Step
132-
{
133-
public CombineChartsStep(string name, Sequence sequence) : base(name)
134-
{
135-
Action = (CancellationToken cancellationToken) =>
136-
{
137-
var channel1 = (ResultMetadataXYChart)sequence.Steps!.Where(s => s.Name == "Channel 1 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0").First().Result!.Metadata!.Where(r => r.GetType() == typeof(ResultMetadataXYChart)).First();
138-
var channel2 = (ResultMetadataXYChart)sequence.Steps!.Where(s => s.Name == "Channel 2 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0").First().Result!.Metadata!.Where(r => r.GetType() == typeof(ResultMetadataXYChart)).First();
139-
var channel3 = (ResultMetadataXYChart)sequence.Steps!.Where(s => s.Name == "Channel 3 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0").First().Result!.Metadata!.Where(r => r.GetType() == typeof(ResultMetadataXYChart)).First();
140-
var channel4 = (ResultMetadataXYChart)sequence.Steps!.Where(s => s.Name == "Channel 4 - NSD - 50R, 8-bit, 1 GSPS, BW FULL, PGA HG L0").First().Result!.Metadata!.Where(r => r.GetType() == typeof(ResultMetadataXYChart)).First();
141-
142-
var metadata =
143-
new ResultMetadataXYChart()
144-
{
145-
ShowInReport = true,
146-
Title = $"Noise spectral density",
147-
XAxis = new ResultMetadataXYChartAxis { Label = "Frequency (Hz)", Scale = XYChartScaleType.Log10, AdditionalRangeValues = [10e3, 1e9] },
148-
YAxis = new ResultMetadataXYChartAxis { Label = "Noise (V/rHz)", Scale = XYChartScaleType.Log10, AdditionalRangeValues = [100e-9, 100e-12] },
149-
LegendLocation = ResultMetadataXYChartLegendLocation.BottomLeft,
150-
Series =
151-
[
152-
channel1.Series.First(),
153-
channel2.Series.First(),
154-
channel3.Series.First(),
155-
channel4.Series.First()
156-
]
157-
};
158-
159-
Result!.Metadata!.Add(metadata);
160-
161-
return Sequencer.Status.Done;
162-
};
163-
}
164-
}
165272
}

source/TS.NET.Sequences/Singletons/Instruments.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ public double GetThunderscopeVppAtFrequencyLsq(int channelIndex, double frequenc
414414
if (!config.Acquisition.IsChannelIndexAnEnabledChannel(channelIndex))
415415
throw new TestbenchException("Requested channel index is not an enabled channel");
416416

417-
var sampleCount = (int)((sampleRateHz / frequency) * 10.0);
417+
var cycleCount = 10.0;
418+
var sampleCount = (int)Math.Round((sampleRateHz / frequency) * cycleCount);
418419

419420
using SpanOwner<sbyte> i8Buffer = SpanOwner<sbyte>.Allocate(sampleCount); // Returned to pool when it goes out of scope
420421
GetChannelDataI8(channelIndex, sampleCount, i8Buffer.Span);
@@ -434,10 +435,19 @@ public double GetThunderscopeVppAtFrequencyLsq(int channelIndex, double frequenc
434435
f64Span[i] = i8Span[i] * vPerBit;
435436
}
436437

438+
// Goertzel & LSQ give approximately same results for amplitude, Goertzel is slightly faster, LSQ needs optimisation.
439+
// LSQ should be more numerically stable.
440+
441+
//GoertzelFilter filter = new GoertzelFilter(frequency, sampleRateHz);
442+
//var result = filter.Process(f64Span);
443+
//var goertzelVp = (2.0/f64Span.Length) * result.Magnitude;
444+
//var goertzelVpp = goertzelVp * 2.0;
445+
//double goertzelVrms = goertzelVp / Math.Sqrt(2.0);
446+
437447
var (amplitude, phaseRadians, dcOffset) = SineLeastSquaresFit.FitSineWave(sampleRateHz, f64Span, frequency);
438-
var vppResult = amplitude * 2;
448+
var lsqVpp = amplitude * 2.0;
439449

440-
return vppResult;
450+
return lsqVpp;
441451
}
442452

443453
public void GetChannelDataI8(int channelIndex, int sampleCount, Span<sbyte> outputBuffer)

0 commit comments

Comments
 (0)