You are on page 1of 3

EL – 413 Digital Signal Processing

Experiment # 06

Audio Processing in MATLAB using commands

Performed on

Student Name:
Roll Number: Section: E

Performance =
Maximum Marks Viva = 05 Total = 10
05
Marks Obtained
Remarks (if any)

Experiment evaluated by
Instructor Name: Engr. Muhammad Waseem Zeeshan Ashrafi

Signature:

Copyright © Department of Electrical Engineering – Usman Institute of Technology


Objective
Audio Processing in MATLAB using commands

Required Equipment:
Software: MATLAB-16
Hardware: Headphone with Mic

Example#01: (Generation and audio observation of Sinusoidal signal and convert into
.wav file)
In this example, a sinusoidal signal is generated and then play it. This should work on any
computer that has MATLAB and a working sound card.
fs = 16000;
f = 2000;
n = 0:1/fs:5;
x = sin(2*pi*f*n); % generating sinusoidal signal
plot(x)
axis([0 100 -2 2])
sound(x,fs); % to hear the signal
audiowrite('tone.wav',x,fs); %to create .wav file

Method to record audio signal and play:


Voice signal can b maniupalted using signal processinng. For this, first record your voice and
execute following command.
audiorecorder(Fs, NBITS, NCHANS)
It creates 8000 Hz, 8-bit, 1 channel audiorecorder object in default conditions. Where Fs is
sampling frequency and common sample rates are 8000, 11025, 22050, 44100, 48000, and
96000 Hz. The number of bits must be 8, 16, or 24. The number of channels must be 1 or 2
(mono or stereo).
Following are the methods to utilize audiorecorder:
record - Start recording.
pause - Pause recording.
resume - Restart recording from paused position.
play - Play recorded audio. This method returns an audioplayer object.
stop - Stop recording.
getaudiodata - Create an array that stores the recorded signal values.
set - Set properties of audiorecorder object.

Example#02:
r = audiorecorder(22050, 16, 1);
record(r); % speak into microphone...
pause(r);
p = play(r); % listen
resume(r); % speak again
stop(r);
p = play(r); % listen to complete recording
mySpeech = getaudiodata(r); % store the recorded values in
array format
plot(mySpeech)

Copyright © Department of Electrical Engineering – Usman Institute of Technology


Example#03: (Addition of AWGN to sinusoidal signal)
Add AWGN(Additive White Gaussian Noise) to sinusoidal signal then hear and plot the
signal. The second variable in the function is SNR(Signal to Noise Ratio). Noise and
sinusoidal signal can be controlled by changing the value of SNR
fs = 16000;
f = 2000;
n = 0:1/fs:5;
x = sin(2*pi*f*n); % generating sinusoidal signal
sound (x, fs)
subplot(2,1,1)
plot(x)
axis([0 100 -2 2])
xlabel ('time');
ylabel ('Amplitude');
title ('original Sinusoidal Signal');
u=awgn(x, 10); % Addition of AWGN in sinusoidal
signal with 10 SNR
sound (u, fs)
subplot(2,1,2)
plot (u)
axis([0 100 -2 2])
xlabel ('time'); ylabel ('Amplitude'); title ('noisy
Sinusoidal Signal')

Example#04: (Filteratiion of Noisy signal)


Consider the previous example, apply low pass filter on it and plot.
y=fir1(1,64/8000,'low');
a=filter(y,1,u);
plot(a)
axis([0 100 -2 2])

Lab Task:
1) Apply different frequencies on sinusoidal signal, and compare the signal on the basis of
hearing.
2) Record and play your voice. Change into double format and plot it.
3) Read any .wav file. Add AWGN to the signal and by changing SNR, plot and hear the
signal.
4) Apply filter on the above signal. Plot and hear the filtered signal.

Open Ended Task:


1) Read an Audio File in MATLAB environment. Play and Plot this audio signal.
Play the same signal backward i.e. in reverse direction. Plot this reverse audio
signal.
2) Create your own music piece and write in .wav format and plot the resulting audio
signal. (by generating multiple sinusoids).

Copyright © Department of Electrical Engineering – Usman Institute of Technology

You might also like