15

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.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Gaucho
  • 1,298
  • 1
  • 17
  • 32
  • 2
    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 Apr 21 '15 at 17:13
  • 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 Apr 21 '15 at 17:17
  • 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 Apr 21 '15 at 17:20
  • @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 Apr 21 '15 at 17:23
  • and thank you for your help – Gaucho Apr 21 '15 at 17:23
  • @ChrisStratton : i added a screenshot to my question. – Gaucho Apr 21 '15 at 17:34
  • That looks more like unintentional coupling than an actual electrical connection to a signal with distortion. Are you sure you headset jack is good, connected, and on that channel vs the other ear? What are the respective input and output amplitudes? Try a higher frequency. Is your scope probe good? Did you connect the ground? – Chris Stratton Apr 21 '15 at 17:36
  • @ChrisStratton I restored the smartphone to factory default and the problem is still present. I'm sure 100% about the cable, the connectors, the oscilloscope, because changing the smartphone all appears perfect. It's incredible that, generating a sine, the output waveform is perfect while generating a square waveform the output is distorted. The uploaded snapshot is not very goot because it was made with my app and not with the wav file. With the wav file the output is different, even if it is always distorted. I will upload it. – Gaucho Apr 22 '15 at 11:48
  • The last doubt: after restoring the smartphone to "factory default" i found that the smartphone is still rooted, and this let me think that the restored operative system is not the original one. I wish to try to remove the root. may be that the restore to factory default doesn't overwrite the operative system with a virgin one. – Gaucho Apr 22 '15 at 11:48
  • @ChrisStratton i updated the question with new performed tests. These are more clear, I suppose it will be easy to find a solution. – Gaucho Apr 22 '15 at 19:04
  • It almost looks as though the audio input you're recording this with has automatic gain control - on the first graph in particular, you can it initially overshoot, then undershoot, then converge. – marko Apr 22 '15 at 22:17
  • @marko yes but that effect is really minor. Since the notebook never changes, that effect is common. The problem that i'm focused on, is a problem of the android device. And I suppose it's a software problem because it is present also passing through bluetooth. Do you agree with me? – Gaucho Apr 23 '15 at 09:32
  • Ok, now I understand. You created a WAV file of a 500Hz square wave. What was the sampling rate used? (Did @ChrisStratton already ask that?). Can you post a link to the source wav file? – Michael Levy Apr 26 '15 at 19:19
  • it's 44100 Hz file. i tried also with an application named "signal generator" installed on both phones, the result doesn't change. i think there is a audio processing library on my android 4.2.2 and may be that i just need to find the way to disable it. – Gaucho Apr 26 '15 at 19:28
  • 1
    I generated it with this website: http://www.audiocheck.net/audiofrequencysignalgenerator_squaretone.php – Gaucho Apr 26 '15 at 19:30

1 Answers1

3

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.

Community
  • 1
  • 1
Michael Levy
  • 12,767
  • 15
  • 60
  • 98
  • Michael, thank you very much, i didn't know there was such possibilities, even if, now that you told me, it's obvious that it is possible. Anyway it is a requirement to use square waveform, and your answer doesn't fit my request. To know what I am trying to do, read this: http://stackoverflow.com/questions/29715866/android-ppm-audio-library – Gaucho Apr 26 '15 at 18:38
  • anyway, don't you think there is some software component generating the problem? why data sent over bluetooth is not the original square waveform? the problem is not present on apple devices and on nexus5. this evening I will try also on the samsung phone of my girlfriend. – Gaucho Apr 26 '15 at 18:39
  • 1
    Keep in mind that human hearing is limited to frequencies of about 20Khz. Audio systems are typically not designed to reproduce signals much above this range (there is no need because humans cannot hear it anyway). Square waves have harmonics (or high frequency components) that go way beyond 20KHz. A squarewave includes frequency components that go way beyond human hearing and beyond the capabilities of audio systems. See http://mathworld.wolfram.com/FourierSeriesSquareWave.html. An audio system is just not designed to recreate those signals, and should not be expected to. – Michael Levy Apr 26 '15 at 18:42
  • Is this a school assignment? Read the article about PPM. It says "It is primarily useful for optical communications systems". Optical communications, optical systems are often digital/binary so this is a good match for optical systems. – Michael Levy Apr 26 '15 at 18:47
  • I still don't see why it must be a square wave. Implement PPM using audio, but send the signalling bit as a human audible tone. PPM seems to be about the position of the signal in the synchronization frame. Why can't the signal be an audible tone instead of a square wave? – Michael Levy Apr 26 '15 at 18:48
  • 1
    I do not agree with you. Take a square waveform at 500Hz, pass it through a passband filter, cutting all the frequencyes under 50/100Hz and all the frequencies over 10/20 kHz. then look at the result in the time domain. You will see again a square waveform but with a little bit rounded corners. The fact you are talking about is really small in this case. In fact, look how good is the iphone audio output shown on my question (and also the most of the phones, try also yours) . – Gaucho Apr 26 '15 at 18:50
  • PPM is used on radiocontrols for airplanes and rovers. it is also used to control motors (with PPM decoder). It needs square wave. look at the linked image, cause the PPM uses pulses length, so it can not use modulated signals as you suggest : http://www.aerodesign.de/peter/2000/PCM/frame_ppm.gif – Gaucho Apr 26 '15 at 18:54
  • wow. thank you very much. I voted you up, can't do more. i will write on that forum. Anyway I understood since a week that my android code is probably correct. It's just that my phone is not working fine. My idea is better cause you don't need a pc but just a smartphone to control your drone (apart the transmitter). – Gaucho Apr 26 '15 at 19:03
  • 2
    This is interesting. It might be helpful, not sure - http://www.andrewhazelden.com/blog/2011/08/analyzing-rc-radio-ppm-signals/ – Michael Levy Apr 26 '15 at 19:06
  • i wrote on that forum my help request. thank you also for the last link: i know how PPM works cause I also analyed it with oscilloscope like it is shown on the link. – Gaucho Apr 26 '15 at 19:11
  • One more link that seems rather interesting. Sounds like you know all this already, but others may not - http://www.epanorama.net/newepa/2014/09/15/android-device-external-mic-wiring/ – Michael Levy Apr 26 '15 at 19:38
  • 2
    This post is neither an answer, nor correct in its claims as to how an audio system would treat a 500Hz square wave. – Chris Stratton Apr 26 '15 at 23:53