数据音频和背部。调制/解调源$ C ​​$ C [英] Data to audio and back. Modulation / demodulation with source code

查看:114
本文介绍了数据音频和背部。调制/解调源$ C ​​$ C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的二进制数据流,并希望将其转换为原始波形声音数据,我可以发送到扬声器。

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

这是老派的调制解调器做才能通过电话线(生产典型modemish音)来传输二进制数据是什么。它被称为调制。

This is what the old school modems did in order to transfer binary data over the phone line (producing the typical modemish sound). It is called modulation.

然后,我需要一个相反的过程 - 从原始波形样本,我要得到确切的二进制数据。这就是所谓的解调

Then I need a reverse process - from the raw waveform samples, I want to obtain the exact binary data. This is called demodulation.

我发现一个特别的方式来做到这一点 - 频移键控。问题是我无法找到任何来源$ C ​​$ C。

I found one particular way to do this - Frequency shift keying. The problem is I can't find any source code.

您可以点我FSK任何语言的实现?或者提供任何替代编码二进制LT;? - >声音源提供code

Can you point me to an implementation of FSK in any language? Or offer any alternative encoding binary<->sound with available source code?

感谢您!

推荐答案

最简单的调制方案将调幅(技术上为数字领域,这将被称为幅移键控)。以一个固定频率(比方说10KHZ),你的载波,并使用位的二进制数据,将其打开和关闭。如果您的数据速率为每秒10位,你会打开和关闭以该速率切换的10KHz的信号。解调将是一个(可选)10KHz的滤波器接着用阈值进行比较。这是一个相当简单的方案来实现。通常较高信号频率和可用的带宽,更快可以切换该信号开启和关闭。

The simplest modulation scheme would be amplitude modulation (technically for the digital realm this would be called Amplitude Shift Keying). Take a fixed frequency (let's say 10Khz), your "carrier wave", and use the bits in your binary data to turn it on and off. If your data rate is 10 bits per second you will be toggling the 10KHz signal on and off at that rate. The demodulation would be an (optional) 10KHz filter followed by comparing with a threshold. This is a fairly simple scheme to implement. Generally the higher the signal frequency and your available bandwidth, the faster you can switch that signal on and off.

有一个非常酷的/有趣的应用程序在这里将是EN code /德code摩尔斯电code,看看你能走多快。

A very cool/fun application here would be to encode/decode as morse code and see how fast you can go.

FSK,两个频率之间移位是带宽更有效和更不受噪声反而会使解调器更为复杂,因为需要在两个频率之间进行区分。

FSK, shifting between two frequencies is more efficient in bandwidth and more immune to noise but will make the demodulator more complex as you need to distinguish between the two frequencies.

高级调制方案相移键控的善于获得最高的比特率对于一个给定的带宽和信噪比但他们更复杂实现。模拟电话调制解调器需要处理一定的带宽(如低至3千赫)和噪声的限制。如果你需要得到尽可能高的比特率定带宽和噪声限制然后是要走的路。

Advanced modulation scheme such as Phase Shift Keying are good at getting the highest bit rate for a given bandwidth and signal to noise ratio but they are more complicated to implement. Analog phone modems needed to deal with certain bandwidth (e.g. as little as 3Khz) and noise limitations. If you need to get the highest possible bitrate given bandwidth and noise limitations then is the way to go.

有关高级调制方案的实际code样品我将调查从DSP供应商应用笔记(如<一个href="http://focus.ti.com/dsp/docs/dsphome.tsp?sectionId=46&DCMP=TIHomeTracking&HQS=Other+OT+home_p_dsp">TI和 ADI公司)的那些是对DSP常见的应用。

For actual code samples of advanced modulation schemes I would investigate application notes from DSP vendors (such as TI and Analog Devices) as those were common applications for DSPs.

实现一个π/ 4移位D-QPSK基带调制解调器使用TMS320C50

QPSK调制器

V.34发射器和接收器实现对TMS320C50 DSP

另一个非常简单和不那么有效的方法是使用DTMF。这些是通过电话的键盘,其中每个符号的两个频率的组合所产生的音调。如果谷歌,你会发现很多的来源$ C ​​$ C。根据您的应用程序/要求,这可能是一个简单的解决方案。

Another very simple and not so efficient method is to use DTMF. Those are the tones generated by phone keypads where each symbol is a combination of two frequencies. If you Google you'll find a lot of source code. Depending on your application/requirements this may be a simple solution.

让我们深入到一些简单的计划实施细节,像莫尔斯code我前面提到的。我们可以用点为0和划线为1。像计划莫尔斯的一个优点是,它也解决了框架问题,因为你可以每一个空间后重新同步采样。为了简单起见,让我们挑载波频率在11KHZ和假设你的波输出为44KHZ,16位,单声道。我们还将用的方波,这将创造谐波但我们真的不介意。如果11KHZ超出你的麦克风的频率响应,然后就除以所有频率由2例如,我们会挑选一些任意的水平10000等我们的波形看起来是这样的:

Let's dive in to some simple scheme implementation details, something like the morse code I mentioned earlier. We can use "dot" for 0 and "dash' for 1. An advantage of a morse like scheme is that it also solves the framing problem as you can resynchronize your sampling after every space. For simplicity let's pick the "Carrier Wave" frequency at 11KHz and assume your wave output is 44Khz, 16 bit, mono. We'll also use a square wave which will create harmonics but we don't really care. If 11KHz is beyond your microphone's frequency response then just divide all frequencies by 2 e.g. We'll pick some arbitrary level 10000 and so our "on" waveform looks like this:

{10000, 10000, 0, 0, 10000, 10000, 0, 0, 10000, 0, 0, ...} // 4 samples = 11Khz period

和我们的关的波形仅仅是全部为零。我离开这个部分的编码作为练习吧读者。

and our "off" waveform is just all zeros. I leave the coding of this part as an excersize to the reader.

所以,我们碰到这样的:

And so we have something like:

const int dot_samples = 400; // ~10ms - speed up later
const int space_samples = 400; // ~10ms
const int dash_samples = 800; // ~20ms

void encode( uint8_t* source, int length, int16_t* target ) // assumes enough room in target
{
  for(int i=0; i<length; i++)
  {
    for(int j=0; j<8; j++)
    {
      if((source[i]>>j) & 1) // If data bit is 1 we'll encode a dot
      {
        generate_on(&target, dash_samples); // Generate ON wave for n samples and update target ptr
      }
      else // otherwise a dash
      {
        generate_on(&target, dot_samples); // Generate ON wave for n samples and update target ptr
      }
      generate_off(&target, space_samples); // Generate zeros
    } 
  }
}

本德codeR是一个比较复杂的,但这里有一个轮廓:

The decoder is a bit more complicated but here's an outline:

  1. 任选的带通滤波器所采样的周围11KHZ信号。这将提高在嘈杂enviornment性能。 FIR滤波器是pretty的简单,有几个在线设计小程序,将产生的过滤器为你。
  2. 阈值的信号。 1/2以上最大振幅每个值低于1的每个值是0。这里假设你已经取样的整个信号。如果这是真实的时候,你要么选择一个固定的阈值或做,你跟踪了一段时间的最大信号电平的某种自动增益控制。
  3. 扫描点或划线的开始。你可能想看到你的点周期至少一定数量的1的考虑采样点。然后继续扫描,看看这是一个破折号。不要指望一个完美的信号 - 你会看到几个0的在你1的中间,几个1在您的0年代中期。如果有噪音小,然后区分了上,从关时间段应该是相当容易。
  4. 然后逆转上述过程。如果你看到仪表板推1位到你的缓冲区,如果一个点按一个零。

这篇关于数据音频和背部。调制/解调源$ C ​​$ C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆