NumDart

Interpolation

Parabolic interpolation to find a peak between samples.

parabolic fits a parabola through a sample and its two neighbours and returns the position and height of its vertex. It is the standard way to read a peak position with more precision than the sample spacing, for example the frequency of an FFT peak.

Find the true peak between samplesParabolic interpolation around the largest sample gives the peak position between grid points.
import 'package:scidart/numdart.dart';

void main() {
  // samples of -(x - 2.3)^2 at x = 0..5: the real peak is at 2.3
  var y = Array([for (var x = 0; x < 6; x++) -(x - 2.3) * (x - 2.3)]);
  var i = arrayArgMax(y);
  var peak = parabolic(y, i);
  print('largest sample at index $i');
  print('interpolated peak at ${peak[0]}, value ${peak[1]}');
}
Output
largest sample at index 2
interpolated peak at 2.3, value 0.0

The FFT guide uses it to estimate a frequency between two FFT bins.

Edit this guide on GitHub