You are on page 1of 9



I've been able to easily duplicate the SDK imagery sample code in Matlab simply by using the straightIorward
Matlab support Ior .NET. I changed the code slightly and used the polling Iunction calls rather than the event
model Irom the original sample code. However, I'm having trouble porting the Speech sample code to Matlab.
Matlab crashes when I try to use the Start method on the KinectAudioSource object. I also tried creating the
KinectAudioStream object Iirst (it is commented out in the code below) but that was not the problem. Any help
greatly appreciated.

Iunction captureVoice( )


b MicrosoIt.Research.Kinect.Audio.KinectAudioSource();
b.FeatureMode true;
b.AutomaticGainControl Ialse;
b.SystemMode MicrosoIt.Research.Kinect.Audio.SystemMode.OptibeamArrayOnly;
s MicrosoIt.Research.Kinect.Audio.KinectAudioStream();
s b.Start();
Ior i 1:10
catch err
'There was an error'


1hls lab ls an lnLroducLlon Lo audlo processlng wlLh MaLLab 1hls lab wlll help Lo
famlllarlze you wlLh some of Lhe maln funcLlons Lo read ln and play muslc flles ln

1he followlng funcLlons LhaL wlll be used ln Lhls lab are

wavread() sound() soundsc() fllpud() wavwrlLe()

1o undersLand how each of Lhese funcLlons ls used ln MaLLab Lype followed
by one of Lhe above commands lnLo Lhe command prompL noLe LhaL ln order Lo
use Lhe wavread() funcLlon you musL use a wav flle lL ls posslble Lo converL
wma and mp3 flles lnLo wav flles ?ou can Coogle search Lo flnd programs Lo do
Lhls lf you can'L flnd one LhaL works send me an emall and l can forward you
some llnks

1hls lab conslsLs of Lhe followlng secLlons

Sect|on 1 kead and Store an Aud|o I||e |n MatLab
Sect|on 2 |ay the Aud|o I||e
Sect|on 3 Aud|o Sca||ng
Sect|on 4 |ay|ng a 1rack 8ackwards
Sect|on S ract|ce What ou've Learned
Sect|on 6 Create Mus|c w|th MatLab

LeL's geL sLarLed!!!

Sect|on 1 kead and Store an Aud|o I||e |n MatLab

1o read and sLore an audlo flle you can use one of Lwo dlfferenL command
llnes 1he followlng sLores Lhe flle lnLo varlable y

y wavread('fllename)

8emember Lo lnclude Lhe enLlre fllename lncludlng Lhe dlrecLory
Lxample CMy uocumenLsLL186LabsAudlowav

1he command llne below sLores Lhe audlo flle lnLo varlable y and Lhe sampllng
frequency ln varlable ls

yls wavread('fllename)

Sect|on 2 |ay the Aud|o I||e

1o play an audlo flle ln MaLLab you use Lhe sound() funcLlon 1he followlng
funcLlon plays Lhe sound lf Lhe ls varlable ls noL deflned or lncluded ln Lhe
command lL wlll assume Lhe defaulL sample raLe of 8192 Pz


Sect|on 3 Aud|o Sca||ng

1o scale an audlo flle Lhe soundsc() command ls used 1hls allows for Lhe
modlflcaLlon of an audlo slgnal's ampllLude or frequency


1o lncrease Lhe volume of Lhe audlo Lrack you can mulLlple Lhe varlable lL ls sLored
ln by a scalar 1o slow down or speed up Lhe Lrack played you can ad[usL Lhe
sampllng raLe CommenL on your observaLlons uslng dlfferenL values

now experlmenL wlLh dlfferenL blL values (1216) ln Lhe followlng command


CommenL on your observaLlons

Sect|on 4 |ay|ng a 1rack 8ackwards

1he command Lo reverse Lhe order of Lhe samples ln a maLrlx ls
fllpud() LxperlmenL wlLh Lhls command

Sect|on S ract|ce What ou've Learned

now for Lhls parL of Lhe lab have fun wlLh MaLLab 1ake your favorlLe muslc flles
and converL Lhem Lo wav flles lf Lhey are noL already converLed l'm sure you all
have audlo flles from some source or anoLher!!! lf you're noL sure how Lo converL
Lhe flles Coogle search lL

Cnce you have a couple of your favorlLe audlo flles you may need Lo crop Lhe
flle MosL audlo flles are falrly large whlch can cause MaLLab Lo lock up

8ead and sLore Lhe cropped audlo flle now use some of Lhe above commands Lo
modlfy Lhe audlo slgnal lay your favorlLe song backwards or make your favorlLe
slnger sound llke a chlpmunk noLe LhaL Lhe above commands are [usL a baslc
look aL MaLLab's audlo processlng capablllLles

CommenL on your flndlngs!!!

lor your help here ls a flle forward and backward LhaL has been done wlLh Lhe
same process

Sect|on 6 Create Mus|c w|th MatLab

1hls secLlon of Lhe lab wlll Leach you how Lo creaLe songs uslng dlfferenL Lones
creaLed ln MaLLab llrsL we are golng Lo code a slne wave of ampllLude A 1
wlLh aL an audlo frequency of 32323 Pz (corresponds Lo C)

cnoLe sln(2*pl*32323*(0000012303))

1hls vecLor cnoLe now conLalns slmples of Lhe slne wave from L 0s Lo L 03s ln
samples LhaL are spaced 0000123s aparL (Lhls ls Lhe sampllng lnLerval 1s) noLe
LhaL Lhls sampllng lnLerval corresponds Lo a sampllng frequency of 8 kPz (1/1s
fs) 1hls ls sLandard for volce grade audlo channels

now Lo wrlLe Lhls sound Lo a wave flle we have Lhe followlng command

wavwrlLe(cnoLe 'cwav')

now Lo play Lhe sound same as before use Lhe sound() funcLlon 1haL ls Lhe
slngle noLe LhaL you [usL creaLed now LhaL you've goL one down only several
more Lo go!!

l've done some of Lhe easy work here for you 1he followlng webpage glves Lhe
frequencles of dlfferenL noLes whlch are also shown on Lhe Lable
below hLLp//wwwdolmeLschcom/muslcLheory27hLm

uslng Lhls lnformaLlon creaLe a few dlfferenL noLes ln MaLLab

noLe LhaL Lhere are dlfferenL ocLaves as you go Lhrough Lhe dlfferenL keys on a
plano 1o geL you sLarLed here are a few

f sln(2*pl*17461*(0000012303))
g sln(2*pl*19399*(0000012303))
a sln(2*pl*220*(0000012303))
b sln(2*pl*24694*(0000012303))

now Lo creaLe a llne of muslc use Lhe followlng command

llne1 abcdef
llne2 abcdef

1he leLLers should represenL Lhe noLes LhaL you have creaLed ln MaLLab uL Lhe
noLes ln Lhe order you wanL Lhem Lo play

1o creaLe your song use

song llne1 llne2

Add as many llnes as you llke now wrlLe your song read and sLore lL lnLo a new
varlable and llsLen Lo lL CommenL on your muslcal ablllLles lf you're muslcally
challenged check ouL Coogle for some songs LhaL you can creaLe leel free Lo
creaLe your own song or aLLempL Lo copy some 8eeLhoven Ln[oy!!!

lf you need some more help wlLh Lhls lab check ouL Lhe followlng llnk


lor anoLher example aL Lhe end of Lhls lab l have aLLached Lhe song LhaL l
creaLed whlch ls a few llnes of PearL and Soul" CeL creaLlve wlLh Lhls
asslgnmenL and commenL on Lhe problems you run ln Lo