{"id":2612,"date":"2017-06-13T07:00:23","date_gmt":"2017-06-13T11:00:23","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=2612"},"modified":"2019-11-01T17:11:40","modified_gmt":"2019-11-01T21:11:40","slug":"frequency-samples-for-the-output-of-fft2","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2017\/06\/13\/frequency-samples-for-the-output-of-fft2\/","title":{"rendered":"Frequency Samples for the Output of FFT2"},"content":{"rendered":"<div class=\"content\"><p>A MATLAB user recently contacted tech support with a question about the output of <tt>fft2<\/tt>. The user had a function, q(x,y), evaluated on an (x,y) grid. The grid evaluation produced a matrix that the user passed to <tt>fft2<\/tt>. The user's question: what are the spatial frequencies associated with the elements of the output from <tt>fft2<\/tt>?<\/p><p>The question was forwarded to the MATLAB Math team. Chris Turnes, a fellow Georgia Tech grad, answered it. Here is Chris' answer, lightly edited.<\/p><p><i>To map discrete Fourier coefficients into samples of the corresponding Discrete Time Fourier Transform, we need to know about the sampling pattern of the spatial signal.  Since the customer presumably has the vectors x and y that she used to query the continuous function q(x,y), this ought to be easy to determine.<\/i><\/p><p><i>To determine the sampling frequencies, we use the spacing of the sampling grid.  The sampling frequencies in each dimension are <tt>fsx = 1\/(x(2)-x(1))<\/tt> and <tt>fsy = 1\/(y(2)-y(1))<\/tt> if the grid is uniform in each dimension.<\/i><\/p><p><i>Next, the normalized DFT frequencies of a (shifted) N-point DFT (where N here is even for convenience) are <tt>fa = ((-N\/2):(N\/2-1))\/N<\/tt>.  Therefore, the corresponding DTFT frequency grid would be composed of the frequencies <tt>fcx = fa*fsx<\/tt> and <tt>fcy = fa*fsy<\/tt>.  That would be the correct way to do the mapping between FFT coefficients and the corresponding continuous spatial frequency.<\/i><\/p><p>Thanks, Chris.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_e379329729cb4f97aa5f52a67a3baff2() {\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='e379329729cb4f97aa5f52a67a3baff2 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e379329729cb4f97aa5f52a67a3baff2';\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 2017 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 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>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\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_e379329729cb4f97aa5f52a67a3baff2()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2017a<br><\/p><\/div><!--\r\ne379329729cb4f97aa5f52a67a3baff2 ##### SOURCE BEGIN #####\r\n%%\r\n% A MATLAB user recently contacted tech support with a question\r\n% about the output of |fft2|. The user had a function, q(x,y),\r\n% evaluated on an (x,y) grid. The grid evaluation produced a\r\n% matrix that the user passed to |fft2|. The user's question: what\r\n% are the spatial frequencies associated with the elements of the\r\n% output from |fft2|?\r\n%\r\n% The question was forwarded to the MATLAB Math team. Chris Turnes,\r\n% a fellow Georgia Tech grad, answered it. Here is Chris' answer,\r\n% lightly edited.\r\n%\r\n% _To map discrete Fourier coefficients into samples of the\r\n% corresponding Discrete Time Fourier Transform, we need to know\r\n% about the sampling pattern of the spatial signal.  Since the\r\n% customer presumably has the vectors x and y that she used to query\r\n% the continuous function q(x,y), this ought to be easy to\r\n% determine._\r\n%\r\n% _To determine the sampling frequencies, we use the spacing of the\r\n% sampling grid.  The sampling frequencies in each dimension are |fsx\r\n% = 1\/(x(2)-x(1))| and |fsy = 1\/(y(2)-y(1))| if the grid is uniform in\r\n% each dimension._\r\n% \r\n% _Next, the normalized DFT frequencies of a (shifted) N-point DFT\r\n% (where N here is even for convenience) are |fa =\r\n% ((-N\/2):(N\/2-1))\/N|.  Therefore, the corresponding DTFT frequency\r\n% grid would be composed of the frequencies |fcx = fa*fsx| and |fcy =\r\n% fa*fsy|.  That would be the correct way to do the mapping between\r\n% FFT coefficients and the corresponding continuous spatial\r\n% frequency._\r\n%\r\n% Thanks, Chris.\r\n##### SOURCE END ##### e379329729cb4f97aa5f52a67a3baff2\r\n-->","protected":false},"excerpt":{"rendered":"<p>A MATLAB user recently contacted tech support with a question about the output of fft2. The user had a function, q(x,y), evaluated on an (x,y) grid. The grid evaluation produced a matrix that the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2017\/06\/13\/frequency-samples-for-the-output-of-fft2\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[392],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/2612"}],"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=2612"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/2612\/revisions"}],"predecessor-version":[{"id":2613,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/2612\/revisions\/2613"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=2612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=2612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=2612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}