# Can someone help explain what this FFT workflow is doing to my signal, and why it works?

I am working with a piece of equipment that does acoustic analysis. It does this by acquiring a time domain signal and performing an FFT on it to extract the amplitude and phase at a single desired frequency, call it f0. Now, I understand the FFT. That part is easy enough. However, what I don't understand is the consequences of all the extra steps I found in this instrument's LabView code. Here's the procedure:

1. Acquire time domain signal and apply calibration coefficient to every point.
2. Subtract mean from signal to remove DC component
3. Mix with a pure tone at f0 by multiplying the complex time domain signal with cos(2πf0) - i sin(2πf0)
4. Window using exact Blackman
5. Perform FFT
6. Take DC component of output, divide by N/2 (where N is the number of samples in the time domain)
7. Get amplitude and phase at f0 from DC component

Specifically, I'm confused on how step 3 allows me to get the value at f0 by looking at the DC component of the FFT output. I've recreated this in python using numpy.fft.fft and some simulated signals and I get similar results.

At the end of the day, I guess this sounds like a theory/math question.

• For every how, there is typically a “why”. Can’t fully explain how without knowing why. – user28715 Oct 21 '19 at 23:02

## 5 Answers

What's going on is a variant of I/Q demodulation, done in batch mode using the FFT.

First, the fast Fourier transform is just an algorithm that realizes the discrete Fourier transform quickly; so it's a perfect subset of the DFT. What you're doing applies to the DFT as a whole.

(Now I get all math-y. Or maths-y, if I want to emigrate to some place they speak British).

Second, the DFT is defined as $$X_k = \sum_{n=0}^{N-1} {x_n e^{j 2\pi\frac{k n}{N}}}$$

So if I define a modulated signal as $$y_n = x_n e^{j 2 \pi \frac{k_0}{N}n}$$ for some integer $$k_0$$, then by the above definition $$Y_k = \sum_{n=0}^{N-1} { x_n \left ( e^{j 2 \pi \frac{k_0 n}{N}} \right) e^{j 2\pi\frac{k n}{N}}}$$

But I can simplify this: $$Y_k = \sum_{n=0}^{N-1} { x_n e^{j 2\pi\frac{(k + k_0) n}{N}}}$$

However, you can pretty much visually compare this with my first equation, to get $$Y_k = X_{k + k_0}$$.

Which is a really hugely long-winded way of saying that if you multiply by a rotating vector ($$e^{j \omega t}$$) in the time domain, then the result has a spectrum that's shifted up by the frequency of the rotating vector. In your case, the vector has a negative frequency (because $$\cos 2 \pi f t - j \sin 2 \pi f t = e^{-j 2 \pi t}$$), so you're shifting whatever interesting thing is happening at $$f_0$$ down to DC.

• So, long story short, it's removing the carrier? – Mast Oct 22 '19 at 8:20
• No. If it were removing the carrier it would be doing a bunch of work to ignore or subtract out the energy at the carrier frequency. This is moving the energy at the carrier frequency around so that it can get just the signal around the carrier. It's a variant of I/Q demodulation (and I'm going to edit my answer to point that out). – TimWescott Oct 22 '19 at 15:09
• Right, an important difference. Thank you. – Mast Oct 22 '19 at 15:54
• This is awesome. You know, if I'd thought even medium-hard about the DEFINITION of the DFT, I'd have probably figured this out! Thanks for the detailed reply. – Ben S. Oct 22 '19 at 15:55

The answer from Bird has it right.

The described setup is an implementation of a lock-in amplifier.

Lock in amplifiers act as very narrow band filters for detecting the presence of a known signal that is buried in noise.

If you multiply two signals (both simple sine waves) you get a new signal that contains a frequency that is the sum of the original two signals and a frequency that is the difference of the original two signals. (1000Hz * 200Hz gives an output of 800Hz mixed with 1200Hz.) This process is used in radio receivers to bring the received radio signal down to a frequency where it is more convenient to do further processing.

Your LabView program makes use of this effect to detect the amplitude and phase of the signal in comparison to a reference signal.

The difference of the input signal and the reference signal is a signal of 0Hz - that's DC. You get it out of bin 0 in your FFT results.

If the frequency of the input and the reference are not the same, then the difference lands in another bin and is ignored by your detector.

That also makes sense of removing the DC offset from the sample sets - any real DC in the input would cover generated DC from the heterodyning step.

As to why your device is doing that, it is probably so that it can recover a transmitted signal to tell how much of it is coming back to the receiver, and do it pretty much no matter how weak the received signal is or how much noise is present.

Since you say it also takes the phase of the output, it may be using it as part of measuring a distance.

You don't say what the result is used for, or in what conditions you use it so there's not really much more I can say about the "why."

• Thanks for the response! This instrument is used to detect incredibly small sound waves generated by the photoacoustic effect, specifically for small carbonaceous particles (like smoke, for example). The phase information is used to get a qualitative measure of the size of the particles being studied. – Ben S. Oct 22 '19 at 15:57
• So, I guess you know beforehand what frequency of sound your particles will generate. Erk "photoacoustic effect." Seriously weak signals. – JRE Oct 22 '19 at 16:01
• OK. I looked up the photoacoustic effect. Your light is modulated with a known frequency ($f_0$ as you called it.) Then it really makes sense - you are detecting a known frequency, so a lock-in amplifier makes sense. – JRE Oct 22 '19 at 20:53

When you multiply an $$x(n)$$ time-domain sequence by $$e^{-j2\pi f_on/F_s}=\cos(2\pi f_on/F_s)-j\sin(2\pi f_on/F_s)$$ you obtain a complex-valued sequence whose spectrum is $$x(n)$$'s spectrum shifted in the negative-frequency direction by $$f_o$$ Hz. So if $$x(n)$$ had a spectral component at $$+f_o$$ Hz, that spectral component will show up at DC (zero Hz) in the new sequence. And the phase of the new sequence's DC spectral component will be the phase of $$x(n)$$'s $$+f_o$$ spectral component.

• @Fat32. I don't see how your "edit" changed my Answer. – Richard Lyons Oct 23 '19 at 10:58
• I've just replaced $cos$ with $\cos$... You can re-edit your answer if you wish to get rid of my picture from appearing there :-) [that's what I do at such times] – Fat32 Oct 23 '19 at 21:47
• @Fat32. Ah ha, OK. No editing needed, for your picture is a nice picture. – Richard Lyons Oct 24 '19 at 11:55
• Thanks Mr.Lyons, not as cool as yours, but it's ok... – Fat32 Oct 24 '19 at 21:13

Looks to me like a Lock-In Amplifier

• @MBaz Just having the term to search on will be a big help. But given that the demodulation is happening at a fixed frequency, I'm not sure it's accurate to call it a lock in amplifier, although I suppose that lock in amplifiers have free-run modes. – TimWescott Oct 22 '19 at 15:06
• @TimWescott Alright -- thanks for the feedback. – MBaz Oct 22 '19 at 15:32

i do not know what the latter half of step 1 is.

step 2 is unnecessary (assuming $$f_0$$ is not zero).

step 4 and step 5 are unnecessary.

step 6 can be done with averaging. because you bumped the spectrum down by multiplying by $$e^{-j 2 \pi f_0 t} = \cos(2 \pi f_0 t) -j \sin(2 \pi f_0 t)$$, the component at frequency $$f_0$$ is now bumped down, real and imaginary parts, to DC.

averaging gets the DC component.

• You're definitely right that performing FT and then taking only the DC component of that is silly. About steps 2 and 4 being unnecessary I wouldn't be so sure though – this could well make sense to surpress spectral leakage. Though still – the whole thing does sound overcomplicated. – leftaroundabout Oct 22 '19 at 9:00
• You're right that averaging gets us the DC component, but we're also interested in a few values around f0, which was unnecessary to the OP (classic X-Y problem). Averaging a few values around f0 gives us this instrument's definition of noise. – Ben S. Oct 22 '19 at 15:19
• Rather than averaging the frequency-translated samples, we should sum the frequency-translated samples to produce the correct complex-valued spectral DC (zero Hz) sample. – Richard Lyons Oct 23 '19 at 11:10