2
$\begingroup$

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

enter image description 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

enter image description here

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?

$\endgroup$
3
  • 1
    $\begingroup$ 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 $\endgroup$
    – malik12
    Jan 5, 2023 at 10:43
  • 1
    $\begingroup$ From the title, it sounds like the answer is "cross-correlation". $\endgroup$ Jan 5, 2023 at 18:03
  • 1
    $\begingroup$ @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.. $\endgroup$
    – malik12
    Jan 6, 2023 at 3:48

1 Answer 1

2
$\begingroup$

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.

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

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.