# Measuring amplitude of a spectral component

I'm trying to measure the amplitude of a spectral component in a signal. The component's frequency is always known beforehand.

I take a given number of samples, apply the flattop window to reduce scalloping loss, then use FFT and look at the bin of interest.

The earlier method used adaptable sampling frequency ($f_s$ was an integer multiple of the signal frequency) -> no windowing was needed.

Compared to the earlier method, measurements with the new method have a lot more variance. I suspect that it is the window that picks up the noise (convolution over the whole spectrum, where there are other strong components).

The $f_s$ is either 312 KS/s or 625 KS/s, the signal frequency is 2-15 KHz.

How could I improve my measurement?

Is there an other method which exploits the fact that the frequency of the signal is always exactly known?

If you know the frequency beforehand you can simply correlate the signal with a sine and cosine of that frequency and find the magnitude of the response. This is what the DFT is doing at that bin.

Let $x[t]$ be your signal, and $f_c$ be the frequency you are interested in, and $f_s$ be your sample rate.

Then let

$$a = \left<x,\cos(2\pi t f_c/f_s)\right>$$ $$b = \left<y,\sin(2\pi t f_c/f_s)\right>$$

Then the amplitude is equal to $\sqrt{a^2 + b^2}$.

However, if you are getting some noise, then other components of the signal are also putting energy into that frequency. It might work to split the signal into blocks, calculate the amplitude for each block, then find median or discard outliers and find the average.

A variation on @geometrikal's answer would be to use the Goertzel Algorithm.

$$y[n] = x[n] + e^{+j\omega_0} y[n-1]$$ where $x[n]$ is your input signal, $\omega_0$ is the frequency you know, and $y[n]$ is the (complex-valued) estimate of the discrete Fourier coefficient.