By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,035 Members | 1,984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,035 IT Pros & Developers. It's quick & easy.

Produce anti-noise

P: n/a
I want to know if the is a way to do something in python to produce
some anti-noise (i.e. I talk in the microphone and the sound go out by
the speakers but with inversed phase).

So I want to know how to control the microphone and to add some sort
of effect to the sound that enter in and to put it out with that
effect and all this at the same time.
Thanks
Jul 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
> I want to know if the is a way to do something in python to produce
some anti-noise (i.e. I talk in the microphone and the sound go out by
the speakers but with inversed phase).

So I want to know how to control the microphone and to add some sort
of effect to the sound that enter in and to put it out with that
effect and all this at the same time.


AFAIK such things need vast amounts of computational power for very
complicated algorithms and very low latencies - a job for specialised DSP
code. Its much more complicated than inverting the amplitude (I don't think
that inverting the phase is possible - AFAIK you can only shift it, and
thats not what you want here...)

So I seriously doubt that you can do that with python - I even doubt that
you can do it with you computer. Not so much from the raw computational
power side of the thing, but much more from your audio-equipment.
Professional noise reduction systems costs several thousands of euro and
feature lots of speakers, especially designed, chosen and arranged to
reflect the acoustic envrionment of _one_ room, e.g. the inside of a
certain car. Then specially adapted algorithms come into play.

And AFAIK they only do a decent job of suppressing predictable signals -
like noise from rolling tyres, wind and engines.

Look at www.bose.de, at least in german they have some explanations on whats
actually going on.

However, it _is_ possible to access microphone and speakers - look for
portaudio or rtaudio-0.2b (for alsa/linux)

Regards,

Diez
Jul 18 '05 #2

P: n/a
In article <bv*************@news.t-online.com>, Diez B. Roggisch wrote:
I want to know if the is a way to do something in python to produce
some anti-noise (i.e. I talk in the microphone and the sound go out by
the speakers but with inversed phase).

So I want to know how to control the microphone and to add some sort
of effect to the sound that enter in and to put it out with that
effect and all this at the same time.


AFAIK such things need vast amounts of computational power for very
complicated algorithms and very low latencies - a job for specialised DSP
code. Its much more complicated than inverting the amplitude (I don't think
that inverting the phase is possible - AFAIK you can only shift it, and
thats not what you want here...)

So I seriously doubt that you can do that with python - I even doubt that
you can do it with you computer. Not so much from the raw computational
power side of the thing, but much more from your audio-equipment.
Professional noise reduction systems costs several thousands of euro and
feature lots of speakers, especially designed, chosen and arranged to
reflect the acoustic envrionment of _one_ room, e.g. the inside of a
certain car. Then specially adapted algorithms come into play.


Hmm. You can buy a $200 set of bose headphones that do it with a simple chip and low power.
I think a regular PC could do this (so long as you know the equations) by brute force. You'd probably want to
use signal processing libraries rather than pure Python, though.

Jul 18 '05 #3

P: n/a
Perhaps I'm not understanding the original question, but if one can get
the signed (-32768...32767) audio input signals, make it into a numeric
array (using Numeric or what have you), multiply that numeric array by
-1, then output the signal, it would be relatively easy to invert the phase.

About the only question is whether or not there is significant overhead
in reading the audio signal, inverting it, then sending the audio signal
back to some set of speakers.
Personally, I'm a big fan of the low-tech approach:
Cut the cable in your microphone, swap the wires, seal the cable.

Adjust the volume on your input microphones (for noise cancellation, one
should optimally have one for each ear), and you are set.
I read an article for doing this kind of thing using just a few
transistors and a 9V battery to produce a few mW amp and a a pair of
very small standard microphones in an electronics hobby book in ~1998.

- Josiah
Jul 18 '05 #4

P: n/a
> Perhaps I'm not understanding the original question, but if one can get
the signed (-32768...32767) audio input signals, make it into a numeric
array (using Numeric or what have you), multiply that numeric array by
-1, then output the signal, it would be relatively easy to invert the
phase.


Then you didn't inverse the phase, but amplitude. Phases can be shift.

Regards,

Diez
Jul 18 '05 #5

P: n/a
> Hmm. You can buy a $200 set of bose headphones that do it with a simple
chip and low power.
I think a regular PC could do this (so long as you know the equations) by
brute force. You'd probably want to use signal processing libraries
rather than pure Python, though.


I'm no acoustics expert, so I'm sort on the speculative side here. But I
described a different scenario: speakers _not_ attached close to your ear.
Then the room accoustics and the place of reception have to be taken into
account. Otherwise, the signal that reaches your ear would have shifts and
other artifacts.

OTOH, when you wear headphones, the scenario seems much simpler, as you then
can detect and produce the appropriate sounds close to the ear. This seem
to be easier.

So, it depends on what the OP had in mind.

Regards,

Diez
Jul 18 '05 #6

P: n/a
>>Perhaps I'm not understanding the original question, but if one can get
the signed (-32768...32767) audio input signals, make it into a numeric
array (using Numeric or what have you), multiply that numeric array by
-1, then output the signal, it would be relatively easy to invert the
phase.

Then you didn't inverse the phase, but amplitude. Phases can be shift.


You are right, I had it confused with something else.

I am curious though, isn't an inverse in phase just a phase shift of 180
degrees? If so, shouldn't inverting the phases of all input waveforms
(if we were to decompose the signal) produce an output that is
funnctionally an amplitude inversion?

- Josiah
Jul 18 '05 #7

P: n/a
Josiah Carlson wrote:
I am curious though, isn't an inverse in phase just a phase shift of 180
degrees? If so, shouldn't inverting the phases of all input waveforms
(if we were to decompose the signal) produce an output that is
funnctionally an amplitude inversion?


That's only true for sin(x).

I think a phase shift is measured in time or as a fraction of the
period, not in degrees. Suppose you have a simple harmonic oscillator,
then a phase shift of a half period means you get a oscillator which
exactly cancels the first one. In the case of harmony, the oscillation
is described with trigonometric functions, so in the simplest case we
define the period to me 2*Pi (or 360 degrees). A half period would then
be Pi (180 degrees) - I think you're confused with that case...

But here, of course, we have no harmonic oscillation, and certainly not
a period of 2*Pi.

yours,
Gerrit.

Jul 18 '05 #8

P: n/a
Gerrit Holl wrote:
I think a phase shift is measured in time or as a fraction of the
period, not in degrees.

But here, of course, we have no harmonic oscillation, and certainly not
a period of 2*Pi.


It's perfectly correct to refer to an amplitude inversion as a
"phase shift of 180 degrees", even when you're not dealing with
a pure sinewave.

When electronic engineers talk about phase shifts, they're
speaking in the frequency domain, not the time domain. For
a non-sinewave signal, a 180 degree phase shift means to
decompose it into sinewave components, shift the phase of
each component by half of that component's period, and
then add the components back together.

In the time domain, this corresponds to simply turning
the signal upside down, and of course this is how it is
usually implemented in hardware. Electronics gurus only
describe it as a phase shift because they're used to
thinking in the frequency domain all the time (where
it's easier to visualise a lot of *other* things that
are more complicated in the time domain).

So the bottom line is, using a DSP to implement a 180
degree phase shift is massive overkill. Just swap the
wires to the speaker. :-)

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

Jul 18 '05 #9

P: n/a
> So the bottom line is, using a DSP to implement a 180
degree phase shift is massive overkill. Just swap the
wires to the speaker. :-)


That is what I said initially. :)
- Josiah
Jul 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.