Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Noise Cancelling in Software? 84

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."
This discussion has been archived. No new comments can be posted.

Noise Cancelling in Software?

Comments Filter:
  • Uh, no. (Score:5, Informative)

    by QuantumET ( 54936 ) on Monday October 17, 2005 @07:52PM (#13813159)
    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.
    • Re:Uh, no. (Score:2, Informative)

      by khanyisa ( 595216 )
      Actually the place to do the noise cancellation is at the source of the sound - i.e. the fan - see http://slashdot.org/article.pl?sid=04/03/15/232222 2 [slashdot.org]
    • You'd only get noise cancellation at the rough area around the microphone is, assuming you'd account for the speaker-microphone distance.

      If I recall a Science News article from a few articles, some people were working on systems to cancel noise at specific places in an area, for example at the operator station for a piece of noisy machinery. As you say, you can't do it everywhere, but I don't think it would have to be at the microphone.

      I'd imagine in some applications, depending on the shape of the "silent
    • Re:Uh, no. (Score:4, Informative)

      by Anonymous Coward on Tuesday October 18, 2005 @08:56AM (#13816241)
      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.)
      • They work better than the Ryckebush hardware posted in the original article (I would know, I wasted probably $50-100 in building the hardware and trying to tweak it to get it to work well). The Philips HN100s and HN110s (same thing except different style as far as I can tell) are only $15 INCLUDING shipping on eBay if you look hard enough.

        Far better battery life than the Ryckebush design (40ish hours on a single AAA instead of 2-3 hours AT BEST on a pair of expensive 9vs), somewhat better cancellation, and
      • 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.

        Unless your receiver is moving around.

        What we have here (not from the parent but from the submitter of this article) is a failure to understand the technology. Any attempts at active noise cancellation are going to suck ass unless you know exactly where the
    • Late to the party, but I'd like to add this.
      This only holds if you ignore the fact that the majority of audible sound does not come directly from the source, but from "re-radiated" sound waves emanating from the (metal) exterior of the case.
      How is this significant?
      Conduction of sound waves through metal is 10-20 times faster than through air( http://www.newton.dep.anl.gov/askasci/phy00/ph y00058.htm [anl.gov]), so positional phase variation can be ignored (it's scaled by the same factor). This vastly simplifies the w
  • Position dependence (Score:3, Informative)

    by addaon ( 41825 ) <(addaon+slashdot) (at) (gmail.com)> on Monday October 17, 2005 @07:53PM (#13813161)
    Do you sit in the exact same relative position to the speakers (within a quarter of a wavelength or so) at all times? If not, that idea's dead.
    • 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.
      • Unless the signal can be predicted, which does not seem wholly unlikely. Most background noises are of a fairly constant nature. Record a couple sample sounds and look at the waveforms very close in; a large number of background sounds are repetitive. These are easy to predict and thus could be cancelled, even given the processing delay.

        There's going to be some variation. The technique will not be perfect, but it should be able to achieve rather significant cancellation for many noise sources.
        • If e.g. the variation is just that the sound phase changed by half a period, you will not hear a difference, but your noise cancellation will turn into noise amplification. And that's assuming you have an otherwise perfectly predictable sound.
  • I think it would be cheaper (and better in the long run) in a rack-mount environment to buy quiet, high-quality fans rather than trying to build a device to counter the noise (not that the high-frequency noises caused by most fans would be easy to cancel anyway).
    • The problem with quiet fans in a server-room / rack style environment is that the quiet fans typically don't move a lot of air.

      I've got a 2u switch, with some 60mm fans in a small 6 foot rack in my basement. The fans aren't too loud in and of themselves, but they make a hell of a lot of wind noise and turbulence - because they run at 5000rpm. Now, since I can control the air temperature a little better in my situation than you might in a server room (by not having a crapload of equipment in the rack), I c
      • The was an article not to long ago about underclocking systems, where you can save more power/heat than you slow the system down by, percentage wise. Would the users really notice the servers underclocked by 10%?
      • In low-profile servers the fans are also needed for redundancy. I think the 2U HP G3 proliant I've played with had around 7 fans - each pretty noisy. They were hot-swappable, and arranged side-by-side along the entire width of the server. They probably moved a ton of air in this way (no way for air to recirculate), and probably had redundancy factored in so that if one or two failed it wouldn't be the end of the world.

        High-end servers can tolerate the loss of just about any part other than the CPU or mot
        • In addition (I know I'm posting way late to this thread) - but I've been told of some really massive boxes that act kind of like the networking switches I'm used to messing with.

          You get a passive backplane, add cards. Then you can associate CPU/Memory/Disk or groups of CPU/etc to a certain OS. If one processor fails? There's a spare board to pick up the slack. If a motherboard fails? No problem, spares in the chassis.

          That's what I'd call high end! (Please note that some of this is heresay from people
  • Don't waste your time implementing this in software. You're not going to be able to get low enough latency to make it work.
  • Real-time sound (Score:5, Informative)

    by mbrubeck ( 73587 ) on Monday October 17, 2005 @08:05PM (#13813232) Homepage
    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.
    • Re:Real-time sound (Score:3, Informative)

      by ivan256 ( 17499 ) *
      That doesn't matter. You only cancel constant background noise, so you're canceling based on feedback from sound heard earlier. That's how the headphones work too. (You don't think they have instantanious electronics do you? Even anlog signals have latency.) The real problem comes with phase alignment, which will only be possible at certain points, not everywhere. If you use headphones you could probably do noise cancelation in software without a problem. It would just be fussy, and you'd have to tweak the
      • Re:Real-time sound (Score:3, Informative)

        by munpfazy ( 694689 ) *
        >That doesn't matter. You only cancel
        >constant background noise,
        > so you're canceling based on feedback
        >from sound heard earlier.
        > That's how the headphones work too.

        But there's a big difference between trying to match the phase of a signal using analog parts with an intrinsic bandwidth of MHz and trying to match the phase of a signal when you're latency is several ms at best and varies wildly depending on what the computer is doing.

        If the latency were constant to within a small fraction of t
        • Re:Real-time sound (Score:1, Insightful)

          by munpfazy ( 694689 ) *
          "you're" should of course be "your," to satisfy the grammar fanatics out there.
        • Re:Real-time sound (Score:3, Interesting)

          by ivan256 ( 17499 ) *
          Judicious use of the hardware buffering and some fiddling by the user should be able to overcome the latency deficiency. You just need to write more than your average latency worth of audio to your buffer at a time, and the padding you place at the beginning of your first sample will give you as fine grained control of the phase as you need.

          But you'll be hard pressed to get there using a multi-tasking OS on a standard laptop.

          It depends on the OS. Some allow you to change kernel code. That lets you do your
      • > You only cancel constant background noise, so you're
        > canceling based on feedback from sound heard earlier. That's how the headphones
        > work too.

        Actually, it isn't. You can cancel one-tone that way unless you constantly do a
        windowed FFT.

        > (You don't think they have instantanious electronics do you? Even anlog signals > have latency.)

        Not instananeous, but orders of magnitude faster than digital. Most do in fact just invert the signal. Headphones make the sound directional enough so that it
  • Too slow (Score:3, Insightful)

    by QuietRiot ( 16908 ) <cyrus@80[ ]rg ['d.o' in gap]> on Monday October 17, 2005 @08:08PM (#13813248) Homepage Journal
    Software would generally be too slow. A DSP-based sound card could potentially be programmed to do phase-inversion and time-slew (to account for distance) but an ordinary desktop machine would generally need to be very fast and incorporate real time extensions in the kernel. This is the reason you generally find hardware-only solutions (and in headphones for the reasons mentioned in a peer post). Of course I could be way off....
  • why not... (Score:5, Funny)

    by croddy ( 659025 ) on Monday October 17, 2005 @08:45PM (#13813436)
    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.
  • I once had some earphones with noise cancelling built in. They were made by Akai, had a reasonable quality sound for the price, but, being made for portability rather than sturdiness, broke apart in less than a year.

    I tried using them in planes, but always got an irate flight attendant demanding me to turn them off. Those people are very suspicious of any non-conventional electronic equipment. Stupid, because those analog phones were certainly less dangerous to flight equimpent than the digital hardware, in

    • funny, that story.

      of course, all those in-flight catalogs selling noise-canceling headphones -- not to mention all the people i've seen using them on flight after flight after flight -- i dunno, it kind of makes me wonder if you're not just lying through your teeth.

      • it kind of makes me wonder if you're not just lying through your teeth.

        No, we are just thinking about different times. I got the first noise-cancelling phones I ever saw, this was in 1999.

        Of course, instead of blaming the electronics passengers carry on board, they should first try to reexamine maintenance procedures. Did you know that, when pilots report problems, in 50% of the cases, maintenance can't find the cause of the problem? [usynaptics.com] This means that one half of the airplanes that have potentially harmful p

        • Re:Not in planes... (Score:1, Interesting)

          by Anonymous Coward
          Did you know that, when pilots report problems, in 50% of the cases, maintenance can't find the cause of the problem? This means that one half of the airplanes that have potentially harmful problems keep flying unrepaired.

          No it doesn't. It means that 50% of the time problems are reported by pilots, maintence can't find the problem.

          Your factoid says nothing about: The harmfulness of the reported problems, the rate at which the problems are reported by pilots, and if pilots ever score false poisitves reporti
        • Comment removed based on user account deletion
    • but always got an irate flight attendant demanding me to turn them off.

      What country was this? I've worn mine accross North America and Europe with never a problem, me along with half the plane on some flights. Just don't whip them out in the first or last ten minutes, and no one should stress.

  • by joelsanda ( 619660 ) on Monday October 17, 2005 @09:08PM (#13813550) Homepage

    ... 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.

  • With present computing technology, the latency involved in running anything through software will be way too high to implement a noise cancellation scheme.
  • Loud Noise (Score:5, Funny)

    by DavidLeeRoth ( 865433 ) on Monday October 17, 2005 @09:20PM (#13813609)
    I dont know how to noise cancel, but I know how to create a ton! cat /dev/urandom > /dev/dsp :)
    • Tired of those loud squealing sounds coming from your speakers every time you run cat /dev/urandom > /dev/dsp? Then try our NEW noise-canceling software! Guaranteed to produce complete silence! Now you can run cat /dev/urandom > /dev/dsp without all that distracting sound!

      "I bought this product and deployed it throughout my company. Now when my employees dump random data to their speakers, I don't hear a thing! Brilliant!"

      Get your urandom-to-dsp noise canceler today! Only $59.95! Order now!

  • by the eric conspiracy ( 20178 ) on Monday October 17, 2005 @09:53PM (#13813733)
    You want one of these [loc.gov]

  • by stvangel ( 638594 ) on Monday October 17, 2005 @10:05PM (#13813784)
    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.
    • That last bit is a great idea. The fans are rather consistent.
    • 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.

      This is wrong. It's not the frequency of the sound that matters, but rather the rate of change in the spectrum. Imagine a constant, 15,000 hertz tone. Are you saying this cannot be cancelled? Of course it can. But a noise which has a rapidly and un

      • This has nothing to do with the system response time (which is fast enough), and everything to do with the frequency. Higher frequencies have shorter wavelengths and are much more directional. A sound with a frequency of 40Hz will have a wavelength of 8.6 meters. A sound with a frequency of 20 kHz will have a wavelength of 17 millimeters, about 500 times shorter.

        • The system could slew phase until the desired cancelation is achieved at some arbitrarily high frequency.
          It is the rate of change of the parameters of the system (whether in time or frequency space) to which it must adapt that ultimately governs its abilities.
          Fan noise is fairly stationary... so.

          However there are all sorts of other issues which can not be easily solved (microphone/speaker placement, limited affected area, etc.).
        • Higher frequencies have shorter wavelengths and are much more directional.

          Yes, but your point is? There are sound cancellation systems in service which operate over the entire audible range. So clearly this is possible. As you said, latency is not necessarily a problem. So the cancellation may occur within a specific volume, not everywhere, but that's fine as long as the destructive interference occurs near the listener's ear.

          My point is that the spectral variations of certain types of sounds are predi

  • by Refrozen ( 833543 ) <email.answers@gmail.com> on Tuesday October 18, 2005 @01:40AM (#13814712)
    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.
  • I'm not an expert nor have I tried this, but a server will likely be making very predictable and repetitive noise, mostly from its fans.

    Given that the sound will be predictable and repeated, can't the noise cancelling software make the same waveform, output it with an adjusted phase?

    It may not be necessary to have low-latency from input sampling to output, if there is enough predictability.

  • If you have problems with latency, it's just a matter of slowing down the noise, or slowing down the noise source. That way you'll have time for your DSP to process the signals. The coding is left as an excercise to the reader. Basic physics meet ask slashdot!
  • I have tried out voice recognition software to control Winamp. I yell "pause", and the microphone hears me say "pause" and pauses the music.

    The problem is that sometimes the music might make a sound that sounds like the word "pause" as well, thus pausing itself.

    Why not simply cancel out "what you hear" coming out of the speakers, from "what is spoken" going into the microphone? Then the voice-recognition software could focus solely on my voice, instead of my voice mixed in with the winamp music....

    T

  • As the other posters said, noice cancelling is really hard, and even when it works, only works to a degree.

    Depending on your motivation, other fun technical solutions may apply. Recently I've been running into situations where wireless headsets would've been really useful; for example, in any noisy environment, or situations where the speakers get separated out of earshot. I would love to have some while shopping or hiking with company. Anyone have any recommendations?

  • Could any of these techniques be used to cancel a specific type of noise?

    I live very near a Master Navy Jet Base and the jet noise can be deafening. Many times there are several planes per minute for hours flying just over the treetops while practicing touch and go landings. I've often wondered if it would be possible to do just what the original poster was asking in order to mitigate the ear piercing noise.
  • I sell noise cancellation material and noise cancellation material accessories. See, a lot of the noise you hear is not primary-source noise, it is 2ndary, meaning that you hear mostly reverberations. The primary waves bounce around (becoming 2ndary) and interfere with new primary waves, creating exessive noise. My material is extremely effective at cancelling 2ndary noise and somewhat effective at cancelling primary noise. Even with primary noise uncancelled, cancelling the 2ndary noise has a profound effe

I tell them to turn to the study of mathematics, for it is only there that they might escape the lusts of the flesh. -- Thomas Mann, "The Magic Mountain"

Working...