chapter thirteen

13 Analyzing sound waves with Fourier series

 

This chapter covers

  • Defining and playing sound waves with Python and PyGame
  • Turning mathematical functions called sinusoidal functions into playable musical notes
  • Combining two sounds by adding their sound waves as functions
  • Decomposing a sound wave function into its Fourier Series to see what musical notes it contains

For a lot of Part 2 we’ve focused on using calculus to simulate moving objects. In this chapter, I’ll show you a completely different application: working with audio data. Digital audio data is a computer representation of sound waves, which are repeating changes of pressure in the air that our ears perceive as sound. We’ll think of sound waves as functions which we can add and scale as vectors, and we can use integrals to understand what kinds of sounds they represent. As a result, our exploration of sound waves will combine a lot of what you’ve learned about both linear algebra and calculus.

13.1   Playing sound waves in Python

13.1.1   Producing our first sound

13.1.2   Playing a musical note

13.1.3   Exercises

13.2   Turning a sinusoidal wave into a sound

13.2.1   Making audio from sinusoidal functions

13.2.2   Changing the frequency of a sinusoid

13.2.3   Sampling and playing the sound wave

13.2.4   Exercises

13.3   Combining sound waves to make new ones

13.3.1   Adding sampled sound waves to build a chord

13.3.2   Picturing the sum of two sound waves

13.3.3   Building a linear combination of sinusoids

13.3.4   Building a familiar function with sinusoids

13.3.5   Exercises

13.4   Decomposing a sound wave into its Fourier Series

13.4.1   Finding vector components with an inner product

13.4.2   Defining an inner product for periodic functions

13.4.3   Writing a function to find Fourier coefficients

13.4.4   Finding the Fourier coefficients for the square wave

13.4.5   Fourier coefficients for other waveforms

13.4.6   Exercises

13.5   Summary