{"id":306,"date":"2009-12-16T17:47:06","date_gmt":"2009-12-16T17:47:06","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2009\/12\/16\/continuous-time-fourier-transform-of-windowed-cosine\/"},"modified":"2009-12-16T17:47:06","modified_gmt":"2009-12-16T17:47:06","slug":"continuous-time-fourier-transform-of-windowed-cosine","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2009\/12\/16\/continuous-time-fourier-transform-of-windowed-cosine\/","title":{"rendered":"Continuous-time Fourier transform of windowed cosine"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/steve\/2009\/12\/11\/continuous-time-fourier-transform-basics\/\">Last week<\/a> I showed a couple of continuous-time Fourier transform pairs (for a cosine and a rectangular pulse).  Today I want to follow\r\n      up by discussing one of the ways in which reality confounds our expectations and causes confusion. Specifically, when we're\r\n      talking about real signals and systems, we never truly have an infinitely long signal.\r\n   <\/p>\r\n   <p>To refresh your memory, here are the ideal cosine signal and its continuous-time Fourier transform plots again:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/cos_t.png\"> <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/F_cos_t.png\"> <\/p>\r\n   <p>The dots at the left and right of the cosine plot are meant to remind you that the cosine signal is defined for all <i>t<\/i>.\r\n   <\/p>\r\n   <p>But what if we modify the cosine signal so that we have only a finite number of periods?  Let's start with a single period,\r\n      for example.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% N = number of desired cosine periods<\/span>\r\nN = 1;\r\n\r\nt1 = -N*pi;\r\nt2 = N*pi;\r\nt = linspace(t1, t2, 1000);\r\nx = cos(t);\r\nplot(t,x)\r\nylim([-1.25 1.25])\r\nxlabel(<span style=\"color: #A020F0\">'t'<\/span>)\r\ntitle(<span style=\"color: #A020F0\">'x(t) = cos(t)'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/ctft_windowed_cosine_01.png\"> <p>In signal processing jargon you'll see this kind of signal referred to as a <i>windowed cosine<\/i> with a rectangular window.  That is, the signal is an infinite-extent cosine multiplied by a finite-extent rectangular pulse.\r\n   <\/p>\r\n   <p>If I've done my math correctly, the continuous-time Fourier transform of a cosine signal truncated to a finite number of periods\r\n      is:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/ctft_windowed_cosine_eq67239.png\"> <\/p>\r\n   <p>where <i>N<\/i> is the number of periods.\r\n   <\/p>\r\n   <p>(And if I haven't done my math correctly, I'm sure a sharp-eyed reader will let me know.  I feel like I'm back at Georgia\r\n      Tech working on homework sets. Except that I'm doing it during the day instead of late at night.)\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">omega = linspace(-5.5, 5.5, 500);\r\nX = sin(pi*N*(omega-1)).\/(omega-1) + sin(pi*N*(omega+1)).\/(omega+1);\r\nplot(omega, X)\r\ntitle(<span style=\"color: #A020F0\">'X(\\Omega)'<\/span>)\r\nxlabel(<span style=\"color: #A020F0\">'\\Omega (rad\/s)'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/ctft_windowed_cosine_02.png\"> <p>Well, that doesn't look very much like the continuous-time Fourier transform for the ideal cosine!  If you run this code yourself,\r\n      try zooming in to look closely at those peaks.  You'll see they aren't even located precisely at 1.0 rad\/s.\r\n   <\/p>\r\n   <p>Let's try 10 periods.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">N = 10;\r\nt1 = -N*pi;\r\nt2 = N*pi;\r\nt = linspace(t1, t2, 1000);\r\nx = cos(t);\r\nplot(t,x)\r\nylim([-1.25 1.25])\r\nxlabel(<span style=\"color: #A020F0\">'t'<\/span>)\r\ntitle(<span style=\"color: #A020F0\">'x(t) = cos(t)'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/ctft_windowed_cosine_03.png\"> <pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">omega = linspace(-5.5, 5.5, 500);\r\nX = sin(pi*N*(omega-1)).\/(omega-1) + sin(pi*N*(omega+1)).\/(omega+1);\r\nplot(omega, X)\r\ntitle(<span style=\"color: #A020F0\">'X(\\Omega)'<\/span>)\r\nxlabel(<span style=\"color: #A020F0\">'\\Omega (rad\/s)'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2009\/ctft_windowed_cosine_04.png\"> <p>That's closer, but there's still a lot of funny stuff going on. The more periods we use, the closer the Fourier transform\r\n      gets to the ideal case, but for any finite number of periods we're going to get this decaying ripple effect.\r\n   <\/p>\r\n   <p>Later, when we start constructing synthetic spatial sinusoid images (like in <a href=\"https:\/\/blogs.mathworks.com\/steve\/2009\/12\/04\/fourier-transform-visualization-using-windowing\/\">this post<\/a>), and what we see in the frequency domain looks \"messy,\" this is one of the big reasons.  All our images have finite extent!\r\n       We'll be coming back to this idea in future posts.\r\n   <\/p>\r\n   <p>Have you heard the term <i>bandlimited<\/i>?  It refers to a signal that has no frequency energy above a certain cut-off frequency.  Ponder this notion: No finite-extent\r\n      signal is bandlimited.  That is, any signal that is nonzero over only a finite portion of the time domain has nonzero frequency\r\n      energy across the entire frequency domain.\r\n   <\/p>\r\n   <p>I think that next time I'll be ready to start talking about the discrete-time Fourier transform, or DTFT.  Conceptually we\r\n      are traveling methodically toward the discrete Fourier transform, or DFT, which is what the MATLAB function <tt>fft<\/tt> computes.  Along the way we'll figure out how all three forms (continuous-time Fourier transform, discrete-time Fourier transform,\r\n      and discrete Fourier transform) relate to each other.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_5128f38efbe3447ab06e748660f9a4df() {\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='5128f38efbe3447ab06e748660f9a4df ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 5128f38efbe3447ab06e748660f9a4df';\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 2009 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_5128f38efbe3447ab06e748660f9a4df()\"><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\n5128f38efbe3447ab06e748660f9a4df ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/steve\/2009\/12\/11\/continuous-time-fourier-transform-basics\/ \r\n% Last week> I showed a couple of continuous-time Fourier transform pairs (for a\r\n% cosine and a rectangular pulse).  Today I want to follow up by discussing one\r\n% of the ways in which reality confounds our expectations and causes confusion.\r\n% Specifically, when we're talking about real signals and systems, we never truly\r\n% have an infinitely long signal.\r\n%\r\n% To refresh your memory, here are the ideal cosine signal and its\r\n% continuous-time Fourier transform plots again:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2009\/cos_t.png>>\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2009\/F_cos_t.png>>\r\n%\r\n% The dots at the left and right of the cosine plot are meant to remind you that\r\n% the cosine signal is defined for all _t_.\r\n%\r\n% But what if we modify the cosine signal so that we have only a finite number\r\n% of periods?  Let's start with a single period, for example.\r\n\r\n% N = number of desired cosine periods\r\nN = 1;\r\n\r\nt1 = -N*pi;\r\nt2 = N*pi;\r\nt = linspace(t1, t2, 1000);\r\nx = cos(t);\r\nplot(t,x)\r\nylim([-1.25 1.25])\r\nxlabel('t')\r\ntitle('x(t) = cos(t)')\r\n\r\n%%\r\n% In signal processing jargon you'll see this kind of signal referred to as a\r\n% _windowed cosine_ with a rectangular window.  That is, the signal is an\r\n% infinite-extent cosine multiplied by a finite-extent rectangular pulse.\r\n%\r\n% If I've done my math correctly, the continuous-time Fourier transform of a\r\n% cosine signal truncated to a finite number of periods is:\r\n%\r\n% $$X(\\Omega) = \\frac{\\sin(\\pi N (\\Omega-1))}{\\Omega - 1} + \\frac{\\sin(\\pi N (\\Omega+1))}{\\Omega + 1}$$\r\n%\r\n% where _N_ is the number of periods.\r\n%\r\n% (And if I haven't done my math correctly, I'm sure a sharp-eyed reader will\r\n% let me know.  I feel like I'm back at Georgia Tech working on homework sets.\r\n% Except that I'm doing it during the day instead of late at night.)\r\n%%\r\n\r\nomega = linspace(-5.5, 5.5, 500);\r\nX = sin(pi*N*(omega-1)).\/(omega-1) + sin(pi*N*(omega+1)).\/(omega+1);\r\nplot(omega, X)\r\ntitle('X(\\Omega)')\r\nxlabel('\\Omega (rad\/s)')\r\n\r\n%%\r\n% Well, that doesn't look very much like the continuous-time Fourier transform\r\n% for the ideal cosine!  If you run this code yourself, try zooming in to look\r\n% closely at those peaks.  You'll see they aren't even located precisely at 1.0\r\n% rad\/s.\r\n%\r\n% Let's try 10 periods.\r\n\r\nN = 10;\r\nt1 = -N*pi;\r\nt2 = N*pi;\r\nt = linspace(t1, t2, 1000);\r\nx = cos(t);\r\nplot(t,x)\r\nylim([-1.25 1.25])\r\nxlabel('t')\r\ntitle('x(t) = cos(t)')\r\n\r\n%%\r\nomega = linspace(-5.5, 5.5, 500);\r\nX = sin(pi*N*(omega-1)).\/(omega-1) + sin(pi*N*(omega+1)).\/(omega+1);\r\nplot(omega, X)\r\ntitle('X(\\Omega)')\r\nxlabel('\\Omega (rad\/s)')\r\n\r\n%%\r\n% That's closer, but there's still a lot of funny stuff going on. The more\r\n% periods we use, the closer the Fourier transform gets to the ideal case, but\r\n% for any finite number of periods we're going to get this decaying ripple\r\n% effect.\r\n%\r\n% Later, when we start constructing synthetic spatial sinusoid images (like in\r\n% <https:\/\/blogs.mathworks.com\/steve\/2009\/12\/04\/fourier-transform-visualization-using-windowing\/ \r\n% this post>), and what we see in the frequency domain looks \"messy,\" this is one\r\n% of the big reasons.  All our images have finite extent!  We'll be coming back to\r\n% this idea in future posts.\r\n%\r\n% Have you heard the term _bandlimited_?  It refers to a signal that has no\r\n% frequency energy above a certain cut-off frequency.  Ponder this notion: No\r\n% finite-extent signal is bandlimited.  That is, any signal that is nonzero over\r\n% only a finite portion of the time domain has nonzero frequency energy across\r\n% the entire frequency domain.\r\n%\r\n% I think that next time I'll be ready to start talking about the discrete-time\r\n% Fourier transform, or DTFT.  Conceptually we are traveling methodically toward\r\n% the discrete Fourier transform, or DFT, which is what the MATLAB function\r\n% |fft| computes.  Along the way we'll figure out how all three forms\r\n% (continuous-time Fourier transform, discrete-time Fourier transform, and\r\n% discrete Fourier transform) relate to each other.\r\n##### SOURCE END ##### 5128f38efbe3447ab06e748660f9a4df\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Last week I showed a couple of continuous-time Fourier transform pairs (for a cosine and a rectangular pulse).  Today I want to follow\r\n      up by discussing one of the ways in which reality... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2009\/12\/16\/continuous-time-fourier-transform-of-windowed-cosine\/\">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":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/306"}],"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=306"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/306\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}