Wednesday 7 May 2014

Reading audio file and removing background noise and saving it back using MATLAB

To read an audio file or to make an audio file..
1. Attach ur hands free that comes with ur mobile that has microphone /headset with microphone to the computer
2.In windows 7,  Go to Start->All Programs ->Accessories ->Sound Recorder
On the Floating window of sound recorder, Click on Start Recording
Now speak to the microphone ..Once done click on STOP recording and save the audio file in D: drive as lp.wma

%To read an audio file to matlab use audioread as shown below
y = audioread('d:/lp.wma');

%To remove background noise, use adaptive filter

n=1:length(y);
mtlb_noisy = y;
noise = n;
% Define Adaptive Filter Parameters
filterLength = 32;
weights = zeros(1,filterLength);
step_size = 0.004;
% Initialize Filter's Operational inputs
output = zeros(1,length(mtlb_noisy));
err = zeros(1,length(mtlb_noisy));
input = zeros(1,filterLength);
% For Loop to run through the data and filter out noise
for n = 1: length(mtlb_noisy),
%Get input vector to filter
for k= 1:filterLength
if ((n-k)>0)
input(k) = noise(n-k+1);
end
end
output(n) = weights * input';  %Output of Adaptive Filter
err(n)  = mtlb_noisy(n) - output(n); %Error Computation
weights = weights + step_size * err(n) * input; %Weights Updating
end
yClean = err;

% to save the output to D drive and with name re.mp4

audiowrite('d:/re.mp4',output,44100);

1 comment:

  1. Nice post...
    This is great blog for background remove service. Click here to get best photo editing service. PhotoEditExperts is a great site for background remove service & more.

    ReplyDelete