title: How do I apply the hanning function to my audio sample?
body: <p>I am a university student. I am developing a music identification system for my final year project. According to the "Robust Audio Fingerprint Extraction Algorithm Based on 2-D Chroma" research paper, the following functions should need to be included in my system.</p>
  
  <p>Capture Audio Signal ----> Framing Window (hanning window) -----> FFT -----> </p>
  
  <p>High Pass Filter -----> etc.....</p>
  
  <p>I was able to code for Audio Capture function and I was applied the FFT API as well to the code. But I am confused about how to apply the hanning window function to my the my code. Please can someone help me to do this function? Tell me where do I need to add this function and how do I need to add it to the code.</p>
  
  <p>Here is the my Audio capturing code and applying FFT code:</p>
  
  <pre><code>  private class RecordAudio extends AsyncTask&lt;Void, double[], Void&gt; {
      @Override
      protected Void doInBackground(Void... params) {
          started = true;
          try {
              DataOutputStream dos = new DataOutputStream(
                      new BufferedOutputStream(new FileOutputStream(
                              recordingFile)));
              int bufferSize = AudioRecord.getMinBufferSize(frequency,
                      channelConfiguration, audioEncoding);
              audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                      frequency, channelConfiguration, audioEncoding,
                      bufferSize);
  
              short[] buffer = new short[blockSize];
              double[] toTransform = new double[blockSize];
              long t = System.currentTimeMillis();
              long end = t + 15000;
              audioRecord.startRecording();
              double[] w = new double[blockSize];
  
              while (started &amp;&amp; System.currentTimeMillis() &lt; end) {
                  int bufferReadResult = audioRecord.read(buffer, 0,
                          blockSize);
                  for (int i = 0; i &lt; blockSize &amp;&amp; i &lt; bufferReadResult; i++) {
                      toTransform[i] = (double) buffer[i] / 32768.0;
                      dos.writeShort(buffer[i]);
                  }
                  // new part
                  toTransform = hanning (toTransform);
                  transformer.ft(toTransform);
                  publishProgress(toTransform);
              }
              audioRecord.stop();
              dos.close();
          } catch (Throwable t) {
              Log.e("AudioRecord", "Recording Failed");
          }
          return null;
      }
  </code></pre>
  
  <p>These links are providing hanning window algorithm and code snippets:</p>
  
  <p><a href="https://code.google.com/p/musicg/source/browse/src/com/musicg/dsp/WindowFunction.java?r=7a0c77284b0d9263ab705821e333f36a38bced96" rel="nofollow">WindowFunction.java</a> </p>
  
  <p><a href="http://in.mathworks.com/help/signal/ref/hann.html" rel="nofollow">Hanning - MATLAB</a></p>
  
  <p>The following code I have used to apply hanning function to the my application and it works for me....</p>
  
  <pre><code>public double[] hanningWindow(double[] recordedData) {
  
      // iterate until the last line of the data buffer
      for (int n = 1; n &lt; recordedData.length; n++) {
          // reduce unnecessarily performed frequency part of each and every frequency
          recordedData[n] *= 0.5 * (1 - Math.cos((2 * Math.PI * n)
                  / (recordedData.length - 1)));
      }
      // return modified buffer to the FFT function
      return recordedData;
  }
  </code></pre>