0

if I record a series of frequencies beeps into a buffer, for example:

15kHz for 50ms, 17k for 50 ms and goes on, is there any way to "go" along the time plain and to decode this freqs(with goertzel or something)?

Hey, this is an update, I've added a code that shows how I find the first delimiter in the sound buffer that I check. If I record 5 seconds of a buffer(I record into a stream buffer and not a file) The first snippet takes something like 30 seconds to analyze the index where the start delimiter starts at. I thinks it is very newbie...must find a better solution. thanks (every delimiter is 0.2 seconds duration) and it's like that - Start delimiter = 12KHz, 1's = 13k, 0's = 14k, End delimiter = 15k

        double max_power = 0;
        int max_power_index = 0;
        double DelimiterSamplesCount = SampleRate * DelimiterTime;
        float[] samples32array = samples32.ToArray();

        //Searching For Delimiter
        for (int i = 0; i < (samples32array.Length); i++) //Delimiter Samples Length = SampleRate*DelimiterTimeLength,( i.e: 44100*0.2=8820 samples)
        {
            if ((i + (int)DelimiterSamplesCount - 1) > samples32array.Length) break;
            double power = Goertzel.GoertzelFilter(samples32array, StartDelimiterFreq, i, i + (int)DelimiterSamplesCount - 1);
            if(power > max_power)
            {
                max_power = power;
                max_power_index = i;
            }
        }

My Goertzel is like that:

public static double GoertzelFilter(float[] samples, double freq, int     start, int end)
    {
        double sPrev = 0.0;
        double sPrev2 = 0.0;
        int i;
        double normalizedfreq = freq / 44100;
        double coeff = 2 * Math.Cos(2 * Math.PI * normalizedfreq);
        for (i = start; i < end; i++)
        {
            double s = samples[i] + coeff * sPrev - sPrev2;
            sPrev2 = sPrev;
            sPrev = s;
        }
        double power = sPrev2 * sPrev2 + sPrev * sPrev - coeff * sPrev * sPrev2;
        return power;
    }
axcelenator
  • 1,497
  • 3
  • 18
  • 42

1 Answers1

1

If you know the set of frequencies and the durations, then a set of sliding Goertzel filters is a good start to building a simple demodulator. Comparing and scanning for for a peak difference between these filters is a better decision criteria than just checking for a certain magnitude output.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Do you have some examples to how do that? because I'm absoloutely a beginner. I just understand that goertzel can detect a specific frequency. but is there any efficient way to search inside the buffer? – axcelenator May 10 '15 at 14:27
  • Google "sliding Goertzel". Dozens of results, some with pseudo-code. For efficiency, you could try one of many gradient maxima search algorithms instead of sliding the filter. But on a mobile processor, sliding the filter window should work just fine, and is a lot simpler. – hotpaw2 May 10 '15 at 16:03
  • Hello, I made a sliding Goertzel implementation in my app(now it's no more windows phone 8, it's wpf for PC) and I have a stream of audio which is something like 5 seconds long - when I slide the Goertzel it takes something like 25 seconds to find a specific frequency in the stream. I didnt find something efficient – axcelenator May 21 '15 at 17:58
  • Since a Goertzel filter only requires a few multiplies and adds (and one more subtract while sliding) per audio sample, 5 seconds of audio samples at 44.1k/s on a roughly GHz Windows Phone ARM CPU should take a few milliseconds to process, not seconds. Even faster on a typical PC. – hotpaw2 May 21 '15 at 18:10
  • Hello, I have added some codes that show my way to decode the delimiter. Would you like to help me? I'm very new to this with no much knowledge of efficient programming... – axcelenator May 22 '15 at 09:39
  • Your posted code is repeated using plain Goertzel filters, not a single sliding Goertzel. That O(N*N) instead of O(N), plus redundantly recomputing the filter coefficient every sample. – hotpaw2 May 22 '15 at 11:34
  • Hello hotpaw2, I changed some of my code. But I saw that as my freq is growing the returned magnitude of the Goertzel is smaller. How can I detect the threshold in that manner? – axcelenator Jun 01 '15 at 08:28