Python Audio Transfer Through Lasers
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
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.
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.
精彩评论