getWidth method
Returns an estimate of the width at half height of the peak at peakindex
of the data given by yvals
.
This assumes a Gauss/Lorentz type line shape.
Implementation
static double getWidth(Float64List yvals, int peakindex) {
double peakheight = yvals[peakindex];
double halfheight = peakheight / 2;
int leftpos = peakindex - 1, rightpos = peakindex + 1;
// move down at the left of the peak
while (true) {
if (!(leftpos >= 1 && leftpos < yvals.length)) break;
if (yvals[leftpos] < halfheight) break;
if (yvals[leftpos - 1] > yvals[leftpos]) break; // raises again
leftpos--;
}
// move down at the right of the peak
while (true) {
if (!(rightpos >= 0 && rightpos < yvals.length - 1)) break;
if (yvals[rightpos] < halfheight) break;
if (yvals[rightpos + 1] > yvals[rightpos]) break; // raises again
rightpos++;
}
double result = (rightpos - leftpos).toDouble().abs();
return result;
}