DSPRelated.com
Forums

adaptive sine-wave cancellation

Started by Robert Adams November 18, 2008
I am trying to solve the following problem;

I drive a speaker with a sine-wave of known frequency = w.
A second speaker is driven with a signal that attempts to cancel the
sound of the first speaker at a nearby microphone.

So the problem is to find the amplitude and phase of the cancellation
signal that drives the cancellation speaker.

The transfer function from either speaker to the microphone is unknown
and possibly slowly time-varying. It is not possible to measure it, as
the user does not expect to hear any "calibration" signals.

Currently I use the following algorithm

let the microphone signal = M, and the cancellation signal C = A*cos
(w*t) + B*sin(w*t)

update A and B according to

A sub(n+1) = A sub(n) + alpha*M*cos(w*t)

B sub(n+1) = B sub(n) - alpha*M*sin(w*t)

where alpha is a small update coefficient.

This works well when the phase-shift of the path from cancellation
speaker to microphone is small (< 90 degrees), but with large phase
shifts the polarity of the adaptive algorithm is reversed and the
whole thing blows up.

If the speaker-to-mic phase shifts were known, one could of course pre-
compensate the phase of the compensation signal and life would be good
again; but this is not possible. Also, the signal to the main speaker
cannot be tuned off.

Another complication is that the listener must perceive the sound
gracefully decaying to zero, so this rules out any trial-and-error
type of procedure.

Any suggestions?

Bob Adams



On Tue, 18 Nov 2008 16:45:02 -0800, Robert Adams wrote:

> I am trying to solve the following problem; > > I drive a speaker with a sine-wave of known frequency = w. A second > speaker is driven with a signal that attempts to cancel the sound of the > first speaker at a nearby microphone. > > So the problem is to find the amplitude and phase of the cancellation > signal that drives the cancellation speaker. > > The transfer function from either speaker to the microphone is unknown > and possibly slowly time-varying. It is not possible to measure it, as > the user does not expect to hear any "calibration" signals. > > Currently I use the following algorithm > > let the microphone signal = M, and the cancellation signal C = A*cos > (w*t) + B*sin(w*t) > > update A and B according to > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > where alpha is a small update coefficient. > > This works well when the phase-shift of the path from cancellation > speaker to microphone is small (< 90 degrees), but with large phase > shifts the polarity of the adaptive algorithm is reversed and the whole > thing blows up. > > If the speaker-to-mic phase shifts were known, one could of course pre- > compensate the phase of the compensation signal and life would be good > again; but this is not possible. Also, the signal to the main speaker > cannot be tuned off. > > Another complication is that the listener must perceive the sound > gracefully decaying to zero, so this rules out any trial-and-error type > of procedure. > > Any suggestions? > > Bob Adams
If the first speaker's frequency is _really_ well known you should be able to acquire the signal, then monitor the change as the second speaker starts up, so you know the phase shift and gain from the second speaker and can adjust the phase and amplitude accordingly. If you don't know that first speaker's frequency all that well I'd suggest a moderately wide, very low level pseudo noise signal coming from the second speaker that you can acquire, use to capture the phase shift and gain, then adjust your cancellation phase and gain accordingly. Good luck... -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
"Robert Adams" <robert.adams@analog.com> wrote in message
news:50766897-75fa-479d-96da-fb6b9e2937e9@z6g2000pre.googlegroups.com...
> I am trying to solve the following problem; > > I drive a speaker with a sine-wave of known frequency = w. > A second speaker is driven with a signal that attempts to cancel the > sound of the first speaker at a nearby microphone. > > So the problem is to find the amplitude and phase of the cancellation > signal that drives the cancellation speaker. > > The transfer function from either speaker to the microphone is unknown > and possibly slowly time-varying. It is not possible to measure it, as > the user does not expect to hear any "calibration" signals. > > Currently I use the following algorithm > > let the microphone signal = M, and the cancellation signal C = A*cos > (w*t) + B*sin(w*t) > > update A and B according to > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > where alpha is a small update coefficient. > > This works well when the phase-shift of the path from cancellation > speaker to microphone is small (< 90 degrees), but with large phase > shifts the polarity of the adaptive algorithm is reversed and the > whole thing blows up.
The update equation signs should be the same for A and B: A -= Alpha x M x cos (wt) B -= Alpha x M x sin(wt) Vladimir Vassilevsky DSP and Mixed Signal Consultant www.abvolt.com
On Nov 18, 11:45&#4294967295;pm, "Vladimir Vassilevsky"
<antispam_bo...@hotmail.com> wrote:
> "Robert Adams" <robert.ad...@analog.com> wrote in message > > news:50766897-75fa-479d-96da-fb6b9e2937e9@z6g2000pre.googlegroups.com... > > > > > > > I am trying to solve the following problem; > > > I drive a speaker with a sine-wave of known frequency = w. > > A second speaker is driven with a signal that attempts to cancel the > > sound of the first speaker at a nearby microphone. > > > So the problem is to find the amplitude and phase of the cancellation > > signal that drives the cancellation speaker. > > > The transfer function from either speaker to the microphone is unknown > > and possibly slowly time-varying. It is not possible to measure it, as > > the user does not expect to hear any "calibration" signals. > > > Currently I use the following algorithm > > > let the microphone signal = M, and the cancellation signal C = A*cos > > (w*t) + B*sin(w*t) > > > update A and B according to > > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > > where alpha is a small update coefficient. > > > This works well when the phase-shift of the path from cancellation > > speaker to microphone is small (< 90 degrees), but with large phase > > shifts the polarity of the adaptive algorithm is reversed and the > > whole thing blows up. > > The update equation signs should be the same for A and B: > > A -= Alpha x M x cos (wt) > B -= Alpha x M x sin(wt) > > Vladimir Vassilevsky > DSP and Mixed Signal Consultantwww.abvolt.com- Hide quoted text - > > - Show quoted text -
Yes, this was a typo, sorry. Bob
On Nov 18, 10:43&#4294967295;pm, Tim Wescott <t...@justseemywebsite.com> wrote:
> On Tue, 18 Nov 2008 16:45:02 -0800, Robert Adams wrote: > > I am trying to solve the following problem; > > > I drive a speaker with a sine-wave of known frequency = w. A second > > speaker is driven with a signal that attempts to cancel the sound of the > > first speaker at a nearby microphone. > > > So the problem is to find the amplitude and phase of the cancellation > > signal that drives the cancellation speaker. > > > The transfer function from either speaker to the microphone is unknown > > and possibly slowly time-varying. It is not possible to measure it, as > > the user does not expect to hear any "calibration" signals. > > > Currently I use the following algorithm > > > let the microphone signal = M, and the cancellation signal C = A*cos > > (w*t) + B*sin(w*t) > > > update A and B according to > > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > > where alpha is a small update coefficient. > > > This works well when the phase-shift of the path from cancellation > > speaker to microphone is small (< 90 degrees), but with large phase > > shifts the polarity of the adaptive algorithm is reversed and the whole > > thing blows up. > > > If the speaker-to-mic phase shifts were known, one could of course pre- > > compensate the phase of the compensation signal and life would be good > > again; but this is not possible. Also, the signal to the main speaker > > cannot be tuned off. > > > Another complication is that the listener must perceive the sound > > gracefully decaying to zero, so this rules out any trial-and-error type > > of procedure. > > > Any suggestions? > > > Bob Adams > > If the first speaker's frequency is _really_ well known you should be > able to acquire the signal, then monitor the change as the second speaker > starts up, so you know the phase shift and gain from the second speaker > and can adjust the phase and amplitude accordingly. > > If you don't know that first speaker's frequency all that well I'd > suggest a moderately wide, very low level pseudo noise signal coming from > the second speaker that you can acquire, use to capture the phase shift > and gain, then adjust your cancellation phase and gain accordingly. > > Good luck... > > -- > > Tim Wescott > Wescott Design Serviceshttp://www.wescottdesign.com > > Do you need to implement control loops in software? > "Applied Control Theory for Embedded Systems" gives you just what it says. > See details athttp://www.wescottdesign.com/actfes/actfes.html- Hide quoted text - > > - Show quoted text -
Tim Thanks for the suggestions. Yes, the frequency is very well known, so on initial startup I could do as you suggest. The problem is that the frequency varies over about a 2:1 range over a period of a few seconds, and as the frequency varies the phase of the cancellation path can vary by a lot; so I would need to "re-start" which means setting the cancellation path to zero and then trying a few different cancellation phases to see which one pushes the error in the right direction; and the listener would of course experience a loss of cancellation during this time. Bob

Robert Adams wrote:
> > I am trying to solve the following problem; > > I drive a speaker with a sine-wave of known frequency = w. > A second speaker is driven with a signal that attempts to cancel the > sound of the first speaker at a nearby microphone. > > So the problem is to find the amplitude and phase of the cancellation > signal that drives the cancellation speaker. > > The transfer function from either speaker to the microphone is unknown > and possibly slowly time-varying. It is not possible to measure it, as > the user does not expect to hear any "calibration" signals. > > Currently I use the following algorithm > > let the microphone signal = M, and the cancellation signal C = A*cos > (w*t) + B*sin(w*t) > > update A and B according to > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > where alpha is a small update coefficient. > > This works well when the phase-shift of the path from cancellation > speaker to microphone is small (< 90 degrees), but with large phase > shifts the polarity of the adaptive algorithm is reversed and the > whole thing blows up. > > If the speaker-to-mic phase shifts were known, one could of course pre- > compensate the phase of the compensation signal and life would be good > again; but this is not possible. Also, the signal to the main speaker > cannot be tuned off. > > Another complication is that the listener must perceive the sound > gracefully decaying to zero, so this rules out any trial-and-error > type of procedure. >
I think you are trying to do too much at once. Try holding the cancel signal at a constant volume until it reaches the correct phase. In other words, normalize A and B so that always A^2+B^2=[some constant]. That means as A grows B will shrink or visa versa. If your process is working correctly it should reach a steady state for A and B fairly shortly. At that point it should be canceling as much as it can at that particular volume and you can then allow the amplitude of C to also vary. -jim ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= - Total Privacy via Encryption =---
On Nov 19, 8:07&#4294967295;am, jim <"sjedgingN0sp"@m...@mwt.net> wrote:
> Robert Adams wrote: > > > I am trying to solve the following problem; > > > I drive a speaker with a sine-wave of known frequency = w. > > A second speaker is driven with a signal that attempts to cancel the > > sound of the first speaker at a nearby microphone. > > > So the problem is to find the amplitude and phase of the cancellation > > signal that drives the cancellation speaker. > > > The transfer function from either speaker to the microphone is unknown > > and possibly slowly time-varying. It is not possible to measure it, as > > the user does not expect to hear any "calibration" signals. > > > Currently I use the following algorithm > > > let the microphone signal = M, and the cancellation signal C = A*cos > > (w*t) + B*sin(w*t) > > > update A and B according to > > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > > where alpha is a small update coefficient. > > > This works well when the phase-shift of the path from cancellation > > speaker to microphone is small (< 90 degrees), but with large phase > > shifts the polarity of the adaptive algorithm is reversed and the > > whole thing blows up. > > > If the speaker-to-mic phase shifts were known, one could of course pre- > > compensate the phase of the compensation signal and life would be good > > again; but this is not possible. Also, the signal to the main speaker > > cannot be tuned off. > > > Another complication is that the listener must perceive the sound > > gracefully decaying to zero, so this rules out any trial-and-error > > type of procedure. > > I think you are trying to do too much at once. > &#4294967295; &#4294967295; &#4294967295; &#4294967295; Try holding the cancel signal at a constant volume until it reaches the > correct phase. In other words, normalize A and B so that always > A^2+B^2=[some constant]. That means as A grows B will shrink or visa versa. > If your process is working correctly it should reach a steady state for A > and B fairly shortly. At that point it should be canceling as much as it can > at that particular volume and you can then allow the amplitude of C to also > vary. > > -jim > > ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----http://www.pronews.comThe #1 Newsgroup Service in the World! >100,000 Newsgroups > ---= - Total Privacy via Encryption =---- Hide quoted text - > > - Show quoted text -
Jim I think this is a good idea, thanks! Bob
On Nov 18, 6:45&#4294967295;pm, Robert Adams <robert.ad...@analog.com> wrote:
> I am trying to solve the following problem; > > I drive a speaker with a sine-wave of known frequency = w. > A second speaker is driven with a signal that attempts to cancel the > sound of the first speaker at a nearby microphone. > > So the problem is to find the amplitude and phase of the cancellation > signal that drives the cancellation speaker. > > The transfer function from either speaker to the microphone is unknown > and possibly slowly time-varying. It is not possible to measure it, as > the user does not expect to hear any "calibration" signals. > > Currently I use the following algorithm > > let the microphone signal = M, and the cancellation signal C = A*cos > (w*t) + B*sin(w*t) > > update A and B according to > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > where alpha is a small update coefficient. > > This works well when the phase-shift of the path from cancellation > speaker to microphone is small (< 90 degrees), but with large phase > shifts the polarity of the adaptive algorithm is reversed and the > whole thing blows up. > > If the speaker-to-mic phase shifts were known, one could of course pre- > compensate the phase of the compensation signal and life would be good > again; but this is not possible. Also, the signal to the main speaker > cannot be tuned off. > > Another complication is that the listener must perceive the sound > gracefully decaying to zero, so this rules out any trial-and-error > type of procedure. > > Any suggestions? > > Bob Adams
It seems that you need to know in which direction to drive the anti- signal. That implies a gradient. Also, it looks lilke you might be trying to apply the gradient with your update equations. IF THAT IS THE CASE, I may be wrong, but it appears to me that A(n+1) = A(n) + alpha M cos(wt), and B(n+1) = B(n) + alpha M sin(wt) is NOT the gradient of the squared error, [M - (A'cos(wt) + B'sin(wt))] ^2, where A' and B' are estimates A and B in M = Acos(wt) + Bsin (wt). Nor is it the gradient of the error M - (A'cos(wt) + B'sin (wt)). As I said, I may be wrong, but you might want to address your update equations again. Maurice Givens
Robert Adams wrote:

> Thanks for the suggestions. Yes, the frequency is very well known, so > on initial startup I could do as you suggest. The problem is that the > frequency varies over about a 2:1 range over a period of a few > seconds, and as the frequency varies the phase of the cancellation > path can vary by a lot; so I would need to "re-start" which means > setting the cancellation path to zero and then trying a few different > cancellation phases to see which one pushes the error in the right > direction; and the listener would of course experience a loss of > cancellation during this time.
I think you should be able to follow it if it is sufficiently slow, and not if the change is too fast. The PLL literature should explain the how fast phase can change and keep the lock as a function of the PLL parameters. It seems to me that you want a PLL for the phase/frequency part and additional circuitry to lock the amplitude. (Call it ALL for Amplitude Locked Loop.) Then you need sufficient damping in the two such that the combination doesn't oscillate. -- glen
Robert Adams wrote:
> I am trying to solve the following problem; > > I drive a speaker with a sine-wave of known frequency = w. > A second speaker is driven with a signal that attempts to cancel the > sound of the first speaker at a nearby microphone. > > So the problem is to find the amplitude and phase of the cancellation > signal that drives the cancellation speaker. > > The transfer function from either speaker to the microphone is unknown > and possibly slowly time-varying. It is not possible to measure it, as > the user does not expect to hear any "calibration" signals. > > Currently I use the following algorithm > > let the microphone signal = M, and the cancellation signal C = A*cos > (w*t) + B*sin(w*t) > > update A and B according to > > A sub(n+1) = A sub(n) + alpha*M*cos(w*t) > > B sub(n+1) = B sub(n) - alpha*M*sin(w*t) > > where alpha is a small update coefficient. > > This works well when the phase-shift of the path from cancellation > speaker to microphone is small (< 90 degrees), but with large phase > shifts the polarity of the adaptive algorithm is reversed and the > whole thing blows up. > > If the speaker-to-mic phase shifts were known, one could of course > pre- compensate the phase of the compensation signal and life would > be good again; but this is not possible. Also, the signal to the main > speaker cannot be tuned off. > > Another complication is that the listener must perceive the sound > gracefully decaying to zero, so this rules out any trial-and-error > type of procedure. > > Any suggestions? > > Bob Adams
This looks to me like a classical line canceller application. input--------->----------------------[spkr 1]->(+)----+----> e[n] ^ | . ^ | . | | . | | noise ->----------------------->[LMS]-[spkr2 ]---+ | ^ | | | +--------------------+ Adaptive line-cancelling filter LMS adaptive filter adjusts to minimize e[n] which cancels noise in the signal by subtracting filtered version of noise. The LMS filter adjusts the amplitude and phase of its periodic input components to cancel the periodic noise component in the signal. In your case, e(n) is the output of the microphone. The "noise" is the signal you're going to use to cancel the "input". i.e. a replica of the sinusoid. The LMS filter adjusts the amplitude and phase of the drive to spkr2 so that it minimizes the output of the microphone. See: http://www.owlnet.rice.edu/~ryanking/elec431/compare.html http://plaza.ufl.edu/badavis/EEL6502_Project_1.html etc. Now, your implementation assumes that both the signal and the cancelling signal (the noise reference here) are sinusoids of the same frequency. Then, the LMS filter might simplify into a simple magnitude and delay which would be an LMS filter with weights [ 0 0 0 ....0 0 0 0 k 0 0 0 0 0 0 0 .......0] where the location of the single weight of gain k is determined to make the delay what you want. Thus, your implementation isn't all that different except it's expressed in continous time. One of the tricks of the trade is to adjust the amplitude steps at each iterative step, trading convergence time against end results. Bigger steps, faster convergence, worse results. Smaller steps, slower convergence, better results .... as long as the situation is static!!! Fred