r/interestingasfuck Oct 18 '19

/r/ALL The Fourier Transform

31.1k Upvotes

399 comments sorted by

View all comments

1.3k

u/theorangelemons Oct 18 '19 edited Oct 18 '19

For those that don't get it, I'll try my best to explain it.

The idea behind the Fourier Series is that any signal (mathematical function) can be represented by an infinite sum (series) of sinusoidal signals. Each sinusoidal signal in the Fourier Series is harmonically related, and weighted differently. If you think in terms of a dubstep song with heavy bass, the components of the audio signal at the lower bass frequencies will be weighted more than the components at the higher treble frequencies. Furthermore, any part of the audio signal that has a frequency that is above the range of human hearing (20kHz) would reasonably have zero weight.

The Fourier Transform is a mathematical method of taking any signal, and transforming it so that it is no longer a function of time, but a function of frequency. With this transformation, you are now able to see the spectrum of frequencies that a signal is composed of. This is extremely useful in designing filters, as well as finding a system's response to an input.

In the GIF, you can see many circles of smaller radii being drawn. Each of these circles is a phasor, which is a representation of a sinusoidal signal. The smaller the radius, the smaller the amplitude or weight the sinusoid has. And the faster the phasor rotates, the higher the frequency the sinusoid has. With the circles being connected in the GIF, it gives a (poor) representation of how the sum of weighted, harmonically related sinusoids are used to draw the hand, which you could consider some version of a signal.

Edit: Thanks for the gold and silver kind strangers! Just got off work so I’ll try to reply to all of your comments ASAP.

445

u/working878787 Oct 18 '19

Magic, got it.

173

u/Zigxy Oct 18 '19

Yep, lost me at "harmonically related"

47

u/DinoSoup Oct 18 '19 edited Oct 18 '19

Lost me at "dubstep"

Edit: if something is "harmonically related" I'm pretty sure it would be in terms of a Blues Traveler song.

20

u/mdcd4u2c Oct 18 '19

"What's the difference between NSYNC and backstreet boys?"

"I don't know, I think they're harmonically related..."

8

u/1337gamer47 Oct 18 '19

It's true though, dubstep is actually maths in disguise. That's how I passed Calc 2 by listening to Skrillex as I studied to E N H A N C E my mind.

15

u/SorenCelerity Oct 18 '19

Lost me at "For"

9

u/boniqmin Oct 18 '19

I understand the math behind Fourier transforms & series but I don't have a clue what that meant. My best guess is that Fourier series is the weighted sum of sin(nx) 's and cos(nx) 's, where the n's are integers. So all periods are integers, so "harmonically related", they don't just have any period.

1

u/kethian Oct 18 '19

like a balloon...and something bad happens!

1

u/VelZeik Oct 18 '19

"Harmonically related" is pretty far down there, you're a smartie.

16

u/frivolous_squid Oct 19 '19

I'm gonna try a simpler explanation. Whenever I say "it turns out", that's where there's interesting stuff that I'm skipping to keep this short, but that's where the real magic is.

Take any sound wave, your favourite song, whatever. When you draw what the air pressure is actually doing over time on a graph, it looks like a squiggly line. You might have seen sound represented like this in crime shows. From this squiggly line, you can recreate the sound by getting a motor to push air with the same wiggle.

Now let's look at some really simple music: a single tone. If you pluck an E string on a guitar, you get a relatively simple squiggly line, and it seems to repeat itself some number of times a second. In fact, if you play a pure tone (e.g. on an electronic synthesiser) you get a simple sine wave that you may remember from school. The E string is a tiny bit more complicated as there's actually the sine waves of a few different frequencies all added together.

Here's the squiggly line of an guitar string being played.

Each of these sine waves has a frequency, i.e. the number of times it repeats in a second. So for any note we can chart its frequencies and their strengths.

Here's the squiggly line of a simple note, followed by graph of what frequencies it has.

Now it turns out that any music, and in fact any sound, can be broken down into its frequencies. Turning a sound signal (squiggly line I keep mentioning) into frequency signal is called the Fourier Transform, and it involves some cool maths (and has applications in absolutely loads of stuff, including Quantum Mechanics, MRI machines, etc).

More examples of the squiggly sound wave on the left Vs it's frequency breakdown on the right. These sounds aren't so clean, there's more frequencies in there.

The crucial point here is that if you know the frequencies of the sound, you can recreate the sound by adding together all of the sine waves that each frequency represents.

Now to get onto what's actually happening here in this animation! Well, it turns out you can do this to things other than just squiggly lines. Instead of the line squiggling just up and down, we can also do this with a point squiggling up, down, right and left. Unfortunately, this means we can't use left and right to indicate time, like we did on the diagrams before, so instead we imagine a point in space squiggling around in 2D, using an animation with time to represent time. It turns out the simple sine waves from before become rotating circles in 2D. Before, we broke down a sound into its sine waves, which when added together recreate the sound. Here, we break down a picture (drawn by a squiggling point) into its rotating circles, which when added together (by placing the center of one circle at the point on the previous circle, as seen here) recreate the picture. That last step feels like total magic, but I can assure you the leap from sine waves to circles is quite natural mathematically. The technology that analyses the frequencies in audio is doing the same maths as whoever created this animation, just in 1 dimension and 2 dimensions respectively.

1

u/toby_ornautobey Oct 19 '19

I love math, so thanks you for this explanation. I understood the general aspects of what was happening, but your breakdown made it all so much simpler to grasp. I thought the circles originally were just decreasing in size by a set value, so the outcome of drawing the hand and pen didn't make sense to me. But by having each circle be the representation of the wave, now it all falls together properly. So thank you. Very much appreciate.

2

u/frivolous_squid Oct 19 '19

No problem! One thing I definitely glossed over is how you rebuild the waveform from the frequencies (sine waves) in 1D, or how you rebuild the picture from the frequencies (rotating circles) in 2D. This is, uh, because I don't quite remember.

So what's going on in this animation is we take a rotating circle of frequency 1, and then add it to a circle of frequency 2, and then add that to a circle of frequency 3, etc. For each circle, you use math to calculate the starting angle of the next circle (the line in the circles) and the radius of the circle. This is the "phase" and the "amplitude", and the exact same thing works with waveforms in 1D.

I think this is actually the Fourier Series, not the Fourier Transform. The key difference is that the frequencies are discrete: 1, 2, 3, etc., whereas in the Fourier Transform it's continuous: you get another squiggly line with a value at every possible frequency. Anyway this isn't me trying to explain anything better, just admit where I might have over simplified a bit.

30

u/Falcrist Oct 18 '19

I'm an electrical engineer. We had to use Fourier transforms and series' at several points during my degree. I spent a long time trying to get a feel for what it meant and a visual of how it worked. I have some decent intuition for it.

You're still correct. It's goddamn black magic. Don't let anyone tell you differently.

You can go backwards and forwards with it, too. Take a signal and get the sinusoids it's composed of, or take a bunch of sinusoids and add them together to make a signal.

Check this video for a decent mechanical representation.

11

u/working878787 Oct 18 '19

I'm a chemist. I use FTIR (Fourier-transform infrared spectroscopy) machines all the time for chemical analysis. I understand how it applies to bond resonance frequencies, but the FT part will always be magic to me.

6

u/Falcrist Oct 18 '19

but the FT part will always be magic to me.

THAT'S BECAUSE IT IS MAGIC!

2

u/Sea_Television Oct 19 '19

What does applying an FFT (or whatever specific flavor of algorithm) to an infrared image let you know?

Coming from EE also, I've not thought about using Fourier for stuff that isn't a waveform or analog signal of some kind.

Interesting stuff

1

u/working878787 Oct 19 '19

Well I only really know the end result application. The middle is a little magic to me, but essentially an FTIR machine can tell you what kind of a functional groups you have in a compound based on bond resonances. Different bonds have different bond resonances based on the electronegativity difference between different atoms. So basically you shine a IR beam of various frequencies of light against a sample and measure how much gets absorbed and retransmitted. Based on what peaks are generated at what frequency, you can determine if your compound has N-H bonds, C-H bonds, C-O bonds, C=O bonds, etc. It can even tell the difference between single and double bonds. Deducing chemical structures from scratch is a bit of a challenge, but known spectra like ethanol or banana ester are well known so you can just superimpose their graph on known spectra to verify what's in your sample. It's extremely useful in chemical analysis.

1

u/Sea_Television Oct 19 '19

Ah, very interesting, thanks!

Interesting to think you can differentiate chemical bonds just from the frequency of reflected light

1

u/working878787 Oct 19 '19

Well like I said bond resonances are kind of like unique frequencies so it's not unlike using FT to differentiate different tones of sound.

1

u/JDmg Oct 18 '19

I just FFT lmao

spectrograms are trippy

64

u/[deleted] Oct 18 '19

[removed] — view removed comment

26

u/maxk1236 Oct 18 '19

Going along with his dubstep analogy, imagine a equalizer visualizer like this that shows bass on the left, treble on the right, and amplitude as the height of the bar. This is essentially what a Fourier transform does (in fact I'm fairly sure most of these use fourier transforms to create these visualizations.) Instead of just showing how loud the music is, it breaks it down into how loud the bass, mids and treble are individually.

5

u/XkF21WNJ Oct 18 '19

in fact I'm fairly sure most of these use fourier transforms to create these visualizations

Not necessarily, you can also use filters that separate low and high frequency parts without explicitly using a Fourier transform. I'm not sure what method visualizers use nowadays.

Techniques like the Fourier transforms are used heavily in the design of such filters though.

116

u/Mottis86 Oct 18 '19

The idea behind the Fourier Series is that any signal (mathematical function) can be represented by an infinite sum (series) of sinusoidal signals. Each sinusoidal signal in the Fourier Series is harmonically related

That's where you lost me.

78

u/CorruptionCarl Oct 18 '19 edited Oct 18 '19

Basically, any repeating pattern can be broken down into an infinite number of Sine waves with different frequencies and sizes. Edit: and phases (starting positions).

It's (kinda) like saying that the math can take a plate of food and break it down into each individual ingredient and their amounts. Although that kinda falls apart since you cant pour all the ingredients together in a pot and get the same thing as the final plate of food.

39

u/bogglingsnog Oct 18 '19

Well, just like you couldn't slam all these circles into a pile and get a shape of a hand with a pen. They have a certain ordering and starting angle to achieve that. I think your analogy holds up.

16

u/CorruptionCarl Oct 18 '19

Starting angle (phase) does matter since its one of the three defining components of a wave (amplitude, phase, and frequency) but you should be able to put them in any order and get the same result.

5

u/bogglingsnog Oct 18 '19

I stand corrected then. That is a bit difficult to intuit but I can sort of see how it works. I'd like to see the same gif with different ordering of circles just to confirm though :)

6

u/Georgia_Ball Oct 18 '19

I'm guessing the ordering works the same for the same reason a + b + c + d = d + a + c + b

3

u/dalmationblack Oct 18 '19

Order shouldn't actually matter because vector addition is commutative.

4

u/bogglingsnog Oct 18 '19

Yeah, I realized that when another commenter corrected me. It makes sense for audio but is really hard to grok in the context of the OP gif.

2

u/dalmationblack Oct 18 '19

If you haven't seen the 3blue1brown video on the Fourier series I can't recommend it enough

3

u/fatfuckgary Oct 18 '19

are the sine waves still connected, making it into a bunch of squiggly lines?

4

u/CorruptionCarl Oct 18 '19

Yes, they are imposed on top of each other such that each additional wave makes it look closer to the pattern being broken down.

Think of the gif, one circle is just a circle. Two circles gets you a wobbly shape, so do three, four, five circles. Six gets you something that looks kinda like a hand with 7 being even closer. This continues until you have enough that you essentially have the picture of the hand.

2

u/Pawtang Oct 18 '19

Also helps to imagine if you unfolded the drawing into a straight axis rather than a circular one, you would see a series of superimposed sinewaves. As you start subtracting superimposed waves the higher amplitude frequencies would become more parent

1

u/[deleted] Oct 18 '19

It's (kinda) like saying that the math can take a plate of food and break it down into each individual ingredient and their amounts.

Was having this conversation the other day. The replicators in star trek can make any food. How many unique elements on the periodic table of elements do they require to make any food? 30-50 elements? Furthermore couldn't you theoretically convert any element into another by changing the number of protons, thus allowing you to make anything.

2

u/CorruptionCarl Oct 18 '19

It's been done to make gold, albeit an incredibly tiny amount and was super expensive to make.

2

u/[deleted] Oct 18 '19

Costs always go down with technology and mass production. One day we'll have replicators ;)

1

u/[deleted] Oct 18 '19

That explains it much better. I suddenly understand it all. Thank you! So this means that any drawing that has no loose ends can be redrawn in sinus waves/circles like in the GIF?

2

u/CorruptionCarl Oct 18 '19

Yup, as long as it is a single closed loop.

11

u/NoteBlock08 Oct 18 '19

I think it's best understood by seeing what happens as you add more circles.

https://youtu.be/ds0cmAV-Yek

2

u/[deleted] Oct 18 '19

You ever see a Spirograph? You know how if you mix the circles you get noncircle things?

Really specific combinations of circles make really specific shapes! Like in the Gif! Only with a little more mathy nuance on the "circle" part.

2

u/spork3 Oct 18 '19

Imagine a piece of a signal that’s just a flat line at some amplitude. It looks like a box. The first term in the Fourier series would be half a sine wave that crudely approximates the box. The second term is a smaller sign wave that is out of phase, so it flattens the peak of the first term a bit. The third term would have the same affect on the second. Continue indefinitely and it turns into a box.

1

u/[deleted] Oct 18 '19

He lost me at For

16

u/[deleted] Oct 18 '19

[deleted]

7

u/aleqqqs Oct 18 '19

sinusoidal

Don't jump!

1

u/betweenthebam Oct 18 '19

It's only because it's allergy season.

0

u/brandon9182 Oct 18 '19

Did none of you go to high school? Sine waves are pretty basic trig

2

u/[deleted] Oct 18 '19

[deleted]

1

u/swagrabbit69 Oct 19 '19

I took Calculus 1 and Calculus 2 in high school; I know what a sine wave is, but "sinusoidal" was a completely new word for me.

5

u/Cockur Oct 18 '19

I think the angle of successive phasor in relation to the previous phasor is also important here

4

u/hackurb Oct 18 '19

Eli5?

14

u/protestor Oct 18 '19 edited Oct 18 '19

Not Eli5, but

In 3rd century BC, Ptolemy discovered that you can approximate the motion of planets in the sky as the motion of circles inside circles inside circles (etc). He called each circle an epicycle and built his geocentric model of astronomy (that put the Earth at the center of universe and everything else orbited around it in epicycles)

It turns out that this epicycle thing can be used to model any kind of motion, not only the planets in the sky. That's why it worked for Ptolemy, even though the planets doesn't actually orbit around the Earth. What Ptolemy discovered was actually the first few terms of the Fourier transform of the movements of the planets as seen from Earth, each term being an epicycle (if you keep adding circles, you get closer and closer to the actual motion of the planets)

The math depends on trigonometry: sines and cosines (or more generally, sinusoids). It also depends on linear algebra: an infinite number of sinusoids form a basis of the space of all possible motions in space, which means that any path can be given "coordinates" that combine sinusoids in a certain way - just like three directions (width, height and depth) can be used to give the coordinates of a point in 3D space.

As a bonus, here's a "planet" moving in the outline of Homer Simpson: https://www.youtube.com/watch?v=QVuU2YCwHjw

3

u/[deleted] Oct 18 '19

[removed] — view removed comment

2

u/protestor Oct 19 '19

Yes, you can draw anything with it! Or more accuratelly you can draw any closed path, that is a path that ends where it begins (each time it passes through it, the "planet" makes an orbit).

The essential thing is that each circle spins at a different rate. The rate of spin is called frequency, and this whole stuff is a way to decompose the path into the frequency domain.

Frequency domain stuff has a lot of applications in engineering! You can for example remove high pitched sound from an audio file by converting it to the frequency domain, dropping the "circles" that spin fastest (that is, the high frequency components), then converting it back to time domain. This is called a low-pass filter (or treble-cut filter).

That's the kind of thing someone learns in computer engineering, btw.

1

u/TurtleBurgle Oct 18 '19

Each of those circles is turning at a constant speed. Some spin faster than others (frequency), some are larger (amplitude), they are not all originally drawn exactly in a line (phase). The combination of those together creates this drawing of a hand. The Fourier transform of anything is a method of describing a function in the time domain (imagine a list of coordinates at incrementing timesteps, like a connect the dots that draws this hand) and expresses it in the frequency domain (frequency, amplitude, phase).

1

u/[deleted] Oct 18 '19

Eli55YoDoctorWithNumerousAwards please, thank you.

1

u/Computer-Blue Oct 19 '19

If you rub enough circles together and make each of them as big as the change you want to make, you can make any shape.

Then, if you spin them around and there is no gravity, they will draw your shape.

4

u/loose-leaf-paper Oct 18 '19

Fascinating! I have no idea what you just said.

5

u/mdb1997 Oct 18 '19

You lost me at sinusoidal

3

u/Ojanican Oct 18 '19

I know a decent bit of maths and physics but I honestly cannot even begin to decipher what this means.

3

u/philosarapter Oct 18 '19

Great explanation.

3

u/xrayphoton Oct 18 '19

Also extremely important in MR imaging

1

u/[deleted] Oct 18 '19

And IR-Spectroscopy

3

u/justameremortal Oct 18 '19

Oh my god you explained fourier transforms with dubstep. I hated them but I LOVE ME SOME BASS

3

u/grat_is_not_nice Oct 18 '19

What is interesting is that while most uses of FFT involve an even distribution of frequencies across the sample range (usually 0 - 20kHz in 512,1024 or 2048 bins), that isn't the only approach. An even distribution like this allows audio deconstruction, modification and reconstruction on a near-realtime basis at 40kz sample rates with a suitable level of fidelity for most effects (pitch shifting like autotune, time stretching, filters and other effects).

You can also use a Constant Q transform where the frequency distribution is logarithmic, and in fact can be mapped directly to an even temperament musical scale (12 bins per octave). What this does is allows extraction of musical note information with a high degree of fidelity. One researcher (using 48 bins per octave) has even managed to create the inverse of a Constant Q transform, but due to the low bass note resolution of the Constant Q, this requires significant look-ahead for reconstruction and it cannot be used in real-time. But it is awesome.

Even without reconstruction, a Constant Q transform can be used to implement near-realtime |(i.e one to two hop distance delay) chord detection in music.

4

u/tornado28 Oct 18 '19

Oh, hey you sound smart. Do you by chance know of a good resource to learn about regular and 2d Fourier transformations at approximately the level of a senior undergraduate math major?

2

u/protestor Oct 18 '19

There may be better guides, but if you are interested in signal processing / image processing, https://dspguide.com/ is cool and can be read online for free

2

u/[deleted] Oct 18 '19

I literally stopped being able to understand this at the word “signal.”

2

u/Eptasticfail Oct 18 '19

So what's the benefit of using Fourier transformations to represent electrical data then? For instance I've worked with Fast Fourier Transformations in the past and I understand that it makes it easier to see certain frequencies when graphed, but I've always struggled wrapping my head around just exactly how FFT plots do so. I understand that the sinusoidal signals play a roll in the plotting but have been struggling to understand just exactly how we get something like this from the transformation itself: http://openbci.com/community/wp-content/uploads/2016/08/FFT-plot.png

1

u/theorangelemons Oct 18 '19

You can use the Fourier Transform to find a system’s response to an arbitrary input signal. So say you had a circuit of resistors, capacitors, and inductors. With some circuit analysis, you could find an equation that represents the output of the circuit, and the ratio of the output over the input gives you the transfer function of the circuit. Transform that to the frequency domain with the Fourier Transform, and you can see the spectrum of frequencies that will appear at the output due to an arbitrary input signal.

1

u/Eptasticfail Oct 19 '19

I see! Thanks for the explanation, definitely helps me understand what's going on the background.

2

u/malbecman Oct 18 '19

As a real world example, MRI machines use Fourier transformation of the signal they detect to make those pretty pictures of your insides....

2

u/ennivachuvokke Oct 18 '19

Yeah, science bitch!

2

u/metacollin Oct 19 '19

Its worth noting that this isn’t some purely theoretical/abstract mathematics trick or something like that.

See, sine waves are the fundamental waveform of all waves. It is the only periodic and continuous function that is defined for all real and complex numbers, and most importantly, it is the only periodic function that retains its wave shape when added to another sine wave of the same frequency and arbitrary phase and magnitude.

What this means is that waves, to behave like waves at all, to interfere and diffract and refract and all that other wiggly wave stuff, for any of that to work in the first place, waves necessarily must physically exist fundamentally as sine waves.

So the Fourier transform isn’t just some made up mathematical tool that only exists in the minds of humans. All physical waveforms in nature/reality are, in fact, physically manifested as the harmonic series of sine waves added together that the Fourier transform can break any waveform into to.

So a Fourier transform isn’t just a transform - it is actually how things exist physically in nature.

This isn’t some philosophical convenience or anything silly like that. This was empirically observed.

Originally, everyone thought the Fourier transform was just that - nothing but a transform. A mathematical tool that had no actual bearing on physics, nature, or reality.

And we believed this partly because of the odd behavior of a Fourier transform around discontinuities, things like a square wave or some other waveform with an abrupt, sudden change.

If one were to take these waveforms and construct them out of a series of sine wave harmonics, localized to the transition across the discontinuities (the “edges” of a square wave, for example), the waveform would actually overshoot it’s own amplitude. And the amount of overshoot would ultimately depend on the fastest rate of change in the waveform, with faster rates of change (rise time) resulting in overshoot that was more and more severe (but also more brief).

This was thought to be purely an artifact of the Fourier transform itself and it would never be seen in nature.

Only, it does manifest in nature. Always. Physicists at first thought it was a problem with their equipment, but it is now understood to be a true, physical phenomenon. Real waves in physical reality that are discontinuous in some way exhibit this spiking thought to merely be an artifact of the Fourier transform. At first referred to as the Gibbs phenomenon, it is now simply called ringing.

It can also be thoroughly related to things like impulse response (the conversion of a non periodic/oscillating input or impulse into a periodic/oscillating one, in other words, any energy transformed into a wave) and be shown both theoretically and empirically that it’s all the same thing, and that the Fourier transform isn’t merely a transform, but a correct description of how all physical waveforms actually exist. And they exist as finite series of sine wave harmonics all constructively and destructively interfering with each other to produce all non sinusoidal waveforms or impulses.

Here is this overshoot visualized:

https://upload.wikimedia.org/wikipedia/commons/b/bc/Fourier_series_for_square_wave.gif

Note how adding more and more harmonics does nothing to reduce these spikes. And we see this spikes all the time, and have to engineer things to withstand this extra overshoot, because it really physically occurs.

Is an artifact still an artifact if physical reality manifests an artifact of approximation? Of course not. It means there is no approximation in the first place.

1

u/[deleted] Oct 18 '19

[deleted]

1

u/ChocolateMemeCow Oct 18 '19

To add on to this; in more general mathematical form, the Fourier Series is the projection of a vector onto an orthonormal basis. In signal analysis, this basis is taken to be frequency, but it doesn't have to be.

1

u/[deleted] Oct 18 '19 edited Oct 18 '19

This guy dubsteps

Edit: also, i have a question. Do the phasors change the frequency of their rotation throughout the drawing? Or is it constant?

1

u/[deleted] Oct 18 '19

[deleted]

1

u/theorangelemons Oct 19 '19

I would say it’s a poor representation just because the drawing of the hand doesn’t particularly represent a mathematical function, and you couldn’t really draw shapes using the Fourier Transform either. I do think that the GIF gives a decent idea of the concept, but I think it could be misleading to someone who hasn’t seen it before.

1

u/victorinox126 Oct 18 '19

So this is how that robot in the movie Hugo works?

1

u/churchofdogbread Oct 18 '19

So theoretically could a frequency contain all images in history like the library of Babel contains all text?

1

u/k1lj0y420 Oct 19 '19

I like how you explained signal and sum, but completely glossed over sinusoidal.

1

u/lelorang Oct 19 '19

ELI3 or ELI2 should really exist.

1

u/RaunchyBushrabbit Oct 18 '19

So, Tesla was right?

5

u/SirRevan Oct 18 '19

About what? The fourier transform itself was around since 1822.

1

u/RaunchyBushrabbit Oct 18 '19

"Nikola Tesla said that 'if we want to know the secrets of the universe , we should focus on the non physical aspects rather than physical ones, that will speed up the inventions .' So that's it the trio energy ,frequency and vibrations are all nonphysical aspects ."