Android - demod FSK using goertzel

好久不见. 提交于 2019-12-12 03:59:04

问题


I am using this code https://stackoverflow.com/questions/23432398/audio-recorder-in-android-process-the-audio-bytes to capture the mic audio but I am writing the data to a ByteArrayOutputStream. After I finish the record I want to demodule the signal captured by using Goertzel Algorithm. The FSK signal consists out of 2 frequencies, 800Hz for '1' and 400Hz for '0' each bit is moduled using 100 samples. I am using this class of Goertzel: http://courses.cs.washington.edu/courses/cse477/projectwebs04sp/cse477m/code/public/Goertzel.java I am trying to use a bin size of 150.

Here is what I try to do: the code, after I finish the recording:

private void stopRecording()
{
    if(recorder != null)
    {
        isRecording= false;
        recorder.stop();
        recorder.release();
        recorder = null;
        recordingThread = null;

        int BlockSize = 150;
        float HighToneFrequency = 800;
        float LowToneFrequency = 400;
        byte[] byteArrayData = ByteArrayAudioData.toByteArray();

        /*final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
        8000, AudioFormat.CHANNEL_OUT_MONO,
        AudioFormat.ENCODING_PCM_16BIT, byteArrayData.length,
        AudioTrack.MODE_STATIC);
        audioTrack.write(byteArrayData, 0, byteArrayData.length);

        audioTrack.play();*/

        double[] daOriginalSine = convertSample2Sine(byteArrayData);

        int i = 0;

        while(i < daOriginalSine.length)
        {
             double t1 = testSpecificFrequency(i, HighToneFrequency,BlockSize, daOriginalSine);
             double t2 = testSpecificFrequency(i, LowToneFrequency,BlockSize, daOriginalSine);
             i+=BlockSize;
        }



    }

}

And the function testSpecificFrequency:

private double testSpecificFrequency(int startIndex, float ToneFreq, int BlockSize, double[] sample) 
    {
         Goertzel g = new Goertzel(RECORDER_SAMPLERATE, ToneFreq, BlockSize, false);
         g.initGoertzel();
         for(int j=startIndex ; j<startIndex+BlockSize ; j++)
         {
             g.processSample(sample[j]);
         }

         double res= Math.sqrt(g.getMagnitudeSquared());
         return res;
    }

I just tried to see what will be the results, by sending 800Hz to the constructor and afterwars sending 400Hz,don't really know how to proceed from this point =\

Any ideas?

来源:https://stackoverflow.com/questions/29049981/android-demod-fsk-using-goertzel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!