0
$\begingroup$

I want to create a program in matlab that could act like karaoke software. At this moment i have following lines of code:

clear all;

[y1, fs1] = audioread('miszmasz.wav');
[y2, fs2] = audioread('voice.wav');

%checking if there is an audio file
if y1 == 0
    return
elseif y2 == 0
    return
end

%spliting into left and righ 
leftSignal = y1(:,1);
rightSignal = y1(:,2);
voiceSignal = y2(:,1);

leftSignalLength = length(leftSignal);
rightSignalLength = length(rightSignal);
voiceSignalLength = length(voiceSignal);

%furier transform of left, right canal and voice sample
NFFT = 2^nextpow2(voiceSignalLength);
leftSignalFFT = fft(leftSignal, NFFT)/voiceSignalLength;
rightSignalFFT = fft(rightSignal, NFFT)/voiceSignalLength;
voiceSignalFFT = fft(voiceSignal, NFFT)/voiceSignalLength;

for i1 = 1:leftSignalLength
    leftSignalFFT(i1) = leftSignalFFT(i1) - voiceSignalFFT(i1);
end

for i2 = 1:rightSignalLength
    rightSignalFFT(i2) = rightSignalFFT(i2) - voiceSignalFFT(i2);
end

leftOutput = ifft(leftSignalFFT);
rightOutput = ifft(rightSignalFFT);
finalOutput(:,1) = leftOutput;
finalOutput(:,2) = rightOutput;

%wavwrite(y_Out, fs1, 'output.wav');
audiowrite('miszmasz_output.wav', finalOutput, fs1);

unfortunately, it does not work. Any tips?

$\endgroup$
  • 1
    $\begingroup$ i've never written a vocal removal utility, but if i did, i would first convert LR to MS (mid and side), do pitch detection for the most prominent quasi-periodic signal, remove it with a well-tuned tracking comb filter (based on the pitch detector output), and convert from MS back to LR. dunno how well that would work. maybe not so well. $\endgroup$ – robert bristow-johnson Jan 24 '15 at 22:35
  • $\begingroup$ This is probably more complicated than you think. You might want to read the answers to this question on Music.SE. $\endgroup$ – Matt L. Jan 25 '15 at 9:08
  • $\begingroup$ I'm trying to understand the intuition behind your code and what you are thinking it does. Can you elaborate a bit? So far I can only see that you are subtracting a vocal sample from your stereo sample in a very complicated way. (Fourier transforms are linear, so you could as well subtract in the time domain). What is the vocal sample supposed to contain? $\endgroup$ – Jazzmaniac Jan 26 '15 at 10:46
  • $\begingroup$ @Jazzmaniac my quickly look, he get two signal i belive that the first is the signal that mixed with voice and the second contains just the voice that he want remove from first signal (I guess), the code try remove the voice from the first audio subtracting one by another after FFT... $\endgroup$ – ederwander Jan 27 '15 at 11:08
1
$\begingroup$

If my guess is right, your code show you trying remove the vocal from second audio, the first audio must be the original vocal and the second is some mix (vocal + music)...

So if my guess is true start trying a simple approach to test, here my simple test.

I get just 4096 points of some audio voice and mix with a sine 4096 points in 200hz sampled in 1600hz, all mono.

Plot 4096 voice points:

enter image description here

Now plot a sine in 200 Hz:

enter image description here

Now the Mix (sine + voice):

enter image description here

Now to get the original sine without the voice you need do:

real((ifft(fft(mix) - fft(voice_Signal))))

The final plot after the step above:

enter image description here

course is a very simple test, and in this case we're telling you to have the original clean audio voice before being mixed ...

$\endgroup$
0
$\begingroup$

You also need to do an inverse Fourier Transform on the FFT data you converted the orginal time domain audio file into. You can listen to it using soundsc() when you have the file in its row data time domain format. However, the way you've taken the fft is inefficient since you're trying to do an FFT on the entire audio file; usually they are taken in frame. Check this MATLAB page on the spectrogram function for Short time fourier transforms in the time-frequency domain: https://uk.mathworks.com/help/signal/ref/spectrogram.html?s_tid=doc_ta.

The computation of the inverse STFT in MATLAB is non trivial as in its not just a one line function. There's working examples online though.

I'm doing this as a proposal in university. I know the thread is 4-5 years old but if anyone stumbles by it like I did looking for insights too then hit me up at st3015@imperial.ac.uk

Audio signal processing is the best

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.