Thursday, 19 April 2012

ADDING TWO AUDIO SIGNALS USING MATLAB

Your inputs, which are audio files have to be in the same format (eg .wav, .mp3). MatLab has all the functions which are necessary for handling the audio files.

MatLab stores everything in Matrices, so in order to understand how audio signals/file are added together, you must first understand how to add matrices together using the ' + ' operator and what is required of them to be added.
When you adding audio signals, they have to be equal, in terms of the time they last when you play them, so basically before adding them, a test must be made to check which one last longer (that is simple, because if an audio file last longer it is stored in a bigger matrix of n x 1) then make their size to be equal by appending the shorter one with zeros which will have no effect of file itself. Then they can be added together and/or played.

There is a link below to a MatLab code for adding only two audio file (.wav). The code starts by playing both the files, add them, save the resulting file and then plays it. Please note that the code can be modified and the way it is done here is not the best way there is.

To download the MatLab code for adding two audio signals click here, when running the code, to do that the audio files are in the same folder as the programme file and the input audio file are in the format .wav.

No comments: