15
votes

I found that my smartphone (android 4.2.2) is not able to generate square waveforms (i need it to use the audio output as serial line for data transfer). At beginning i supposed it was my application, but then i made many significant tests. These are latest tests. I hope you can find an explanation for the phenomenon.

I generated a wav file with a square waveform at 500Hz inside it. I play the wav file on a android phone and on a apple iphone. I recorded and analyzed the signal with my notebook (the audio cable connected to the notebook audio input).

Then i repeated the tests with the audio cable connected between a bluetooth transceiver device and the notebook audio input. And the smartphones connected via bluetooth (one at time) to the bluetooth transceiver device.

NOTE: the bluetooth transceiver device is a device that receives audio data via bluetooth and gives a audio output with a standard audio jack.

This is the signal generated by the iphone directly connected on the audio jack: iphone directly connected on the audio jack

This is the signal generated by the bluetooth device receiving data from the iphone: signal generated by the bluetooth device receiving data from the iphone

This is the signal generated by the android device directly connected with the audio jack: android device directly connected with the audio jack

This is the signal generated by the bluetooth device receiving data from the android smartphone:

bluetooth device receiving data from the android smartphone

Analisys:

-The bluetooth device introduces a cut to the bandwidth of the signal (it seems to me acceptable).

-The iphone has really good analog part (it outputs a very good square waveform)

-The android device has really bad analog part (even if it is perfect for music play)

-the data sent by the android phone to the bluetooth device is not correct, in fact the aquired signal is different than the one aquired with data coming from iphone.

I restored the smartphone to factory default but the problem was not solved. I also tried to install kitkat custom rom but the problem is still there. I also tried with a Nexus 5 (android 5) and samsung S4 mini (android 4.2.2 like mine) and they acts like the iphone.

I suspect that the problem has to do with DTS studio sound (i tried disabiling it and setting it in different ways without success). the DTS seems to be the only software difference between my phone and the samsung s4 mini.

QUESTION: I can understand that the analog side of my android device is not good as the iphone, i could also suppose that the analog part of my android device is broken... but i don't understand why i don't obtain the same result when i insert the bluetooth transceiver device.

1
There is most definitely filtering both lowpass and quite often highpass in series capacitors if nowhere else. There is also quite possibly all sorts of ugly processing such as sample rate conversion going on. But there could also be issues with your program, such as buffer underrun on some devices. To really diagnose please show pictures of the distorted output, at various frequencies, and covering multiple cycles of the square wave. How big is your buffer size? What does the minimum buffer size query return on the bad device? Including the generation and playback code would also be useful. - Chris Stratton
You can also try creating your signal as a .wav file on a PC with something like Audacity or a port of your program which writes samples to a file, verifying it plays back as desired there, and then trying to play that back on the Android device. That will help determine if it is an issue with the device's hardware or factory software, or one with your program. - Chris Stratton
hi @Cris Stratton, it is not important my app, because the problem is present also if i play a wav file from the default audio app (the one supplied with android). I'll try to supply a snapshot - Gaucho
@ChrisStratton read again my question, i did what you suggested with your second message. this is why i'm going crazy. i edited my question.. - Gaucho

1 Answers

3
votes

why are you using a square wave? Is this a requirement? Square waves make sense in digital systems, but as an analog signal it has all sorts of nasty characteristics (like infinite spectrum if I recall). Why not use two tones in the human audible range which the phone's audio systems is design for?

There are lots of signalling and modulation techniques used for sending data over analog or audio channels. Have you looked at any of the following?

How could you transfer data over an audio line?

Audio Modem: data over sound

Transfering data using audio signal in android

The third link describes using Frequency-shift keying in Android. This looks like a very good solution. The wikiepedia page for FSK includes the following comments on Audio FSK

Audio frequency-shift keying (AFSK) is a modulation technique by which digital data is represented by changes in the frequency (pitch) of an audio tone, yielding an encoded signal suitable for transmission via radio or telephone. Normally, the transmitted audio alternates between two tones: one, the "mark", represents a binary one; the other, the "space", represents a binary zero. ... AFSK has the advantage that encoded signals will pass through AC-coupled links, including most equipment originally designed to carry music or speech.