<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sat, 06 Jun 2026 19:49:33 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Stephan Müller - 2014-04-08 13:42:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;[…] and sometimes with inverted components […]&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;&lt;code&gt;float imag = buf[i] * sin(-angle);&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;Its a convolution… one of the signals needs to go "backwards". </description><guid isPermaLink="true">99a6e7ba177d0901ac331d919f9aab72</guid><pubDate>Tue, 08 Apr 2014 13:42:21 GMT</pubDate></item><item><title>Stephan Müller - 2014-04-08 13:33:34</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>What helped me understand the discrete fourier transform was looking at easy examples: A signal consisting of only two samples. Such a signal contains two frequencies, &lt;code&gt;[1,1]&lt;/code&gt; (the DC offset) and &lt;code&gt;[1,-1]&lt;/code&gt; (the Nyquist component). It is pretty obvious that by combining those two vectors, any two samples can be "created". 
&lt;br /&gt;
&lt;br /&gt;Larger signals require phase offsets (hence the complex numbers): &lt;code&gt;[0,1,0,-1]&lt;/code&gt; (sampled sine) can be shifted to create &lt;code&gt;[1,0,-1,0]&lt;/code&gt; (sampled cosine). 
&lt;br /&gt;
&lt;br /&gt;And the final missing link to understanding fourier (at least for me) was realising that different frequencies are orthogonal: if you multiply two different frequencies sample by sample and sum up the results, the sum will always be 0. Hence if you do this with a complex signal and a single frequency, all other frequencies in the signal sum up to 0. (try summing up &lt;code&gt;[0,1,0,-1]&lt;/code&gt; and &lt;code&gt;[1,-1,1,-1]&lt;/code&gt;). </description><guid isPermaLink="true">32c6aa902816927318b1674cf552a1a0</guid><pubDate>Tue, 08 Apr 2014 13:33:34 GMT</pubDate></item><item><title>Stephan Müller - 2014-04-08 13:02:26</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;[…] for reasons I don't fully understand, the results of this function are off by a factor of two […]&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;(Note that the whole article is not about the fourier transform, but the &lt;i&gt;discrete&lt;/i&gt; fourier transform. But anyway…)
&lt;br /&gt;
&lt;br /&gt;While the scaling of the transformed result is nothing but convention, it can still be helpful to understand where the 2 comes from. Lets take an easy signal, say &lt;code&gt;sin(x)&lt;/code&gt; over a whole period (&lt;code&gt;x in [0, 2pi]&lt;/code&gt;). 
&lt;br /&gt;
&lt;br /&gt;This signal contains exactly one frequency. So the transformation basically becomes summing up &lt;code&gt;sin(angle)*sin(angle)&lt;/code&gt;. Lets just assume the sampling rate is really high and integrate the function from 0 to 2pi (which gives us pi). Now I want the result to only depend on the signal amplitude and not the signal length, so I divide by the signal length of 2pi, which gives us our famous 1/2 (even though the original amplitude was 1). 
&lt;br /&gt;
&lt;br /&gt;In short: the factor of 2 is created by squaring the sine! The transformed signal has more direct meaning if it is multiplied by 2, but any scaling is just convention. </description><guid isPermaLink="true">bb3147b6779e3a0dddf4688cddbd5e50</guid><pubDate>Tue, 08 Apr 2014 13:02:26 GMT</pubDate></item><item><title>tgree - 2014-02-10 00:56:01</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>Your spinny description of the FFT was fantastic, and breaking it down into sin/cos instead of complex exponential arithmetic really helped to clarify what is going on for me.
&lt;br /&gt;
&lt;br /&gt;Thanks for your article!</description><guid isPermaLink="true">dfb523da2a1942ce5211a5d16b2a42cf</guid><pubDate>Mon, 10 Feb 2014 00:56:01 GMT</pubDate></item><item><title>:) - 2013-10-12 20:42:40</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>*Of course* it'll be twice as large.
&lt;br /&gt;
&lt;br /&gt;It's a sine wave; it has a positive and a negative peak. During the positive peak you're facing in the right direction, during the negative peak you're facing the opposite direction and walking backwards.
&lt;br /&gt;
&lt;br /&gt;So you're walking in the same direction with a speed corresponding to the sampled intensity   twice per cycle -- and that works out to a speed corresponding to one times the amplitude.
&lt;br /&gt;
&lt;br /&gt;The inverted sign can be explained just as easily: you're in the *negative* halfwave when you think you are in the *positive* halfwave, and the other way around.</description><guid isPermaLink="true">265dbd4ba283f143093e5578e81e336d</guid><pubDate>Sat, 12 Oct 2013 20:42:40 GMT</pubDate></item><item><title>Jarryd - 2013-06-03 20:50:24</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>Thanks for the great explanation of the FFT. 
&lt;br /&gt;
&lt;br /&gt;Should all of these steps be done.
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vDSP_ctoz((COMPLEX *)data, 2, &amp;amp;out, 1, bufferFrames / 2);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vDSP_fft_zrip(fftSetup, &amp;amp;out, 1, bufferlog2, FFT_FORWARD);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vDSP_fft_zrip(fftSetup, &amp;amp;out, 1, bufferlog2, FFT_INVERSE);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float outData[bufferFrames];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vDSP_ztoc(&amp;amp;out, 1, (COMPLEX *)outData, 2, bufferFrames / 2);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cblas_sscal(bufferFrames, 1.0 / (bufferFrames * 2), outData, 1);
&lt;br /&gt;
&lt;br /&gt;I dont get where the dominant frequency can be found.</description><guid isPermaLink="true">eb9a75e5506ee3386816ab521c4201cf</guid><pubDate>Mon, 03 Jun 2013 20:50:24 GMT</pubDate></item><item><title>mikeash - 2012-11-09 21:40:26</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>&lt;b&gt;SSteve:&lt;/b&gt; Yes, I can imagine. The fun thing about this bug is that, since OS X's audio pipeline is all floating-point, values in excess of 1.0 will, at least on some hardware, be louder than your set output volume. I had my speakers turned all the way down, but this stuff still came out at full blast.</description><guid isPermaLink="true">3b90b9ac5c5f3e7e2da2c8600ec90a25</guid><pubDate>Fri, 09 Nov 2012 21:40:26 GMT</pubDate></item><item><title>SSteve - 2012-11-09 21:18:01</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>"This needs to be removed before treating the result as audio data, unless you like frightening everybody in the restaurant with the sudden blast of sound from your MacBook (ask me how I know this)."
&lt;br /&gt;
&lt;br /&gt;I was doing beta testing for an audio software company during the PPC to Intel transition. The occasional endian bug could be deafening when we started playback.</description><guid isPermaLink="true">8ad332ca686acc8ff08c40d4dc96a2c1</guid><pubDate>Fri, 09 Nov 2012 21:18:01 GMT</pubDate></item><item><title>jamie - 2012-11-01 22:36:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>By the way, your narrative description of the Fourier transform is the best I've read.  I've been trying to come up with a slightly more memorable one involving two turtles on a beach arguing over how long the tide lasts :)</description><guid isPermaLink="true">759b635849345159c034552b007b912c</guid><pubDate>Thu, 01 Nov 2012 22:36:23 GMT</pubDate></item><item><title>nevyn - 2012-10-28 08:55:05</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>Yay, thank you! Will have to experiment more using this knowledge...</description><guid isPermaLink="true">70416d995130dbfa6aa1c6e9b6c022b3</guid><pubDate>Sun, 28 Oct 2012 08:55:05 GMT</pubDate></item><item><title>TJ Usiyan - 2012-10-27 00:54:07</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>The reason that they are scaled and how is explained here
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://developer.apple.com/library/mac/documentation/Performance/Conceptual/vDSP_Programming_Guide/UsingFourierTransforms/UsingFourierTransforms.html#//apple_ref/doc/uid/TP40005147-CH202-15952"&gt;http://developer.apple.com/library/mac/documentation/Performance/Conceptual/vDSP_Programming_Guide/UsingFourierTransforms/UsingFourierTransforms.html#//apple_ref/doc/uid/TP40005147-CH202-15952&lt;/a&gt;</description><guid isPermaLink="true">c5b446e6d39a7104f921cf1261247dfe</guid><pubDate>Sat, 27 Oct 2012 00:54:07 GMT</pubDate></item><item><title>mikeash - 2012-10-26 20:37:08</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>&lt;b&gt;vasi:&lt;/b&gt; Sorry, a bit of habitual shorthand there. &lt;code&gt;rate&lt;/code&gt; refers to the sample rate of the audio, e.g. &lt;code&gt;44100&lt;/code&gt;. &lt;code&gt;hz&lt;/code&gt; is the target frequency for the analysis.</description><guid isPermaLink="true">1188d75d3f8069ed5f311ba9a7664a16</guid><pubDate>Fri, 26 Oct 2012 20:37:08 GMT</pubDate></item><item><title>jamie - 2012-10-26 19:54:47</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>"rate" is the sample rate of the float *.
&lt;br /&gt;
&lt;br /&gt;"The result of this inverse transformation, for reasons I don't fully understand, comes out multiplied by a factor of bufferFrames * 2."
&lt;br /&gt;
&lt;br /&gt;A bare FFT always gives amplitudes as a product of the block size.  You might be getting the 2 from the fact that the output is the real part of an analytic signal?  I dunno the conventions for veclib, my FFT experience is completely from Pure Data (which is great for learning but a bit tough for making polished products).
&lt;br /&gt;
&lt;br /&gt;Also while you could definitely use something like this for cool visualization, you're just doing a straight rectangular window here, so you're going to end up with a lot of spectral leakage in the forward transform and when you resynthesize it'll sound distorted.</description><guid isPermaLink="true">bf6d5a10eb75156f70ff8372a52f7ddb</guid><pubDate>Fri, 26 Oct 2012 19:54:47 GMT</pubDate></item><item><title>vasi - 2012-10-26 16:33:59</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>The signature for Rotate() is really confusing:
&lt;br /&gt;
&lt;br /&gt;COMPLEX Rotate(float *buf, int samples, float hz, float rate)
&lt;br /&gt;
&lt;br /&gt;It's not clear to me what the last two parameters mean: 'hz' is presumably a rate, and 'rate' is presumably measured in Hertz. I guess one of them indicates the frequency of our rotation, but which one, and what does the other one mean?</description><guid isPermaLink="true">c5b36b0c83f21325e570eadc8e964f80</guid><pubDate>Fri, 26 Oct 2012 16:33:59 GMT</pubDate></item><item><title>Clark - 2012-10-26 15:31:56</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2012-10-26-fourier-transforms-and-ffts.html#comments</link><description>Next up spherical bessel functions for fun and profit…
&lt;br /&gt;
&lt;br /&gt;More seriously, do you know what the two other main classes of functions for analysis aren't in vDSP? Admittedly they aren't used quite as much but still. Spheres and cylinders are very useful for anlayzing symmetries and the like.</description><guid isPermaLink="true">42c366183655e98e8eaee1a6905ec0de</guid><pubDate>Fri, 26 Oct 2012 15:31:56 GMT</pubDate></item></channel></rss>
