ECEN 314: Matlab Project 1 Fourier Series Synthesizer: Due April 8th, 2013
ECEN 314: Matlab Project 1 Fourier Series Synthesizer: Due April 8th, 2013
1 Overview
In this project, you will develop a simple digital music synthesizer in Matlab. The continuous-time
Fourier series will be used to generate the waveforms and basic Matlab will be necessary to sequence
multiple notes. For more realistic sounding synthesis, one can extend this by introducing amplitude
envelopes.
Students may work by themselves or in pairs. When working on the project, please follow the
instructions and respond to each item listed. Your project grade is based on: (1) your Matlab scripts,
(2) your report (plots, wave files, explanations, etc. as required), and (3) your final results. The
project report should include all your scripts and all requested plots. It is often easier to combine these
using Microsoft Word or Powerpoint. For example, you can copy/paste figures from Matlab into these
applications. You must clearly display the associated problem number and label the axes and on your
plots to get full credit.
The following should be e-mailed (in a single e-mail) to the instructor and TA: the report in PDF
format, the wave file of generated by your synthesizer, and a zipfile containing all your Matlab code. The
subject line of the e-mail should be “314Project1-lastname1-lastname2” and the files should be named:
“lastname1_lastname2_report.pdf”, “lastname1_lastname2.wav”, and “lastname1_lastname2.zip”.
2 Exercises
2.1 A Signal Generator Based on CT Fourier Series
In many signal processing applications, it is necessary to generate a variety of periodic waveforms with
a programmable fundamental frequency. One way to accomplish this is by storing the Fourier series
coefficients of the desired waveforms. Let {ak } be the CT Fourier series coefficients of the desired
CT waveform. Suppose we would like to produce a DT signal x[n], sampled at fs = 8000 Hz, whose
fundamental frequency, f0 , ranges from 100 Hz to 1000 Hz. One solution would be to compute
K
X
x[n] = ak ejk(2πf0 /fs )n , (1)
k=−K
Let bk be the Fourier series coefficients of a periodic triangle wave with T = 1 defined, for |t| ≤ 12 , by
(
1 − 4t if t ≥ 0
x(t) =
1 + 4t otherwise.
Repeat the following steps using both a periodic square wave and a periodic triangle wave.
1
(a) Now, we will choose K = 19, fs = 8000, f0 = 210, and compute x[n] for n = 0, . . . , 2fs (i.e.,
2 seconds of signal). In Matlab, we choose K=19, fs=8000, f0=210, n=0:(2*fs). Then, we
compute the signal vector x using for-loop over k. The result can be played as a sound using
soundsc(real(x),fs). Describe how this waveform sounds.
(b) Now, repeat part (a) using f0 = 420 Hz. Describe how this waveform sounds. What is happening?
(c) Next, find a value of K where the synthesizer sounds good for f0 = 420 Hz. How should one choose
K as a function of f0 ? Why?
(f) There should be a main Matlab script named testsynth.m that generates and plays the synthesized
waveform.
Extra Credit
Add something new and interesting to your synthesizer. Generate a new .wav file using your improved
digital synthesizer. A few ideas are listed below. Honors students are required to choose one of the
below or implement their own idea.
A New Sound
Create your favorite synthesizer sound by choosing new Fourier series coefficients. The cooler it sounds
the better. For example, you could use a microphone to sample any periodic waveform (e.g., your voice)
and perform Fourier analysis on one period. To make this more robust, you can cut an integer number
of periods (e.g., 10) and multiply by a window function before performing analysis. Let x be M periods
of the signal you want to analyze and assume x has length N . Then, xw=x.*hamming(length(x)) will
give you a windowed version of the signal. Then, you can estimate the Fourier series coefficients of one
period with
XN
ak = x[n]e−j2πkM/N .
n=1
ADSR
A realistic synthesizer also shapes the amplitude envelope of each note. The standard shaping is based
on the physics of most instruments and is known as attack, decay, sustain, release (ADSR). Consider,
for example, a piano where the hammer striking the strings gives the attack, the decay is caused by
losses induced by large amplitude oscillations, the sustain is due to resonance between the strings and
the sounding board, and the release is caused by the felt returning to mute the strings when the key is
released. For a nice picture, see
http://en.wikipedia.org/wiki/ADSR_envelope
Pick an ADSR envelope (i.e., window function) for each note to get a more realistic sounding song.
For the attack try a linear ramp from 0 to 1 over 0.05 seconds. For the release, try a linear ramp from 1
to 0.8 over 0.1 seconds (an exponential decay over a longer time is more realistic). For the sustain, try
a constant level of 0.8 for the part of the note that is not attack, decay, or release. For the decay, try a
linear ramp from 0.8 to 0 over 0.05 seconds.
Multi-track
Let’s face it, you’re not going to impress too many people with “Mary had a little lamb”. So pick a
new song. If you’re musically inclined, try another song with two notes playing simultaneously (e.g., a
repetitive bass line with a melody above it).