How to Read an Audio File in Matlab

Audio Processing with MatLab

An Introduction

By:Rachel Hager

This lab is an introduction to sound processing with MatLab.This lab will help to familiarize you with some of the master functions to read in and play music files in MatLab.

The post-obit functions that will be used in this lab are:

wavread()�������� sound() soundsc()�������� flipud() wavwrite()

To sympathise how each of these functions is used in MatLab, type help followed by one of the above commands into the control prompt.Notation that in society to use the wavread() function you must utilise a .wav file.It is possible to convert .wma and .mp3 files into .wav files.You can Google search to find programs to do this.If you tin can�t find one that works, send me an email and I tin can forwards you some links.

This lab consists of the post-obit sections:

Section i:Read and Store an Audio File in MatLab

Department 2:Play the Sound File

Section 3:Audio Scaling

Department iv:Playing a Track Backwards

Department five:Exercise What You�ve Learned

Section 6:Create Music with MatLab

Let�s go started!!!

Section 1:Read and Shop an Sound File in MatLab

To read and store an audio file, you tin use one of 2 different command lines.The post-obit stores the file into variable y.

y = wavread(�filename');

Remember to include the entire filename including the directory.

����������� Example: C:\My Documents\EE186Labs\Audio.wav

The control line below stores the audio file into variable y and the sampling frequency in variable Fs.

[y,Fs] = wavread(�filename');

Section 2:Play the Audio File

To play an audio file in MatLab you utilize the sound() function.The following function plays the sound.If the Fs variable is not defined or included in the control, information technology will assume the default sample charge per unit of 8192 Hz.

sound(y,Fs);

Section 3:Audio Scaling

To scale an audio file the soundsc() command is used.This allows for the modification of an audio bespeak�s amplitude or frequency.

soundsc(y,Fs);

To increase the volume of the audio track you can multiple the variable it is stored in by a scalar.To slow downward or speed up the track played you lot tin can adjust the sampling charge per unit.Comment on your observations using different values.

At present experiment with dissimilar bit values (1,2,..,16) in the following command:

soundsc(y,Fs,bits);

Comment on your observations.

Section four:Playing a Track Backwards

The control to reverse the order of the samples in a matrix is flipud().Experiment with this command.

Section 5:Practice What You lot�ve Learned

Now for this function of the lab take fun with MatLab.Take your favorite music files and catechumen them to .wav files if they are not already converted.I�thou sure you all have audio files from some source or another!!! If yous�re not sure how to convert the files, Google search information technology.

Once yous have a couple of your favorite audio files, you may need to ingather the file.Most audio files are adequately large which can cause MatLab to lock upward.

Read and shop the cropped audio file.At present use some of the above commands to modify the audio signal.Play your favorite song backwards or brand your favorite singer sound like a chipmunk.Note that the above commands are just a basic look at MatLab�southward audio processing capabilities.

Comment on your findings!!!

For your assist here is a file frontwards and backward that has been done with the same process

Section 6:Create Music with MatLab

This section of the lab will teach you lot how to create songs using different tones created in MatLab.Commencement we are going to code a sine moving ridge of aamplitude A = 1, with at an audio frequency of 523.25 Hz (corresponds to C).

cnote = sin(2*pi*523.25*(0:0.000125:0.5));

This vector cnote now contains simples of the sine wave from t = 0s to t = 0.5s, in samples that are spaced 0.000125s apart (this is the sampling interval Ts).Annotation that this sampling interval corresponds to a sampling frequency of viii kHz (1/Ts = fs).This is standard for voice grade audio channels.

At present to write this sound to a wave file we take the post-obit control.

wavwrite(cnote, �c.wav�);

At present to play the audio, same as before utilise the sound() function.That is the single annotation that you just created.Now that you�ve got ane downward� only several more to go!!

I�ve washed some of the like shooting fish in a barrel piece of work here for you.The post-obit webpage gives the frequencies of unlike notes which are as well shown on the table below. http://www.dolmetsch.com/musictheory27.htm

Using this information create a few dissimilar notes in MatLab.

Note that in that location are unlike octaves as yous become through the dissimilar keys on a piano.To get yous started here are a few:

f = sin(two*pi*174.61*(0:0.000125:0.5));

g = sin(2*pi*195.99*(0:0.000125:0.5));

a = sin(2*pi*220*(0:0.000125:0.5));

b = sin(ii*pi*246.94*(0:0.000125:0.v));

At present to create a line of music use the following command:

line1 = [a,b,c,d,east,f];

line2 = [a,b,c,d,east,f];

The letters should represent the notes that you accept created in MatLab.Put the notes in the society you want them to play.

To create your song use:

song = [line1, line2];

Add equally many lines equally you like.Now write your song, read and shop it into a new variable, and heed to it.Comment on your musical abilities.If you�re musically challenged, check out Google for some songs that you tin create.Feel free to create your own song or attempt to copy some Beethoven.Enjoy!!!

If yous demand some more help with this lab, check out the following link:

http://users.rowan.edu/~shreek/networks1/music.html

For some other example, at the end of this lab I have attached the song that I created which is a few lines of �Centre and Soul�.Get creative with this assignment and comment on the problems you lot run in to.

vegaunpled.blogspot.com

Source: http://class.ece.iastate.edu/mmina/ee186/labs/audio.htm

0 Response to "How to Read an Audio File in Matlab"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel