Audio Manipulation in Matlab

As you would expect, Matlab can manipulate with audio. Saving and Opening .wav files, playing them, and recording are the basic operations.

The record operation, is carried out by creation of something called an object (similar to Object-Oriented Programming). The object under consideration for recording is audiorecorder.

Obviously Matlab help covers all the below mentioned, but here is a personal experience touch to it. You instantiate an object by just calling it and assigning a name to it. Also are given a few properties.

y = audiorecorder(8000, 16, 1);

is the most commonly used of the lot. It creates the object, with a Sampling Frequency of 8000Hz, 16bits/sample and mono channel recording. The Sampling Frequency of 8kHz is ideal for speech and voice. But for high pitch music, its ideal to have a higher sampling frequency of the order of 22050Hz or 44.1kHz.

  • record(y); – starts the recording with control to execute other statements (useful)
  • pause(y); – pauses recording
  • resume(y); – resumes recording
  • play(y); – plays recording done until now and finally
  • signal = getaudiodata(y); – passes the recording data to the variable called signal

Generally signal processing applications, then would check for saturation, i.e. most of the absolute values of the signal being close to 1 (hampers audibility).

You would now store this recorded signal to your hard disk by
wavwrite(signal,8000,16,wavfilename);
Note that the sampling frequency and no. of bits / sample should be kept the same.

These wav files can be read as
[data, Fs] = wavread(wavfilename);
The data is the actual -1 to 1 audio information, and Fs the sampling frequency, a key information required to do any further processing.

This data can be played using wavplay(data, Fs). This is supported on 32-bit Windows machines. So a better alternative would be to use soundsc(data, Fs). This automatically scales the data vector amplitudes [MIN,MAX] to [-1,1] and then plays the entire data stream with given sampling rate.

More on audio processing using Matlab to come soon…

Advertisements

3 thoughts on “Audio Manipulation in Matlab

  1. srinivas naik

    lol is there any way we can specify that we like this blogpost like in facebook? Interesting post da… hope to see more.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s