This experimental page started off experimenting with the CANVAS for drawing and audio.
This page uses IIR filters to look for tones.
DTMF is using in ITU V.18 Annex B. Not all characters map.
|
|
|
x scale:
|
Y scale: |
duration(ms): inter Digit pause(ms):
var tonesA="697,770,852,941,1209,1336,1477,1633,1300".split(",") var map ="123A456B789C*0#D"
Decoded:
found
http://jaggedplanet.com/iir/iir-explorer.asp#:~:text=IIR%20Filter%20Explorer%20The%20IIR%20Filter%20Explorer%20is,order%2C%20in%20low-pass%2C%20high-pass%2C%20band-pass%20and%20notch%20configurations.
// Table B.1/V.18 − Line-to-DTE code conversion (DTMF to 7-bit) Hello. GA Hello. GA Hello. GA Hello. GA Hello. GA Hello. GA "##32#4#4#5#90##*3##*10##32#4#4#5#90##*3##*10##32#4#4#5#90##*3##*10##32#4#4#5#90##*3##*10##32#4#4#5#90##*3##*10##32#4#4#5#90##*3##*10" input --- filters --- comparators --- 8000 samples per seconds The filter function uses an iir filter. The energy is measured using the delayed output squared. // take 4 samples opA[ i ] = z[0]*z[0] +z[1]*z[1] +z[2]*z[2] +z[3]*z[3] One of the filters resonated with amplitude about half of the other one so it is doubled. /* * * iir filter. * * --X---[ z-1 ]----[z-1]----- | | | | k -1 | | | \------------------------ * * from wikipedia:- Nterms defined here Kterm selected here ω = 2 * π * Kterm / Nterms; cr = cos(ω); ci = sin(ω); coeff = 2 * cr; sprev = 0; sprev2 = 0; for each index n in range 0 to Nterms-1 s = x[n] + coeff * sprev - sprev2; sprev2 = sprev; sprev = s; end power = sprev2*sprev2 + sprev*sprev - coeff*sprev*sprev2 ; * */ /* * https://sites.google.com/site/hobbydebraj/goertzel-algorithm-dtmf-detection */ var z1= "0,0,0,0".split(",") var z2= "0,0,0,0".split(",") var k1= "0.5,-0.7,0.2,0.2".split(",") k1[0] = 2.0*Math.cos( 2.0*Math.PI*(980*1.0/RC=3492.0) ) k1[1] = 0.7 var k2= "0.5,-0.7,0.2,0.2".split(",") k2[0] = 2.0*Math.cos( 2.0*Math.PI*(1180*1.0/RC=3492.0) ) k2[1] = 0.7 function iir2_ts( i, ip,z, k, opA ){ z[3]=z[2]*1.0 z[2]=z[1]*1.0 z[1]=z[0]*1.0 z[0]= ip*1 +k[0]*z[1] +k[1]*z[2] // take 4 samples opA[ i ] = z[0]*z[0] +z[1]*z[1] +z[2]*z[2] +z[3]*z[3] }
ITU V.18 AnnexB DTMF:
B.3 Timing The DCE shall detect characters at least 40 ms in length with silent intervals of at least 40 ms. The DCE shall transmit DTMF characters at least 70 ms in length with silent intervals of at least 50 ms.
The string below can be used to encode decode text sent using DTMF.
// add // Table B.1/V.18 − Line-to-DTE code conversion (DTMF to 7-bit) // ~ is a subsitute for the real code. // var codes = " "+ // pad two spaces as slice "behknqtwz "+ // "adgjmpsvy\b"+ //* "cfilorux.?"+ //# "1234567890"+ //*# "+-=:%(),\r~"+ //** "~~~~~~~~~~"+ //#* "ADGJMPSVY~"+ //##* "BEHKNQTWZ "+ //## "CFILORUX; " //### //-------------- //"1234567890" Hello. GA is sent as ##32#4#4#5#90##*3##*10 It has a prefix and a single digit
Morse code look up string used, look up the character and the dot dash pattern follows.
MorseCodemorseCode = " --....- a.- b-... c-.-. d-.. e. f..-. g--. h.... i.. j.--- k-.- l.-.. "+ "m-- n-. o--- p.--. q--.- r.-. s... t- u..- v...- w.-- x-..- y-.-- z--.. "+ "1.---- 2..--- 3...-- 4....- 5..... 6-.... 7--... 8---.. 9----. 0----- "+ "&.-... '.----. @.--.-. }-.--.- (-.--. :---... ,--..-- "+ "=-..- !-.-.-- +.-.-. \".-..-. ?..--.. /-..-. "