Anda di halaman 1dari 2

!"#$%&' )*' +,'-.'"/% #"0 1),'"2)* 3+ 13."0 4" !


5 6.,731'
In oiuei to get the uistance between two phones, one methou is to let the phone
geneiate high fiequency tone anu the othei one uetect the signal stiength of the
sounu in the specific fiequency iange. In oui expeiiment we use two anuioiu
phones to geneiate high fiequency (>1SSuuBz) sounu anu get it so that its
fiequency anu stiength can be analyzeu.

8 9'"',#)' 13."0 4" 17'/4+4/ +,'-.'"/%
AuuioTiack class allows to stieam PCN auuio buffeis to the auuio haiuwaie foi
playback. So heie we use it to geneiate the high fiequency sounu. Accoiuing to the
theoiy of "Nyquist Fiequency" (Fmax = SampleRate 2), we use 441uuBz as the
sample iate so that latei we can have a banu fiom u to 22uSuBz.

: 9') 13."0 +,3; ;4/,37*3"'
AuuioRecoiu class iecoius uata fiom the auuio input haiuwaie. In oiuei to get
the coiiect uata, the sample iate foi iecoiuing shoulu be the same as that of input
// construct audio stream in 16bit format with sample rate of 44100Hz
int minSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC,
AudioFormat.ENCODING_PCM_16BIT, minSize,
//use formula to get the wave data in specific frequency (15500Hz)
void genTone(){
int angle = 0;
int increment = 2 * Math.PI * freqOfTone / sampleRate; // angular increment
for (int i = 0; i < sample.length; i++) {
sample[i] = Math.sin(angle) * Short.MAX_VALUE;
angle += increment;
track.write(sample, 0, sample.length); // write data to audio hardware; // play an AudioTrack
// construct AudioRecord to record audio from microphone with sample rate of 44100Hz
int minSize = AudioRecord.getMinBufferSize(sampleRate,AudioFormat.
AudioRecord audioInput = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate,
short[] buffer = new short[readSize];
audioInput.startRecording();, index, readSize); // record data from mic into buffer

< !"#$%&' )*' +,'-.'"/% #"0 1),'"2)* =% .14"2 >>?
The uata in the buffei fiom ieau() aie uigital signals of the sounu which is
sampleu eveiy 22us (- 1441uuBz). In oiuei to plot the fiequency spectium, we
neeu FFT (Fast Fouiiei Tiansfoim) to piocess the uata.
FFT is an effective algoiithm to conveit signals fiom time oi space uomain to the
fiequency uomain. The !"#$% of FFT is a complex vectoi anu we use the uata in the
buffei as its ieal pait anu u as its image pait. The &$%#$% of the algoiithm ietuins a
complex aiiay. Then we calculate the absolute value of the aiiay anu plot the
fiequency spectium with spectium bais, each of which contains the
magnituue(eneigy) of a fiequency iange. Say sample iate is 441uuBz anu the buffei
size is 4u96. Then a fiequency iange of 22uSuBz is equally split into 2u48 bais anu
each bai is 22uSu2u48 - 1u.77 Bz wiue which is also calleu '()*$)"+, ().&/$%!&".
In oiuei to get the stiength in uB unit, we can fiist calculate the sum of the uata
anu the sum of the squaieu values. Then use the foimula "(squaieusum-
sum*sumnumbei)numbei" anu conveision of log1u() to get the powei value. In
the application we use the usei inteiface pioviueu by moonblink anu Fig 1 shows
some scieenshots. The left pait shows the noimal situation anu the iight one is got
when the othei phone neaiby geneiates a tone with fiequency of 1uuuBz.

(a) (b)
Figuie 1. Fiequency spectium anu stiength value

@ A"13$B'0 7,3=$';
Right now we get some obstiuction to get the pitch in the specific high fiequency
since miciophone of Nexus 0ne filteis out the high fiequency tone anu cannot pick it
up. We lookeu up the technical specifications anu the uetaileu fiequency iange is
still unknown.

|1j http:uevelopei.anuioiu.cominuex.html
|2j Examples of AuuioRecoiu
|Sj Intiouuction of FFT http:www.vlf.itfft_beginneisfft_beginneis.html
|4j FFT souice coue
|Sj Examples of AuuioTiack http:apistuuios.comhosteumaizecbaulogicwoiupiess.p=228