Applied Metaphors: Learning TRIZ, Complexity, Data/Stats/ML using Metaphors
  1. Teaching
  2. Math Models for Creative Coders
  3. Media
  4. Fourier Series
  • Teaching
    • Data Analytics for Managers and Creators
      • Tools
        • Introduction to R and RStudio
        • Introduction to Radiant
        • Introduction to Orange
      • Descriptive Analytics
        • Data
        • Summaries
        • Counts
        • Quantities
        • Groups
        • Densities
        • Groups and Densities
        • Change
        • Proportions
        • Parts of a Whole
        • Evolution and Flow
        • Ratings and Rankings
        • Surveys
        • Time
        • Space
        • Networks
        • Experiments
        • Miscellaneous Graphing Tools, and References
      • Statistical Inference
        • 🧭 Basics of Statistical Inference
        • 🎲 Samples, Populations, Statistics and Inference
        • Basics of Randomization Tests
        • 🃏 Inference for a Single Mean
        • 🃏 Inference for Two Independent Means
        • 🃏 Inference for Comparing Two Paired Means
        • Comparing Multiple Means with ANOVA
        • Inference for Correlation
        • 🃏 Testing a Single Proportion
        • 🃏 Inference Test for Two Proportions
      • Inferential Modelling
        • Modelling with Linear Regression
        • Modelling with Logistic Regression
        • 🕔 Modelling and Predicting Time Series
      • Predictive Modelling
        • 🐉 Intro to Orange
        • ML - Regression
        • ML - Classification
        • ML - Clustering
      • Prescriptive Modelling
        • 📐 Intro to Linear Programming
        • 💭 The Simplex Method - Intuitively
        • 📅 The Simplex Method - In Excel
      • Workflow
        • Facing the Abyss
        • I Publish, therefore I Am
      • Case Studies
        • Demo:Product Packaging and Elderly People
        • Ikea Furniture
        • Movie Profits
        • Gender at the Work Place
        • Heptathlon
        • School Scores
        • Children's Games
        • Valentine’s Day Spending
        • Women Live Longer?
        • Hearing Loss in Children
        • California Transit Payments
        • Seaweed Nutrients
        • Coffee Flavours
        • Legionnaire’s Disease in the USA
        • Antarctic Sea ice
        • William Farr's Observations on Cholera in London
    • R for Artists and Managers
      • 🕶 Lab-1: Science, Human Experience, Experiments, and Data
      • Lab-2: Down the R-abbit Hole…
      • Lab-3: Drink Me!
      • Lab-4: I say what I mean and I mean what I say
      • Lab-5: Twas brillig, and the slithy toves…
      • Lab-6: These Roses have been Painted !!
      • Lab-7: The Lobster Quadrille
      • Lab-8: Did you ever see such a thing as a drawing of a muchness?
      • Lab-9: If you please sir…which way to the Secret Garden?
      • Lab-10: An Invitation from the Queen…to play Croquet
      • Lab-11: The Queen of Hearts, She Made some Tarts
      • Lab-12: Time is a Him!!
      • Iteration: Learning to purrr
      • Lab-13: Old Tortoise Taught Us
      • Lab-14: You’re are Nothing but a Pack of Cards!!
    • ML for Artists and Managers
      • 🐉 Intro to Orange
      • ML - Regression
      • ML - Classification
      • ML - Clustering
      • 🕔 Modelling Time Series
    • TRIZ for Problem Solvers
      • I am Water
      • I am What I yam
      • Birds of Different Feathers
      • I Connect therefore I am
      • I Think, Therefore I am
      • The Art of Parallel Thinking
      • A Year of Metaphoric Thinking
      • TRIZ - Problems and Contradictions
      • TRIZ - The Unreasonable Effectiveness of Available Resources
      • TRIZ - The Ideal Final Result
      • TRIZ - A Contradictory Language
      • TRIZ - The Contradiction Matrix Workflow
      • TRIZ - The Laws of Evolution
      • TRIZ - Substance Field Analysis, and ARIZ
    • Math Models for Creative Coders
      • Maths Basics
        • Vectors
        • Matrix Algebra Whirlwind Tour
        • content/courses/MathModelsDesign/Modules/05-Maths/70-MultiDimensionGeometry/index.qmd
      • Tech
        • Tools and Installation
        • Adding Libraries to p5.js
        • Using Constructor Objects in p5.js
      • Geometry
        • Circles
        • Complex Numbers
        • Fractals
        • Affine Transformation Fractals
        • L-Systems
        • Kolams and Lusona
      • Media
        • Fourier Series
        • Additive Sound Synthesis
        • 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
    • Data Science with No Code
      • Data
      • Orange
      • Summaries
      • Counts
      • Quantity
      • 🕶 Happy Data are all Alike
      • Groups
      • Change
      • Rhythm
      • Proportions
      • Flow
      • Structure
      • Ranking
      • Space
      • Time
      • Networks
      • Surveys
      • Experiments
    • Tech for Creative Education
      • 🧭 Using Idyll
      • 🧭 Using Apparatus
      • 🧭 Using g9.js
    • Literary Jukebox: In Short, the World
      • Italy - Dino Buzzati
      • France - Guy de Maupassant
      • Japan - Hisaye Yamamoto
      • Peru - Ventura Garcia Calderon
      • Russia - Maxim Gorky
      • Egypt - Alifa Rifaat
      • Brazil - Clarice Lispector
      • England - V S Pritchett
      • Russia - Ivan Bunin
      • Czechia - Milan Kundera
      • Sweden - Lars Gustaffsson
      • Canada - John Cheever
      • Ireland - William Trevor
      • USA - Raymond Carver
      • Italy - Primo Levi
      • India - Ruth Prawer Jhabvala
      • USA - Carson McCullers
      • Zimbabwe - Petina Gappah
      • India - Bharati Mukherjee
      • USA - Lucia Berlin
      • USA - Grace Paley
      • England - Angela Carter
      • USA - Kurt Vonnegut
      • Spain-Merce Rodoreda
      • Israel - Ruth Calderon
      • Israel - Etgar Keret
  • Posts
  • Blogs and Talks

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
  • Wait, But Why?
  • A Sound Vocabulary
  • References
  • Resources
    • Other tools to explore
  1. Teaching
  2. Math Models for Creative Coders
  3. Media
  4. Fourier Series

Fourier Series

Euler Formula
Fourier Series
Harmonics
Published

May 2, 2024

Modified

May 18, 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 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 aj, 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 aj, 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:

coeff for sin(ωc∗t)=Average Product(sin(ωc∗t)∗target.waveform)

(1)=1Waveform Period∗∫0Waveform Periodsin(ωc∗t)∗target.waveform∗dt

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.

1Waveform Period∗∫sin(m∗ωc∗t)∗sin(n∗ωc∗t)∗dt=0 (2)where m and n are multiples of some base frequency

Note

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:

(3)Base Frequency=1Period of Target Waveform

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 fc=1T using Equation 3.
  2. Take say M integer multiples of this base frequency (n=1.....M) and create sine 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.
  4. Write the Fourier Series for the target waveform as:

target waveform∼∑i=1Mcorr(i)∗sin/cos(2π∗i∗fc∗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

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:

  1. Oscillation: Any periodic change in amplitude. https://natureofcode.com/oscillation/
  2. Sinusoid: A Sine Wave Oscillation, created typically with p5.Oscillator
  3. Waveform: A graph of amplitude vs time
  4. Frequency: The rate of the oscillation, in cycles per second. Look for a repeating pattern, and measure its time period. 1/time.period will give you frequency in Hertz(Hz)
  5. Amplitude: The height, or scaling factor of the oscillation. Easiest to decipher for a simple repeating pattern like sine, square, or triangle.
  6. 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.
  7. Harmonic: A (usually) Sine Oscillation that is at some integer multiple frequency of a reference Sine Oscillation. 2X = octave; 10X = decade.
  8. In-harmonic: TBW
  9. Partials: TBW
  10. Transient: TBW
  11. Alias: TBW

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

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
R Package Citations
Package Version Citation
ambient 1.0.2 Pedersen and Peck (2022)
mosaicCalc 0.6.4 Kaplan, Pruim, and Horton (2024)
plot3D 1.4.1 Soetaert (2024)
Kaplan, Daniel T., Randall Pruim, and Nicholas J. Horton. 2024. mosaicCalc: R-Language Based Calculus Operations for Teaching. https://CRAN.R-project.org/package=mosaicCalc.
Pedersen, Thomas Lin, and Jordan Peck. 2022. ambient: A Generator of Multidimensional Noise. https://CRAN.R-project.org/package=ambient.
Soetaert, Karline. 2024. plot3D: Plotting Multi-Dimensional Data. https://CRAN.R-project.org/package=plot3D.
Back to top

Citation

BibTeX 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}
}
For attribution, please cite this work as:
“Fourier Series.” 2024. May 2, 2024. https://av-quarto.netlify.app/content/courses/MathModelsDesign/Modules/35-Media/10-FourierSeries/.
Media
Additive Sound Synthesis

License: CC BY-SA 2.0

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

Hosted by Netlify .