2

The project I'm working on poses a curious technical challenge.

A digital device needs to transmit data to the iPhone via the microphone jack socket.

I need to code an interface from both the microcontroller and from the iPhone end.

Is there any established protocol for this particular problem? I don't have the luxury of twin clock and data line (ala PS/2 protocol https://en.wikipedia.org/wiki/PS/2_connector ).

I am aware of F2F ( https://en.wikipedia.org/wiki/Biphase_mark_code ) but this is a royal PITA to decode.

There is also an issue of optimising bandwidth (to some sensible balance between efficiency and algorithmic complexity). The iPhone samples at 44.1 kHz; in theory each sample could transmit at least one bit depending on whether it is high or low (ie which side of zero -- theoretically of course each sample is 16 bits but trying to really optimise bandwidth to a theoretical maximum would be... what is the word... mad?), realistically I might need to use 3 sample lengths for each bit just to make sure everything gets received and a bit doesn't fall between 2 consecutive samples.

Is there some open source code I can lift to do this? I would imagine software engineers have been cracking this problem since the early days of digital. I don't really want to reinvent the wheel here.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
P i
  • 29,020
  • 36
  • 159
  • 267

3 Answers3

3

Your theoretical data rate will be limited by synchronization overhead, various types of distortion plus the signal to noise ratio. Otherwise something close to 16*44100 bps would be possible.

More realistically you might want to search for some ham radio RTTY or PSK source code as those protocols are known to work somewhat over audio width channels with noise.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
2

From my understanding of and experience with modems, achieving efficiency (as in, decent data rate with acceptable BER) and having low algorithmic complexity/cost is nothing more than a pipe dream.

Here are a few things that you're going to face in one way or another when transmitting data:

  • The channel (e.g. room) noise. It will distort the signal and contribute to decoding errors. Information encoded with amplitude modulation is the most affected here.
  • Multiple signal paths. The receiver (microphone) will pick up signal reflections from objects in the room. The signal will further degrade.
  • Changing communication channel/signal paths. If the devices aren't stationary and/or other things move around in the room, the signal will be changing its properties over time and will be further hard to decode (at times, impossible).
  • The oscillators used in the transmitter and receiver are going to work at slightly different rates. What's more, their frequencies are going to fluctuate over time. This necessitates additional synchronization at high data rates/long data packets.
  • Distortions, especially non-linear, in the hardware and software, especially on the iPhone's side, seriously hampering any high-speed data communication over its audio channel. iPhone was not designed to function as a modem and did not have to meet all the typical requirements for a modem. You may encounter that the microphone is very non-linear and its frequency range is quite narrow, that from time to time audio samples get lost or appear out of thin air, that there are noticeable gaps in the audio between blocks of sent or received samples, etc etc.

I personally recommend looking into implementing something extremely simple and low-speed. Implement a 2-FSK modem similar to that described in the ITU-T recommendations V.21 and V.23. Use one frequency to transmit 0's and another to transmit 1's.

First get it to work at rates not more than 1200 bits/second in software before integrating into the devices. Get it to fully work in software with added white noise and when the encoder's and decoder's sample rates are somewhat different (hint: you'll need a sample rate converter here, but some audio editors are able to resample wave files and you can do that by hand).

Unless the iPhone is terribly screwed up, you should be able to implement a modem on it, but it's not an easy task and I don't think you can find any code online that you can take as-is and almost instantaneously make work.

Btw, it may be a good idea to ask this question at dsp.stackexchange.com.

EDIT: See my answer to a different question and code in it. Though not spectacularly fast, a simple V.23-like 1200 bits/second modem might work here. With some tweaks it can be made to support higher data rates. The FSK transmitter code is simple enough to port to a microcontroller.

Community
  • 1
  • 1
Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
1

AFAIK, similar approach is used in applications which decode signals from IR receiver by using microphone. Anyway, if there is a DAC on the microcontroller site, you can easily form impulses that can be decoded by such software. You can look at WinLIRC: http://winlirc.sourceforge.net/audioreciever.html .

Volodymyr Rudyi
  • 638
  • 11
  • 25