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