Applied Math for Creative Coders
  1. Math Models for Creative Coders
  2. Systems
  3. Fourier Series and Fourier Transform
  • Math Models for Creative Coders
    • Tech
      • Tools and Installation
      • Adding Libraries to p5.js
      • Using Constructor Objects in p5.js
      • The Open Sound Protocol
    • Maths
      • Complex Numbers
      • Vectors
      • Matrix Algebra Whirlwind Tour
      • Things at Right Angles
    • Systems
      • Frequency and Time Domains
      • Fourier Series and Fourier Transform
      • Filters
      • Convolution
    • Geometry
      • Circles
      • Complex Numbers
      • Fractals
      • Iterated Functions
      • Affine Transformation Fractals
      • Chaos Games
      • L-Systems
      • Kolams and Lusona
    • Media
      • Additive Sound Synthesis
      • FM based Sound Synthesis
      • content/courses/MathModelsDesign/Modules/35-Media/65-GrainSynth/index.qmd
      • Making Noise Predictably
      • The Karplus-Strong Guitar Algorithm
    • AI
      • Working with Neural Nets
      • The Perceptron
      • The Multilayer Perceptron
      • MLPs and Backpropagation
      • Gradient Descent
    • Projects
      • Projects

On this page

  • Introduction
  • Inspiration
  • What is the Fourier Series?
  • Rolling Circles and the Fourier Series
  • How does the Fourier Series Compute?
  • Videos
  • Fourier Series in Code
  • And what of the Fourier Transform?
    • An Analogy
  • Wait, But Why?
  • References
  • Resources
    • Other tools to explore
  1. Math Models for Creative Coders
  2. Systems
  3. Fourier Series and Fourier Transform

Fourier Series and Fourier Transform

Euler Formula
Fourier Series
Harmonics
Published

May 2, 2024

Modified

December 15, 2025

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:

Also see: https://x.com/jagarikin/status/962449509782495232

What is the Fourier Series?

Important

A Fourier Series is a way of composing/decomposing a continuous 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 \(M\) and their complex amplitudes \(a_j\), \(j={1..M}\) relying on our (hopefully growing) intuition, we could systematically generate symmetric patterns based on the idea of rolling circles. By trial and error, we can design both the value of \(M\) and the values for \(a_j\), \(j={1..M}\). So far, so good.

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:

\[ Fourier~coeff~for~sin(\omega_c*t) = \\ \] \[ \begin{align*} \\&= Average\Big(sin(\omega_c*t) \times target.waveform\Big)\\ \\&= \frac{1}{Waveform~Period} * \displaystyle{\int}_{0}^{Waveform~Period} sin(\omega_c*t) \times target.waveform * dt \end{align*} \tag{1}\]

OK, but how does one make use of these time-waveform correlations? By using many of them!

B. Orthogonal Waveforms: We need one more concept here: that of an “orthogonal family of waveforms”: these are waveforms whose mutual 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.

\[ \frac{1}{Waveform~Period} * \int sin(m*\omega_c*t) \times sin(n*\omega_c*t)* dt = 0\\ \] \[ \text{where m and n are multiples of some base frequency} \tag{2}\]

C: “Base Frequency”: So what is this base frequency we have been assuming? It is determined by the target waveform:

\[ Base~ Frequency = \frac{1}{Period~of~Target~Waveform} \tag{3}\]

NoteArvind V on Quora

For more on Orthogonality, see here: https://qr.ae/pATe4W

How does the Fourier Series Compute?

So now we are ready to define the steps in computing the Fourier Series:

  1. Compute the base-time-period \(T\) of the target waveform, and calculate the base frequency \(f_c = \frac{1}{T}\) using Equation 3.

  2. Take say \(M\) integer multiples of this base frequency (\(n = 1.....M\)) and create sine/cosine waves with these. These are called harmonics.

  3. 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. Let’s call these \(corr(i)\) for the \(i^{th}\) harmonic.

  4. Write the Fourier Series for the target waveform as:

\[ target~waveform \sim \sum_{i=1}^{M} corr(i) \times sin/cos(2\pi*i*f_c*t) \]

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.

  • p5.js
  • R

And what of the Fourier Transform?

In short layman’s terms, a Fourier Transform is what we compute when our waveform is not periodic. Since the input waveform is aperiodic, or has infinite period effectively, the base frequency \(f_c\) becomes infinitesimally small, and the harmonics become a continuous spectrum of frequencies.

How should we understand the two?

An Analogy

An analogy may help here: Recall this discussion on Frequency Density Plots. There we said that a Frequency Density Plot was like a Histogram with infinitely small frequency bins. In a similar fashion, we could say that a Fourier Transform is a Fourier Series with “infinitely small bins”, and hence is a continuous function of frequency and not discrete like the Fourier Series.

Let us examine this analogy in detail

Histogram (Discrete, Sampled View):

A histogram takes a continuous dataset (e.g., the heights of thousands of people). It divides this data into discrete bins (e.g., 150-155cm, 155-160cm, etc.). It then counts how many data points fall into each bin. This results in a bar chart showing discrete counts in discrete intervals. It’s a discrete representation of a continuous dataset.

Density Plot (Continuous View):

A density plot is a smoother, continuous version of a histogram. It uses the same binning concept (or kernel smoothing) but aims to represent the underlying probability density function of the continuous data. The height of the density plot at any point represents the density of data points around that value, providing a continuous curve that describes the distribution much more smoothly and informatively than the discrete counts of a histogram.

Fourier Series (Discrete, Sampled View):

The Fourier Series represents periodic signals. It decomposes the periodic signal into a discrete sum of sine and cosine waves (the Fourier basis functions). It calculates discrete coefficients for these specific frequencies (the fundamental frequency and its harmonics). This results in a discrete set of amplitudes and phases for discrete frequencies. It’s a sampled view of the frequency content, specifically tailored for periodic signals.

Fourier Transform (Continuous View):

The Fourier Transform generalizes the Fourier Series to represent any signal, including non-periodic ones. It decomposes the signal into a continuous spectrum of frequencies. It calculates a continuous function describing the amplitude and phase contribution of every possible frequency in the signal continuum. This provides a continuous, infinitely detailed view of the frequency content, analogous to the density plot revealing the true underlying distribution rather than just discrete counts. The Similarity:

Discrete to Continuous

Both pairs involve a transformation from a discrete, sampled, or finite view to a continuous, infinite-resolution view. Nature of the Input: Both transformations start with something that, in its basic form, involves discrete elements (bins in a histogram, coefficients in a Fourier Series) representing underlying continuous phenomena (the data distribution, the signal).

Both aim to provide a more complete, detailed, and often smoother representation of the underlying continuous quantity being analyzed (the data distribution or the signal’s frequency content).

The analogy between histograms and density plots and between Fourier Series and the Fourier Transform captures the fundamental idea that a Fourier Series provides a discrete “histogram” of frequency content for periodic signals, while the Fourier Transform provides the continuous “density plot” of frequency content for general (aperiodic) signals.

TipFourier Transform Analogy

\[ Histogram \sim Frequency~Density <=> Fourier~Series \sim Fourier~Transform \]

What is done in practice is the take the sample aperiodic input waveform and pretend that we can repeat it over and over again. Then we compute the Fourier Transform in a similar way as the Fourier Series, using a fine comb of sine/cosines: anything between 64 to 2048 is not uncommon.

Wait, But Why?

  • The (infinite) set of sines and cosines are a waveform alphabet.
  • We can decompose any periodic continuous waveform using this alphabet.
  • The set of sines/consines in the alphabet are integer multiples of a fundamental frequency.
  • How are their amplitudes calculated? By taking a correlation between the original waveform and the given sine/cosine wave from the alphabet (unit amplitude)
  • How is this accurate? By minimizing a “least square error” between the original waveform and the sum of sinusoids.

References

  1. Jez Swanson. An Interactive Introduction to Fourier Transforms https://www.jezzamon.com/fourier/index.html
  2. Alex Miller. (2018). Fourier Series and Spinning Circles. https://alex.miller.im/posts/fourier-series-spinning-circles-visualization/
  3. Better Explained. An Interactive Guide to the Fourier Transform. http://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/
  4. 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

  1. https://mathlets.org/mathlets/fourier-coefficients/
  2. Working with Audio in p5.js. https://pdm.lsupathways.org/3_audio/
  3. Violet Whitney. (Sep 28, 2023) Sounds: Working with sounds and speech in P5.js. https://medium.spatialpixel.com/sounds-bd05429aba38
  4. Mister Bomb. p5.Sound project tutorials. https://www.youtube.com/playlist?list=PLIsdHp2z9wFl7A1wWb2VmQUUojEGsKELE
  5. https://musiclab.chromeexperiments.com/oscillators
  6. https://www.electronicbeats.net/the-feed/excel-drum-machine/
  7. https://junshern.github.io/algorithmic-music-tutorial/
  8. https://blackwhiskercult.com/visual-music-in-p5-js-i/
  9. Jason Sigal.Visualizing Music with p5.js https://therewasaguy.github.io/p5-music-viz/
  10. Doga Kurkcuoglu. https://bilimneguzellan.net/en/?s=Fourier
  11. https://ccrma.stanford.edu/~jos/mdft/

Other tools to explore

  1. Strudel REPL https://strudel.cc
  2. 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)
  3. https://algorithmicpattern.org/2023/05/15/strudel-live-coding-patterns-on-the-web/
  4. https://betterexplained.com/articles/vector-calculus-understanding-the-dot-product/
  5. Freesound: Find Any Sound you Like. https://freesound.org
  6. WebSpeech API. https://developer.chrome.com/blog/voice-driven-web-apps-introduction-to-the-web-speech-api/
  7. https://dogbotic.com
  8. https://gjmvanboxtel.r-universe.dev/gsignal
R Package Citations
Package Version Citation
ambient 1.0.3 Pedersen and Peck (2025)
gsignal 0.3.7 Van Boxtel, G.J.M., et al. (2021)
mosaicCalc 0.6.4 Kaplan, Pruim, and Horton (2024)
Kaplan, Daniel T., Randall Pruim, and Nicholas J. Horton. 2024. mosaicCalc: R-Language Based Calculus Operations for Teaching. https://doi.org/10.32614/CRAN.package.mosaicCalc.
Pedersen, Thomas Lin, and Jordan Peck. 2025. ambient: A Generator of Multidimensional Noise. https://doi.org/10.32614/CRAN.package.ambient.
Van Boxtel, G.J.M., et al. 2021. gsignal: Signal Processing. https://github.com/gjmvanboxtel/gsignal.
Back to top

Citation

BibTeX citation:
@online{2024,
  author = {},
  title = {Fourier {Series} and {Fourier} {Transform}},
  date = {2024-05-02},
  url = {https://mathforcoders.netlify.app/content/courses/MathModelsDesign/Modules/20-Systems/20-FourierSeries/},
  langid = {en}
}
For attribution, please cite this work as:
“Fourier Series and Fourier Transform.” 2024. May 2, 2024. https://mathforcoders.netlify.app/content/courses/MathModelsDesign/Modules/20-Systems/20-FourierSeries/.
Frequency and Time Domains
Filters

License: CC BY-SA 2.0

Website made with ❤️ and Quarto, by Arvind V.

Hosted by Netlify .