>>  Lectures >>  Matlab 2

 Navigator

## 2.2 Introduction - Practial Foundation - Vectors

For a practical example using vectors, we will now look at a one dimensional data structure, namely sound. A sound wave is merely a collection of values that, when graphed in the x/y plane, exhibits a large number of sine waves at different heights (amplitudes) and different periods.

To load a wave sound file, we issue the command: authoritah=wavread('authoritah.wav'); Analogous to function imread, wavread returns the content of the wave file in terms of numbers. In the previous command, this vector of numbers is assigned to variable authoritah.

We can play back the sound file by issuing the command: wavplay(authoritah) . Note that the file is played back too fast, i.e. at a higher frequency than what the file was recorded in. To change the playback frequency, we merely pass the correct frequency to the function: wavplay(authoritah, 8000) . The sound file is now played back at frequency 8000 Hz = 8 KHz.

Just as we have evaluated the size of the image, we can find out the size of this sound file: size(authoritah) . This sound file is a data structure of size 16565*1, which essentially means that it is a vector with 16565 elements.

When plotting the wave form with plot(authoritah) , we can roughly make out words and syllables by the concentrated high amplitudes.

While multiplication of an image with a scalar resulted in a change in brightness/contrast, multiplication of a wave form with a scalar results in a change of amplitude (volume). Since the data type of the wave form vector is double, we need not convert it:

authoritahAmp = authoritah*4; wavplay(authoritahAmp, 8000);

We can extract portions of the wave form by indexing into the vector, e.g. the individual words:

wordYou=authoritah(1:2400); wordWill=authoritah(2000:4400); wordRespect=authoritah(4500:8000); wordMy=authoritah(8000:9000); wordAuthoritah=authoritah(9800: length(authoritah)); and then play and plot them, e.g.:

wavplay(wordAuthoritah, 8000); plot(wordAuthoritah);