Slashdot Mirror


Software Noise Cancellation?

DangerTenor asks: "As I flew around the world, lusting after my coworker's $300 BOSE Quiet Comfort Noise-cancelling headphones, I looked down at my laptop computer and noticed the built-in microphone. Has anyone written or considered writing software to run noise-cancellation based on the built-in mic?"

9 of 38 comments (clear)

  1. Reasons this may not work by quantax · · Score: 4, Insightful

    Here is how noise-dampening works:

    A quick overview of sound; all sounds are comprised of varying frequency, and amplitude pressure waves. A sound dampener 'listens' to a sound, and emits it 180 degrees out of phase. This means the crests and troughs of the 2 waves are overlapped, negating one another.

    The main issue to be overcome is direction and such that shifts the pitch of sounds coming from a computer. Unless you are using a very high quality, wide pickup mic (which are rather expensive), you are probably not going to be able to get enough sound precision to be able to get the damper working effectively. Also, positioning the mic would take a while to get the best location for maximal damping effect for overall sound. This is still work checking out though cause it may yield greater results than I think it will. However, most computer users do not have high quality mics in the first place (and a $20 mic wont cut it). The more mics used, the more effective this would be due to wider sound coverage.

    --
    "What can a thoughtful man hope for mankind on Earth, given the experience of the past million years? Nothing." -Bokonon
  2. Yeah, to some degree.... by IshanCaspian · · Score: 5, Informative

    Although previous posters were correct in saying that it's impossible to have the speakers cancel sound on the fly, because the delay would cause the inverse wave to be out of sync, I could definitely see writing some software that would cancel constant or regular, repetitive sounds. My only isse is that the built-in mics are generally very low-quality.

    Has anyone considered writing software to filter a computer's fan? That would be really cool, and probably pretty easy to do...some little tray program that constantly runs the inverse sound over your speakers...hmmm.

    --

    But there is another kind of evil that we must fear most... and that is the indifference of good men.
    1. Re:Yeah, to some degree.... by Descartes · · Score: 3, Funny

      I love the fan idea, my computer is so noisy that it's started to harm my social life.

      "I don't think I can spend the night again, your computer kept me awake all night last time."

      of course maybe she was just trying to protect my feelings...

    2. Re:Yeah, to some degree.... by Jerf · · Score: 3, Interesting

      It would be great if reality were that cooperative, but unfortunately there is no such thing as a "constant or regular, repetitive sound", unless you're talking a digitally-generated sine wave out of a good speaker.

      This become especially noticable with high-pitched sounds (or components of sounds) you are trying to cancel. Suppose for the sake of argument there's a 5,000 Hz sound you are trying to cancel that varies randomly in absolute pitch over the course of a second or two by up to 1%, or +/- 50Hz. (1% is easily detectable with training of any sort, but still a lot of people won't notice it, esp. in a noisy situation like fan noise.) Kick in a fudge factor for the fact that your mic can probably barely "hear" that as it is. If your sound canceller is not instantly reactive, it will "cancel" sound from the past (and it can only react at the speed of sound at best), and you could turn an annoying high pitched sound into an annoying 20-50Hz sound, that for bonus points is phased all over the place with all kinds of fun harmonics. Thanks, but no thanks.

      And this assumes some sort of ideal environment. It's actually quite hopeless because each speaker of the laptop, assuming it even has two, will affect both ears, plus the reflections of each speaker, plus the reflections of the noise. Real noise dampers put one damper on each ear, because the interaction between the two would take a very challenging math problem and make it an impossible one.

      Oh, and the sounds your speaker is making can't reach the mic, either. (Because the sounds can't be cancelled at both of your ears and the mics... in fact, you'll be lucky to manage cancelling the sound at one ear, let alone three places!)

      In short, the laptop noise canceller would be interesting to see what kind of crazy phased noises you could get out of your environment, and could even conceivably be useful in some small degree to someone mining their environment for sound effects (musicians, sound effect artists) as an intriguing filter on the world, but for actual noise cancellation, you might as well just stick your fingers in your ears and hmm loudly.

  3. Just Gotta Say by matt.fotter · · Score: 5, Informative
    I fly weekly and those Bose headphones were one of the best investments I've made. Really, if you fly with any regularity, burn the cash or the AMEX points.

    Mod me offtopic - those damn headphones are worth it.

    --
    quis fimum scribit?
  4. Lust not Required by Kalak · · Score: 4, Informative

    NoiseBuster Headset. Spent $40 or so on these a year and half ago. Great for the server room.

    http://www.spiritcorp.com/noise_cancellation.htm l for some software. That was a 3 second google search for "noise cancellation software". Never used it, but it seems based on the same principles. Not for live listening though.

    --
    I am, and always will be, an idiot. Karma: Coma (mostly effected by .hack)
  5. Re:Sound is slow by orangesquid · · Score: 3, Informative

    Eletricity is the phenomena of charged particle interaction such as to cause a ``current'' that can be made to do useful work. Electrons in an electric current move *VERY* slowly. However, the EMF field induced by the charged particle motion propagates at the speed of light (light is just an EM wave, after all). Imagine the creation of an electric current as an explosion from a bomb; the shock wave propagates outwards at the speed of sound, even though very little motion happened near the bomb. The shock wave is a pressure wave, and its speed is a function of the propagation of pressure waves through the surrounding medium (e.g. the speed of sound in air or in water). The creation of the electric current does something very similar, except the "shock wave" is replaced by a causality horizon (in other words, because information can travel no faster than the speed of light, I can't cause something to happen in a galaxy far away any faster than light can travel, and an electric current that creates an EMF field can't zap your brain with microwaves any sooner than however long it would take for a "light wave" to get there) whose boundary expands at the speed of propagation of an electromagnetic wave through a medium (e.g., the speed of light in a vacuum).

    However, digital devices are slow things. When you want a transistor to switch on, you have to push electrons over a quantum "cliff" (in a sense). This happens much slower than EM wave propagation; that's why silicon switching speeds are measured in nanoseconds rather than fractions of a femtosecond...

    If you are confused (I may be a bit confused too, it's been a while since I studied this stuff), check out http://www.amasci.com/ for more info. It's a very informative site.

    As for the noise cancellation idea, the laptop mic's own frequency response would have to be compensated for, otherwise the cancellation signal will have noticable imperfections. You'll need a really, really fast machine to do this too (lots of overlapping fast fourier transforms), if you want to keep up with the sound.

    An easier way to get cheap noise cancellation is to take a "snapshot" of the noise in the current room and play back the inverse of that overtop of your sound. You'll still get some white noise, of course, but it'll be evenly distributed across the spectrum, rather than being focused at certain frequencies; your ears will get used to the background white noise fairly easily, though, and you'll have the added benefit of perceived distortion being even across the spectrum, so the sound will probably "feel" a bit cleaner. If you want to calibrate the system, though, you'll need to do a few measurements. You need the audio "fingerprint" of your mic, your headphones, your sound card input, and your sound card output; you can use two different mics, two different sound inputs, two different sound outputs, and two different sets of output devices. Then, you can emit test frequencies and see how much they get reduced by all 2x2x2x2=16 combinations of apparatus (I *think* that will work), do some algebra, and solve many many systems of equations to find a decent audio profile of each of the pieces in the chain. One sample equation would be: SoftwareOutputVolume * SoundCardDtoAReduction * HeadphoneReduction * MicReduction * SoundCardAtoDReduction = SoftwareInputVolume. Compare the output level you think you're sending to the soundcard, the input level from the soundcard, and repeat ad nauseum. Or, if you don't mind some loss of quality, and you have at least one very good sound card, pair of headphones, and microphone (you want the flattest frequency response possible for all of these), you can simplify the above approach quite a bit (just record signals from your laptop through your everyday headphones with the good equipment, then play signals with the good equipment and record them with your laptop; you get the idea).

    Just some thoughts =)
    If you decide to do a project for this, best of luck (you'll need it).

    --
    --TheOrangeSquid Is it any wonder things seem so awry? We swim in a sea of confusion and don't have to think to survive
  6. Re:There IS a way... by Jerf · · Score: 5, Informative

    What some other people here forget is that by-and-large, the noise created by a PC's fans are stationary signals.

    No, they are not.

    Don't take my word for it. Record some and run it through your favorite MP3 player, with a reasonably sized FFT filter going in realtime. Watch the FFT display jerk spasmodically. Even the wiggling isn't as regular as you think; if you could do an FFT of the FFT, you'd see that. It's noise, it really is, and even if it sounds to your ear like it's "the same" noise, your computer hears it as anything but.

    For extra bonus points (and to really enhance your understanding of what noise really is!), open that noise recording in a sound program. Zoom in really tight, until you can see one wave cycle (from 0, to max, to 0, to min, back to 0 again. It may cross 0 a few times in that span, so eyeball it. You can't really be wrong, so it's not that big a deal, as long as the two ends meet up when you're done.) Copy that sound for 1 or 2 seconds worth, and play it. (Copy and paste it twice, highlight that, copy and paste again, and duplicate that; you'll be into seconds in no time.) Take a moment and ask yourself what you expect this to sound like. Then play it. Is that what you expected? Still don't believe me? Take a larger snippet, three or four waves.

    Noise is really, really dynamic, and you can't predict what it is going to do next.

    Oh, and there's no such thing as noise cancellation, by the way, only cancelling certain sounds at certain isolated locations. That's why you need two headphones, one dedicated to each ear, to cancel noise. A single microphone cannot cancel noise for two ears across a set of frequencies, period, especially if it doesn't know where those ears are.

    Again, don't take my word for it, draw it. Draw equally-spaced concentric circles emanating from a point. Draw equally spaced concentric circles of the same size emanating from another point. The distance between the two concentric circles is the frequency, and let's say one circle's lines is the bottom of the signal, and the other the top. The places where the circle touch the sound is canceled (in this hopelessly perfect little world where nothing is interfering with the sound). In the middle of each of the little quadrangles you build, the sound is doubled. You'll see it's impossible to complete and totally cancel the sound unless the two sources are exactly the same... which is not surprising because that's equivalent to preventing it in the first place!

    And lest ye think that you can put your ears at two of the meeting points (again, totally and completely ignoring the sound's interaction with the environment)... draw another set of circles using the same sources, but multiplying the distance between each concentric circle by, say, 8/7s. And 1/3. And 87/34s. And everything in between. All at once.

    Please try these things before trying to pick them apart; human intuition and wave phenomena are notoriously poor bedfellows.

  7. Re:Better to be slient and be suspected a fool... by arnex · · Score: 3, Informative

    Great Ghu save us from people who think they know more than they actually do!

    Indeed.

    You are evidently unaware that PC audio processing takes place on chunks of audio as it passes through the sound card's buffers. This is where the latency comes from. And since it would require two buffer trips (read buffer -> phase shift -> write buffer) the latency will be doubled.

    Furthermore, the environmental noise sample would need to be taken as close as possible to the point in space where the "dead zone" is to be simulated. This means we'll need to attach two mics to the ears of the listener. It follows then that we'll need to process two independent signals, so double the effective size of your buffers and figure on devoting a few more CPU cycles to the "phase shift" step in the scenario above.

    All things considered, with a fast CPU and extremely small buffers you might be able to reduce latency to fifty or sixty milliseconds, but this simply won't suffice for the requested application.

    Face it, PC sound cards were designed for making asynchronous beep-beep game noises, not for realtime signal processing. Laptop sound "cards" are even worse.