/*
- Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+ Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
This file is part of aubio.
return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0);
}
+smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t pos) {
+ smpl_t s0, s1, s2;
+ uint_t x0 = (pos < 1) ? pos : pos - 1;
+ uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos;
+ if (x0 == pos) return (x->data[pos] <= x->data[x2]) ? pos : x2;
+ if (x2 == pos) return (x->data[pos] <= x->data[x0]) ? pos : x0;
+ s0 = x->data[x0];
+ s1 = x->data[pos];
+ s2 = x->data[x2];
+ return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2);
+}
+
uint_t fvec_peakpick(fvec_t * onset, uint_t pos) {
uint_t tmp=0;
tmp = (onset->data[pos] > onset->data[pos-1]
/** finds exact peak index by quadratic interpolation*/
smpl_t fvec_quadint (fvec_t * x, uint_t pos);
+/** finds exact peak index by quadratic interpolation
+
+ See [Quadratic Interpolation of Spectral
+ Peaks](https://ccrma.stanford.edu/~jos/sasp/Quadratic_Peak_Interpolation.html),
+ by Julius O. Smith III
+
+ \f$ p_{frac} = \frac{1}{2} \frac {x[p-1] - x[p+1]} {x[p-1] - 2 x[p] + x[p+1]} \in [ -.5, .5] \f$
+
+ \param x vector to get the interpolated peak position from
+ \param p index of the peak in vector `x`
+ \return \f$ p + p_{frac} \f$ exact peak position of interpolated maximum or minimum
+
+*/
+smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t p);
+
/** Quadratic interpolation using Lagrange polynomial.
Inspired from ``Comparison of interpolation algorithms in real-time sound