You are on page 1of 1

Code for read sound(.

wav) in Matlab

clear all;
%make sure that you have this 3 files in the same directory
[bass, fs1] = audioread('bass.wav');
[guita, fs2] = audioread('guita.wav');
[drum, fs3] = audioread('drum.wav');
%---------- step1, we can play the sound -------------
sound(bass, fs1); %listen to the sound
length(bass)/ fs1; %get the length of the sound in t(s)

%---------- step2, lets combine sound together --------


y=bass+guita+drum; % it will error since it has difference length

%-----------step3, we can take all signals only 3s each ----

drum_seg=drum(44100*1:44100*4);
bass_seg=bass(44100*1:44100*4);
guita_seg=guita(44100*1:44100*4);

y= drum_seg + bass_seg + guita_seg;


sound(y,44100); %listen to the sound with sampling rate 44,1khz

%-----------step4, you want to make some signals louder------


y_amp=drum_seg*2 + bass_seg*3 + guita_seg;
sound(y_amp,44100);

Note:
1. Please do it from one step to one step
2. If you run one step please put comment (%) for other steps
Ex. If you run step1, make sure that step2,step3,step4 are all place with comments (%) in
front.

You might also like