@@ -367,7 +367,7 @@ static Function/WAVE PSX_DeconvoluteSweepData(WAVE sweepData, WAVE/C psxKernelFF
367367 // no window function on purpose
368368 WAVE /C outputFFT = DoFFT ( sweepData, padSize = numPoints)
369369
370- Multithread outputFFT[] = outputFFT[ p] / psxKernelFFT[ p]
370+ Multithread outputFFT[] = outputFFT[ p] / ( psxKernelFFT[ p] + 1 e -5 )
371371
372372 IFFT / DEST= Deconv/ FREE outputFFT
373373
@@ -376,7 +376,8 @@ static Function/WAVE PSX_DeconvoluteSweepData(WAVE sweepData, WAVE/C psxKernelFF
376376
377377 CopyScales sweepData, Deconv
378378 FilterIIR / LO= ( lowFrac) / HI= ( highFrac) / ORD= ( order) Deconv; err = GetRTError ( 0 )
379-
379+ // FilterIIR/LO=(lowFrac)/ORD=(order) Deconv; err = GetRTError(0)
380+ // smooth/E=2 47, Deconv
380381 if ( err)
381382 printf "Error applying deconvolution filter: %s\r " , GetRTErrMessage ()
382383 ClearRTError ()
@@ -476,7 +477,7 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_FindPeaks(WAVE sweepDataOffFilt
476477 Make / FREE/ D/ N= ( numPeaksMax) peakX, peakY
477478
478479 for ( i = 0; i < numPeaksMax; i += 1 )
479- FindPeak / B=10 / M= ( threshold) / Q/ R= ( start, stop) sweepDataOffFiltDeconv
480+ FindPeak / B=100 / M= ( threshold) / Q/ R= ( start, stop) sweepDataOffFiltDeconv
480481
481482 if ( V_Flag != 0 )
482483 break
@@ -593,11 +594,11 @@ static Function [variable peak_t, variable peak] PSX_CalculateEventPeak(WAVE pea
593594 return [ peak_t, peak]
594595End
595596
596- static Function [variable baseline_t, variable baseline] PSX_CalculateEventBaseline ( WAVE sweepDataOffFilt, variable peak_t, variable kernelAmp, variable kernelRiseTau)
597+ static Function [variable baseline_t, variable baseline] PSX_CalculateEventBaseline ( WAVE sweepDataOffFilt,variable peak_t_prev, variable peak_t, variable kernelAmp, variable kernelRiseTau)
597598
598599 variable range
599600
600- WaveStats / M=1/ Q/ R= ( peak_t - PSX_BASELINE_RANGE_FACTOR * kernelRiseTau, peak_t) sweepDataOffFilt
601+ WaveStats / M=1/ Q/ R= ( max ( peak_t - PSX_BASELINE_RANGE_FACTOR * kernelRiseTau, peak_t_prev ) , peak_t) sweepDataOffFilt
601602
602603 if ( kernelAmp > 0 )
603604 baseline_t = V_minloc
616617
617618static 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)
618619
620+ variable peak_t_prev = - inf
621+ variable peak_prev
622+
619623 [ peak_t, peak] = PSX_CalculateEventPeak ( peakX, peakY, sweepDataOffFilt, kernelAmp, kernelRiseTau, kernelDecayTau, index)
620- [ baseline_t, baseline] = PSX_CalculateEventBaseline ( sweepDataOffFilt, peak_t, kernelAmp, kernelRiseTau)
624+
625+ if ( index > 0 )
626+ [ peak_t_prev, peak_prev] = PSX_CalculateEventPeak ( peakX, peakY, sweepDataOffFilt, kernelAmp, kernelRiseTau, kernelDecayTau, index - 1 )
627+ endif
628+
629+ [ baseline_t, baseline] = PSX_CalculateEventBaseline ( sweepDataOffFilt, peak_t_prev, peak_t, kernelAmp, kernelRiseTau)
621630
622631 amplitude = peak - baseline
623632
@@ -764,7 +773,7 @@ static Function [variable start, variable stop] PSX_GetEventFitRange(WAVE sweepD
764773
765774 variable calcLength, maxLength
766775
767- start = psxEvent[ eventIndex][ % deconvPeak_t ]
776+ start = psxEvent[ eventIndex][ % peak_t ]
768777
769778 maxLength = PSX_FIT_RANGE_FACTOR * JWN_GetNumberFromWaveNote ( psxEvent, SF_META_USER_GROUP + PSX_JWN_PARAMETERS + "/psxKernel/decayTau" )
770779
@@ -2226,7 +2235,7 @@ static Function PSX_UpdateAverageTraces(string win, WAVE/T eventIndexFromTraces,
22262235 numEvents = DimSize ( eventIndexFromTraces, ROWS)
22272236
22282237 Make / WAVE /FREE/ N= ( numEvents) contAverageAll, contAverageAccept, contAverageReject, contAverageUndet
2229- Make / FREE/ D/ N= ( numEvents) eventStopTime
2238+ Make / FREE/ D/ N= ( numEvents) eventStopTime, eventPeakTime
22302239
22312240 for ( i = 0; i < numEvents; i += 1 )
22322241 idx = str2num ( eventIndexFromTraces[ i ])
@@ -2249,6 +2258,7 @@ static Function PSX_UpdateAverageTraces(string win, WAVE/T eventIndexFromTraces,
22492258 // single event waves are zeroed in x-direction to extractStartAbs
22502259 [ extractStartAbs, extractStopAbs] = PSX_GetSingleEventRange ( psxEvent, sweepDataOffFilt, idx)
22512260 eventStopTime[ acceptIndex] = extractStopAbs - extractStartAbs
2261+ eventPeakTime[ acceptIndex] = psxEvent[ idx][ % peak_t] - extractStartAbs
22522262
22532263 acceptIndex += 1
22542264 break
@@ -2275,7 +2285,7 @@ static Function PSX_UpdateAverageTraces(string win, WAVE/T eventIndexFromTraces,
22752285 PSX_UpdateAverageWave ( contAverageAll, numEvents, averageDFR, PSX_ALL)
22762286
22772287 Redimension / N= ( acceptIndex) eventStopTime
2278- PSX_FitAcceptAverage ( win, averageDFR, eventStopTime)
2288+ PSX_FitAcceptAverage ( win, averageDFR, eventPeakTime , eventStopTime)
22792289End
22802290
22812291/// @brief Helper function to update the average waves for the all event graph
@@ -2299,10 +2309,10 @@ static Function/DF PSX_GetAverageFolder(string win)
22992309 endif
23002310End
23012311
2302- static Function PSX_FitAcceptAverage ( string win, DFREF averageDFR, WAVE eventStopTime)
2312+ static Function PSX_FitAcceptAverage ( string win, DFREF averageDFR, WAVE eventPeakTime, WAVE eventStopTime)
23032313
23042314 string specialEventPanel, str, htmlStr, rawCode, browser, msg, fitFunc
2305- variable err, numAveragePoints, start, stop, meanStopTime
2315+ variable err, numAveragePoints, start, stop, meanStopTime, meanPeakTime
23062316
23072317 WAVE acceptedAverageFit = GetPSXAcceptedAverageFitWaveFromDFR ( averageDFR)
23082318
@@ -2333,10 +2343,17 @@ static Function PSX_FitAcceptAverage(string win, DFREF averageDFR, WAVE eventSto
23332343 else
23342344 meanStopTime = Inf
23352345 endif
2346+
2347+ WAVE /Z eventPeakTimeClean = ZapNaNs ( eventPeakTime)
2348+ if ( WaveExists ( eventPeakTimeClean))
2349+ meanPeakTime = mean ( eventPeakTime)
2350+ else
2351+ ASSERT ( 0, "Could not find any events with finite peak_t" )
2352+ endif
23362353
2337- start = 0
23382354 stop = min ( IndexToScale ( average, DimSize ( average, ROWS) - 1, ROWS) , meanStopTime)
2339-
2355+ start = 0.1 * meanPeakTime
2356+
23402357 AssertOnAndClearRTError ()
23412358 fitFunc = GetPopupMenuString ( specialEventPanel, "popupmenu_accept_fit_function" )
23422359 strswitch ( fitFunc)
0 commit comments