@@ -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]
594596End
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]
615617End
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
628630static 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
0 commit comments