To detect a single freq I will try to do a correlation between the known freq qith the time domain signal. Each sample in the frequency domain is found by multiplying the time domain signal by the sine or cosine wave being looked for, and adding the resulting points.. But this will not be the fastest method.
Have a look at Goertzel Algorithm.
https://www.mstarlabs.com/dsp/goertzel/goertzel.html#Ref1
The goertzel is a special case of the DFT. It does not tell you anything about adjacent frequency energy, hence cannot be used in my case, which is a very noisy channel.
For example, suppose there is an impulse during the sampling period. Then the frequency bin power detected by the goertzel will be significant non-zero, and will result in possible false detection.
I have to avoid this situation & similar ones caused by just noise.
- - - Updated - - -
Everything starts with the definition of detection criteria, e.g. absolute signal level, SNR, accepted frequency range, minimal signal duration for detection.
You apparently altready decided to use DFT processing for detection, that should basically work, but the DFT window length should be selected according to detection criteria.
The detection criteria is : Frequency bin +/- half bin on either side. Which also decides the frequency range.
Regarding SNR: thats a tricky one, since there is of necessity an AGC in the input path, and noise will get magnified in the absence of a signal. In addition, even with the signal present, substantial noise & interfering signals can be also present in the spectrum.
I need an algorithm/ decision matrix which can help me decide.
My current actual parameters are as follows :
Fs = 250 Hz, 4mS
Sample length: 128
Hence Bin spacing: 1.9531.. Hz
F1 = 25 Hz --> bin #12.8 (#13)
F2 = 37.5Hz --> bin #19.2 (#19)
The input (F1 & F2) are essentially square waves, hence the 3rd harmonics will not interfere, nor do I think the aliased components be a problem.
Ideally one of these 2 freqs will ALWAYS be present. However low power w.r.t noise impulses or 'other' frequencies might & do cause trouble.
As of now I simply look for adequate power (above some arbitrary threshold) in the respective bins, and also check to see if these are local maxima. In addition I check to see whether this happens at least 4 times in a period of 8 samples.
However this is simplistic. Occasionally I get 'no signal'. Sometimes I get 'no signal' for longish periods. Otherwise it seems to work well.
I need something more robust, and which can handle different noise profiles reliably.
Regarding minimal signal duration: The signal is supposedly present at all times. However it could be buried in noise, or been destroyed at times for same reasons. But a signal pickup which lasts for 1/2 of the sampling period would be good enough.
QUESTION:
Would using multiple samples help in improving SNR ? Say by adding or averaging ?