Você está na página 1de 2

AUDIO PROCESSING IN MATLAB

Objectives:
1. This laboratory experiment is an introduction to audio processing with MatLab.
2. To familiarize you with some of the main functions to read in and play music files in
MatLab.

The following functions that will be used in this lab are:

wavread! sound! soundsc! flipud! wavwrite!

To understand how each of these functions is used in MatLab" type help followed by one
of the above commands into the command prompt. #ote that in order to use the wavread!
function you must use a .wav file. $t is possible to convert .wma and .mp% files into .wav
files. &ou can 'oogle search to find programs to do this. $f you can(t find one that wor)s" send
me an email and $ can forward you some lin)s.


This lab consists of the following sections:

Section 1: Read and Stoe an A!dio "i#e in MatLab
Section $: P#a% t&e A!dio "i#e
Section ': A!dio Sca#in(
Section ): P#a%in( a Tac* Bac*+ads
Section ,: Ceate M!sic +it& MatLab
Section 1: Read and Stoe an A!dio "i#e in MatLab

To read and store an audio file" you can use one of two different command lines. The following
stores the file into variable y.

y * wavread+filename,!-

.emember to include the entire filename including the directory.
/xample: 0:1My 2ocuments1//134Labs15udio.wav

The command line below stores the audio file into variable y and the sampling fre6uency in
variable 7s.

8y"7s9 * wavread+filename,!-


Section $: P#a% t&e A!dio "i#e

To play an audio file in MatLab you use the sound! function. The following function plays the
sound. $f the 7s variable is not defined or included in the command" it will assume the default
sample rate of 31:2 ;z.

soundy"7s!-


Section ': A!dio Sca#in(

To scale an audio file the soundsc! command is used. This allows for the modification of an
audio signal(s amplitude or fre6uency.

soundscy"7s!-

To increase the volume of the audio trac) you can multiple the variable it is stored in by a
scalar. To slow down or speed up the trac) played you can ad<ust the sampling rate. 0omment
on your observations using different values.

#ow experiment with different bit values 1"2".."14! in the following command:

soundscy"7s"bits!-

0omment on your observations.


Section ): P#a%in( a Tac* Bac*+ads

The command to reverse the order of the samples in a matrix is flipud!. /xperiment with this
command.
This section of the lab will teach you how to create songs using different tones created in
MatLab. 7irst we are going to code a sine wave of amplitude 5 * 1" with at an audio fre6uency of
=2%.2= ;z corresponds to 0!.

Section ,: Ceate -!sic +it& Mat#ab
cnote * sin2>pi>=2%.2=>?:?.???12=:?.=!!-

This vector cnote now contains simples of the sine wave from t * ?s to t * ?.=s" in samples that
are spaced ?.???12=s apart this is the sampling interval Ts!. #ote that this sampling interval
corresponds to a sampling fre6uency of 3 );z 1@Ts * fs!. This is standard for voice grade audio
channels.

#ow to write this sound to a wave file we have the following command.

wavwritecnote" +c.wav(!-
"e.!enc% Tab#e:

Você também pode gostar