{"id":315,"date":"2010-02-22T19:58:32","date_gmt":"2010-02-23T00:58:32","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2010\/02\/22\/aliasing-and-the-discrete-time-fourier-transform\/"},"modified":"2019-10-29T13:21:29","modified_gmt":"2019-10-29T17:21:29","slug":"aliasing-and-the-discrete-time-fourier-transform","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2010\/02\/22\/aliasing-and-the-discrete-time-fourier-transform\/","title":{"rendered":"Aliasing and the discrete-time Fourier transform"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>Many of you were onto me immediately last week.  I asked you to estimate the frequency of the sampled cosine signal below,\r\n      and <a href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/02\/16\/sampling-a-cosine\/#comments\">readers quickly chimed in<\/a> to guess that this question was really a teaser about aliasing.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_sampling_teaser.png\"> <\/p>\r\n   <p>As it happened, I started with a 1 rad\/second cosine, <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq55573.png\"> , <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq44066.png\"> :\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">t = linspace(-2.3*pi, 2.3*pi, 800);\r\nalpha = 1;\r\nx_c = cos(alpha * t);\r\nplot(t, x_c, <span style=\"color: #A020F0\">'k'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_01.png\"> <p>And I sampled that signal to get <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq97429.png\">  with <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq33441.png\">  so that <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq61698.png\"> .\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">T = 1;\r\nn = -7:7;\r\nnt = n * T;\r\nx = cos(alpha*n*T);\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(nt, x, <span style=\"color: #A020F0\">'ok'<\/span>)\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_02.png\"> <p>But I could have started with a completely different frequency and still ended up with <b>exactly the same samples<\/b>.  For example, let's see what happens when we try <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq94118.png\"> :\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">alpha_2 = 2*pi - 1;\r\nx2_c = cos(alpha_2 * t);\r\nplot(t, x2_c, <span style=\"color: #A020F0\">'k'<\/span>)\r\n\r\nx2 = cos(alpha_2 * n * T);\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(nt, x2, <span style=\"color: #A020F0\">'ok'<\/span>)\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_03.png\"> <p>The two sets of samples are the same (within floating-point round-off error):<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">max(abs(x - x2))<\/pre><pre style=\"font-style:oblique\">\r\nans =\r\n\r\n  1.1657e-015\r\n\r\n<\/pre><p>Let's look at this phenomenon in terms of the <a href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/01\/18\/relationship-between-continuous-time-and-discrete-time-fourier-transforms\/\">relationship between the continuous-time Fourier transform and the discrete-time Fourier transform (DTFT)<\/a>. Below is the continuous-time Fourier transform of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq38695.png\"> .\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_a.png\"> <\/p>\r\n   <p>The DTFT is a collection of copies of the continuous-time Fourier transform, spaced apart by the sampling frequency, and with\r\n      the frequency axis scaled so that the sampling frequency becomes <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq03041.png\"> . Here's the DTFT of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq17606.png\"> .\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_b.png\"> <\/p>\r\n   <p>Now <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq02938.png\">  has a higher frequency as you can see in the plot of its continuous-time Fourier transform:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_c.png\"> <\/p>\r\n   <p>But when you make a bunch of copies of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq07495.png\">  spaced apart by the sampling frequency, you find that the DTFT of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq60919.png\">  is exactly the same as the DTFT of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq17606.png\"> .\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_d.png\"> <\/p>\r\n   <p>Usually only a single period of the DTFT is plotted:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_e.png\"> <\/p>\r\n   <p>In other words, when you use a sampling rate of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq33441.png\"> , the frequencies 1 and <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq61117.png\">  are indistinguishable.  This is called <i>aliasing<\/i>.  In general, the continuous-time frequency <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq87919.png\">  is indistinguishable from any other frequency of the form <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq72870.png\"> , where <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_example_eq86607.png\">  is an integer.\r\n   <\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/steve\/category\/fourier-transforms\/\">So far<\/a> we've talked about the continuous-time Fourier transform, the discrete-time Fourier transform, their relationship, and a\r\n      little bit about aliasing.  Next time we'll bring the discrete Fourier transform (DFT) into the discussion.  That's what the\r\n      MATLAB function <tt>fft<\/tt> actually computes.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_432bd6e43db6470c9240fc69c4b3cbac() {\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='432bd6e43db6470c9240fc69c4b3cbac ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 432bd6e43db6470c9240fc69c4b3cbac';\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        author = '';\r\n        copyright = 'Copyright 2010 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_432bd6e43db6470c9240fc69c4b3cbac()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n432bd6e43db6470c9240fc69c4b3cbac ##### SOURCE BEGIN #####\r\n%%\r\n% Many of you were onto me immediately last week.  I asked you to estimate the\r\n% frequency of the sampled cosine signal below, and \r\n% <https:\/\/blogs.mathworks.com\/steve\/2010\/02\/16\/sampling-a-cosine\/#comments \r\n% readers quickly chimed in> to guess that\r\n% this question was really a teaser about aliasing.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_sampling_teaser.png>>\r\n%\r\n% As it happened, I started with a 1 rad\/second cosine, $x_c = \\cos(\\alpha\r\n% t)$, $\\alpha = 1$: \r\n\r\nt = linspace(-2.3*pi, 2.3*pi, 800);\r\nalpha = 1;\r\nx_c = cos(alpha * t);\r\nplot(t, x_c, 'k')\r\n\r\n%%\r\n% And I sampled that signal to get $x[n] = x_c(nT)$ with $T=1$ so that $x[n] =\r\n% cos(\\alpha n)$.\r\n\r\nT = 1;\r\nn = -7:7;\r\nnt = n * T;\r\nx = cos(alpha*n*T);\r\nhold on\r\nplot(nt, x, 'ok')\r\nhold off\r\n\r\n%%\r\n% But I could have started with a completely different frequency and still ended\r\n% up with *exactly the same samples*.  For example, let's see what happens when\r\n% we try $\\alpha_2 = 2\\pi - 1$:\r\n\r\nalpha_2 = 2*pi - 1;\r\nx2_c = cos(alpha_2 * t);\r\nplot(t, x2_c, 'k')\r\n\r\nx2 = cos(alpha_2 * n * T);\r\nhold on\r\nplot(nt, x2, 'ok')\r\nhold off\r\n\r\n%%\r\n% The two sets of samples are the same (within floating-point round-off error):\r\n\r\nmax(abs(x - x2))\r\n\r\n%%\r\n% Let's look at this phenomenon in terms of the\r\n% <https:\/\/blogs.mathworks.com\/steve\/2010\/01\/18\/relationship-between-continuous-time-and-discrete-time-fourier-transforms\/ relationship between the\r\n% continuous-time Fourier transform and the discrete-time Fourier transform (DTFT)>.\r\n% Below is the continuous-time Fourier transform of $x_c(t)$.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_a.png>>\r\n%\r\n% The DTFT is a collection of copies of the continuous-time Fourier transform,\r\n% spaced apart by the sampling frequency, and with the frequency axis scaled so\r\n% that the sampling frequency becomes $2\\pi$. Here's the DTFT of $x[n]$.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_b.png>>\r\n%\r\n% Now $x_{2c}(t)$ has a higher frequency as you can see in the plot of its\r\n% continuous-time Fourier transform:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_c.png>>\r\n%\r\n% But when you make a bunch of copies of $X_{2c}(\\Omega)$ spaced apart by the\r\n% sampling frequency, you find that the DTFT of $x_2[n]$ is exactly the same as\r\n% the DTFT of $x[n]$.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_d.png>>\r\n%\r\n% Usually only a single period of the DTFT is plotted:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/aliasing_e.png>>\r\n%\r\n% In other words, when you use a sampling rate of $T=1$, the frequencies 1 and\r\n% $2\\pi-1$ are indistinguishable.  This is called _aliasing_.  In general, the\r\n% continuous-time frequency $\\alpha$ is indistinguishable from any other\r\n% frequency of the form $F_s k \\pm \\alpha$, where $k$ is an integer.\r\n%\r\n% <https:\/\/blogs.mathworks.com\/steve\/category\/fourier-transforms\/ \r\n% So far> we've talked about the continuous-time Fourier transform, the\r\n% discrete-time Fourier transform, their relationship, and a little bit about\r\n% aliasing.  Next time we'll bring the discrete Fourier transform (DFT) into the\r\n% discussion.  That's what the MATLAB function |fft| actually computes.\r\n\r\n##### SOURCE END ##### 432bd6e43db6470c9240fc69c4b3cbac\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Many of you were onto me immediately last week.  I asked you to estimate the frequency of the sampled cosine signal below,\r\n      and readers quickly chimed in to guess that this question was... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/02\/22\/aliasing-and-the-discrete-time-fourier-transform\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[208,74,90,32,122,532,68],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/315"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":3665,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/315\/revisions\/3665"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}