Page 104 - A Guide to MATLAB for Beginners and Experienced Users
P. 104
Sound 85
Sound
You can use sound to generate sound on your computer (provided that your
computer is suitably equipped). Although, strictly speaking, sound is not a
graphics command, we have placed it in this chapter since we think of “sight”
and “sound” as being allied features. The command sound takes a vector, views
it as the waveform of a sound, and “plays” it. The length of the vector, divided by
8192, is the length of the sound in seconds. A “sinusoidal” vector corresponds
to a pure tone, and the frequency of the sinusoidal signal determines the pitch.
Thus the following example plays the motto from Beethoven’s 5th Symphony:
>> x=0:0.1*pi:250*pi; y=zeros(1,200); z=0:0.1*pi:1000*pi;
>> sound([sin(x),y,sin(x),y,sin(x),y,sin(z*4/5),y,...
sin(8/9*x),y,sin(8/9*x),y,sin(8/9*x),y,sin(z*3/4)]);
Note that the zero vector y in this example creates a very short pause between
successive notes.