2

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?

Eric Urban
  • 133
  • 6
  • 1
    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 – malik12 Jan 05 '23 at 10:43
  • 1
    From the title, it sounds like the answer is "cross-correlation". – robert bristow-johnson Jan 05 '23 at 18:03
  • 1
    @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.. – malik12 Jan 06 '23 at 03:48

1 Answers1

2

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(2pift + pi/3); %carrier noise = 0.5 randn(1, length(x)); % noise x = x + noise;

probe1 = exp(-1j2pift); % correct probe signal probe2 = exp(-1j2pi446t); % incorrect probe signal

% correlation with both probes corr1 = abs(xprobe1'); corr2 = abs(xprobe2');

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

Jdip
  • 5,980
  • 3
  • 7
  • 29