Digital Sound & Music: Concepts, Applications, & Science, Chapter 2, last updated 6/25/2013
fplot('-sum((sin(2*pi*262*([1:100])*t)./([1:100])))',[0 0.005 -2 2])
The triangle wave is an infinite sum of odd-numbered harmonics that alternate in their signs, as
Let f be a fundamental frequency. Then a triangle wave created from this
fundamental frequency is defined by the infinite summation
( ) ( )
Equation 2.11
is a scaling factor to ensure that the result of the summation is in the range of 1 to 1.
We leave the creation of the triangle wave as a MATLAB exercise.
If you actually want to hear one of these waves, you can generate the
array of audio samples with
s = 1;
sr = 44100;
t = linspace(0, s, sr*s);
y = sawtooth(262*2*pi*t);
and then play the wave with
wavplay(y, sr);
It's informative to create and listen to square, sawtooth, and triangle waves of various
amplitudes and frequencies. This gives you some insight into how these waves can be used in
sound synthesizers to mimic the sounds of various instruments. We'll cover this in more detail in
Chapter 6.
In this chapter, all our MATLAB examples are done by means of expressions that are
evaluated directly from MATLAB's command line. Another way to approach the problems is to
write programs in MATLAB's scripting language. We leave it to the reader to explore
MATLAB script programming, and we'll have examples in later chapters.
Chapter 5.
2.3.4 Reading and Writing WAV Files in MATLAB
In the previous sections, we generated sine waves to generate sound data and manipulate it in
various ways. This is useful for understanding basic concepts regarding sound. However, in
practice you have real-world sounds that have been captured and stored in digital form. Let‟s
look now at how we can read audio files in MATLAB and perform operations on them.
We've borrowed a short WAV file from Adobe Audition's demo files, reducing it to
mono rather than stereo. MATLAB's wavread function imports WAV files, as follows:
y = wavread('HornsE04Mono.wav');
Creating a
Triangle Wave
Previous Page Next Page