Skip to content

Commit

Permalink
PSQ_DAScale (Adapt): Round calculated DAscale to integer values
Browse files Browse the repository at this point in the history
We don't need the sub pA precision. In PSQ_DS_GatherOvershootCorrection we
now also check if the calulated value is the same as the before/after
value, as this can now happen with rounding.

In PSQ_DS_CalculateDAScale we also use ceil for the too large/small cases
so that we always get a different value.
  • Loading branch information
t-b committed Nov 27, 2024
1 parent 3834f38 commit 1c1b367
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 74 deletions.
12 changes: 7 additions & 5 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2443,15 +2443,17 @@ static Function/WAVE PSQ_DS_GatherOvershootCorrection(STRUCT PSQ_DS_DAScaleParam
x = DAScales[i]
xp = DAScales[i + 1]
xs = (xp - x) / 2
xm = x + xs
xm = round(x + xs)

frac = yp / y - 1
DAScaleStepMin = cdp.daScaleStepMinNorm * y

maxFreqRelCond = frac > (cdp.maxFrequencyChangePercent * PERCENT_TO_ONE)
minFreqDistCond = abs(yp - y) > cdp.absFrequencyMinDistance
minDaScaleCond = xs > DAScaleStepMin
alreadyMeasured = WaveExists(futureDAScalesHistoric) && !IsNaN(GetRowIndex(futureDAScalesHistoric, val = xm))
alreadyMeasured = WaveExists(futureDAScalesHistoric) && !IsNaN(GetRowIndex(futureDAScalesHistoric, val = xm)) \
&& xm != x \
&& xm != xp

newDAScaleValue = maxFreqRelCond && minFreqDistCond && minDaScaleCond && !alreadyMeasured

Expand Down Expand Up @@ -2500,20 +2502,20 @@ static Function PSQ_DS_CalculateDAScale(STRUCT PSQ_DS_DAScaleParams &cdp, variab

ASSERT(cdp.maxFrequencyChangePercent > PSQ_DS_MAX_FREQ_OFFSET, "Invalid PSQ_DS_MAX_FREQ_OFFSET")
yp = y * (1 + (cdp.maxFrequencyChangePercent - PSQ_DS_MAX_FREQ_OFFSET) * PERCENT_TO_ONE)
xp = (yp - a) / (m)
xp = round((yp - a) / (m))

sprintf msg, "result %g with a=%g, m=%g, [x, xp]=[%g, %g], [y, yp]=[%g, %g], maxFrequencyChangePercent=%g, absDAScaleStepMin=%g, absDAScaleStepMax=%g\r", xp, a, m, x, xp, y, yp, cdp.maxFrequencyChangePercent, absDAScaleStepMin, absDAScaleStepMax
DEBUGPRINT(msg)

if(CheckIfSmall(m) || abs(x - xp) > absDAScaleStepMax)
// avoid excessive too large values
xp = x + absDAScaleStepMax
xp = ceil(x + absDAScaleStepMax)

sprintf msg, "corrected result: %g\r", xp
DEBUGPRINT(msg)
elseif(abs(y - yp) < cdp.absFrequencyMinDistance)
// or too small values
xp = x + absDAScaleStepMin
xp = ceil(x + absDAScaleStepMin)

sprintf msg, "corrected result: %g\r", xp
DEBUGPRINT(msg)
Expand Down
Loading

0 comments on commit 1c1b367

Please sign in to comment.