Digital Sound & Music: Concepts, Applications, & Science, Chapter 2, last updated 6/25/2013
34
Figure 2.36 Sawtooth wave
fplot('2*pulstran(t,[0:10],''tripuls'')-1',[0,10]);
Figure 2.37 Triangle wave
(Notice that the tripuls parameter is surrounded by two single quotes on each side.)
This section is intended only to introduce you to the basics of MATLAB for sound
manipulation, and we leave it to you to investigate the above commands further. MATLAB has
an extensive Help feature which gives you information on the built-in functions.
Each of the functions above can be created “from scratch” if you understand the nature of
the non-sinusoidal waves. The ideal square wave is constructed from an infinite sum of odd-
numbered harmonics of diminishing amplitude. More precisely, if

f
is the fundamental
frequency of the non-sinusoidal wave to be created, then a square wave is constructed by the
following infinite summation:
Let f be a fundamental frequency. Then a square wave created from this
fundamental frequency is defined by the infinite summation

Equation 2.9
Of course, we can‟t do an infinite summation in MATLAB, but we can observe how the graph of
the function becomes increasingly square as we add more terms in the summation. To create the
first four terms and plot the resulting sum, we can do
f1 = 'sin(2*pi*262*t) + sin(2*pi*262*3*t)/3 + sin(2*pi*262*5*t)/5 +
sin(2*pi*262*7*t)/7';
fplot(f1, [0 0.01 -1 1]);
This gives the wave in Figure 2.38.
0 5 10 15 20 25 30
-1
-0.5
0
0.5
1
0 1 2 3 4 5 6 7 8 9 10
-1
-0.5
0
0.5
1
Previous Page Next Page