From a480852e157c9c11c8799bd1a0a2c41117a5b195 Mon Sep 17 00:00:00 2001 From: Jiahao Yuan Date: Fri, 19 Apr 2024 21:49:18 +0800 Subject: [PATCH] fix: pulse start phase calculation (#142) --- src/Bosing/WaveformUtils.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bosing/WaveformUtils.cs b/src/Bosing/WaveformUtils.cs index 2728426..9a1973e 100644 --- a/src/Bosing/WaveformUtils.cs +++ b/src/Bosing/WaveformUtils.cs @@ -24,7 +24,8 @@ public static PooledComplexArray SampleWaveform(PulseList pulseList, doubl var tStart = time + delay; var iFracStart = TimeAxisUtils.NextFracIndex(tStart, sampleRate, alignLevel); var iStart = (int)Math.Ceiling(iFracStart); - var envelopeInfo = new EnvelopeInfo(iStart - iFracStart, sampleRate); + var indexOffset = iStart - iFracStart; + var envelopeInfo = new EnvelopeInfo(indexOffset, sampleRate); var envelopeSample = WaveformSampler.GetEnvelopeSample(envelopeInfo, binKey.Envelope); if (envelopeSample is null) { @@ -35,7 +36,7 @@ public static PooledComplexArray SampleWaveform(PulseList pulseList, doubl var localFrequency = binKey.LocalFrequency; var totalFrequency = globalFrequency + localFrequency; var dt = 1 / sampleRate; - var phaseShift = Math.Tau * globalFrequency * (iStart * dt - delay); + var phaseShift = Math.Tau * (globalFrequency * (iStart * dt - delay) + localFrequency * indexOffset * dt); var amplitude = pulse.Amplitude * pulseList.AmplitudeMultiplier * Complex.FromPolarCoordinates(1, phaseShift); var complexAmplitude = amplitude.Amplitude; var dragAmplitude = amplitude.DragAmplitude * sampleRate;