# Subtracting Original Audio Signal

here is my scenario: one speaker is sending a chirp, and a microphone is recording it as well as all following echoes. The function of the chirp is already know.

My goal: subtract the original chirp from the recorded sound, and leave only the echoes.

I think this questions is hard for me in these ways:

1. To match the original chirp and recorded sounds, I don't know which approach to use: cross-correlation, or minimize sum(abs(difference between two vectors)). The difference here means element-wise difference.
2. The echo may be mixed with the chirp itself, so I'd better only do cross-correlation on the first small portion of the chirp.
3. The amplitude of recorded sound depends on the microphone.

Thank you very much!

• May I ask you what is your goal? Why are you interested in these echoes, but not for example in the impulse response? Why you have chosen this particular method? – jojek Apr 7 '14 at 8:07
• Please refer to following answer as you might find it usefull: link – jojek Apr 7 '14 at 13:24
• @jojek, I'm trying to measure how long does the echo come back. Thank you for the link and it is pretty helpful. But to get impulse response, as described in the link, requires sending sweep sine and recording it. Do we need to subtract the original sound x(t) from recorded sound y(t) to get the "pure" response sound? That is my question in this post. – Kaifei Apr 7 '14 at 20:33
• you have a detailed answer. – jojek Apr 8 '14 at 7:39
• @jojek Yes, I was just spending my time absorbing it. It's great and inspiring, Thanks a ton! – Kaifei Apr 8 '14 at 7:57

Well my friend, let me answer your questions here. You've asked why subtraction of recorded sweep from original one will not produce any info about echos. So I took exponential sinusoid in range of $5\mathrm{Hz}$ up to $7995\mathrm{Hz}$, sampling frequency is $16\mathrm{kHz}$. Then I've used some crude filtering:

In result we get the following:

You can see that amplitude is modulated according to filtering applied. Now if we want to get some info about the impulse response of our system, then let's try simple subtraction as suggested by you, that's what we get:

What you can get from this time domain signal is what is the difference between different frequencies in time. Any info about reflections would not be straightforward. This is simple filtering, so there are none, but imagine you have some reverberation in the end, then your recorded signal is longer than played. Thus you have some tail of decaying sinusoids - nightmare to analyse anything But when you deconvolve filtered signal with the inverse filter, that's what you get:

How beautiful is that! ;) You've obtained the impulse response of a filter that was applied at the very beginning. What's more, you can perform Fourier Transform of that impulse response and that will give you frequency response of this filter. I quickly did some frequency analysis, so you can see result below. Upper normalised frequency axis is forced to be logarithmic. You can easily relate that to filtering applied in the beginning. What's more, you can deduce that this plugin is using FIR filter because phase is linear!

If it was for example measurement of acoustic space, then your impulse response would be:

From that you can very easily detect any reflections, delays between arrivals via different paths and even flutter echo or different fancy stuff.

Because you are interested in detection of echo, then I suggest you to read the work of Dietsch (unfortunately in German): Ein objektives Kriterium zur Erfassung von Echostörungen bei Musik- und Sprachdarbietungen

Above all following thesis: Evaluation of objective echo criteria. Guy is investigating echos a lot - you even have MATLAB files in the appendix.

Some bits about theory standing behind sweep-sine measurements: Advancements in Impulse Response Measurements by Sine Sweeps, and: Simultaneous Measurement of Impulse Response and Distortion with a Swept-Sine Technique

And bit more about derivatives from IR to convince you how powerfull it is: Theoretical and Applied Room Acoustics Including Parameters and IR Derivatives (although that one is targeting more at Architectural Acoustics)

I hope I did convinced you - good luck!

• Hi @jojek, Thank you so much! It takes me a while to review and learn some DSP knowledge before I realize how correct you are! There are just a few points I want to double check. Please correct me if I'm wrong: 1. This filter is determined by the surrounding environment, e.g. a room. 2. After I get this filter using the "sweep-sine measurement", how do I get the "delays between arrivals"? I think the last graph already show the "theoretical" echoes of a spike in the room? And I'll definitely read the "sweep-sine measurement" paper you suggested. Thank you so much again. – Kaifei Apr 8 '14 at 7:52
• The filter shown on the beginning is an example of LTI system - very basic stuff, it only changes frequency response without adding any reflections. Once you do your sweep measurement you can do almost anything with your impulse response. While looking for some echoes (or I would say reflections, because echoes are special kind of these with a minimum delay of $50ms$), you are just checking IR (example on the last plot) for delays between consecutive arrivals (spikes) after main sound. – jojek Apr 8 '14 at 8:02
• More info you can find for example in book of Cavanaugh - Architectural Acoustics: Principles and Practice. Starting from page 224 he's describing kind's of impulse responses with respect to conditions. Luckily for you, pages 224-227 are free to read on google books ;) CLICK! – jojek Apr 8 '14 at 8:12

You can't really subtract out the original sweep. You have a transfer function between speaker and microphone that's heavily dependent on frequency so the amplitude of the sweep will be different at every point in time.

The standard method would be to de-convolve the sweep (convolve with the frequency inverse of the excitation signal) and calculate the impulse response this way.