Mercurial > hg > qm-dsp
comparison maths/Correlation.cpp @ 16:2e3f5d2d62c1
* Move dsp/maths to maths ; bring PCA and HMM across from Soundbite
| author | cannam | 
|---|---|
| date | Wed, 09 Jan 2008 10:31:29 +0000 | 
| parents | dsp/maths/Correlation.cpp@d7116e3183f8 | 
| children | e5907ae6de17 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 15:10c3f9df4a07 | 16:2e3f5d2d62c1 | 
|---|---|
| 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
| 2 | |
| 3 /* | |
| 4 QM DSP Library | |
| 5 | |
| 6 Centre for Digital Music, Queen Mary, University of London. | |
| 7 This file copyright 2005-2006 Christian Landone. | |
| 8 All rights reserved. | |
| 9 */ | |
| 10 | |
| 11 #include "Correlation.h" | |
| 12 | |
| 13 ////////////////////////////////////////////////////////////////////// | |
| 14 // Construction/Destruction | |
| 15 ////////////////////////////////////////////////////////////////////// | |
| 16 | |
| 17 Correlation::Correlation() | |
| 18 { | |
| 19 | |
| 20 } | |
| 21 | |
| 22 Correlation::~Correlation() | |
| 23 { | |
| 24 | |
| 25 } | |
| 26 | |
| 27 void Correlation::doAutoUnBiased(double *src, double *dst, unsigned int length) | |
| 28 { | |
| 29 double tmp = 0.0; | |
| 30 double outVal = 0.0; | |
| 31 | |
| 32 unsigned int i,j; | |
| 33 | |
| 34 for( i = 0; i < length; i++) | |
| 35 { | |
| 36 for( j = i; j < length; j++) | |
| 37 { | |
| 38 tmp += src[ j-i ] * src[ j ]; | |
| 39 } | |
| 40 | |
| 41 | |
| 42 outVal = tmp / ( length - i ); | |
| 43 | |
| 44 if( outVal <= 0 ) | |
| 45 dst[ i ] = EPS; | |
| 46 else | |
| 47 dst[ i ] = outVal; | |
| 48 | |
| 49 tmp = 0.0; | |
| 50 } | |
| 51 } | 
