experiments

All kinds of coding experiments
Log | Files | Refs | Submodules

getperiod.cpp (667B)


      1 #include <iostream>
      2 #include <math.h>
      3 #define PI2 6.28318530718
      4 
      5 using namespace std;
      6 
      7 double getPeriod(double* signal, int N)
      8 {
      9     /* 1.   Calculate the autocorrelation function (acf)
     10      * 2.   Find the next local maximum of the acf.
     11      *      This can be found by finding the next max value that 
     12      *      is bigger than both its neighbor values, or at least 
     13      *      bigger than the previous value. 
     14      */
     15 }
     16 
     17 int main()
     18 {
     19     int N = 44100;
     20     double f = 2.565;
     21     double* audio = new double[N];
     22     for(int n = 0; n < N; n++)
     23     {
     24         audio[n] = sin(PI2*f*n/N);
     25     }
     26 
     27     cout << "T = " << getPeriod(audio, N) << endl;
     28     delete[] audio;
     29 }