Code covered by the BSD License  

Highlights from
Handling Sound in MATLAB

Handling Sound in MATLAB

by

 

Take input from a wav file and process it

Sound_handling.m
%Handling sounds in Matlab
%After downloading them to your local machine, you can manipulate these sounds in Matlab, as shown in the following transcript: 
% Read in the sound data
[d,r] = wavread('msmn1.wav');
% r is the sampling rate
r;
%r =22050
% d is the data
size(d);
%ans =110250
% i.e. 110250 samples = 5 seconds * 22050 samples/sec
% Listen to it
soundsc(d,r);
% Look at the spectrogram (spectrum as a function of time)
specgram(d,1024,r);
% Design a quick high-pass filter at 1000 Hz (relative to nyquist rate r/2)
[b,a] = ellip(8,1,50,1000/(r/2),'high');
% Pass it through the filter
df = filter(b,a,d);
% See how the spectrogram is changed
specgram(df,1024,r);
% Most of the energy below 1000 Hz has been removed
% Take a listen
soundsc(df,r);
% .. all the 'bass' is gone
% Write it out to a new soundfile
wavwrite(df,r,'tmp.wav');

Contact us