Slashdot Mirror


Noise Cancelling in Software?

doc_verma wonders: "There are directions to build noise-cancelling devices in hardware, but what would it take to create noise cancelling in software? Since computers have a speaker-of-sorts and can possibly have a microphone, why not take the input from the mic, reverse-phase it via software, and output it through the speaker? A noise-cancelling feature would be great to run on servers in a rack. It would also be a great app to run on your laptop when you are on a plane."

11 of 84 comments (clear)

  1. Uh, no. by QuantumET · · Score: 4, Informative

    You'd only get noise cancellation at the rough area around the microphone is, assuming you'd account for the speaker-microphone distance. You have to cancel phase _everywhere_ for it to work for a room, and you can't do that, really, without a huge array of speakers, or speakers exactly co-located with noise sources.

    So you could do it in software for headphones, since you just need to cancel noise right at the headphones, which is fine. But it's no good for speakers, unless you have very specific configurations of noise sources that lend themselves to simple cancellation. In general, no way.

    1. Re:Uh, no. by Anonymous Coward · · Score: 4, Informative
      I am an electrical engineer.

      Parent is exactly right. There are two ways to handle noise cancellation. #1 is source cancellation (very hard unless the source is confined). #2 is receiver cancellation (very easy). However, don't expect either method to work at high frequencies.

      Sound is a complex beast. Literally. Imagine you could have enough samples to make a 3D spectrum analysis of the sound. What would it look like? You'd see high frequencies "beaming" off of reflective surfaces. You'd see low frequencies "wrapping around" small objects.

      To do source cancellation, you have to find a way to negate all of the sound energy before it reaches *any* receiver. Put your computer in a box with a long, narrow air take. Carefully design the intake/exhaust to minimize "port noise". Add noise cancellation *inside* the box. Walk around. You shouldn't hear anything coming out of the box.

      If you can't control the source, you have to resort to receiver cancellation. "Why?," you ask. Because if you mess up on the phase, you can/will end up contributing 3dB to the noise source at various frequencies/locations. That's not acceptable.

      Receiver cancellation works just like source cancellation, except you put the box around the receiver. In our case, the "box" is headphones. Put a high quality microphone on one side. Feed a phase-inverted signal into the output speakers.

      Earlier I mentioned that noise cancellation doesn't work well at high frequencies. Why is that? Delay. At low frequency, the signal changes very slowly. If I'm "off" by 1 microsecond, it won't make any difference to a signal that oscillates at 60Hz. Here's a little exercise for the reader:
      F(t) = cos (2 * pi * f * t) - cos (2 * pi * f * (t + d))
      In this example, we're considering only one frequency and one point in space. Let f = 60Hz. Let d vary from 0 to 16ms. Observe the results. What happened at 2.79 ms? At 8.33 ms? Nasty, eh? But we're pretty confident our system can handle those latencies without any trouble, so we'll crank this thought experiment up to 4kHz.

      Let's do some envelope calculations: our latency has to be under 42 microseconds to do *any* good (i.e. avoid adding to the noise), under 21 microseconds to get a 3dB attenuation, under 4.2 microseconds to get -10dB, and under 0.4 microseconds to get -20dB. No sweat, right? :-)

      I'm going to be a bit facetious here and start by examing the CPU aspects. Ok you've got a 3GHz cpu. Let's be "generous" and assume you get about 1.67 instructions/clock. That means you can execute about 5e9 instructions/second (0.2 microseconds/instruction). There's no way you could hope to get any meaningful work done in 2 instructions, so that rules out the possibility of getting -20dB. In fact, there's not much you could hope to do in ~20 instructions, so there goes -10dB. You *might* be able to write a dedicated driver that could handle -3dB. Whooptee freaking doo *twirls finger*. The padding on your headphones probably does a better job. Or just stick some cotton in your ears.

      Even if you manage to get your digital hardware up to speed, you've got another problem: the analog hardware. That's right: between your $0.50 microphone and your $0.50 speaker, there's a pretty decent chance that they've got more than a few microseconds of slew error. Even if you bumped those up to $100.00 each, you're still not likely to get it right. In short: don't expect to do -20dB at 4kHz for under a few grand (*).

      Last I heard, the $100 sony headphones do about -10dB at 100-400Hz. As far as I can tell, the hardware is only worth about $2, and you're paying $98 in salesman, middleman, marketing and engineer salaries.

      (* No, this is not an offer. I wouldn't try building you a pair for less than a million in R&D funds, and even then I couldn't guarantee results.)
  2. Real-time sound by mbrubeck · · Score: 4, Informative

    Your computer's sound input and output are buffered in both software and hardware. This means that there will be a minimum latency measured in tens or hundreds of milliseconds between reading input from the microphone and being able to send corresponding output to the speakers. You can make this latency smaller and more predictable with well-designed hardware, drivers, and applications software, but you'll never be able to do the same "real-time" processing that you can do with dedicated hardware.

  3. Re:Position dependence by Ratso+Baggins · · Score: 3, Informative

    and further and perhaps more importantly there's time delay. In order for the wave to be present at your ear at the exact same time as the anti-phase wave, the ant-phase must be calculated and delivered in real time. The only real way to do this today is with an analog amplifier because dealing with the signal digitally introduces delay (eg: A/D) which cannot be compensated for (in that, the event is over before the anti-phase signal is produced.

    --

    --
    "we live in a post-ideological world..." - Billy Bragg.

  4. why not... by croddy · · Score: 4, Funny

    why not take the input from the mic, reverse-phase it via software, and output it through the speaker? well, i suppose the howling, squealing feedback would make you forget about the server fans for a few seconds, but i suspect it would just end up giving you a bigger headache in the long run.

  5. My child once talked for eight hours straight ... by joelsanda · · Score: 3, Funny

    ... on a road trip across the West. Eight solid hours of a four year old pontificating. I searched the car high and low for the travel headphones so I could get a break with my MP3 player. Couldn't find them and the only stores for thousands of miles in any direction sold only alcohol, Mormon cookbooks, and knives.

    This is a cool idea.

    --
    The Luddites were ahead of their time.
  6. Loud Noise by DavidLeeRoth · · Score: 5, Funny

    I dont know how to noise cancel, but I know how to create a ton! cat /dev/urandom > /dev/dsp :)

  7. Fenton Silencer by the+eric+conspiracy · · Score: 3, Funny

    You want one of these

  8. This is possible with two specific caveats. by stvangel · · Score: 3, Insightful

    The biggest issue is to only have one specific sound source you're trying to muffle. You have to place the microphone as near to the sound source as possible, and the location of your speaker will depend on how long it takes to process the signal. It will also be highly directional unless you rig something up with multiple speakers all aimed in different directions. You will also need to be a certain distance away to allow the reverse-phase sounds to merge and cancel each other out.

    The other issue is that it will only work on low pitched sounds, the lower the better. The slower the frequency, the more time you have to do the math and output your opposite signal. High frequency sounds you can pretty much forget about being able to process.

    One use for this might be to muffle a single exhaust pipe from a loud motor, but you won't be able to get it to work for general noise. The reason it works in Noise-cancelling headsets is that the microphone is located at the destination of the sound (your ear), rather than at the source. The closer you can get it either end, the better it will work. It's not really worth doing it in Software

    One interesting thought about quieting individual fans or motors is to use an Adaptive algorithm. Because most of these devices make a consistent repeating sound, it would be interesting to be able to anticipate the sound source over time and broadcast an estimated calculation before the current sound is even processed and use the processed result to tweak the future estimation. This would work on only reasonably consistent sources and there would be issues with feedback and unexpected noise changes.

  9. Re:My child once talked for eight hours straight . by OneDeeTenTee · · Score: 5, Funny

    the only stores for thousands of miles in any direction sold only alcohol, Mormon cookbooks, and knives.

    Sounds like a bad day for the Mormons if you're hungry.

    --
    Stop the world; I need to get off.
  10. Why did this get approved? by Refrozen · · Score: 3, Informative

    This isn't Slashdot worthy material, but I'll answer it with some information anyways.

    The key to noise cancelling is direction. The inversed noise has to be travelling in the same direction the noise otherwise would, and it has to be inverted and spat out at almost the exact same time.

    While the speed issue isn't a problem, the microphone and speakers aren't good for the directionalness. It works well in headphones, because with headphones you have a very specific direction: in to your ear. The microphone can pick up things relatively directional (depending on the type of mic.) but the speakers are made to spread sound, not to aim it.

    That and they would have to be in roughly the same location (within a few cm.) for it to work properly.

    What I want, is a noise cancelling dome, so two people can go under it, talk, and have no one outside hear anything, that'd be cool.