Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

MATLAB EQ: Sound Sampling


Sampling Windows Audio Data in MATLAB

This module will walk you through the coding process of saving input audio data from a Windows sound card.

Setup

The first thing you need to do is set how often you would like MATLAB to access your sound card, and how fast you want it to do so. This multiplying these two values together will give you the total size of your sample space. The code below is how we initialized our data input.
refreshrate = .04644; % sec
samplerate = 44100; % Hz
ai = analoginput('winsound', 1); %windows addchannel(ai,[1 2]); %two channels
samplerate = setverify(ai, 'SampleRate', samplerate);

Trigger

Next, you must set a command structure to let MATLAB know when to access the sound data. In the case of our graphical equalizer we wanted MATLAB to sample until we told it to stop so we created an infinite trigger loop. To do this you must set the triggers on your input class.
ai.TimerPeriod = refreshrate;
spt = round(samplerate * refreshrate);
ai.SamplesPerTrigger = spt;
set(ai, 'TriggerRepeat', Inf);
set(ai, 'TimerFcn' , @getdata);
start(ai);

Storing Data and Stopping

Now that you have begun to sample the soundcard, you have to store the sampled data in a buffer for analysis. You need to flush the data in your acquisition structure or you will suffer serious memory leaks. Also, the try and catch structure allows the loading of empty values if the peekdata is empty (a type of error suppression).
try
timesig = peekdata(ai,samples);
flushdata(ai)
catch
timesig = [];
end
Stopping the data acquisition is simple:
stop(ai)

0 comments:

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.