Skip to content

Commit 34a85c2

Browse files
committed
PSX_CalculateEventProperties: Tweak baseline calculation
The current algorithm for determining the left boundary for the baseline search did not take into account events which are close-by. Fix that by using the peak time of the previous event as maximum boundary.
1 parent ca281f2 commit 34a85c2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Packages/MIES/MIES_SweepFormula_PSX.ipf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_FilterEventsKernelAmpSign(WAVE/
505505
variable peak, peak_t, baseline, baseline_t, amplitude
506506
variable overrideSignQC = NaN
507507
string comboKey
508+
variable peak_t_prev = -Inf
508509

509510
if(!WaveExists(peakXUnfiltered) || !WaveExists(peakYUnfiltered))
510511
return [$"", $""]
@@ -516,7 +517,7 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_FilterEventsKernelAmpSign(WAVE/
516517

517518
for(i = 0; i < numCrossings; i += 1)
518519

519-
[peak, peak_t, baseline, baseline_t, amplitude] = PSX_CalculateEventProperties(peakXUnfiltered, peakYUnfiltered, sweepDataOffFilt, kernelAmp, kernelRiseTau, kernelDecayTau, i)
520+
[peak, peak_t, baseline, baseline_t, amplitude] = PSX_CalculateEventProperties(peakXUnfiltered, peakYUnfiltered, sweepDataOffFilt, peak_t_prev, kernelAmp, kernelRiseTau, kernelDecayTau, i)
520521

521522
#ifdef AUTOMATED_TESTING
522523
WAVE/Z overrideResults = GetOverrideResults()
@@ -539,7 +540,8 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_FilterEventsKernelAmpSign(WAVE/
539540
peakX[idx] = peakXUnfiltered[i]
540541
peakY[idx] = peakYUnfiltered[i]
541542

542-
idx += 1
543+
idx += 1
544+
peak_t_prev = peak_t
543545
endfor
544546

545547
if(idx == 0)
@@ -593,11 +595,11 @@ static Function [variable peak_t, variable peak] PSX_CalculateEventPeak(WAVE pea
593595
return [peak_t, peak]
594596
End
595597

596-
static Function [variable baseline_t, variable baseline] PSX_CalculateEventBaseline(WAVE sweepDataOffFilt, variable peak_t, variable kernelAmp, variable kernelRiseTau)
598+
static Function [variable baseline_t, variable baseline] PSX_CalculateEventBaseline(WAVE sweepDataOffFilt, variable peak_t_prev, variable peak_t, variable kernelAmp, variable kernelRiseTau)
597599

598600
variable range
599601

600-
WaveStats/M=1/Q/R=(peak_t - PSX_BASELINE_RANGE_FACTOR * kernelRiseTau, peak_t) sweepDataOffFilt
602+
WaveStats/M=1/Q/R=(max(peak_t - PSX_BASELINE_RANGE_FACTOR * kernelRiseTau, peak_t_prev), peak_t) sweepDataOffFilt
601603

602604
if(kernelAmp > 0)
603605
baseline_t = V_minloc
@@ -614,10 +616,10 @@ static Function [variable baseline_t, variable baseline] PSX_CalculateEventBasel
614616
return [baseline_t, baseline]
615617
End
616618

617-
static Function [variable peak, variable peak_t, variable baseline, variable baseline_t, variable amplitude] PSX_CalculateEventProperties(WAVE peakX, WAVE peakY, WAVE sweepDataOffFilt, variable kernelAmp, variable kernelRiseTau, variable kernelDecayTau, variable index)
619+
static Function [variable peak, variable peak_t, variable baseline, variable baseline_t, variable amplitude] PSX_CalculateEventProperties(WAVE peakX, WAVE peakY, WAVE sweepDataOffFilt, variable peak_t_prev, variable kernelAmp, variable kernelRiseTau, variable kernelDecayTau, variable index)
618620

619621
[peak_t, peak] = PSX_CalculateEventPeak(peakX, peakY, sweepDataOffFilt, kernelAmp, kernelRiseTau, kernelDecayTau, index)
620-
[baseline_t, baseline] = PSX_CalculateEventBaseline(sweepDataOffFilt, peak_t, kernelAmp, kernelRiseTau)
622+
[baseline_t, baseline] = PSX_CalculateEventBaseline(sweepDataOffFilt, peak_t_prev, peak_t, kernelAmp, kernelRiseTau)
621623

622624
amplitude = peak - baseline
623625

@@ -628,6 +630,7 @@ End
628630
static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffFiltDeconv, WAVE sweepDataOffFilt, WAVE sweepData, WAVE/Z peakXUnfiltered, WAVE/Z peakYUnfiltered, variable maxTauFactor, variable kernelAmp, variable kernelRiseTau, variable kernelDecayTau, WAVE riseTimeParams, WAVE psxEvent, WAVE eventFit)
629631

630632
variable i, numCrossings, deconvPeak, deconvPeak_t, peak, peak_t, baseline, baseline_t, amplitude, iei
633+
variable peak_t_prev = -Inf
631634

632635
// we need to first throw away events with invalid amplitude so that
633636
// we can then calculate the distance to the neighbour in peakX[i + 1] below
@@ -649,8 +652,8 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF
649652
deconvPeak_t = peakX[i]
650653
deconvPeak = peakY[i]
651654

652-
[peak, peak_t, baseline, baseline_t, amplitude] = PSX_CalculateEventProperties(peakX, peakY, sweepDataOffFilt, \
653-
kernelAmp, kernelRiseTau, kernelDecayTau, i)
655+
[peak, peak_t, baseline, baseline_t, amplitude] = PSX_CalculateEventProperties(peakX, peakY, sweepDataOffFilt, \
656+
peak_t_prev, kernelAmp, kernelRiseTau, kernelDecayTau, i)
654657

655658
if(i == 0)
656659
iei = NaN
@@ -667,6 +670,8 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF
667670
psxEvent[i][%baseline_t] = baseline_t
668671
psxEvent[i][%amplitude] = amplitude
669672
psxEvent[i][%iei] = iei
673+
674+
peak_t_prev = peak_t
670675
endfor
671676

672677
// safe defaults

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8243,7 +8243,8 @@ End
82438243
/// in the filtered sweep wave
82448244
/// - 4/peak_t: peak time
82458245
/// - 5/baseline: Maximum (negative kernel amp sign) or minimum (positive kernel amp sign) in the range of
8246-
/// [peak_t – 10 * kernelRiseTau, peak_t], averaged over +/- 5 points, in the filtered sweep wave
8246+
/// [peak_t – 10 * kernelRiseTau or peak_t of previous event (whichever comes later),
8247+
/// peak_t], averaged over +/- 5 points, in the filtered sweep wave
82478248
/// - 6/baseline_t: baseline time
82488249
/// - 7/amplitude: Relative amplitude: [3] - [5]
82498250
/// - 8/iei: Time difference to previous event (inter event interval) [ms]

0 commit comments

Comments
 (0)