|
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.
|