Matlab removing vocals

5.7k views Asked by At

I write the program removing vocals from song using fft. Before C# I decided to test the algorithm of reduce frequency in Matlab, but can't get result as in example. There's a noise. I've tried select any range (0.7 - 1.5), but all the same...noise. What I do not? Please, help me to write it right) Thanks in advance!

[y, fs] = wavread('Song.wav');
left = y(:,1);
right = y(:,2);
fftL = fft(left);
fftR = fft(right);

for i = 1:683550 %in my example 683550
  dif = fftL(i,1) / fftR(i,1);
  dif = abs(dif);
  if (dif > 0.7 & dif < 1.5)
    fftL(i,1) = 0;
    fftR(i,1) = 0;
  end;
end;

leftOut = ifft(fftL);
rightOut = ifft(fftR);
yOut(:,1) = leftOut;
yOut(:,2) = rightOut;

wavwrite(yOut, fs, 'tmp.wav');
2

There are 2 answers

2
KlausCPH On BEST ANSWER

From the code I can see that you simply classify frequency content as being a vocal if it is "equal" in strength between left and right (equal being defined as a ratio in between 0.7 and 1.5). I'm not familiar with your reasons for this scheme, but it may actually yield a decent result.

What you are doing wrong does most likely have to do with fft size and the fact that you are treating the complete signal in one go, so to say.

Vocals in e.g. a song vary over time, therefore your masking has to vary as well. What this means is that you have to break up your signal in frames in the time-domain and do your fft and masking separately for each frame. Also you should consider to use an overlap in your time-domain framing.

Regards

0
mohammad karim hardani asl On

maybe this help someone:

[file, path] = uigetfile('*.wav','Select a .wav file');
if file == 0
    return
end

[y,Fs]= audioread(file);

if size(y,2) == 1
    msgbox('The selected file is Mono. This algorithm is applicable only for Stereo files.');
    return;
end

% fc=input('Enter Cutoff Frequency (HPF):');
% fc=round(fc);

fc = 3000;
if fc > 20
    fp = fc+5;
    fs = fc/(Fs/2);
    fp = fp/(Fs/2);
    [n wn] = buttord(fp,fs,0.5,80);
    [b, a] = butter(5,wn,'High');
    channel_2 = filtfilt(b,a,y(:,2));
else
    channel_2 = y(:,2);
end

background = y(:,1) - channel_2;

%Write it to a file
audiowrite([cd '\background.wav'],background,Fs);