# How do I decode(demodulation) and get original data from audio sample data

Here I'm talking about the less-than-ideal situations, in other words, the audio sample data may have burrs or error bits in it.

Encode and decode theory: I am using FSK to encode my original binary data (0,1 and lead-byte), and transform the square wave it generated to sine wave. Then I generate a stream of audio samples through mic (for example, a stream of 44100 16-bit integers for every second etc.). When I decode (c language), the key factor is, 0:1:lead-byte = 1:2:4(or other ratio).

For example:

original binary data: 0|1...0|1.

encoded wave data: lead-byte...lead-byte 0|1...0|1 lead-byte.

The typical ideal samples and bad samples waveform are as below. good wave

Now my decode method is simple (just count the samples up and below zero, and get stable lead-byte width first, then use 1:2:4 to calculate 0 and 1's width). Should I use more complex mathematical analysis in decoding? If so, what theory can I use, Fourier? Gaussian Noise? Rayleigh Fading? Goertzel algorithm?

I have to point out that I am totally new in audio stuff. Any help would be much appreciated!

• Currently, I'm decoding with Zero Crossing method in software. It works fine as long as the waveform is good (like the first waveform shown above). But the problem is, there are so many android smartphones and not all of them can generate waveform like that. What demodulation methods can I use in software decoding besides Zero Crossing so that I can get those bad waveform (consider bad wave 1 above) decoded correctly? – SevenWow Nov 16 '15 at 3:30
• Some 2-FSK modem examples from Texas Instruments: 1, 2. – Alexey Frunze Nov 16 '15 at 11:33