{"id":4388,"date":"2010-01-03T11:57:17","date_gmt":"2010-01-03T11:57:17","guid":{"rendered":"http:\/\/scienceblogs.com\/principles\/2010\/01\/03\/finding-patterns-in-data-fouri\/"},"modified":"2010-01-03T11:57:17","modified_gmt":"2010-01-03T11:57:17","slug":"finding-patterns-in-data-fouri","status":"publish","type":"post","link":"http:\/\/chadorzel.com\/principles\/2010\/01\/03\/finding-patterns-in-data-fouri\/","title":{"rendered":"Finding Patterns in Data: Fourier Series"},"content":{"rendered":"<p>Over at Faraday&#8217;s Cage, Cherish has a <a href=\"http:\/\/mareserinitatis.livejournal.com\/701756.html\">very nice post on Fourier series<\/a>, following on an <a href=\"http:\/\/mareserinitatis.livejournal.com\/614349.html\">earlier post on Fourier transforms in the <cite>Transformers<\/cite> movie<\/a>. She gives a nice definition of the process in the earlier post:<\/p>\n<blockquote>\n<p>A Fourier Transform takes a signal and looks at the waves and then shows us the frequencies of all the waves. If we only have a single sine wave, like above, we will have a frequency that is zero everywhere except for the frequency of that sine wave. More complicated signals will be made up of several of these different frequencies and thus will have several peaks. The idea is that you could move back and forth between the period of the wave and the frequency by using the Fourier Transform. If you only have the frequency information, for example, you can use that to figure out which waves you need. Add them together, and you have your original signal back.<\/p>\n<\/blockquote>\n<p>Of course, you might not see the point in this, as expressed that way&#8211; it sounds sort of like a game, just flipping back and forth between different representations of the same thing. This is actually an extremely powerful analysis tool, though, because it lets you pick patterns out of what otherwise can look like random noise.<\/p>\n<p>In order to demonstrate, I will do what may be the dorkiest thing I&#8217;ve ever done here, namely taking the Fourier transform of the traffic on this blog. Here&#8217;s a graph showing the number of pageviews per day for the last 1024 days of Uncertain Principles (for technical reasons, it needs to be a power of 2):<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/wp-content\/blogs.dir\/467\/files\/2012\/04\/i-902173a73948df380f791637cdb9297c-traffic_1024.jpg\" alt=\"i-902173a73948df380f791637cdb9297c-traffic_1024.jpg\" \/><\/p>\n<p>Looking at that, you might be saying &#8220;This is just noise&#8211; a bunch of low-level hash with a handful of big spikes up above it.&#8221; Which is true&#8211; the really big spike corresponds to the <a href=\"http:\/\/scienceblogs.com\/principles\/2007\/05\/many_worlds_many_treats.php\">Many Worlds, Many Treats<\/a> post hitting Boing Boing, and the smaller, more recent one is this year&#8217;s <a href=\"http:\/\/scienceblogs.com\/principles\/2009\/09\/the_speed_of_god.php\">Speed of God<\/a> post. But is there some hidden pattern here that we&#8217;re not seeing?<\/p>\n<p>The next graph is the Fourier transform of the traffic data:<\/p>\n<p><!--more--><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/wp-content\/blogs.dir\/467\/files\/2012\/04\/i-f55a8f4467383328e0e6516fd55cca42-traffic_fft.jpg\" alt=\"i-f55a8f4467383328e0e6516fd55cca42-traffic_fft.jpg\" \/><\/p>\n<p>I&#8217;ve zoomed in the vertical scale, because there&#8217;s always an enormous spike at a frequency of zero, again for technical reasons that don&#8217;t really matter. What you see here is a measure of the &#8220;power&#8221; at a given frequency, with the frequency measured in units of &#8220;per day.&#8221; This &#8220;power&#8221; tells you how much of a sine wave at that frequency you would need to put in in order to recreate the original graph of blog traffic.<\/p>\n<p>This still looks like a bunch of crap with two spikes rising above the noise: one at around 0.14 day<sup>-1<\/sup>, the other at around 0.28 day<sup>-1<\/sup>. What does that mean for our data? That tells us that there&#8217;s a big concentration of power at a couple of frequencies, which indicates that there&#8217;s a strong recurring pattern in the traffic signal with that frequency.<\/p>\n<p>So what is it? It&#8217;s maybe a little easier to understand if I plot the power as a function of one over the frequency, which is to say, the period in days:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/wp-content\/blogs.dir\/467\/files\/2012\/04\/i-1aec26808c2a9039e839e43680f36702-traffic_fft_period.jpg\" alt=\"i-1aec26808c2a9039e839e43680f36702-traffic_fft_period.jpg\" \/><\/p>\n<p>OK, in order to see anything, you need to plot it on a log scale (which is why this isn&#8217;t usually done), but I&#8217;ve taken the liberty of labelling the peaks. The biggest peak in the signal is at a period of 7.014 days, meaning that there is a pattern in the data that repeats every 7 days. What&#8217;s that? Well, it&#8217;s the days of the week. If we zoom in on the original traffic graph a bit, you can see it:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/wp-content\/blogs.dir\/467\/files\/2012\/04\/i-b8e810de617425618bc09221d9284b66-traffic_detail.jpg\" alt=\"i-b8e810de617425618bc09221d9284b66-traffic_detail.jpg\" \/><\/p>\n<p>Traffic is generally lower on weekends, so every seven days, you see a dip in the numbers. This is just visible in the raw data, but really pops out in the Fourier transform.<\/p>\n<p>What&#8217;s with the 3.5 day peak? Well, the weekly variation isn&#8217;t really sinusoidal&#8211; it&#8217;s kind of flat for five days, then drops down for two. That sort of pattern requires additional frequencies that are harmonics of the fundamental pattern, as discussed in Cherish&#8217;s posts. 3.5 days is half a week, so this is twice the freuqency of the main signal, reinforcing the idea of a weekly pattern. The next harmonic would be at a frequency of around 0.42, or a period around 1.75 days, but it would also be small enough that it would get lost in the other stuff.<\/p>\n<p>So that&#8217;s why scientists use Fourier analysis, and why it&#8217;s important enough to merit a (clunky and essentially undocumented) tool in the Excel analysis tool pack. Fourier analysis lets you find recurring patterns in large data sets, even when those patterns aren&#8217;t obvious in looking at the raw data. The result is kind of trivial in this case&#8211; I had thought there might be something at a period of around a year, because traffic usually dips significantly in December, but there isn&#8217;t enough data to really see it (there might be a peak at about 170 days, if you squint, but I&#8217;m not sure that&#8217;s real).<\/p>\n<p>(Back when I was <a href=\"http:\/\/scienceblogs.com\/principles\/2008\/11\/baby_quantization_update.php\">tracking baby feeding times<\/a> and <a href=\"http:\/\/scienceblogs.com\/principles\/2008\/11\/baby_science_still_no_pattern.php\">making colorful graphs<\/a>, I had intended to follow up with a Fourier analysis of the feeding data, but things got busy at work, and I never found the time. That probably would&#8217;ve been more interesting, given that I didn&#8217;t see as clear a pattern in the raw data, but I no longer have SigmaPlot at home, so I can&#8217;t get at that data.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over at Faraday&#8217;s Cage, Cherish has a very nice post on Fourier series, following on an earlier post on Fourier transforms in the Transformers movie. She gives a nice definition of the process in the earlier post: A Fourier Transform takes a signal and looks at the waves and then shows us the frequencies of&hellip; <a class=\"more-link\" href=\"http:\/\/chadorzel.com\/principles\/2010\/01\/03\/finding-patterns-in-data-fouri\/\">Continue reading <span class=\"screen-reader-text\">Finding Patterns in Data: Fourier Series<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"1","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9,7,11],"tags":[],"class_list":["post-4388","post","type-post","status-publish","format-standard","hentry","category-blogs","category-math","category-physics","category-science","entry"],"_links":{"self":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/posts\/4388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/comments?post=4388"}],"version-history":[{"count":0,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/posts\/4388\/revisions"}],"wp:attachment":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/media?parent=4388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/categories?post=4388"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/tags?post=4388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}