Noise cancellation setup - combining the microphone's signals intelligently

1.5k views Asked by At

I built a noise cancellation setup with two microphones and two different microphone preamplifiers that go to two different channels of a stereo recording.

Here is a sample

http://filestore.to/?d=U5FN2IH96K

I tried

char  ergebnis[80];                                                  
sprintf(ergebnis, "%s.neu.raw", Datei);
FILE* ausgabe = fopen(ergebnis, "wb");
FILE* f = fopen(Datei, "rb");

if (f == NULL) 
{
    return;
}

int i   = -1;
int r1  =  0;
int r2  =  0;
int l1  =  0;
int l2  =  0;
int l   =  0;
int r   =  0;
int wo  =  0;
int dif =  0;

while (wo != EOF) 
{
    wo = getc(f);  
    i++;

    if (i == 0) 
    {
        r1 = (unsigned)wo;
    }

    if (i == 1) 
    {
        r2 = (unsigned)wo;
        r = (r2 << 8) + r1;   //r1 | r2 << 8;  
    }

    if (i == 2) 
    {
        l1 = (unsigned)wo;
    }

    if (i == 3) 
    {
        l2  = (unsigned)wo;
        l   = (l2 << 8) + l1;   //l1 | l2 << 8;   
        dif = r - (l * 2);
        putc((char)( (unsigned)dif       & 0xff), ausgabe);
        putc((char)(((unsigned)dif >> 8) & 0xff), ausgabe); 
        i = -1;
    }
} 

when the magic happens in

dif = r - (l * 2);

But this does not eliminate the noise surrounding it, all it does is create crackling sounds.

How could I approach this task with my setup instead? I prefer practical solutions over "read this paper only the author of the paper understands".

While we are at it, how do I normalize the final mono output to make it as loud as possible without clipping?

1

There are 1 answers

18
Bjorn Roche On

I don't know why you would expect this

dif = r - (l * 2);

to cancel noise, but I can tell you why it "create[s] crackling sounds". The value in dif is often going to be out of range of 16-bit audio. When this happens, your simple conversion function:

    putc((char)( (unsigned)dif       & 0xff), ausgabe);
    putc((char)(((unsigned)dif >> 8) & 0xff), ausgabe); 

will fail. Instead of a smooth curve, your audio will jump from large positive to large negative values. If that confuses you, maybe this post will help.

Even if you solve that problem, a few things aren't clear, not the least of which is that for active noise canceling to work you usually assume that one mike provides a source of noise and the other provides signal + noise. Which is which in this case? Did you just place two mikes next to each other and hope to hear some sound source with less ambient noise after some simple arithmetic? That won't work, since they are both hearing different combinations of signal and noise (not just in amplitude, but time as well). So you need to answer 1. which mike is the source of signal and which is the source of noise? 2. what kind of noise are you trying to cancel? 3. what distinguishes the mikes in their ability to hear signal and noise? 4. etc.

Update: I'm still not clear on your setup, but here's something that might help:

You might have a setup where your signal is strong in one mike and weak in the other, and a noise is applied to both mikes. In all likelyhood, there will be signal leak into both mikes. Nevertheless, we will assume

l = noise1
r = signal + noise2

Note that I have not assumed the same noise values for l and r, this reflects the reality that the two mikes will be picking up different noise values due to time delays and other factors. However, it is often the case (and may or may not be the case in your setup) that noise1 and noise2 are correlated at low frequencies. Thus, if we have a low pass filter, lp, we can achieve some noise reduction in the low frequencies as follows:

out = r - lp(l) = signal + noise2 - lp(noise1)

This, of course, assumes that the noise level at l and r is the same, which it may or may not be, depending on your setup. You may want to leave a manual parameter for this purpose for manual tuning at the end:

out = r - g*lp(l)

where g is your tuning parameter and close to 1. I believe in some high-end noise reduction systems, g is constantly tuned automatically.

Selecting a cutoff frequency for your lp filter is all that remains. An approximation you could use is that the highest frequency you can cancel has a wavelength equal to 1/4 the distance between the mikes. Of course, I'm REALLY waving my arms with that, because it depends a lot on where the sound is coming from, how directional your mikes are and so on, but it's a starting point.

Sample calculation for mikes that are 3 inches apart:

Speed of sound = 13 397 inches / sec
desired wavelength = 4*3 inches = 12 inches
frequency = 13,397 / 12 = 1116 Hz

So your filter should have a cutoff frequency of 1116 Hz if the mikes are 3 inches apart.

Expect this setup to cancel a significant amount of your signal below the cutoff frequency as well, if there is bleed.