Sie sind auf Seite 1von 5

Week 2 Fourier Series: The Math Behind the Music

Introduction:
This lab has two parts. In the last lab you learned how to approximate Fourier series coefficients
using Matlab. This will allow you to find the Fourier series for any periodic signal even if it does
not have a form that can be represented in an equation. The second part will cover how to
create a music synthesizer. You will submit a separate lab report for each part of the lab.

You have been working at Electronics Team Gurus (ETG) for several years, but they just
transferred you to the Audio Engineering Department to work on a new synthesizer. Music
synthesizers use a variety of techniques. A simple approach to music synthesis is to record the
sounds of actual musical instruments and play them back at variable speeds to produce the
desired pitches, called wavetable synthesis. Another simple approach is to filter basic signals
like square waves or sawtooth waves to achieve a desired effect, called subtractive synthesis.
Another approach (that requires more circuitry if implemented with analog electronics) is to
produce each harmonic of a note separately and add these sinusoids together, called additive
synthesis. We will be performing additive synthesis in this project.

Learning Goals:
● Define the musical concepts of pitch and timbre.
● Learn how to synthesize signals using Fourier Series Coefficients from music samples.

Lab Goal:
● Use Fourier Series to make a simple musical synthesizer using Fourier Series
coefficients to approximate different instruments.

Music Synthesizers Prelab:


Every wonder why two musical instruments playing the same note can sound so drastically
different? Each musical note corresponds to a frequency. So, if two instruments are playing the
same note, then their sounds waves are oscillating to the same fundamental frequency. The
reason they sound so different is due to the varying amplitude and phase of the harmonics
between the two instruments. The difference in sound is called the “timbre” of an instrument.
Timbre is a musical quality of an instrument that differs from both pitch and intensity. Pitch
refers to the frequency of the sound wave and intensity refers to the amplitude. Timbre refers to
the harmonic content of a sound wave and can be used to tell the difference between two
instruments.

The diagram below demonstrates the differences between a few instruments. Each of them has
the same frequency and amplitude, but the timbre is different. Notice how there are other
frequencies in the signal other than the fundamental one. These are often referred to as
harmonics, which are positive integer multiples of the fundamental frequency. The first
harmonic, or fundamental frequency, corresponds to the note that is being played, so the
harmonic needs to be easily heard when trying to match pitch or tune an instrument. Musicians
often listen to another instrument to tune their own. After the values for phase and amplitude of
each harmonic 𝑎" have been found, an approximated signal can be reconstructed (synthesized)
using the Fourier approximation.

Figure 1. Examples of different timbres (image from https://www.simplifyingtheory.com/timbre/).

Pitch Detection: Pitch is the rate of vibrations of a musical wave, or in other words the
frequency of the note as it travels through air. Therefore, pitch and frequency can be used
almost interchangeably. There is a specific pitch/frequency for every defined musical note. Pitch
is difficult to figure out in many musical instruments as musical signals are time varying and
notes are usually modulated when they are played. In this lab, we use the built-in Matlab
routine, pitch to detect the dominant pitch across a musical file.

Musical Notes: At the end of the lab, you will need to create a scale using the best sounding
instrument synthesis. The frequencies for the notes are given in the table below and are related
logarithmically to one another in the middle octave as: f note = 440 ⋅ 2 n/12 where n is the number
of steps between the notes.
Musical Experiment (week 2):

Goal:
As a new Audio Engineer at Electronic Team Guru, your supervisor has tasked you with
creating a new synthesizer. As a newly empowered Audio Engineer, your goal is to sample an
instrument and then make it playable at different pitches using Fourier Series. The value of 𝑎#
can be omitted because the DC offset of a signal is filtered out by the speakers. DC offsets in
music cannot be heard and are ignored by setting it to 0 during reconstruction.

Lab Description
Part 1: Finding pitch and recreating notes. A library of sound samples of single instruments
being played is provided for your convenience. You may use any file that you would like. Just be
sure to put it in a .wav file format. We are continuing to collect sound samples and look forward
to receiving more from the talented ECpE students at ISU! Once a .wav or .aif file has been
found, use the audioinfo command to find the sampling frequency, fs. Make a note of this
information and compute how many samples to expect at the fundamental frequency of the
instrument. Some of the samples are in stereo, so you will need to create a mono (single-
channel signal) by just keeping one row of the signal: newaudio = audioIn(:,1);.

After you have a sampled instrument in the form of an audio file, you will need to find areas of
constant pitch in the signal. PlotPitch will plot the instrument’s time signal on top and the “pitch”
at which the instrument is playing on the bottom. Please note that PlotPitch requires the Audio
Toolbox in Matlab v2019 or higher. Pitch is the rate of vibrations of a musical wave, or in other
words the frequency of the note as it travels through air. Therefore, pitch and frequency can be
used almost interchangeably. There is a specific pitch/frequency for every defined musical note.
The pitch on the bottom of the plot is measured in hertz. A higher pitch/frequency will have a
higher note. Consequently, low bass notes have a lower pitch/frequency. The plot below comes
from a synthesized version of a trumpet, trumpet.wav.
Find a range of samples such that the pitch is constant and use the data cursor function to get
the sample value and the pitch value. Zoom in on the top graph to look at a single period of the
signal. Make sure that it is at least one period of samples on screen. You will need to know the
starting point and the number of samples in a single period for the next step, which will show
you how to use the cursor tool to find a sample number.

Once these have been found you can use CutSample to cut out one period of the signal
CutSample takes an input of a row vector x, the signal, the starting point of the cut and the
number of samples to use. Then it returns a row vector of samples that are cut from start to
(start + samples).

Lab Exercises:
1. Select three different sound files from the directory. Read in the files and find their pitch and
give the starting point and number of samples in your cut part of the signal. Fill in the table
below for each signal and include it in your lab report.
Signal File Name Fs Pitch Starting Number of
# Frequency sample of cut Samples
1
2
3

2. Plot each piece of “cut” signal on a plot with three subplots stacked vertically. Comment on
how the signals differ from each other in shape.

3. Use the functions from week 1 of this lab to estimate the Fourier coefficients, a_ks for each
instrument. Plot the magnitude and phase for the coefficients ranging from -21 to +21. Which
instrument would be best for tuning an orchestra? (hint: compare the magnitude of 𝑎$ to that of
the other positive harmonics). Turn in the frequency coefficient plots.

4. Now, use fsynt to recreate the sound of the signal. Plot this synthesized signal alongside the
original cut of samples and comment on the differences/similarities. Is the approximation good?
Also, create 2 second-long files of each instrument and include them in your report. Comment
on how closely they represent the instrument sound.

Part 2: In this section you will need to put all the pieces together to create a simple synthesized
scale using the frequency table from the pre-lab. Each note should last 1 second and the half
notes (A#, etc.) should last 0.5 seconds. Choose the synthesized instrument that you liked the
best, this only needs to be done for one instrument. Include your code and a wav file playing the
scale.

For extra credit, adapt the system so that you can play chords (multiple notes at once).

References:

1. See Wikipedia, Pitch, https://en.wikipedia/wiki/Pitch (as of Mar. 8, 2020).

Sound Samples and Sources:

1. Guitar notes: Weston Yohe, ISU EE student, March 9, 2020.

2. Bass guitar notes: Jacob Miller with audio engineer Long Yu, ISU EE students, March 13,
2020.

3. Assorted instruments, SampleSwap.org, downloaded 2/18/2020.

Das könnte Ihnen auch gefallen