通过激光传输 Python 音频
我目前正在从事一个到目前为止相对容易的项目。底层项目是使用音频转换通过激光传输数据/消息。 简而言之,目前的过程是这样的
- 用户输入一条消息
- 消息被转换为二进制
- 对于二进制消息中的每个 1 和 0,它会播放相应的信号音,在我的例子中,1 和 450 hz 分别为 250hz对于 0。
- 传出的音调通过立体声电缆发送到安装有激光器的音频变压器
- 太阳能电池板充当麦克风并将传入的“声音”记录为文件
- 它们播放文件并读取音调并尝试将每个 250 和 450 Hz 与 1 或 0 匹配(这就是我的问题所在)。
在声音的实际处理良好之前,我当前的问题如下。
我将每个音调播放 x 次,在接收端将其记录 y 次,对 y 时间进行多次采样,然后逐个样本进行分析,然后记录每个频率。这是低效且不准确的。无论我何时播放音调,我都会遇到很多问题,因为它经常听到两次音调或根本听不到它,这完全打乱了整个消息。
我试图将采样速率与每个音调播放的时间相匹配,但除非相应地对齐,否则它不起作用。我只对“test”和“hi”等消息进行了几次成功的测试。我已经研究过 bpsk 和 fsk,但我感觉好像我已经在做类似的事情了,但我的接收端很差,无法破译这一切。
这一切都是用 Python 编写的,我将非常感谢您提供的任何提示、建议或可能的实现。另外,对于音调发射,我使用pyaudiere
,对于录音,我使用pyaudio
。
谢谢!
-史蒂夫
I'm currently working on a project that has been relatively easy, up until now. The underlying project is to transmit data/messages over lasers using audio transformation.
In a nutshell the process is currently like this
- The user enters a message
- Message is turned into binary
- For each 1 and 0 in the binary message, it plays a corresponding tone to signal which is which, in my case 250hz for a 1 and 450 hz for a 0.
- The outgoing tone is sent over a stereo cable to an audio transformer rigged to a laser
- A solar panel acts as a microphone and records the incoming "sound" as a file
- It them plays the file back and reads off the tones and tries to match each 250 and 450 hz to a 1 or 0 (which is where my issue lies).
Up until the actual processing of the sound is fine, my current issue is the following.
I play the tones each for x time, on the receiving end it is recorded for y time, y time is cut sampled many times and then analyzed sample by sample which then logs each frequency. This is inefficient and inaccurate. I have had many issues regardless of the time I play the tones for it often hears a tone twice or doesn't hear it at all, which completely throws off whole messages.
I have tried to match the rate at which it samples with the time each tone plays, but unless aligned accordingly it does not work. I've only had a few successful tests for messages like 'test' and 'hi'. I have already looked into bpsk and fsk, but I feel as if I'm already doing something like it but that I have a bad receiving end to decipher it all.
This is all written in Python and I'd be very grateful for any tips, suggestions, or possible implementations that you can provide. Also for tone emission I'm using pyaudiere
and for recording I'm using pyaudio
.
Thanks!
-Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这听起来像是硬件问题。我很确定这是 FSK 的工作。大多数现代 FSK 型系统使用 PLL(锁相环芯片)进行实际检测。频率转电压或频率转电流电路也是可用的。
我在许多业余爱好者书籍、数据表和网站上看到了实用电路。以下是一些:
用于解调 FSK 信号的电路
PLL 教程
我希望这对您来说不仅仅是又一次掉入兔子洞的旅程 - 祝您好运!
This sounds like a hardware problem. I'm pretty sure it is a job for FSK. Most modern FSK-type systems use PLLs (Phase-Locking Loop chips) for the actual detection. Frequency-to-Voltage or Frequency-to-current circuits are also usable.
I've seen practical circuits in dozens of hobbyist books and in data sheets and on websites. Here are a few:
Circuit for demodulating an FSK signal
PLL Tutorial
I hope this isn't just another trip down the rabbit hole for you -- good luck!
您是否通过聆听声音文件(发送和接收)或使用音频编辑器查看波形来进行完整性检查,看看它们听起来或看起来是否大致相同?这样您就可以将问题范围缩小到通道引起的错误与软件分析的关系。
您的解码/解调软件将需要一种同步方法,该方法可以确定并跟踪音频信号从一个调制频率变为另一个调制频率的时间,然后您将需要单独测试该同步方法的偏移误差。
Did you do a sanity check by listening to the sound files (both transmit and receive), or viewing the waveforms with an audio editor, to see if they roughly sound or look the same? That way you can narrow down the problem to channel induced errors versus your software analysis.
Your decoding/demodulation software will need a synchronization method that can determine and track the times that the audio signal changes from one frequency of modulation to another, then you will need to separately test this synchronization method for offset errors.
我会使用两个 FIR 滤波器来处理接收端,每个滤波器对应您要检测的每个频率。滤波器的系数只是您正在寻找的信号的副本(即,一种情况下为 250Hz,另一种情况下为 450Hz)。您必须查看太阳能电池板的输出来确定它是方波、正弦波还是介于两者之间的波。过滤器的长度对应于音调的持续时间(即问题中的“x”)。样品被并行送入两个过滤器。
每个滤波器的输出都需要进行整流(即取绝对值)和平滑。可以使用大约一半 x 的时间段内的简单移动平均值来完成平滑(您可以尝试找到最佳值)。然后,如果您比较平滑值(即 a>b,或 b>a),您应该得到 0 和 1 的流。
需要注意的事项:这假设通道对于两个频率的行为相同(即您获得相似的信噪比和衰减)。您可能需要稍微调整频率,因为 450Hz 非常接近 500Hz,500Hz 是 250Hz 的谐波。
I would tackle the receiving end using two FIR filters, one for each frequency that you are trying to detect. The coefficients of the filters are just a copy of the signal you are looking for (i.e. 250Hz in one case and 450Hz in the other). You would have to look at the output of your solar panel to decide whether that is a square wave, sine wave, or something in between. The length of the filter corresponds to the duration of the tone (i.e. 'x' in your question). The samples are fed into both filters in parallel.
The output of each filter needs to be rectified (i.e. take the absolute value) and smoothed. The smoothing can be done using a simple moving average over a period of about half x (you can experiment to find the best value). Then if you compare the smoothed values (i.e. is a>b, or b>a) you should get a stream of 0's and 1's.
Things to be aware of: This assumes the channel behaves the same for both frequencies (i.e. you get similar snr and attenuation). You might need to tweak your frequencies a bit because 450Hz is quite close to 500Hz which is a harmonic of 250Hz.
使用自时钟信号表示,例如曼彻斯特代码。这样,您的时机只需“足够好”,并且您主要担心的是检测频率的变化(在这种情况下)。在链接的文章中,高电平和低电平指的是电压,但没有理由必须如此。您可以轻松地使用高频和低频,或打开/关闭单个激光。
Use a self-clocking signal representation such as Manchester code. That way your timing only has to be "good enough", and you primarily worry about detecting the change, in this case, of frequency. In the linked article the high and low levels refer to voltage, but there is no reason they have to. You can just as easily use a high and low frequency, or turning a single laser on/off.