I did a spectral analysis of recorded notes from a trumpet, a harmonica, a flute and clarinet, then used MATLAB to mathematically approximate the sound. On this page you will find power spectra, waveforms, and sounds. Please listen and compare the recorded sounds of actual instruments with my reproductions.
Exploration of Harmonics
Synthesis of Musical Sounds
Prepared for EE107: Projects in Music and Science.
Instructor: James Boyk
March 12, 2003
Why do different instruments produce distinctly different musical sounds? The answer is complicated, but simple mathematics can explain many of the differences we hear.
When we hear a musical note, we can describe the pitch, or frequency, of the note. For example, the A above middle C on the piano has a frequency of 440 Hz. A list of the frequencies of many notes can be found here. The note we hear is called the fundamental. If the note is a pure tone, it can be described mathematically with a cosine wave:
tone generated = A * cos(2 * pi * frequency * time)
However, unless the note is a pure tone, we also hear other frequencies at higher pitches. These are called harmonics. By changing the relative level of the harmonics, we can change the sound of the tone. Harmonics occur at integer multiples of the fundamental. Now the formula for the wave we hear looks like this:
tone generated = A1 * cos(2 * pi * f * t) + A2 * cos(2 * 2 * pi * f * t) + . . . + An * cos(n * 2 * pi * f * t)
Listen and compare:
A440 with equal amounts of fundamental and first four harmmonics
Here is how the waves look:
Additionally, we can change the phase of a note. This changes the formula to:
tone generated = A1 * cos(2 * pi * f * t + phase1) +
A2 * cos(2 * 2 * pi * f * t + phase2) +
. . . + An * cos(n * 2 * pi * f * t + phasen)
I did not explore the relationship of phase to the sound of a tone, but I did write a MATLAB script which you may use in your own explorations.
Another component of the sound is the envelope. The envelope determines the overall amplitude of the tone as it progresses. To mathematically apply an envelope, multiply your signal as generated above by the overall shape you would like your wave to have. Some listening samples involving envelopes are available in the results section.
First, I pleaded with my musician friends for a few minutes of their time to record some musical instrument sounds onto the MasterLink in the Music Lab. Then, I fed the audio out signal to the HP3567A FFT analyzer. I looked at both the power spectrum and envelope of several notes on each of four instruments: trumpet, harmonica, flute, and clarinet.
Sampling Instruments for Harmonics and Envelope
After obtaining measurements, I used the mathematical formulas described above to approximate the sounds in MATLAB. I wrote several short scripts to assist in this task:
Methods of Reproduction
notegennophase.m Script used to generate tones. User specifies frequency of fundamental and relative amplitude of harmonics.
notegen.m Script used to generate tones. User specifies frequency of fundamental, relative amplitude of harmonics, and phase of harmonics.
sinenvelope.m Script used to put a sine envelope on the first half of a function.
trumpet.m Script used to create a trumpet sound. Also contains several different envelopes, most of which do not sound trumpet-like.
harmonica.m Script used to create a harmonica sound. Also contains several different envelopes, most of which do not sound harmonica-like.
flute.m Script used to create a flute sound. Also contains several different envelopes, most of which do not sound flute-like.
clarinet.m Script used to create a clarinet sound. Also contains several different envelopes, most of which do not sound clarinet-like.
Click on a power spectrum to hear the sound that created it. The cursor is at the peak of the fundamental in all plots. Note that it may not be at the exact frequency because of where the actual sample points are located.
Power spectrum of a trumpet playing C261.
The waveform of an actual trumpet C261 note.
The waveform of the "trumpet" C261 note I created in MATLAB.
My recreation of the waveform of a trumpet is very close to the waveform of an actual trumpet note. The peaks are more pronounced in the graph of the recreated waveform, but this is probably a scaling issue. Notice that the sound of the waveform itself is not enough to create a trumpet sound, but does have a brassy quality.
The envelope of an actual trumpet C261 note.
The envelope of the "trumpet" C261 note I created in MATLAB.
The envelope I created puts a sine wave on the first half of the trumpet tone. I purposefully caused the abrupt drop in amplitude half way through the note becuase this contributes to a more realistic human-made sound. More appropriately placed abrupt changes of amplitude could help this sound even better. Here is what the final trumpet recreation sounds like.
Power spectrum of a harmonica playing F698.
Zoom of the first part of the power spectrum of a harmonica playing F698.
The waveform of an actual harmonica F698 note.
The waveform of the "harmonica" F698 note I created in MATLAB.
The harmonica has TONS of harmonics. If you compare the waveform of an actual harmonica note with my recreated "harmonica" note, you will notice they look completely different. This is probably because the script I used to generate the note only allowed me to include the fundamental and the first 10 harmonics. However, it is easy to identify 31 harmonics in the power spectrum of the actual note! Although most of these harmonics are much smaller than the fundamental on a linear scale plot, they nonetheless contribute greatly to the overall sound.
The envelope of an actual harmonica F698 note.
The envelope of the "harmonica" F698 note I created in MATLAB.
A comparison of the actual harmonica envelope and the envelope I created reveals them to be quite different. I did succeed in creating a wavy envelope, which helped the note sound much better than the note generated with no envelope. However, the sound is still not accurate enough to be identified as a harmonica.
Power spectrum of a flute playing G392.
Power spectrum of a flute playing D587.
The waveform of an actual flute D587 note.
The waveform of the "flute" D587 note I created in MATLAB.
It was very difficult to see the harmonics of a flute on a linear scale plot of the spectrum. I had to magnify some of the peaks 1000 times in order to obtain linear values to use for the first three harmonics! Some of the higher harmonics may have played a role in creating the blip on the right side of each period in the actual waveform. This blip is not noticeable in the waveform of the mathematically created waveform. Notice how much is sounds like a pure sine tone.
The envelope of an actual flute D587 note.
The envelope of the "flute" D587 note I created in MATLAB.
A flute envelope varies a lot with time. It appears to be almost a sine wave that tapers off on either end of the note. I tried to recreate this, but had trouble with the tapering off part. If you look closely at the top of the end half of my envelope, you can see the sine wave shape running along the edge. You can also hear the sine wave in the wavering of the note. My roommate thinks this "flute" sound is more like a recorder. This makes sense, since I have been told that a recorder produces a waveform that is purely a sine wave.
Power spectrum of a clarinet playing Bb233.
Power spectrum of a clarinet playing A440.
The waveform of an actual clarinet A440 note.
The waveform of the "clarinet" A440 note I created in MATLAB.
The actual waveform and my recreated waveform look similar. They are on different scales, so this might be difficult to see. However, if you look closely at the recreated waveform, you can see the graph is bumpy in approximately the same locations as the bumps in the actual waveform.
The envelope of an actual clarinet A440 note.
The envelope of the "clarinet" A440 note I created in MATLAB.
The recreated envelope is very close to what the actual envelope would look like for a much shorter note. Can you imagine this mathematically reproduced sound as a shorter version of the note as played on an actual clarinet? The recreated sound without the envelope does not sound very much like a clarinet. This demonstrates how much we depend on the envelope of a tone to identify what instrument created it.
The human errors we are bound to make during play are not easily reproducible. These "errors" could possibly be introduced randomly to the generated tones to make them more believable, but that is beyond my MATLAB abilities. Additionally, if the random "errors" introduced were not done just right, the result could easily be a sound that the instrument being "played" would never be able to produce! For instance, listen to this sound that I produced with the waveform of a clarinet, and an envelope I was experimenting with. I think it sounds like a cross between a harmonica and a train whistle. I tried applying the same envelope to the harmonica waveform with disastrous results. Separating the envelope and waveform of a tone is tricky.
Other Interesting Stuff
Given more time, it would be interesting to explore how the phase of a harmonic affects the sound. It would also be interesting to compare the relative harmonics of instruments by family of instrument (i.e. woodwinds vs. brass) to discover how similar harmonics are within a family. One more thing I would like to do is write a synthesizer computer program which allows the user to adjust the frequency, harmonics, phase, and envelope of a tone and immediately hear the results and see plots of the waveform and power spectra.
For the Future
References and Credits
Special thanks to Craig Countryman, David Hardee, and Evan Murphy for assistance with recording.
This page was created by Tasha Vanesian.
Send me e-mail!