Sei sulla pagina 1di 6

Exp # 6 Manipulation of Sound Signals – Part I

Objective:
1. To learn to how to read, play, and write sound signals (audio files) in
MATLAB.
2. To learn the how to plot sound signals in time and frequency domain.
3. Do exercises to practice manipulation of sound signals in MATLAB.
Notes:
v Solve all the exercises and submit a report containing each question followed
by MATLAB code , followed by result figure (s) if any.
v All exercises to be attempted during lab allocated time .

Introduction

Sound signals are the consequence of changing air pressure over time. These pressure
variances propagate as analog waves from a vibrating source (mouth in case of
humans is the source of the sound). When entering the sound signal into a computer
using microphone for example , it will be converted to discrete signal using Analog to
Digital converter, that's where MATLAB comes in handy, because now we can
represent and store the sound signals in vector or matrix format. MATLAB provides
basic commands to read (load) sound signals that will be treated as data vectors –
mostly column vectors -. Microsoft wave sound files (".wav") can be read using
MATLAB command ‘wavread’. After executing this command it will return the
samples of the sound file, its sampling frequency and the number of bits used per
sample. Sampling frequency plays a critical part when you listen to the signal using
the sound command of MATLAB. A similar command ‘wavwrite’ can write the data
from MATLAB to a wav file (".wav") that can be played later.

Lab Work :

Part I. Reading, Playing, and writing sound signals in MATLAB

§ Reading sound signals using ‘wavread’:

Multimedia Technology Lab Manual 1


The ‘wavread’ command read Microsoft wave (".wav") sound file. The syntax of the
command is: Y=wavread ('file_name') which reads a wave file specified by the
string 'file_name', returning the sampled data in Y. The ".wav" extension is appended
if no extension is given. Another syntax is [Y,FS,Nbits]= wavread ('file_name')
which returns the sample rate (FS) in Hertz and the number of bits per sample (Nbits)
used to encode the data in the file. The memory storage requirements for a sound file
can be computed using this formula: Memory_storage = length (Y) * Nbits / 8. Note
that if the formula to be used for stereo signals, length must be multiplied by 2.

§ Playing sound signals using ‘sound’ and ‘soundsc’:


In order to play an audio file within MATLAB, we can use ‘sound’ command.
‘sound’ plays Y vector as sound. The syntax of this command is: sound (Y,FS)
which sends the signal in vector Y (with sample frequency FS) out to the speaker .
Values in Y are assumed to be in the range -1.0 <= Y <= 1.0, values outside that
range are clipped. If FS is not provided ‘sound’ plays the sound at the default
sample rate of 8192 Hz ~ 8 KHz. Also it is possible to add the number of bits to be
used per sample in the command as follow: sound (Y,FS,BITS).
Another useful command used to play sound files is ‘soundsc’, it is used to prevent
clipping that may occur if the values in he audio signal are too large. ‘soundsc’
rescales the audio signal before playing it in order to place it within the dynamic
range of the hardware so that data is scaled and the sound is played as loud as
possible without clipping. The syntax is the same as for ‘sound’ command.

§ Writing sound signals using ‘wavwrite ’:


The ‘wavwrite’ command writes a Microsoft wave (.wav) sound file that can be
played later using widows media player. The syntax of the command is: wavwrite
(Y,FS,Nbits ,WAVEFILE) writes data Y to a Windows wave file specified by the file
name WAVEFILE, with a sample rate of FS Hz and with Nbits number of bits. If
Stereo data to be written, it should be specified as a matrix with two columns.
Exercises:

1- Use 'wavread' command to read a sound signal (ms.wav) provided to you.


What are the values of:
a. Numberof samples of the sound signal?

Multimedia Technology Lab Manual 2


b. Sampling frequency?

c. Number of bits per sample?

2- Use the 'sound' command to play and listen to (ms.wav):


a. With the sampling frequency you got in exercise 1.

b. Without specifying sampling frequency.

c. Using double the sampling frequency.

d. Using one half of the sampling frequency.

3- Compare the quality of sound results you got in exercise 2. Are they
completely different sounds? Why?

4- Write the sound data you got from exercise 1 above to a new wav file using
'wavwrite' command with appropriate parameters. Listen to the sound
samples through Windows media player without using the MATLAB
sound command.

5- Use windows sound recorder and open the file ms.wav. Observe the
properties of the file. Save the file with different names with the following
properties:

Multimedia Technology Lab Manual 3


Size of data Memory Quality
vector requirements

PCM 22.05 kHz, 16 bits


mono

PCM 32 kHz, 16 bits stereo

PCM 32 kHz, 8 bits stereo

PCM 32 kHz, 16 bits mono

PCM 32 kHz, 8 bits mono

6- Load all these sound files and listen to them. In each case, observe the data
vector containing the samples of the sound signal and comment on the
following points:
a. What is the difference between mono and stereo signals? How the
data vector differs for mono and stereo in MATLAB ?

b. How does the sampling frequency affect the quality of sound?

c. What is the effect of sampling frequency on the size of the data


vector?

d. How does the number of bits per sample affect the quality of
sound?

e. What is the effect of number of bits per sample on the size of the
data vector?

7- ‘wavrecord’ command can be used to record sounds using Windows audio


input device. In MATLAB prompt window, run the following example:

Multimedia Technology Lab Manual 4


%Example: Record and play back 5 seconds of 16-bit audio sampled at 11.025
kHz.
Fs = 11025;
Y = wavrecord(5*Fs, Fs);

8- Play the Y file using ‘sound’ and ‘soundsc’ command.

9- Which command results in distorted sound signal? Why?

10- Which command results in fine sound signal? Why?

Part II. Time and Frequency domain plots of sound signals in


MATLAB
Exercise:
11- Use 'wavread' command to read a sound signal (ms.wav) provided to you.

12- Use plot command to sketch the samples of the sound signal in time
domain. You need to define a proper time vector based on the sampling
time and end time.

13- Obtain the spectrum of sound signals using fft command.

14- Plot the spectrum of the sound signal. You need to define a proper
frequency vector.

Part III. Manipulation of sound signals


Exercise:
15- Use 'wavread' command to read a sound signal (ms.wav) provided to you.
Store the samples of sound in vector x.

Multimedia Technology Lab Manual 5


16- Signal reversal in time
Perform the operation x1[n] = x[-n] as we did in the last Lab. Listen to the
new signal x1. Can you find any sound/ speech signal that sounds the same
after time reversal?

17- Delay (pause) or shift in signal


Insert a delay of exactly 3 secs in the signal i.e. perform the operation x2[n] =
x [n-nd]. You need to calculate the value of nd based on the sampling
frequency and concatenate as many zeros to the start of the original signal.
Listen to the delayed signal and see if it is delayed by 3 secs or not.

18- Compressing or fast forwarding


To experience signal compression, perform the operation x3[n] = x[3n]. Listen
to the new signal x3. What should be the new sampling freqeuncy? Listen to
the signal. Use wavwrite command to store the new signal in the wav format.
Comapare the size of the two wave files. Did you get some compression
without the loss of sound quality? Try with x4[n] = x[10n] and compare the
quality and the size of the file.

Multimedia Technology Lab Manual 6

Potrebbero piacerti anche