I would like to cancel out a known audio signal at my receiver.

Specifically at my transmitter I am playing a song, and at my receiver I am recording it. Both transmit and receive sampling rate is 44.1kHz.

At the receiver I basically want to null out the song so that the only thing that is left is the ambient noise in the room.

When I lined up the received and transmitted signal, I noticed that there is sampling offset so I cannot simply subtract out the transmitted signal.

Are there tools in Matlab that are designed for this task? And what are the general principles I can use to solve this?


2 Answers 2


What you are describing is basically an acoustic echo cancellator, as used in e.g. any car with a «hands free» phone solution. Use the (known) dry song track as a reference, and use a stochastic gradient search algorithm (eg NLMS) to online identify the FIR filter which relate your recorded signal to the known reference. As long as the channel (room acoustics) remains relatively stationary (LTI) and the ambient noise is uncorrelated to the reverberated music, you should be able to adopt standard methods to your application.

  • $\begingroup$ might be an awful long LMS filter unless you have a good idea what the delay is (which you might be able to guess with cross-correlation). sometimes you might need thousands of taps if there is a reverberant portion to the delayed signal we're trying to cancel. but a Normalized LMS filter with some predelay is the way to do it. $\endgroup$ Dec 3, 2020 at 21:34

So bad news first: you can't just subtract your transmission.

Any room has more than one path that sound waves can take. Hence, there will be multiple different "copies" of your transmit signal, and they will arrive at the receiver with different delays, according to the path lengths. There, they will add up. You know this as echo / reverberation.

This has a lot of interesting effects, such as frequency selectiveness of your audio channel. Long story short: you can't just assume the signal you receive is transmit signal + noise. That's not how the basic physics below this works, at all.

Then: Good news is that there's ways to "reverse" the effect of a room. We call these methods equalizers; you'll need one that perfectly matches the room (including all obstacles in it). There's ways of "learning" about the room impulse response (which fully describes the described multipath environment, should it not change over time and be linear).

Especially, when you have a reference signal you know has been sent: You can use the same song as kind of a matched filter (if you're from a wireless comms background), or pulse compression (same thing, but if you're from a RADAR background) by correlating with it in the receiver. By doing so, you'd get an estimate for the overall system's impulse response, from DAC to speaker to room to microphone to ADC.

Problem is that it's just an estimate, and the less easy your system model is, the more complex this computation would have to look. Essentially, the assumption that a cross-correlation is sufficient to get the channel impulse response is that your system is linear and time-invariant.

While time-invariance might be given for a static room with no movement, linearity is usually simply not fully true for audio problems. Your speaker does not cause twice the amplitude in air pressure when actuated with twice the signal, for example.

One can, these days, to a high degree calibrate all these disturbing effects out. But I think you might have been underestimating the complexity of your problem there.

  • 1
    $\begingroup$ actually, i think there is a way to determine the primary delay of the signal using cross-correlation, to delay the signal applied to the loudspeaker by a precision of a fraction of a sample, to determine the flat gain at that delay, and to subtract that delayed and scaled signal from what the microphone receives. i am not saying that you would be happy with the result. $\endgroup$ Aug 11, 2019 at 18:17
  • $\begingroup$ well, sure, that'd be kind of an equalizer with channel state information gathered through cross-correlation :) Point I was trying to make is that you can't just subtract a single copy of the original signal and expect that the rest be uncorrelated noise! $\endgroup$ Aug 11, 2019 at 19:20
  • $\begingroup$ right. you would try to subtract the "direct path" signal and then all of those reflections are "the room" (as well as the source). $\endgroup$ Aug 11, 2019 at 21:39
  • $\begingroup$ kind of like a successive interference cancellation equalizer $\endgroup$ Aug 12, 2019 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.