Fourier Series
Introduction
Can Circles do more for us than draw these lovely patterns? Can they give us an alphabet, a universal way of generating and representing many forms of interest? Can we treat them like a bunch of kitchen ingredients, that we throw into a recipe to conjure up new dishes that look different?
Inspiration
Take a look at these paintings:
What is the Fourier Series?
A Fourier Series is a way of composing/decomposing a complex waveform into a set of harmonically related sine Oscillations, which are summed up to create the original waveform.
In Circles, we saw how we could make symmetric patterns from rotating circles. We did not have a pattern in mind, except for the symmetry order. So, when we chose number of circles
But how about the other way around? What if we had a pattern in mind, and wanted to compute the circles, their number and amplitudes, that would generate that pattern? This is where the Fourier Series comes in.
The best way to form this intuition is to play some of the Wave Game that is available on the University of Colorado PHET Simulations website:
Rolling Circles and the Fourier Series
By sliding the amplitudes of various sine Oscillators (whose number you could choose), you were hopefully able to visually create a waveform that looked very close the one on the screen. This was a way of doing waveform synthesis. How did you know, visually speaking, how to set the amplitude?
A. Correlation of Time waveforms: We adjusted the slider on each sine wave when the selected sine Oscillation that you were manipulating had the best possible correlation with the target waveform!! But how does this correlation work here, with waveforms, instead of data variables?
We all know what Pearson Correlations are: we take the product of two (scaled and centered) quantitative variables, value by value, and take the average of these products. With waveforms, we can intuitively do the same thing to determine the coefficient of each component of the Fourier Series:
OK, but how does one make use of these time-waveform correlations?
B. Orthogonal Waveforms: We need one more concept here: that of “orthogonal waveforms”: these are waveforms whose correlations, as defined above, are zero! But which are these? Our good old sine and cosine waves!!
When we take sine/cosine waves whose frequencies are integer multiples of some base frequency, then all such waveforms are orthogonal.
For more on Orthogonality, see here: https://qr.ae/pATe4W
C: “Base Frequency”: So what is this base frequency we have been assuming? It is determined by the target waveform:
How does the Fourier Series Compute?
So now we are ready to define the steps in computing the Fourier Series:
- Compute the
base-time-period
of the target waveform, and calculate thebase frequency
using Equation 3. - Take say
integer multiples of thisbase frequency
( ) and create sine waves with these. These are called harmonics. - Compute the correlations of each harmonic with the target waveform, as indicated in Equation 1. These are the coefficients (i.e. amplitudes) for each of these harmonics.
- Write the Fourier Series for the target waveform as:
Videos
Let us now hear from Dan Schiffman, and also from 3Blue1Brown!
Fourier Series in Code
How if we just enter a series of numbers, representing our waveform, or pick up sounds off the micrphone, and then make up a Fourier Series for that? We will use pretty much the techique used in creating the rolling circles for the drawing that we saw at first.
Wait, But Why?
- Think of the Fourier Series as a set of sinewaves that are derived by decomposing an original waveform
- How are these components related? As integer multiples of a fundamental frequency.
- How are their amplitudes calculated? By taking a correlation between the original waveform and the given sinewave component (unit amplitude)
- How is this accurate? By minimizing a “least square error” between the original waveform and the sum of sinusoids.
A Sound Vocabulary
Some terms will show up repeatedly in our work and we should be clear what they mean:
-
Oscillation
: Any periodic change in amplitude. https://natureofcode.com/oscillation/ -
Sinusoid
: A Sine Wave Oscillation, created typically withp5.Oscillator
-
Waveform
: A graph of amplitude vs time -
Frequency
: The rate of the oscillation, in cycles per second. Look for a repeating pattern, and measure its time period. will give youfrequency
in Hertz(Hz) -
Amplitude
: The height, or scaling factor of the oscillation. Easiest to decipher for a simple repeating pattern likesine
,square
, ortriangle
. -
Phase
: The instantaneous angle-position of a rotating vector which generates the wave: Remember the Euler’s Formula. Also the instantaneous angle-value of a repeating wave at a certain amplitude. -
Harmonic
: A (usually) Sine Oscillation that is at some integer multiple frequency of a reference Sine Oscillation. 2X =octave
; 10X =decade
. -
In-harmonic
: TBW -
Partials
: TBW -
Transient
: TBW -
Alias
: TBW
References
- Jez Swanson. An Interactive Introduction to Fourier Transforms https://www.jezzamon.com/fourier/index.html
- Alex Miller. (2018). Fourier Series and Spinning Circles. https://alex.miller.im/posts/fourier-series-spinning-circles-visualization/
- Better Explained. An Interactive Guide to the Fourier Transform. http://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/
- Aatish Bhatia (November 6, 2013). The Math Trick Behind MP3s, JPEGs, and Homer Simpson’s Face. https://nautil.us/the-math-trick-behind-mp3s-jpegs-and-homer-simpsons-face-234629/
Resources
- https://mathlets.org/mathlets/fourier-coefficients/
- Working with Audio in
p5.js
. https://pdm.lsupathways.org/3_audio/ - Violet Whitney. (Sep 28, 2023) Sounds: Working with sounds and speech in P5.js. https://medium.spatialpixel.com/sounds-bd05429aba38
- Mister Bomb. p5.Sound project tutorials. https://www.youtube.com/playlist?list=PLIsdHp2z9wFl7A1wWb2VmQUUojEGsKELE
- https://musiclab.chromeexperiments.com/oscillators
- https://www.electronicbeats.net/the-feed/excel-drum-machine/
- https://junshern.github.io/algorithmic-music-tutorial/
- https://blackwhiskercult.com/visual-music-in-p5-js-i/
- Jason Sigal.Visualizing Music with p5.js https://therewasaguy.github.io/p5-music-viz/
- Doga Kurkcuoglu. https://bilimneguzellan.net/en/?s=Fourier
Other tools to explore
- Strudel REPL https://strudel.cc
- Introducing Jukebox, a neural net that generates music, including rudimentary singing, as raw audio in a variety of genres and artist styles. We’re releasing a tool for everyone to explore the generated samples, as well as the model and code: https://openai.com/index/jukebox/ (OpenAI, April 30, 2020,via Twitter https://twitter.com/OpenAI)
- https://algorithmicpattern.org/2023/05/15/strudel-live-coding-patterns-on-the-web/
- https://betterexplained.com/articles/vector-calculus-understanding-the-dot-product/
- Freesound: Find Any Sound you Like. https://freesound.org
- WebSpeech API. https://developer.chrome.com/blog/voice-driven-web-apps-introduction-to-the-web-speech-api/
- https://dogbotic.com
R Package Citations
Citation
@online{2024,
author = {},
title = {Fourier {Series}},
date = {2024-05-02},
url = {https://av-quarto.netlify.app/content/courses/MathModelsDesign/Modules/35-Media/10-FourierSeries/},
langid = {en}
}