0

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.

Capture Audio Signal ----> Framing Window (hanning window) -----> FFT ----->

High Pass Filter -----> etc.....

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.

Here is the my Audio capturing code and applying FFT code:

  private class RecordAudio extends AsyncTask<Void, double[], Void> {
    @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 && System.currentTimeMillis() < end) {
                int bufferReadResult = audioRecord.read(buffer, 0,
                        blockSize);
                for (int i = 0; i < blockSize && i < 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;
    }

These links are providing hanning window algorithm and code snippets:

WindowFunction.java

Hanning - MATLAB

The following code I have used to apply hanning function to the my application and it works for me....

public double[] hanningWindow(double[] recordedData) {

    // iterate until the last line of the data buffer
    for (int n = 1; n < 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;
}
Hash_S
  • 79
  • 4
  • 18
  • Please some one help me to do this function. Because it's very urgent. – Hash_S Jan 29 '15 at 13:48
  • Any urgency is your own problem, you should not try to encourage volunteers on the site in this way. – Neil Slater Jan 29 '15 at 14:10
  • Just realised my answer tries to insert Matlab code into your Java, so it won't work - going to delete. Why is the question tagged `matlab`? Shouldn't it be tagged `java`? You may well get better attention and help if you need assistance with the Java code. – Neil Slater Jan 29 '15 at 16:34
  • @Neil you are right. But that is the formula which is needed to apply my code. Thats why I tagged it – Hash_S Jan 30 '15 at 00:45

1 Answers1

1

At first, I think you should consider having your FFT length fixed. If I understand your code correctly, you are now using some kind of minimum buffer size also as the FFT length. FFT length has huge effect on the performance and resolution of your calculation.

Your link to WindowFunction.java can generate you an array, that should be the same length as your FFT length (blockSize in your case, I think). You should then multiply each sample of your buffer with the value returned from the WindowFunction that has the same id in the array.

This should be done before the FFT.

  • Yes that is how I want to do it. So can you explain it through the code snippet ? – Hash_S Jan 30 '15 at 00:58
  • @ Mikael check my edited code.I have shown that how i was tried hanning function and how was added to the code.But problem is now it is generation very small frequency and i don't think it is correct. Because something wrong is there. – Hash_S Jan 30 '15 at 01:05
  • @ Mikael I am not clear with last part that u have mentioned in the comment " You should then multiply each sample of your buffer with the value returned from the WindowFunction that has the same id in the array. " – Hash_S Jan 30 '15 at 01:15
  • @hashS: The implementation you added to your code returns the multipliers. It doesn't use them. I don't know enough Java syntax to correct it, but for each `n` inside your hann function, you should multiply the original value, so a variation like `w[n] *= 0.5 - 0.5*Math.cos((2*Math.PI*n)/(w.length - 1));` might work (assuming Java has the combined multiply-and-assign operator `*=`) – Neil Slater Jan 30 '15 at 07:31
  • @Neli thanks alot...it works fine..both you and @ Mikael was did a big help to me...:) – Hash_S Jan 30 '15 at 16:36