Introduction: What Is Music? an Adventure in Math, Music and Computing.

About: I write software and do other stuff too.

This lecture serves as a standalone presentation for a curious audience as well as a motivating first lecture in a University 300 Level interdisciplinary class.

As a standalone presentation there is no prerequisite. As a university class basic calculus and introductory computer programming are assumed. This Instructable is formatted as a screenplay, to be rehearsed, tweaked, and polished by the instructor to ensure that every minute of the lecture is scripted and planned. The lecturer's speaking parts are in the standard font and actions and audience participation are denoted by italics.

The goal of this lesson is to inspire passion for studying the world and it offers a fun look at the intersection of math, music, physics, and software.

Supporting class materials are being continually updated here https://github.com/melvyniandrag/WhatIsMusic

Supplies

The tools used in this class are:

  1. A computer lab with a variety of software pre-installed on the machines.
  2. Several musical instruments ( guitar, ukulele, and piano provided by instructor )
  3. An Android device(s) with the Spectrum Spectrogram Analyzer and GuitarTuna apps, both available on the Play Store.
  4. A particularly loud fan I have that makes a very particular sound
  5. A tape measure
  6. A standard guitar tuner
  7. A projector of some sort for the android device

Step 1: Introduction

Turn on the spectrum analyzer app. Project analyzer to a large screen.

What is music? Over the course of the next few hours we'll learn a little bit about the math and physics underlying music. I'll play you a little piece of music and allow you to look at the graph up here on the screen to see the sounds you're hearing in graphical form.

Play a pretty little piece of music to lighten the mood in the class and win the affection of the classroom.


Step 2: A First Look at a Musical Spectrogram

What you saw on the screen here were the frequencies of the various sounds I'm making with the guitar. Right now you see some random spikes, which is just the background noise in the room. As I talk you'll see some spikes in a particular region here on the graph indicating the frequencies generated by my voice. If I can get the ladies in the class to shout "What is music?" on the count of three . . . one . . . two . . . three

Ladies shout. Repeat as necessary until the shout produces a good wave form we'll see some big spikes a little bit to the left of the spikes generated by my voice as the sound is a bit higher pitched.

And just for a laugh I'll show you the sound produced by this obnoxious fan I had blowing in my apartment while I was preparing this lecture:

Turn on fan and see the huge spike from the fan in the spectrum analyzer

Now this is important and this maybe the takeaway from this lecture for some people! - the fan spike is one large spike in the graph, the guitar diddy I played created a bunch of big spikes and all the shouting and background noise have create a bunch of random spikes. The motor in the fan is spinning at a fixed rate and generating a particular humming sound at a particular frequency, hence this app creates a particular spike. You may have noticed that while I played the guitar there were a bunch of distinct peaks in the spectrogram, corresponding to the loud sounds the guitar made.

I encourage you all to talk now, start talking to your neighbor! Talk about your major, your family, your car, your pet, whatever.

Wait for noise in room.

Now you will see random spikes on the graph from the random noises of all your voices. For the duration of this lecture we will look at music not as a pleasing auditory stimulus, but as a series of well defined spikes on these graphs. From now on we won't care about rock or rap or lambada, but we'll just see what physical frequencies are being generated by the sounds of music. A note ( or a pitch, we'll nail down these terms more precisely later ) is particular frequency that has been given a certain name for a number of physical and historical reasons.

Step 3: Spectrograms, Scales, and Instrument Layouts

In western music there are 12 notes ( A, A#, B, C, C#, D, D#, E, F, F#, G, G# ) that are repeated across octaves. We can plainly see that each of these notes creates a different spike on our graph. For reference now I'll just tell you that the black keys are "flat" notes and the white keys are not-flat-notes. You'll see:

Walk up the keyboard showing A (white key), A# ( black key ) . . . etc.. Walk up the keyboard again, this time showing how the spikes change on the spectrum analyzer each time a different key is pressed.

These notes are also plainly and obviously listed on guitar with the frets:

Play a chromatic scale on the guitar, saying aloud the note as it is fretted on the guitar, and again calling attention to how the spikes move in the spectrum graph as the note is changed. While dictating this next paragraph, demonstrate ideas clearly with the indicated instrument:

Just as a technical curiosity for those who didn't know this yet - the guitar frets and piano keys are laid out in the same way. On the piano, you'll notice there are black keys between some of the white keys - those are the flats. So there is a black key between the white A and B keys, but no black key between the B and C white keys. The guitar is the same way. This second string from the top on the guitar is an A string. The first fret is an A#. The second fret is a B. The third fret is a C! There is no space between B and C on the guitar, but there is a space between A and B. The same as the piano. This is not particularly important to our lesson, but it is an interesting thing to know that may prompt you to get an instrument and play with it after this talk is over.

I've been using the word "frequency" a bit without defining it. A frequency - the spikes we see in the graph - are a measurement of how fast a sound wave perturbs the air in the room. Imagine sitting out on the ocean feeling waves rock your boat. You would be able to feel a high frequency wave if your boat undulated up and down rapidly, or if it slowly rose and gently fell with gentle waves. Sound waves are like that, but they cause the air in the room to move and your ear and brain ( talk to a biologist for more details here ) detect the frequency of the stimulus. As we use inches for length and pounds for weight, we use Hertz to measure frequency. Hertz represent the number of oscillations per second. If your ear is hit once per second by a wave, that is a frequency of 1Hz. If your ear is hit 440 times per second by sound waves, we would say that sound had a frequency of 440Hz.

Step 4: The 440Hz Oscillation Aka A4

The oscillation at 440Hz is referred to ( as I mentioned before, for historical and physical reasons ) as an A. An A4 to be more precise. Now I'll show you that this is accepted all over the world as an A4 in the following way: I'll tune my ukulele with this spectrum analyzer and then show you that commercial tuner (that doesn't tell me frequencies, but letter names) will agree that I am playing an A4. This string here on the bottom of my ukulele should play an A4 when the uke is in standard tuning ( I can tighten and loosen the strings to get different tunings, but this is the standard, commonly used tuning ). So lets tune it until we get an A4.

Detune the string and then ask for audience participation as we get the right frequency

Good so now we have the string generating the proper frequency. Now lets look at the Guitartuna app and this off the shelf tuner I have.

Have a student click "A4" in the GuitarTuna app ukulele tuner, pick the string I tuned, and verify that the note is an A4.

This is how tuning apps work, they analyze the frequency generated by the instrument and then they tell you what note you've played. Now, I can play an A4 on a variety of instruments and make the tuners happy, because all of these instruments are generating a 440Hz sound wave!

Have a student play an A4 on my tuned guitar. Verify it checks out with guitar tuna. Then have another student hit the A4 key on a piano while holding the android phone close and verify that it says that the note is an A4.

The tuner says that the piano and guitar are in tune, even though we used a ukulele tuner! So we see that all of these instruments can generate a 440Hz vibration! To recap: We verified that the app thinks an A4 is a 440Hz vibration, then we checked that other instruments could make a 440Hz vibration.

Step 5: The 220Hz Oscillation Aka A3

Now for completeness, I'll introduce one more idea. The notes we talked about ( A, A#, B, C, ... ) repeat in octaves. It becomes obvious that they repeat when we look at the keyboard.

Walk down the keyboard from A to G and then ask the students what comes after the G? Then walk down the Ukulele from A to G and ask the same question.

We've said that A in the 4th octave resonates at 440Hz. I'll give you some physics to back up the idea in a moment, but know that we get to other octaves by multiplying or diving a frequency by 2. To get an A3 ( 220Hz ), we divide the A4 frequency in half. To get an A2 we divide 220Hz in half and get (audience participation). Similarly, an A5 resonates at twice the frequency of an A4, which is 440Hz, so A5 resonates at ( audience participation). So now we'll look at a variety of A notes on a guitar. I think I've already demonstrated that I can use my guitar, or piano, or Ukulele for this demonstration. I'm just using the guitar from here on out for the majority of our experiments because I like it best.

Check out A2 on both the first and second strings using the frequency analyzer

Now there's a cool bit of trivia for the non-guitar players in the room. I'm a novice player still and when, in the not too distant past, I learned that the same pitch could be produced on different strings that really blew my mind. In any event, lets find the A3, A4 and A5 on this guitar. The guitar is in tune now, we don't have time to tune it right now, so just trust me that all the strings are in tune.

Make sure the spectrogram app is being projected on a big screen. Request a student with strong hands come forward and hold the strings down on the guitar. Have the student finger A3, A4 and A5. There will be a laugh in the class as the student says that his or her fingers hurt holding down the string. Have audience confirm the frequencies produced by the strings agree with the doubling and halving math we just did.

So we see that we can produce the note "A" at different frequencies on the guitar. But note that the A2, A3, A4 and A5 all sound different. And yet they are all called A! Now my own ignorance is at play here - I don't know if the musicians all those years ago when they were nailing down what sound was an A, and what was a B and so forth - I don't know if those musicians had some sort of primitive frequency analyzers they used. We are learning about notes now with the help of a smart phone app. There certainly weren't Android phones a hundred or two hundred years ago. In addition, my ears aren't very pitch-sensitive as I'm not much of a musician. But at least when I do signal processing on the various notes, a pattern emerges that reveals why different notes that sound different are referred by a common name. Let's have a look at the pattern.

Step 6: Overtones and the Relationships Between Notes

By this point we have noticed that the guitar strings generate multiple resonant frequencies. The open A string on the guitar plays an A2 - with a fundamental frequency of 110Hz - but we saw spikes around 110, 220, 330, 440, 550, 660, 770 and 880 - this is the result of "overtones" which are harmonic frequencies that resonate along with the fundamental frequency generated by the string. When we pluck a string, we give energy to a variety of frequencies due to the physical properties of the string. This A string will oscillate at a variety of frequencies associated with the 110Hz frequency. In the list of these overtones is 220Hz ( an A3 ) and 440Hz ( an A4 ) so we see that on some level an A2, A3, A4, etc. all sound somewhat the same because they are resonating at many, though not all, of the same frequencies. A B2, for example, does not sound like any of the A's because it oscillates at ~123Hz, 246Hz, etc.. The overtones of the Bs you play are also going to be different from the A overtones. Just to make sure what I've just said is clear, I'll repeat it and then we'll do an exercise.

To go up an octave you multiply by two. To go down an octave you divide by two. The overtones of a note will be natural number multiples of the fundamental frequency. As such, you will hear a bit of an A4 in an A3, because one of the overtones of A3 is 220Hz * 2 = 440Hz. = A4. A3 is NOT an overtone of A4, however, as 220Hz is not a multiple (n >1 ) of 440 Hz.

Invite a student up. Tell him where to finger the guitar. Instruct the class to navigate to here: http://www.poly-ed.com/source-code/note-frequency-... and guess the notes being played. Have the students see that A3 and A4 have some common frequencies, but B2 and A have none.

I've seen alot of videos on youtube where people put a high speed camera inside their guitars to record the undulations of the strings. I'll just show you a clip right now to make sure you understand what we mean when we talk about waves on guitar strings. The strings are actually undulating like ocean waves!

Show a few seconds of this video from about 1:10 of The "The Last of Us" cover on Youtube on the AcousticTrench channel.

Step 7: Guitar Harmonics

We've discussed overtones a bit so far, but now I want to show you how they look. The fundamental frequency of the string vibrates up and down, with nodes only at the nut and bridge of the guitar. Signal and point out the nut and bridge of the guitar. The fundamental frequency will then have a big lump here in the middle and be held by the ends. Show a graph of the fundamental frequency sine wave ( in the images folder of the git repo). The first overtone will have a frequency twice as fast as that of the fundamental, and will have twice as many bumps, so it should have bumps here and here and have fixed points here and here

gesticulate as appropriate to indicate the nodes and antinodes on the fretboard. Show a graphical image of the vibrating string. Show the animated gif from the images folder of the git repo.

Similarly, the second overtone ( in the case of the A string, this is the string oscillating at 3*110Hz ) will have not one, not two, but three lumps and four fixed points.

Show the graph and the animation.

With this bit of information we can do some cool stuff on the guitar. First we'll take some measurements. I need you to tell me which frets are a half, a third, and a fourth way up the fretboard.

Hand out tape measures, guitars and ukuleles to small groups of students and allow them to figure out which frets are at the half, quarter and third positions ( the answer is the 12th, 5th, and 7th respectively).

The first harmonic oscillates with a peak on the middle of the string. The nodes of the other frequencies are at other places in the string. The A string oscillates with a fundamental frequency of 110Hz. We can eliminate that frequency by damping out that part of the wave. If we lightly place a finger here on the guitar at the halfway point on the fretboard - which is at the 12th fret - we will prevent the fundamental frequency from oscillating.

Show how if I put a finger there on the fretboard the guitar sounds pretty and chimey. This should impress the audience. Then turn attention to the spectrogram. See that the fundamental oscillation is gone! Show the graph again of how the different overtone waveforms look to emphasize that the fundamental frequency is gone now because it cannot oscillate there. the peak cannot move up and down.

Now I challenge you to take the idea a bit further. Lets look at the A2 spectrogram again. Also, on your computers, you can see the various overtone waveforms I generated with Python scripts. The waveform images are in the images/ directory of the class git repo. Looking at those wave forms and knowing what we know now - which overtones ( besides the fundamental frequency ) willl be eliminated by fretting the A string lightly at the 12th fret? We already saw that we could eliminate the 110 Hz oscillation by lightly touching the string. The question now ( to reiterate ) is "which other oscillations are removed by touching lightly on the A string above the 12th fret?".

All time for discussion, then show the spectrogram again while playing with the 12th fret lightly touched. The students will see that the frequencies they guessed are gone ( this is a continuation of the previous exercise where we just focused on the fundamental frequency being damped out ).

Step 8: More Experiments With Guitar Harmonics

Lets do an experiment. I've had you measure the fretboad to find the locations 1/4 and 1/3's way up the fretboard. Now in your groups I want you to make a conjecture. I want you all to work in your group, take a few minutes to conjecture which frequencies will be gone from the spectrogram if we lightly tap the frets 1/4 and 1/3 up the neck. Have a look at the wave form graphs in the images directory of the class git repo to see the different waveforms.

Wait 2 minutes - not much longer, this can be boring if drawn out - and then proceed.

Okay so now I'll play these guitar harmonics on my guitar so you all can see the spectrogram.

Play the 5th fret harmonic and the 7th fret harmonic. Poll the class to see who got it right!

You can do this harmonic stuff on any string. I'll just show you really quick that you can do this all over the fretboard, and even with a capo.

Show harmonics on 5th, 7th and 12th frets for all strings. Then turn back to audience and secretly capo the fifth fret. The spectrogram is still visible to everyone. Pluck the high E string and challenge the class to identify the note. Then play the harmonics on it. Hopefully they all recognize it as an A4. Hopefully they see the overtones removed by harmonics.

Guitarists exploit this technique of damping out particular frequencies to great effect. You will hear harmonics being played in music all the time. Van Halen and Steve Vai are two very famous guitarrists who use alot of harmonics in their playing. Now in the future you can sound super educated if you happen to be out with your musical friends - if you hear a chimey sound on the guitar you can make a snooty remark about the guitarrists great use of harmonics! Here is a piece that serves up harmonics as the main course:

Play a small sample of Alan Gogoll Bell's Harmonic, which can be found on youtube.

Step 9: A Python Programming Interlude

This part of the lesson is very challenging if the class has no familiarity with programming. The idea is I just want them to look at some code that has the sine function in it, type a few things in to feel like they've done something interesting, and then run the code, seeing that it generates results relevant to our class. This part of the lecture is mainly to stimulate curiosity. If it inspires more fear than hunger, eliminate it.

Up to this point I have showed you some graphs that illustrate the wave forms of various overtones. I'd like us to just get our feet wet programming a bit. If you have a look in the code folder in the class git repo you will find a python script called ( subject to change: plotOvertones.py ).

For the sake of the non-mathematical members of our audience I am trying to avoid getting too technical in this presentation, but I think it is worth noting that the wave forms on the guitar strings are sinusoids. The waveforms can be plotted with sine functions, that is. If you look in the provided script you will see that I've provided code that plots the first few overtones using some computations involving the sine function - now I invite you to extend the code to plot the next few. I recommend that you pair up with a friend who knows how to program so you all can generate these plots. We've already done some cool hands on activities by fretting the guitar in the right places and seeing how the sound changes - this is now your opportunity to bring the computer in to help you a bit.

Offer instructions for running the programs, probably using the command line and typing

python plotOvertones.py

and using sublime or Notepad++ to edit the program. Show the class how to add one overtone and then allow them to add one or two by themselves.

As I mentioned, we don't have time to go too deep into the mathematics or the computer programming right now. I hope that for at least one of you in this class this was your first computer program! You will see that computers are useful instruments for math and science. If you aren't already adept at it, I recommend you put some time towards getting better at math and software development.

Step 10: Timbre. Or, What Makes Instruments Special.

We've seen how we can get a variety of strange sounds out of our guitar by playing with damping out overtones on the strings. Now here's a related juicy detail about music. A short while ago we saw that that a Ukulele, a Piano, and a Guitar can all be tuned using the same tool. And yet, they sound different! If you've never had this thought before, I would think that this is very interesting to you! All of these instruments can create the same notes, but the notes sound different on each one! When I first had this thought it was before I knew much about software or playing music and I immediately knew I had to understand why!

The reason behind this is that different instruments have different amplitudes for their resonant frequencies due to a variety of reasons, e.g. the material they are made of, the shape of the instrument, etc.. Different instruments can create the same fundamental frequency, but the strength of that frequency, the strengths of the overtones it produces, and whatever additional noises it might make, will be different. The musical word that accounts for these different sounds is "timbre".

Step 11: Generating a Pure Tone

Here is an interesting aside. For the most part I've said what needed to be said, but this is interesting. In nature you will find few pure tones. Even our instruments - tools designed to generate particular sounds - are generally not good at producing pure tones. By pure tones, I mean a pure note, for example a pure 440Hz frequency for an A4. Computers, on the other hand, are generally good at making pure tones. There is another Python script here I encourage you all to run right now to generate a pure tone.

You can open the code folder in the git repo and run the makeTone.py script. As you will hear, pure tones are rather unpleasant. Feel free to open the repo and change the frequency of the tone in the script and play it again. I'll play the tone up here so you can see it generates a single large spike.

Allow a few minutes for audience experimentation.

Computerized musical instruments like synthesizers are able to emulate the sounds of other instruments by generating a number of pure tones simultaneously that match the overtones generated by the instrument in question. We can have a look at this 99 dollar keyboard I have, for example.

Change the instrument setting on the keyboard to replicate a number of different instruments.

As you can see not all instrument emulators do a very good job! But that's the idea. If you buy a more expensive keyboard, download a few hundred dollars of computer software onto your PC, or write some complex computer code of your own, you can get more faithful instrument representations.

One last detail is that cicadas have been shown to generate pure frequencies! I saw an interesting article on this and I've linked it in the references section of the lecture notes. There aren't many pure frequencies in nature, and it's interesting that these bugs can generate them.

Step 12: Class Assignment 1: Classify Instrument by Waveform.

Please refer to the spectrograms in the classAssignment01/ directory of the github repo. You will find two images. One is from my piano, the other from my ukulele. I'm going to play an E4 on my Ukulule and an E4 on my keyboard. Your job is to guess if image01.png is piano or ukulele. Then I'll play a G4 on both instruments and your job is to guess which instrument the image02.png represents.

Do the exercise with the class.

Step 13: Class Assignment 2: Comparing the Same Note on Different Strings.

As I mentioned before, you can play the same note on different strings on a guitar. This is great, because it facilitates playing chords more easily! Sometimes you may have all your fingers one one part of the neck, but want to play a a certain note which is far away. Look around, because the note might reappear closer to your hand, but on a different string. That's one of the great parts of playing guitar.

Give an example with a chord shape that relies on a note being moved to a different location.

This is also how you tune a guitar. You will put one string in tune, then adjust the other string until it plays the same note. For example, tuning the A string by comparing it to the 5th fret on the low E string.

Show how this is done. The class will agree that the two strings sound the same.

Now we've spent this whole class looking deep into the waveforms of different strings. In the class assignments folder I've given you some images of the spectrograms of these different A2s, one played on the low E string, one played on the A string. I want you to look and see if they are actually the same.

Later in this class we will learn how to do a more rigorous mathematical analysis of the spectrograms, and we will write some computer programs to measure how similar they are. For now, we are doing it by eye.

Step 14: This Ain't Kentucky: Sturm-Liouville, Not Strumming Louisville.

I hope to have whet your appetite for understanding the math and science behind music. Later in this semester we will look at a very important equation called the wave equation. We'll look at how to solve this equation and how it relates to a guitar to see if we can find out why the guitar makes the sweet sounds it does. We will develop pen-and-paper as well as computer based solutions to this equation.

Step 15: Later This Semester: the Most Important Algorithm of Our Time

For the second half of our semester we will delve into what has been called "The Most Important Algorithm of Our Time". The spectrum analyzer app we've been using in this class to measure the frequencies in the music we've been making uses this very special algorithm. The algorithm is called the Fast Fourier Transform and it's an interesting bit of mathematics that determines the frequencies in a periodic signal. The FFT listens to a signal and decomposes it into frequencies - in our case we've extracted specific pitches from music played into a microphone.

We'll be using a very gentle book called "Who Is Fourier" that was written by non-mathematicians to learn about this algorithm. Then we'll implement our own as an Android application and check out it's performance.

Step 16: References

I'm a novice musician, an amateur mathematician, and a professional computer programmer. I've had to resort to many references on the internet while preparing this presentation, and if this presentation has awoken something in your heart, you should check out some of these great references that I've used.

Pure Tone Pitch in Cicadas: https://link.springer.com/article/10.1007/BF006111...

FFT: https://en.wikipedia.org/wiki/Fast_Fourier_transfo...

Sturm-Liouville: http://mathworld.wolfram.com/Sturm-LiouvilleEquati...

Why do harmonics happen?: https://music.stackexchange.com/questions/5489/why...

Vibrational Modes: https://en.wikipedia.org/wiki/Normal_mode

Mathematics, Music and Guitar: http://jwilson.coe.uga.edu/EMAT6450/Class%20Projec...

Guitar Mathematics: http://passyworldofmathematics.com/guitar-mathemat...

String harmonics: https://en.wikipedia.org/wiki/String_harmonic

Strings, standing waves, and harmonics: https://newt.phys.unsw.edu.au/jw/strings.html

Classroom Science Contest

Participated in the
Classroom Science Contest