c@241: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@241: c@241: /* c@241: QM DSP Library c@241: c@241: Centre for Digital Music, Queen Mary, University of London. c@309: This file 2005-2006 Christian Landone. c@309: c@309: This program is free software; you can redistribute it and/or c@309: modify it under the terms of the GNU General Public License as c@309: published by the Free Software Foundation; either version 2 of the c@309: License, or (at your option) any later version. See the file c@309: COPYING included with this distribution for more information. c@241: */ c@241: c@241: #include "Correlation.h" c@241: cannam@489: #include "MathAliases.h" cannam@489: c@241: ////////////////////////////////////////////////////////////////////// c@241: // Construction/Destruction c@241: ////////////////////////////////////////////////////////////////////// c@241: c@241: Correlation::Correlation() c@241: { c@241: c@241: } c@241: c@241: Correlation::~Correlation() c@241: { c@241: c@241: } c@241: c@241: void Correlation::doAutoUnBiased(double *src, double *dst, unsigned int length) c@241: { c@241: double tmp = 0.0; c@241: double outVal = 0.0; c@241: c@241: unsigned int i,j; c@241: cannam@477: for( i = 0; i < length; i++) { cannam@477: for( j = i; j < length; j++) { cannam@477: tmp += src[ j-i ] * src[ j ]; cannam@477: } c@241: cannam@477: outVal = tmp / ( length - i ); c@241: cannam@477: if( outVal <= 0 ) { cannam@477: dst[ i ] = EPS; cannam@477: } else { cannam@477: dst[ i ] = outVal; cannam@477: } cannam@477: cannam@477: tmp = 0.0; c@241: } c@241: }