From 7380327ba64f096391cec5b361c63bf1a76bd999 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 8 Mar 2014 17:30:49 -0300 Subject: [PATCH] src/mathutils.h: add fvec_quadratic_peak_mag to find the magnitude of interpolated peaks --- src/mathutils.c | 13 ++++++++++++- src/mathutils.h | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/mathutils.c b/src/mathutils.c index be89c98b..766016cb 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2003-2013 Paul Brossier + Copyright (C) 2003-2014 Paul Brossier This file is part of aubio. @@ -429,6 +429,17 @@ smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t pos) { return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2); } +smpl_t fvec_quadratic_peak_mag (fvec_t *x, smpl_t pos) { + smpl_t x0, x1, x2; + uint_t index = (uint_t)(pos - .5) + 1; + if (pos >= x->length || pos < 0.) return 0.; + if ((smpl_t)index == pos) return x->data[index]; + x0 = x->data[index - 1]; + x1 = x->data[index]; + x2 = x->data[index + 1]; + return x1 - .25 * (x0 - x2) * (pos - index); +} + uint_t fvec_peakpick(fvec_t * onset, uint_t pos) { uint_t tmp=0; tmp = (onset->data[pos] > onset->data[pos-1] diff --git a/src/mathutils.h b/src/mathutils.h index d4905a74..fe04647e 100644 --- a/src/mathutils.h +++ b/src/mathutils.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2003-2013 Paul Brossier + Copyright (C) 2003-2014 Paul Brossier This file is part of aubio. @@ -234,6 +234,19 @@ smpl_t fvec_median (fvec_t * v); */ smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t p); +/** finds magnitude of peak by quadratic interpolation + + See [Quadratic Interpolation of Spectral + Peaks](https://ccrma.stanford.edu/~jos/sasp/Quadratic_Peak_Interpolation.html), + by Julius O. Smith III + + \param x vector to get the magnitude of the interpolated peak position from + \param p index of the peak in vector `x` + \return magnitude of interpolated peak + +*/ +smpl_t fvec_quadratic_peak_mag (fvec_t * x, smpl_t p); + /** Quadratic interpolation using Lagrange polynomial. Inspired from ``Comparison of interpolation algorithms in real-time sound -- 2.11.0