Hacker News new | comments | show | ask | jobs | submit login
Fourier Toy (toxicdump.org)
348 points by alxndr 1080 days ago | hide | past | web | 70 comments | favorite

Try the Fibonacci sequence:

0.01, 0.01, 0.02, 0.03, 0.05, 0.08, 0.13, 0.21

It generates a beautiful wave [1].

There's also this interesting property that you can use any part of the sequence, and it will be the same wave [2].

[1] https://www.dropbox.com/s/89fg14dvsi3wuox/Captura%20de%20tel...

[2] https://www.dropbox.com/s/yu05xs10tauumgu/Captura%20de%20tel...

Nice findings!

By the way, try the reverse sequence (0.21 .. 0.01). I find it much more calmed and the LHS graph looks quite beautiful

Hit enter in each parameter box to update it

Well, it won't be the exact same wave, but it approaches the same wave. It's because the ratio between consecutive numbers in the Fibonacci sequence approaches phi.

what phases did you use?

All in phase.

how do you set all in phase?

Align all the blue lines inside each circle, hold shift and drag.

This article and related commentary are relevant:



In fact, it looks like Lucas Viera may have used that blog post as inspiration.

I think you're being downvoted because anyone who is interested in DSP already knows about Fourier transforms, they're fundamental and quite well known. Frankly, I'm surprised to find that they're new to so many HN readers.

Fundamental if you ever finished a CS degree. Shamefully, the Wikipedia articles (German and English) aren't really good, and I dropped out of university before FFT was a topic.

Lots of HN readers are self-thaught hackers or come from non-theoretic backgrounds... so they likely won't have had a good explanation of it. (Speaking of which, the circle analogy is truly awesome - but how does it work in code?!)

And not necessarily if you did finish a CS degree. I was never taught about them, apparently only electronics/signal processing folks were at my uni.

I'll just mention http://www.dspguide.com/ as a really fantastic resource - a free book aimed at scientists and engineers but so well written as to be easily accessible to the interested lay person.

A lot of the math-related articles on Wikipedia are terrible. When you look at the page for the Math project the FAQ basically says 'it's an encyclopaedia, not a textbook, go write on the talk page of individual articles.' The project managers seem hyper-defensive about it, in constrast to the comprehensive and inclusive approach of many other fields. The Wikibooks project is not much better (so far).

I find the Wolfram Mathematica pages more accessible for dealing with new concepts.

It's more of an electronic engineering thing than CS

In fairness, it's more of an everything thing. You won't get far in any science without hitting a Fourier transform somewhere!

Yes, and in music too. When I worked as intern at IRCAM FFT was a big deal, and was the only part of the code we weren't allowed to checkout.

I learned about Fourier this way from an old "American Scientist" book. The writer had a very powerful remark at the end. He explained how Ptolemeus first used epicycles as a base model to explain planetary motion [edit: their paths]. The criticism that led to the demise of this model was basically "yeah, well, you can make planets have square paths this way". If someone connected the dots at that point we could have had Fourier transform a couple of hundred years earlier. Maybe we did, but the documents disappeared.

Right-click the page for some pre-defined wave patterns (pulse, sawtooth, triangle, etc.)--at least it worked for me in FF.

Beautiful .. has my 6 year old entranced. You know what he said, though? "This thing needs sound." I'm proud of him. :)

This is really awesome. First thing I did was try a sawtooth wave by entering sequential powers of 0.5... this had the intended effect of creating a sawtooth wave, but also the circle diagram was tracing an almost perfect circle in 2D. Really cool for discovering things like that!

These guys are one of the reasons I love mathematics.

Check this out too: http://www.youtube.com/watch?v=QVuU2YCwHjw

Edit: Didn't realize that this was also linked to in another thread on the front page as well.

Anybody got the sequence to draw Homer's head?

Reminder: http://www.youtube.com/watch?v=QVuU2YCwHjw

This is very cool and reminds me of something I've wanted for a long time: a tool like this that is used to make sound. The synthesizers I've used seem predisposed to making a certain type of sound, however, something like but which gives you complete control of the wave form, should give you complete freedom when creating sounds. Maybe I've been looking at the wrong synths... Neat though :)

What you want is an additive synthesizer. Usually these contain a lot of fairly high level 'helpers' rather than control over every individual sine wave, because while 8 sine waves are fun to play with full sound sculpting requires more, and applying envelopes, LFOs and other modulation sources to 64 (or 128 or 356 or 512...) sine waves rapidly becomes tedious.

You could easily make one with (or download a premade one for) Reaktor or Synthmaker (now called Flowstone DSP) or Max/MSP. Kyma is another system for doing so, but very expensive as it's hardware based. Pd/Puredata is free, albeit ugly. Various plugins exist, from VSTi's to rack extensions for Propellerheads' Reason. If you're feeling brave/patient and you want to do it in a hardware instrument, then you can get hold of a Kawai K5000 for only a few hundred $. If you're code-inclined (ugh* ) then try Supercollider or Csound. A related but slightly orthogonal techniques is spectral manipulation using tools such as Metasynth (Mac, $$$) or Coagula (Win, free). Neither of these latter two have seen an update for a long, time, reflecting the general lack of popularity of this technique.

(All these Italicized words are well-known product names, BTW that should come at or near the top in any search engine)

Also, check out http://amaranthaudio.com/ for Cycle which is new and impressive, though a bit clunky last time I checked. I'm hardware based but this is the first instrument I've seen in a while that could draw me back to the PC. I'm sure there's a bunch of iPad apps too, but not having an iPad I only check that platform occasionally.

Additive synthesis is a lot of fun but because there are so many harmonics to play with it's very easy to go astray and end up making clangorous noises that are not particularly musical or natural sounding; of course this makes them an automatic go-to for sci-fi noises, but the problem is that everything sounds unnatural in much the same way, if you see what I mean - the brain says 'ah, that's a very unnatural arrangement of harmonics' and gives up for all but the simpllest cases, much as it decides that poorly-designed FM sounds are quite noisy or that distorted sounds certainly involve a lot of clipping. It's still interesting territory for any sound nerd to explore, but don't expect m/any of your friends/loved ones to share your enthusiasm for such esoteric timbres.

* writing code is a rather masochistic approach to producing sounds IME.

I'll add SynthEdit, because the demo version is fully-featured, intuitive, standalone and free.

If you just want to do it by numbers without interface, and get as mathematically crazy as you like, R has some simple "turn a timeseries to a wav file" libraries.

Also to add: quite a few ipad apps that let you sketch in either a wave form or a spectrum, then turn knobs on it like a synth. Addictive Synth is one that lets you draw spectra freehand; WaveGenerator lets you put in various surfaces or even pictures and "listen" to them. This specific method is called "Wavetable Synthesis".

Oh good catch, I had forgotten about that. Good product, but their website really, really needs an overhaul.

I should also have mentioned that Mathematica makes this sort of thing quite accessible as well, and if you can't afford it or are just a hobbyist they are pretty liberal with their student licensing. http://reference.wolfram.com/mathematica/guide/SoundAndSonif...

Just FYI editing the spectra is usually referred to spectral or additive sysnthesis.

Wavetable synthesis involves a table of single-cycle waveforms that you then sweep through, either manually or preferably with some sort of modulation source. The PPG Wave is the most famous case, and Ensoniq's Transwave technology was basically the same thing. Typically you'll start with 2 waves of completely different harmonic spectra and interpolate between them. IIRC there's a quite affordable PPG wave for iPad now from Wolfgang Palm (who is the authority on this method of synthesis).

I was forgetting for a moment the key part of wavetable was the sweep/interpolation. Silly me! The name of the Wolfgang Palm App is the Wavegenerator I mentioned above -- been playing with it a while, v. v. cool, but (as per your original comment) I can't stray to far from presets without sounding horribly metallic.

You can do additive and additive-like synthesis with ZynAddSubFX, but instead of using per-harmonic envelopes and shift amounts, you can control the bandwidth and spacing of each harmonic.

To mimic an existing sound, such as an organ, I once used audio software to plot the FFT of the original sound, then manually entered the amplitudes of the fundamental and harmonics in a ZynAddSubFX XML instrument definition. I'd like something that automates that process.

Edit: regarding spectral manipulation, there is also SpectraLayers.

Back in my day, real men had to buy all these damn synths! My fave setup was to use additive synths for a lead, analog for the bass/strings/background texture, and fm for chunky mid ranges.. Worked really well... I kind of missing having all that crap.

You may be looking for an Analog synthesizer ( I can recommend the Arrick) or an FM synthesizer (like the DX11) which was based on Chowning's FM synthesis work at Stanford.

If you really want to create an arbitrary waveform (and I caution you that much of the timbre is in the attack and decay and harmonic filtering effects) the simplest way for non-engineers to do that is to use something like an Arduino with a Adafruit Waveshield and a scripted tool to generate .WAV files. The production path then is 'gen file, copy to SD card, stick in WaveShield and hit reset'.

GP wants additive synthesis, not subtractive or FM.

As for copying a file to an Arduino... you know you can play wav files on your computer right?

FM synthesis is additive, and it's a fair point you can play .wav files directly on your machine. I have been tying them to external events which was a bit more difficult.

Additive may not mean what you think it means perhaps? FM involves modulating the frequency of one oscillator with the value of another, whereas additive synthesis involves simply (lol) mixing multiple sinewave oscillators to generate a harmonic series.

Unless there is some more fundamental way in which they are equivalent, in which case I would be eager to learn more.

So I stand somewhat corrected, I had a memory of Chowning describing it as additive in his book "FM Theory & Applications" which I got with my TX11 but as it turns out he felt calling it additive was too simplistic as modulating a frequency is multiplicative. Each 'Op' however is added together to give the resulting tone. Now contrast that to my Arrick where I'll feed a square wave into a VCLF and peel the push filter out the harmonics over time to get a nice 'gong' sound which is definitely subtractive.

I did get a chance though to re-read chapter Chapter 3 "What is FM" and marvel at the relatively simple way it composes into very complex waveforms.

It's possible to calculate the exact frequencies that would be generated by FM synthesis and additively produce exactly those partials that are under Nyquist instead. IIRC, "alias-free" FM synthesis is the name of this technique when used to produce cleaner, band-limited waveforms.

Actually the DX/TX series allowed limited additive synthesis using their 4 or 6 operators (oscillators in Yamaha lingo). That's how the phonic-wheel organ sounds were programmed.

Your post prompted me to get off my ass and upload my .WAV file writer to BitBucket. I wrote it almost two years ago to do exactly what you're talking about -- generate a waveform and learn how to design my own sounds. There are a lot of sophisticated synth tools out there already, but I wanted to start from first principles and really understand what I was doing.

Here's a link to the library: https://bitbucket.org/cmcfarla/waveout

It's stupidly simple C code -- you just need to use three functions: One to open a file for writing audio, one to write a stereo sample, and one to close the file performing cleanup and bookkeeping. I included two examples -- a really basic example to just create a sine wave, and a slightly more complicated one that creates a sine wave with a panning effect.

While I've written a lot of code before, it's rare for me to put code up as open source. So, if I've missed something important, please let me know.

Try pure data. You can fill a table (an array) with whatever function you like, and then use the tabosc4~ object to generate a signal with that as the waveform of a single cycle.

Just read that he was an orphan at age 9 and then made governor of lower Egypt at age 30 by Napoleon, what a life!


And he tutored Champollion at age of 11!

Such Fourier decomposition for an interactive quantum simulation:


(A rare piece of software not getting older with time; and in general, other Falstad's simulations are great, especially Ripple Tank for optical interference and electric circuits.)

nice. The circuit simulator is wonderful - have used it for years. In fact I actually tried to port it to .Net but never finished it.

I would love to see such things rewritten to JS. And it does not sounds strange, as there are some applications based on Falstad's code, e.g. http://icircuitapp.com/.

Wow! So cool. I love the connection between the waveform and the trochoid curve on the left.

Very nice overview of fourier transforms: http://betterexplained.com/articles/an-interactive-guide-to-...

Very much reminds me of the Spirograph I had when I was a young.


I'd like to be able to make a triangle wave, but I think the program needs to be able to input negative values for the components.

Nicely done.

You can change the phase by holding ctrl-shift and dragging the circle. If you want a negative value just use the absolute magnitude with the component in antiphase.

There's a triangle wave preset already available. Right click on the page to select it. It uses values: 0.75, 0, 0.083, 0, 0.03, 0, 0.015, 0

Very helpful - thanks.

It uses the phase. The 0.75 is 180 deg out of phase (blue line of circle points to the left) compared to the 0.083. Compare to the square wave, as well.

Yes, that was the only thing I was missing. I'm tempted to adapt this UI though, it's lovely design.

This is a really nice demo, but note that it's not the full Fourier series. This is only the 'sine' contribution. I'm not sure how you could expand the animation to include cosine as well.

Cosine can be approximated by rotating the sine phase 90 degrees.

It would be cool if someone created the inverse of this, where you could input a signal (audio) and have it show the fft decomposition circles moving around in real time :)

Isn't that approximately every Winamp visualization plugin ever created?

You sure dem younguns ever heard of Winamp?

Doesn't work in Shumway yet.

and probably won't for some time without an official bug report ;)


Though perhaps a canvas rewrite would be better?

Brilliant! But where's the algebra of complex numbers. :-)

I'd love this as an OS boot time animation.

What determines the time/speed of each circle?

The nth circle from the right is n times the speed of the first circle.

Why is this? Could you make it work using, say, 2n instead of n? or n^2 instead of n?

The definition of the Fourier series is an infinite series of integer frequency multiples adding up to reproduce any periodic signal, sort of like how the Taylor series can additively reproduce a function.


Yes! If you skip every other term you'll be going up by 2n.

I'm a bit rusty but going up by 2n (1n,2n,4n,6n...) gives you the even harmonics, the opposite (1n,3n,5n,7n...) gives you the odd harmonics. Old tube-amps are known for keeping the odd harmonics around, it's a "warmer" sound.

edit: fixed the series

That would be the same as this, actually. (For 2n, leave odd terms blank. Etc.)

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact