2

I am trying to record a race bike's sound and analyse the recorded audio with FFT and find the engines frequency. If i only whistle, everything works fine, i can see a clear graph which corresponds to my whistling low and high and so on. I create a heatmap with different colors for the different amplitudes i get from the FFT for frequency vs time. The Audio gets recorded like this:

private class RecordAudio extends AsyncTask<Void, float[], Void> {
        @Override
        protected Void doInBackground(Void... params) {
            try {
            int bufferSize = AudioRecord.getMinBufferSize(sampleRateMain,
                    channelConfiguration, audioEncoding);
            AudioRecord audioRecord = new AudioRecord(
                    MediaRecorder.AudioSource.DEFAULT, sampleRateMain,
                    channelConfiguration, audioEncoding, bufferSize);
            short[] buffer = new short[blockSize];
            audioRecord.startRecording();
            float[] audioData = new float[blockSize];
            try{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
            String currentDateandTime = sdf.format(new Date());

            BufferedWriter writer;
            String pathtemp = Environment.getExternalStorageDirectory().getAbsolutePath();
            String filename ="/"+currentDateandTime;
            path = pathtemp +filename;
            writer = new BufferedWriter (new FileWriter(path,false));
            int i2=0;
            while (started) {   
                if(i2==10){                 
                    datastructures tempdata = new datastructures();
                    i2=0;
                    audioRecord.read(buffer, 0, blockSize);         
                    float sum = 0;
                    for (int i = 0; i < blockSize; i++) {
                        audioData[i] = (float) ( buffer[i]);
                        writer.write(audioData[i]+" ");
                            if (audioData[i] <= 0) {
                                audioData[i] = audioData[i] * (-1);
                            }
                            sum = sum + audioData[i];
                    }   
                    writer.newLine();
                    tempdata.freqsum = sum;
                    mainData.add(tempdata);
                }
                i2++;                   
            }
            writer.close();
            }
            catch(IOException e){
                e.printStackTrace();
            }               
            audioRecord.stop();         
        } catch (Throwable t) {
            Log.e(TAG, "Audio recording Failed");
        }
        return null; 
    }
}

So i am storing the audiodata on the sd-card. To reduce the data i loop through i2 and only record once in i2=0...10; In the next part of the app i let the user cut out a part of the audiodata and load only this part in a vector called trimmed. I then do a FFT of those frequencies. But it seems like there is only overdrive in the data.

Is it possible to trigger the automatic gain for the microphone while recording ?

How would i load the recorded and saved audiodata into Audacity ? (I tried different import setting for raw data but it doesnt seem to work) Here is an example file

I implemented a butterworth filter, if i got this right the filter should be applied before the FFT ?

user1222353
  • 55
  • 1
  • 10
  • Just an idea, would it be enough to trigger audiorecord.start audiorecord.stop in the while(started) loop to get the gain from the mic ? Without trying i think this would result in speed issues. – user1222353 May 03 '12 at 08:43
  • answering my comment: its too slow, unfortunatly – user1222353 May 03 '12 at 09:08

1 Answers1

0

I can't answer your mic gain issue, but as for your filters question: It depends on how you realized your filter. A Butterworth filter would normally be realized as an IIR (infinite impulse response, i.e. the output of the filter depends on the previous outputs) filter via the Z-transform (recurrence relation). If you realized the filter this way, then you should apply the filter to the time domain samples before taking the FFT.

If you need a filter, and you are taking the FFT anyways, you're probably better off implementing an FIR filter via convolution and the Convolution theorem instead of using a butterworth or other s/z domain filters.

dsharlet
  • 1,036
  • 1
  • 8
  • 15