Data to audio and back. Modulation / demodulation with source code

前端 未结 2 1534
予麋鹿
予麋鹿 2021-01-30 04:56

I have a stream of binary data and want to convert it to raw waveform sound data, which I can send to the speakers.

This is what the old-school modems did in order to tr

2条回答
  •  臣服心动
    2021-01-30 05:14

    One purpose of modulation/demodulation is to adapt to channel characteristics. For instance, the channel might not be able to pass DC. Another purpose is to overcome a given amount and type of noise in the channel, while still transferring data above some given error rate.

    For FSK, you simply want routines than can generate sine waves at two different frequencies on the transmit end, and filter and detect two different frequencies on the receiving end. The length of each segment of sine waves, the separation in frequency, and the amplitude will depend on the data rate and amount of noise you need to overcome.

    In the simplest case, zero noise, simply produce N or 2N sine waves within successive fixed time frames. Something like:

    x[i] = amplitude * sin( i * 2 * pi * (data[j] ? 1.0 : 2.0) * freq) / sampleRate )
    

    On the receiving end, you can sample the signal at well above twice the max frequency and measure the distance between zero crossings, and see if you find an bunch of short period or long period waveforms. Much fancier methods using digital signal processing filters (IIR, FIR, etc.) and various statistic detectors can be used in the presence of non-zero noise.

提交回复
热议问题