title: cross correlation in android takes too much time
body: <p>I am working on an application, this application allows user to recite into the phone, and after that, this recited audio is taken, and FFT is applied to it, and then it is cross correlated with another audio ( previosely stored) . everything is working fine, but the cross correlation technique i am using is taking way too long!!!</p>
  
  <p>so i need another cross correlation method, which takes less time. or maybe an alternative to cross correlation.</p>
  
  <p>i searched alot, and from this link i found that cross correlation could be implemented as follows:</p>
  
  <pre><code>           corr = ifft(fft(a and zeroes) * fft(b and zeroes[reversed]))
  </code></pre>
  
  <p>here is the link:</p>
  
  <pre><code>  http://dsp.stackexchange.com/questions/736/how-do-i-implement-cross-correlation-to-prove-two-              audio-files-are-similar
  </code></pre>
  
  <p>but i dont really understand it, and i dont get how i could implement it in java code...
  if someone can please help me out i would greatly appeciate it.</p>
  
  <p>here is the cross correlation code i am currently using:</p>
  
  <pre><code>          public void Correlation (){
            int d;
            if(audioDataDoubles.length&gt;audioDataDoubles3.length)
            d=audioDataDoubles3.length;
            else
            d=audioDataDoubles.length;
            int t,g,delay,maxdelay = (d+1);
            double mean1,mean2,sx,sy,sxy = 0,denom,r;
            int c=0;
            ArrayList &lt;Double&gt; CorrelationArray=new ArrayList &lt;Double&gt;();
           /* Calculate the mean of the two series x[], y[] */
           mean1 = 0;
           mean2 = 0; 
           for (t=0;t&lt;(int)(d/2);t++) {
           mean1 += magnitude[t];
           mean2 += magnitude3[t];
           }
           mean1 /= (int)(d/2);
           mean2 /= (int)(d/2);
          /* Calculate the denominator */
           sx = 0;
           sy = 0;
           for (t=0;t&lt;(int)(d/2);t++) {
           sx += (magnitude[t] - mean1) * (magnitude[t] - mean1);
           sy += (magnitude3[t] - mean2) * (magnitude3[t] - mean2);
            }
           denom= Math.sqrt(sx*sy);
           /* Calculate the correlation series */
           for (delay=-maxdelay;delay&lt;maxdelay;delay++) {
           sxy = 0;
           for (t=0;t&lt;(int)(d/2);t++) {
           g = t + delay;
          if (g &lt; 0 || g &gt;= (int)(d/2))
          continue;
           else
           sxy += (magnitude[t] - mean1) * (magnitude3[g] - mean2);
  
          }
          r = sxy / denom;
         CorrelationArray.add(c,r);
         c++;
         /* r is the correlation coefficient at "delay" */
           }
         MaximumCoefficient= Collections.max(CorrelationArray);
  
  
        String data2 = String.valueOf(MaximumCoefficient); 
        display.setText(data2); 
  
        }         
  </code></pre>