0

我正在开发一个应用程序,该应用程序允许用户在手机中朗诵,然后将朗诵的音频提取出来,对其应用 FFT,然后将其与另一个音频(预先存储的)交叉关联。一切正常,但我使用的互相关技术太长了!!!

所以我需要另一种互相关方法,这需要更少的时间。或者可能是互相关的替代方案。

我搜索了很多,从这个链接我发现互相关可以实现如下:

           corr = ifft(fft(a and zeroes) * fft(b and zeroes[reversed]))

链接在这里:

  http://dsp.stackexchange.com/questions/736/how-do-i-implement-cross-correlation-to-prove-two-              audio-files-are-similar

但我真的不明白它,我不明白如何在java代码中实现它......如果有人可以帮助我,我会非常喜欢它。

这是我目前使用的互相关代码:

          public void Correlation (){
          int d;
          if(audioDataDoubles.length>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 <Double> CorrelationArray=new ArrayList <Double>();
         /* Calculate the mean of the two series x[], y[] */
         mean1 = 0;
         mean2 = 0; 
         for (t=0;t<(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<(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<maxdelay;delay++) {
         sxy = 0;
         for (t=0;t<(int)(d/2);t++) {
         g = t + delay;
        if (g < 0 || g >= (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); 

      }         
4

0 回答 0