# What is the name for the technique of comparing a time domain signal to an expected signal with a sliding window?

I was trying to think about how to do time-domain analysis of a real-valued signal to determine if it contains a particular carrier. I can obviously just compute an FFT, but that transforms a window of samples into the frequency domain. I don't necessarily need a measurement of the entire frequency domain, just to determine if it contains a particular frequency.

I generated a signal at a sample rate of 8000 samples per second, a carrier of 444 Hz, and some uniform noise. The carrier amplitude is 0.7 and the noise amplitude is 0.3, for a range of [-1,1].

To analyze the signal I generated a filter that has a buffer of samples and a buffer of expected values. The expected values are populated with a sine wave from [0, 2*pi]. When a new sample comes in, the oldest is pushed out of the filter. The filter's measurement is obtained by computing the product of each sample with the expected value, summing it and diving by half the filter length.

This gave really poor results, but I had the idea that the filters was just responding too quickly. I increased the expected values from [0, 8*pi] and increased the samples buffer accordingly. This seemed to reproduce the expected signal and rejects other signals. So I took the output of this filter and put that into a moving average. The moving average is computed with a window of samples that is large enough to hold [0,4*pi]. The sum of squares of the samples is divided by the filter length to get the measurement of that filter. This rises to a value of above 0 when the filter chain is input with a signal of the freq. it is trying to test for.

A graph of this output is shown here

All the filters are initialized to zero values at first, so it rises after a few periods and levels off. I also tested the 2nd harmonic of my signal to make sure there it was not a fluke

The filter passes a small amplitude but the average stays right around 0. So it seems this method is reasonably effective. Computationally I guess it is pretty expensive.

I do see an issue if the input signal is not approximately in the amplitude of [-1, 1]

I don't know much about DSP but is there a terminology for this kind of filter?

• For efficiently determining the presence of exact frequencies, you may want to have a look at the Goertzel Algorithm. It analyses the signal for the presence of selected frequency components which may be more computationally efficient than taking the FFT Jan 5, 2023 at 10:43
• From the title, it sounds like the answer is "cross-correlation". Jan 5, 2023 at 18:03
• @robertbristow-johnson yes I agree the first terms that came to mind were 'cross-correlation' and 'matched filtering' but since the OP mentioned FFT so I thought I should mention the Goertzel Algorithm as well. Hope it was not misleading.. Jan 6, 2023 at 3:48

You have the right idea, except you don't need a complicated filtering (i.e. convolution) process. You can use a similar idea though, outlined here.

In essence, the approach is to correlate your signal with a tone at the frequency of interest (this is what the DFT does at every frequency).

Here is sample Matlab code that applies the method:

fs = 8000;
t = (0:1/fs:1);

f = 444; % carrier frequency
x = 0.7 * sin(2*pi*f*t + pi/3); %carrier
noise = 0.5 * randn(1, length(x)); % noise
x = x + noise;

probe1 = exp(-1j*2*pi*f*t); % correct probe signal
probe2 = exp(-1j*2*pi*446*t); % incorrect probe signal

% correlation with both probes
corr1 = abs(x*probe1');
corr2 = abs(x*probe2');


For one run, I get corr1 = 2844 and corr2 = 12, showing the effectiveness of the method.

• What language is the sample code in? Jan 5, 2023 at 10:52
• The sample code is Matlab. Edited my answer ;)
– Jdip
Jan 5, 2023 at 10:54
• I think the only thing I don't understand in this is the factor "-j" What quantity is that? Jan 6, 2023 at 13:25
• That’s the imaginary number $i$, usually called $j$ by engineers. In equation form:$$\texttt{probe_1}= e^{-i2\pi ft}$$
– Jdip
Jan 6, 2023 at 14:48