On Mon, 9 Jul 2001, adastra wrote:
{Quote hidden}> I need to measure the frequency (or period) of a sinewave signal in the
> range of 1KHz to 10KHz, which is only present for about 0.5 second.
>
> The trouble is that there is another signal present ALL of the time that is
> in the same frequency range and of approximately the same amplitude. It
> seems I need to filter out the always-there signal so I can measure the
> intermittent one. The exact frequency of the interfering signal is not
> known, and could be higher or lower than the signal of interest. It
> probably must be determined before the filtering can occur, but that part
> shouldn't be too difficult since the interfering signal is there prior to
> the appearance of the signal of interest.
>
> I realize that if the signal-of-interest happens to be the same as the
> interfering signal, I probably cannot detect it, but if the filter is narrow
> enough, I can live with that.
>
> I thought I could do this with a couple of analog PLLs ahead of the PIC, but
> lately I am wondering if I need something more along the lines of a FFT
> system, or maybe a DSP chip. I would really like to do everything in a
> 16F877 if possible.
>
> If anyone could point me in the right direction I would appreciate it very
> much. Any and all suggestions welcome.
Foster,
You didn't explicitly say it, but I'm assuming the "noise" is a sine
wave too. If so here are a couple of suggestions:
1) Digital phase lock loop
With the DPLL, you can lock onto the "noise" sine wave. As long as the
DPLL is locked, there should be little or no correction applied.
Suppose the loop filter has a very long time constant. It may take a
long time to lock, but it will tend to also stay locked or even
continue to "run" even if the reference is removed.
Use the error signal in this DPLL as an indicator for when the "noise"
is being perturbed by your signal. Let this start a second DPLL that
has a much shorter time constant.
Now if you're really clever, you could use the first DPLL to cancel
out the "noise" sine wave!
2) autocorrelation filter.
Suppose your unknown signal is not present. If so, then you should be
able to take a sample of the "noise" and see that it's correlated to
itself. The easiest way is perhaps to do something like:
f(t+i*dt) = samples at t, t+dt, t+2dt, ... t+Ndt
I = sum( f(t+i*dt) * f(t+i*dt + M*T)) / sum(f(t+i*dt))
Q = sum( f(t+i*dt) * f(t+i*dt + (M+1/4)*T)) / sum(f(t+i*dt))
Where
M is an integer
T is the period of the known noise (determined by another algorithm)
dt is the sampling interval
N is the number of samples
I is the "in phase" component
Q is the "out of phase"
In other words, a sample window of the signal is multiplied with a
copy of itself that has been shifted an integer # of cycles and the
sum of products is obtained. Similarly, a second window is shifted an
integer # plus an extra quarter to obtain the "quadrature" component.
(The stuff in the denominator of the two expressions normalizes the
result.)
Strictly speaking, this is NOT autocorrelation. Autocorrelation would
compute an infinite number of the above computations and not just two.
In other words, the window over which the signal slides varies
continuously and not just M*T. However, the autocorrelation of a sine
wave produces a series of delta functions spread M*T units apart. So
if you can zero in on one of the delta functions you'd tend to save a
little computation time!
Now, the goal, like in the DPLL, is to determine when the
autocorrelation peak is perturbed. Again, like above, you could
control the rate at which the window is adjusted. So sudden changes in
the input would manifest them selves in reducing the autocorrelation.
This information can be used as a trigger to begin looking for the
other signal.
One of the problems with the autocorrelation is that it is incapable
of distinguishing harmonics. In other words, if the noise is a 5kHz
sine wave and the signal is a 1kHz sine wave, the autocorrelation
would not change.
Another problem is that the autocorrelation approach is
computationally expensive.
3) Filter banks
Since we're talking about computationally expensive algorithms, we
might as well mention filter banks. In the brute force case, you can
imagine having say 10 notch filters centered on 1kHz, 2kHz, etc. and
each having a bandwidth of around 2kHz. You could monitor the output
of each of these filters and then look for changes in signal strength
output. When a change is detected, then that's a clue to start looking
more closely in another area.
A brute-force filter bank is a DFT. It will take the time domain
signal and place the energies of each frequency into the appropriate
bins. However, unless this information is going to be viewed by a
human, I'd argue that it's a total waste of resources. For one reason,
it computes all of the frequency decomposition up front - even for
those frequency band for which it's not needed. Second, a DFT provides
no way to control the width of the frequency bins.
Having a set of discrete filters solves both problems mentioned with
the DFT. In addition, a set of discrete filters requires fewer RAM
resources. However, this approach is not computationally efficient.
The DFFT is of order N*ln(N) and the filter bank is M*N where M is
the number filter banks. A bank of just 8 filters is about
computationally inefficient as a 256 point DFFT. However, instead of
discrete filter banks it's possible to construct cascaded filters
constructed from "Quadrature Mirror Filters". For example, suppose you
split the frequency band into two parts: LOW and HIGH. The LOW portion
is passed through another filter that splits it again into low and
high portions. Similarly the HIGH portion is split in two. This will
result in the original signal being split into four pieces. Now the
trick is that since the filters are cascaded there's certain
information known. For example, when the LOW portion is generated,
there are no frequencies from the "HIGH" portion. Consequently the
samples fed to the filters cascaded off the LOW portion can be
"decimated", i.e. the sample stream can be sub-sampled.
(This whole subject is heavy DSP {and beyond the scope of a [PIC]:
tag} and discussed in "Advanced Digital Signal Processing - Theory and
Applications", Zelniker and Taylor, ISBN 0-8247-9145-2. In fact, a
problem quite similar to this is discussed in the section that
introduces Wavelet Transforms.)
The filter bank approach won't find your signal per se. However, it
can be a relatively quick way of determing that the signal is present.
I imagine this couple with a DPLL would be the best solution. If
you're stuck with the '877 then there's always the "1-bit" tone
decoder that can be used to put the signal into frequency bins:
http://www.dattalo.com/technical/theory/dtmf.html
Scott
--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTTakeThisOuTmitvma.mit.edu