{"id":1047,"date":"2014-09-01T12:00:22","date_gmt":"2014-09-01T17:00:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=1047"},"modified":"2016-12-05T14:00:38","modified_gmt":"2016-12-05T19:00:38","slug":"touch-tone-telephone-dialing","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2014\/09\/01\/touch-tone-telephone-dialing\/","title":{"rendered":"Touch-Tone Telephone Dialing"},"content":{"rendered":"<div class=\"content\"><!--introduction-->We all use Fourier analysis every day without even knowing it. Cell phones, disc drives, DVDs, and JPEGs all involve fast finite Fourier transforms. This post, which describes touch-tone telephone dialing, is the first of three posts about the computation and interpretation of FFTs. The posts are adapted from chapter 8 of my book, <i>Numerical Computing with MATLAB<\/i> .\r\n\r\n<!--\/introduction-->\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n \t<li><a href=\"#a339f74f-5018-4e54-a618-e75961a9031d\">DTMF<\/a><\/li>\r\n \t<li><a href=\"#0a7f2066-d3b6-4664-b912-7326769f4875\">Synthesis<\/a><\/li>\r\n \t<li><a href=\"#75e67712-3c0b-4fc2-b769-f0f613a50ef8\">The \"1\" button<\/a><\/li>\r\n \t<li><a href=\"#b92b02b7-d702-40a3-8c29-ac529626a908\">Analysis<\/a><\/li>\r\n \t<li><a href=\"#6639c336-9104-48fb-9386-0a9727cb6aca\">Extra<\/a><\/li>\r\n \t<li><a href=\"#f96dbcab-4572-49f2-bade-755d593f6744\">Reference<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\n<h4>DTMF<a name=\"a339f74f-5018-4e54-a618-e75961a9031d\"><\/a><\/h4>\r\nTouch-tone telephone dialing is an example of everyday use of Fourier analysis. The basis for touch-tone dialing is the Dual Tone Multi-Frequency (DTMF) system. <i>Synthesis<\/i> is the generation of analog tones to represent digits in phone numbers. <i>Analysis<\/i> is the decoding of these tones to retrieve the digits. The program <tt>touchtone<\/tt>, which is <a href=\"https:\/\/www.mathworks.com\/content\/dam\/mathworks\/mathworks-dot-com\/moler\/ncm\/touchtone.m\">available here<\/a>, or which is included with my NCM App, demonstrates both these aspects of DTMF.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/touchtone0.jpg\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n<h4>Synthesis<a name=\"0a7f2066-d3b6-4664-b912-7326769f4875\"><\/a><\/h4>\r\nThe telephone dialing pad acts as a 4-by-3 matrix. Associated with each row and column is a frequency. These basic frequencies are\r\n<pre class=\"language-matlab\">fr = [697 770 852 941];\r\nfc = [1209 1336 1477];\r\n<\/pre>\r\nThese frequencies were chosen so that none is an integer multiple of any other. In fact the ratios are 21\/19. This avoids interfering overtones.\r\n\r\nIf <tt>s<\/tt> is a character that labels one of the buttons on the keypad, the corresponding row index <tt>k<\/tt> and column index <tt>j<\/tt> can be found with\r\n<pre class=\"language-matlab\"><span class=\"keyword\">switch<\/span> s\r\n   <span class=\"keyword\">case<\/span> <span class=\"string\">'*'<\/span>, k = 4; j = 1;\r\n   <span class=\"keyword\">case<\/span> <span class=\"string\">'0'<\/span>, k = 4; j = 2;\r\n   <span class=\"keyword\">case<\/span> <span class=\"string\">'#'<\/span>, k = 4; j = 3;\r\n   <span class=\"keyword\">otherwise<\/span>,\r\n      d = s-<span class=\"string\">'0'<\/span>; j = mod(d-1,3)+1; k = (d-j)\/3+1;\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre>\r\nAn important parameter in digital sound is the sampling rate.\r\n<pre class=\"language-matlab\">Fs = 32768\r\n<\/pre>\r\nA vector of points in one-fourth of a second at this sampling rate is\r\n<pre class=\"language-matlab\">t = 0:1\/Fs:0.25\r\n<\/pre>\r\nThe tone generated by the button in position <tt>(k,j)<\/tt> is obtained by superimposing the two fundamental tones with frequencies <tt>fr(k)<\/tt> and <tt>fc(j)<\/tt>.\r\n<pre class=\"language-matlab\">y1 = sin(2*pi*fr(k)*t);\r\ny2 = sin(2*pi*fc(j)*t);\r\ny = (y1 + y2)\/2;\r\n<\/pre>\r\nIf your computer is equipped with a sound card, the statement\r\n<pre class=\"language-matlab\">sound(y,Fs)\r\n<\/pre>\r\nplays the tone.\r\n<h4>The \"1\" button<a name=\"75e67712-3c0b-4fc2-b769-f0f613a50ef8\"><\/a><\/h4>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/touchtone1.jpg\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nFor example, this is the display produced by <tt>touchtone<\/tt> for the \"1\" button. The top subplot depicts the two underlying frequencies and the bottom subplot shows a portion of the signal obtained by averaging the sine waves with those frequencies.\r\n<h4>Analysis<a name=\"b92b02b7-d702-40a3-8c29-ac529626a908\"><\/a><\/h4>\r\nHow is it possible to determine a phone number by listening to the signal generated? This involves the FFT, the Finite Fourier Transform, or, more likely, some specialized version of the FFT adapted to this task. I will discuss the FFT in my next post.\r\n\r\nThe data file <tt>touchtone.mat<\/tt> contains a recording of a telephone being dialed. The file is available from\r\n<pre class=\"language-matlab\">https:\/\/www.mathworks.com\/moler.htmlncm\/touchtone.mat\r\n<\/pre>\r\nGo to the <tt>Home<\/tt> tab above the MATLAB command window, click on the <tt>Open<\/tt> tab and insert this URL into the <tt>File name<\/tt> slot. This will load a structure <tt>y<\/tt> into your MATLAB workspace. Then the statement\r\n<pre>  y<\/pre>\r\nwill produce\r\n<pre>  y =\r\n   sig: [1x74800 int8]\r\n    fs: 8192<\/pre>\r\nThis shows that <tt>y<\/tt> has two fields, an integer vector <tt>y.sig<\/tt>, of length 74800, containing the signal, and a scalar <tt>y.fs<\/tt>, with the value 8192, which is the sample rate.\r\n<pre>  max(abs(y.sig))<\/pre>\r\nreveals that the elements of the signal are bounded in absolute value by 127. So the statements\r\n<pre>  Fs = y.fs;\r\n  y = double(y.sig)\/128;<\/pre>\r\nsave the sample rate, rescale the vector and convert it to double precision. The statements\r\n<pre>  n = length(y);\r\n  t = (0:n-1)\/Fs<\/pre>\r\nreproduce the sample times of the recording. The last component of <tt>t<\/tt> is <tt>9.1307<\/tt>, indicating that the recording lasts a little over 9 seconds. The next figure is a plot of the entire signal.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/touchtone2.jpg\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nThis recording is noisy. You can even see small spikes on the graph at the times the buttons were clicked. It is easy to see that 11 digits were dialed, but, on this scale, it is impossible to determine the specific digits.\r\n\r\nHere is the magnitude of the FFT of the signal, which is the key to determining the individual digits.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/touchtone3.jpg\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n<pre class=\"language-matlab\">p = abs(fft(y));\r\nf = (0:n-1)*(Fs\/n);\r\nplot(f,p);\r\naxis([500 1700 0 600])\r\n<\/pre>\r\nThe <i>x<\/i> -axis corresponds to frequency. The <tt>axis<\/tt> settings limit the display to the range of the DTMF frequencies. There are seven peaks, corresponding to the seven basic frequencies. This overall FFT shows that all seven frequencies are present someplace in the signal, but it does not help determine the individual digits.\r\n\r\nThe <tt>touchtone<\/tt> program also lets you break the signal into 11 equal segments and analyze each segment separately. The next figure is the display from the first segment.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/touchtone4.jpg\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nFor this segment, there are only two peaks, indicating that only two of the basic frequencies are present in this portion of the signal. These two frequencies come from the \"1\" button. You can also see that the waveform of a short portion of the first segment is similar to the waveform that our synthesizer produces for the \"1\" button. So we can conclude that the number being dialed in <tt>touchtone<\/tt> starts with a 1. We leave it as an exercise to continue the analysis with <tt>touchtone<\/tt> and identify the complete phone number.\r\n<h4>Extra<a name=\"6639c336-9104-48fb-9386-0a9727cb6aca\"><\/a><\/h4>\r\n<tt>touchtone<\/tt> has a hidden \"Easter egg\" that, as far as I know, has never been uncovered. If anyone finds it, submit a comment and let us know.\r\n<h4>Reference<a name=\"f96dbcab-4572-49f2-bade-755d593f6744\"><\/a><\/h4>\r\nCleve Moler, <i>Numerical Computing with MATLAB<\/i>, Electronic Edition, MathWorks, <a href=\"https:\/\/www.mathworks.com\/moler\/index_ncm.html\">&lt;https:\/\/www.mathworks.com\/moler\/index_ncm.html<\/a>&gt;,\r\n\r\nPrint Edition, SIAM Revised Reprint, SIAM, 2008, 334 pp., <a href=\"http:\/\/bookstore.siam.org\/ot87\">&lt;http:\/\/bookstore.siam.org\/ot87<\/a>&gt; .\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_80ba0ed1569942ca838be25d239b161a() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='80ba0ed1569942ca838be25d239b161a ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 80ba0ed1569942ca838be25d239b161a';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n\r\n\r\n\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae R2014a<\/p>\r\n\r\n<\/div>\r\n<!--\r\n80ba0ed1569942ca838be25d239b161a ##### SOURCE BEGIN #####\r\n%% Touch-Tone Telephone Dialing\r\n% We all use Fourier analysis every day without even knowing it.\r\n% Cell phones, disc drives, DVDs, and JPEGs all involve fast\r\n% finite Fourier transforms.  This post, which describes touch-tone\r\n% telephone dialing, is the first of three posts about the computation\r\n% and interpretation of FFTs.  The posts are adapted from\r\n% chapter 8 of my book, _Numerical Computing with MATLAB_ .\r\n\r\n%% DTMF\r\n% Touch-tone telephone dialing is an example of everyday use\r\n% of Fourier analysis.  The basis for touch-tone\r\n% dialing is the Dual Tone Multi-Frequency (DTMF) system.\r\n% _Synthesis_ is the generation of analog tones to represent digits\r\n% in phone numbers.  _Analysis_ is the decoding of these tones to\r\n% retrieve the digits.  The program |touchtone|, which is\r\n% <https:\/\/www.mathworks.com\/moler.htmlncm\/touchtone.m available here>,\r\n% or which is included with my NCM App, demonstrates both these\r\n% aspects of DTMF.\r\n%\r\n% <<touchtone0.jpg>>\r\n%\r\n\r\n%% Synthesis\r\n% The telephone dialing pad acts as a 4-by-3 matrix.\r\n% Associated with each row and column is a frequency.\r\n% These basic frequencies are\r\n%\r\n%   fr = [697 770 852 941];\r\n%   fc = [1209 1336 1477];\r\n%\r\n% These frequencies were chosen so that none is an integer multiple\r\n% of any other.  In fact the ratios are 21\/19.  This avoids\r\n% interfering overtones.\r\n\r\n%%\r\n% If |s| is a character that labels one of the buttons on\r\n% the keypad, the corresponding row index |k| and column\r\n% index |j| can be found with\r\n%\r\n%   switch s\r\n%      case '*', k = 4; j = 1;\r\n%      case '0', k = 4; j = 2;\r\n%      case '#', k = 4; j = 3;\r\n%      otherwise,\r\n%         d = s-'0'; j = mod(d-1,3)+1; k = (d-j)\/3+1;\r\n%   end\r\n%\r\n% An important parameter in digital sound is the sampling rate.\r\n%\r\n%   Fs = 32768\r\n%\r\n% A vector of points in one-fourth of a second at this sampling rate is\r\n%\r\n%   t = 0:1\/Fs:0.25\r\n%\r\n% The tone generated by the button in position |(k,j)| is obtained by\r\n% superimposing the two fundamental tones with frequencies |fr(k)| and\r\n% |fc(j)|.\r\n%\r\n%   y1 = sin(2*pi*fr(k)*t);\r\n%   y2 = sin(2*pi*fc(j)*t);\r\n%   y = (y1 + y2)\/2;\r\n%\r\n% If your computer is equipped with a sound card, the statement\r\n%\r\n%   sound(y,Fs)\r\n%\r\n% plays the tone.\r\n\r\n%% The \"1\" button\r\n%\r\n% <<touchtone1.jpg>>\r\n%\r\n% For example, this is the display produced by |touchtone| for the\r\n% \"1\" button.  The top subplot depicts the two underlying frequencies\r\n% and the bottom subplot shows a portion of the signal obtained by\r\n% averaging the sine waves with those frequencies.\r\n\r\n%% Analysis\r\n% How is it possible to determine a phone number by listening\r\n% to the signal generated?  This involves the FFT, the Finite\r\n% Fourier Transform, or, more likely, some specialized version\r\n% of the FFT adapted to this task.  I will discuss the FFT in my\r\n% next post.\r\n\r\n%%\r\n% The data file |touchtone.mat| contains a recording of a telephone\r\n% being dialed.  The file is available from\r\n%\r\n%   https:\/\/www.mathworks.com\/moler.htmlncm\/touchtone.mat\r\n%\r\n% Go to the |Home| tab above the MATLAB command window, click on the\r\n% |Open| tab and insert this URL into the |File name| slot.  This\r\n% will load a structure |y| into your MATLAB workspace.  Then the statement\r\n%\r\n%    y\r\n%\r\n% will produce\r\n%\r\n%    y =\r\n%     sig: [1x74800 int8]\r\n%      fs: 8192\r\n%\r\n% This shows that |y| has two fields, an integer vector |y.sig|,\r\n% of length 74800, containing the signal, and a scalar |y.fs|, with\r\n% the value 8192, which is the sample rate.\r\n%\r\n%    max(abs(y.sig))\r\n%\r\n% reveals that the elements of the signal are bounded in absolute\r\n% value by 127.  So the statements\r\n%\r\n%    Fs = y.fs;\r\n%    y = double(y.sig)\/128;\r\n%\r\n% save the sample rate, rescale the vector and convert it to\r\n% double precision.  The statements\r\n%\r\n%    n = length(y);\r\n%    t = (0:n-1)\/Fs\r\n%\r\n% reproduce the sample times of the recording.  The last component of\r\n% |t| is |9.1307|, indicating that the recording lasts a little over\r\n% 9 seconds.  The next figure is a plot of the entire signal.\r\n%\r\n% <<touchtone2.jpg>>\r\n%\r\n\r\n%%\r\n% This recording is noisy.  You can even see small spikes on the graph\r\n% at the times the buttons were clicked.  It is easy to see that 11 digits\r\n% were dialed, but, on this scale, it is impossible to determine the\r\n% specific digits.\r\n%\r\n% Here is the magnitude of the FFT of the signal, which is the\r\n% key to determining the individual digits.\r\n%\r\n% <<touchtone3.jpg>>\r\n\r\n%%\r\n%   p = abs(fft(y));\r\n%   f = (0:n-1)*(Fs\/n);\r\n%   plot(f,p);\r\n%   axis([500 1700 0 600])\r\n%\r\n% The _x_ -axis corresponds to frequency.  The |axis| settings\r\n% limit the display to the range of the DTMF frequencies.  There are\r\n% seven peaks, corresponding to the seven basic frequencies.\r\n% This overall FFT shows that all seven frequencies are present\r\n% someplace in the signal, but it does not help determine the individual\r\n% digits.\r\n\r\n%%\r\n% The |touchtone| program also lets you break the\r\n% signal into 11 equal segments and analyze each\r\n% segment separately.  The next figure is the\r\n% display from the first segment.\r\n%\r\n% <<touchtone4.jpg>>\r\n%\r\n% For this segment, there are only two peaks, indicating that only\r\n% two of the basic frequencies are present in this portion of the signal.\r\n% These two frequencies come from the \"1\" button.\r\n% You can also see that the waveform of a short portion of the first\r\n% segment is similar to the waveform that our synthesizer produces for\r\n% the \"1\" button.  So we can conclude that the number being dialed\r\n% in |touchtone| starts with a 1.  We leave it as an exercise\r\n% to continue the analysis with |touchtone| and identify the complete\r\n% phone number.\r\n\r\n%% Extra\r\n% |touchtone| has a hidden \"Easter egg\" that, as far as I know, has never\r\n% been uncovered.  If anyone finds it, submit a comment and let us know.\r\n\r\n%% Reference\r\n% Cleve Moler, _Numerical Computing with MATLAB_, Electronic Edition,\r\n% MathWorks, <https:\/\/www.mathworks.com\/moler\/index_ncm.html % https:\/\/www.mathworks.com\/moler\/index_ncm.html>,\r\n%\r\n% Print Edition,\r\n% SIAM Revised Reprint, SIAM, 2008, 334 pp.,\r\n% <http:\/\/bookstore.siam.org\/ot87 % http:\/\/bookstore.siam.org\/ot87> .\r\n\r\n##### SOURCE END ##### 80ba0ed1569942ca838be25d239b161a\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/touchtone0.jpg\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction-->We all use Fourier analysis every day without even knowing it. Cell phones, disc drives, DVDs, and JPEGs all involve fast finite Fourier transforms. This post, which describes touch-tone telephone dialing, is the first of three posts about the computation and interpretation of FFTs. The posts are adapted from chapter 8 of my book, <i>Numerical Computing with MATLAB<\/i> .\r\n\r\n<!--\/introduction-->... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2014\/09\/01\/touch-tone-telephone-dialing\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,5,4,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1047"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=1047"}],"version-history":[{"count":16,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1047\/revisions"}],"predecessor-version":[{"id":2185,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1047\/revisions\/2185"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}