Searching \ for 'Digital signal is stumping me!' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=digital+signal+stumping
Search entire site for: 'Digital signal is stumping me!'.

Truncated match.
'Digital signal is stumping me!'
1998\07\14@231605 by

I must lean on the collective intelligence for this one.

I have a stream of pulses (real pulses are 1Us wide, but are stretched
out to whatever I please).  The signal of interest varies from 10 Hz to
200 Hz.  I must extract the average overall frequency and generate a new
stream of pulses that are perfectly cleaned of interference.

The trouble arose from the presence of interfering pulses.  I might have
missing pulses, say one in every 20 or so.  I might have added pulses,
added to the stream in a seemingly random fashion.  I might have a pair
of pulses close together for every pulse that should appear in the
stream.  I have to look through the interference and pull out the
fundamental frequency.

I have tried a PLL (digital type, CD4046).  It locks to a clean signal,
but looses track completely in the presence of interference.

I am tempted to do a FFT.  Problem is, I am not sampling a continuously
varying wave, but a stream of pulses.  The real data in my case is the
measurement of time between each subsequent pulse.  Therefore, I cannot
find any method of implementing an FFT.

The PIC in this project is a 16C73, with the input pulses triggering
intB0.  I get magnificent interrupts and generate great data.

I just don't know how to analyze it!!!

All ideas welcomed.  Thanks.

Chris Eddy, PE
Pioneer Microsystems, Inc.

> I have a stream of pulses (real pulses are 1Us wide, but are stretched
> out to whatever I please).  The signal of interest varies from 10 Hz to
> 200 Hz.  I must extract the average overall frequency and generate a new
> stream of pulses that are perfectly cleaned of interference.

How fast does the signal of interest vary ? ie Is it likely to step
from 10Hz to 200Hz (if there weren't any erroneous pulses) ?

If that change is slow compared to the 10Hz signal, you could use the
"if in doubt, chuck it out" method (which probably has a fancy
mathmatical name).

Keep a running average of the pulse rate and use that as your output.
Then apply a window to that average and if a pulse arrives before the
beginning of the window, throw it out (it's noise) or if one doesn't
arrive by the end of the window, make one up (missed pulse).

Steve.
======================================================
Steve Baldwin                Electronic Product Design
TLA Microsystems Ltd         Microcontroller Specialists
PO Box 15-680, New Lynn      http://www.tla.co.nz
Auckland, New Zealand        ph  +64 9 820-2221
email: stevebtla.co.nz      fax +64 9 820-1929
======================================================

Hi,
an idea:

try to sample your data instead of IT caused by incoming pulses with a
constant time window using the Shannon-Nyquist theorem: if you have a
highest frequency of 200 Hz, use 1 / (2 * 200Hz) = 1 / 400 sec =  2.5
msec. Of course, the pulses you receive should be stretched on the sending
side say 1 msec or so. Using this data, you can apply FFT. Beware
aliasing!

Imre

On Tue, 14 Jul 1998, Chris Eddy wrote:

{Quote hidden}

Hi,

> > I have a stream of pulses (real pulses are 1Us wide, but are stretched
> > out to whatever I please).  The signal of interest varies from 10 Hz to
> > 200 Hz.  I must extract the average overall frequency and generate a new
> > stream of pulses that are perfectly cleaned of interference.
>
> How fast does the signal of interest vary ? ie Is it likely to step
> from 10Hz to 200Hz (if there weren't any erroneous pulses) ?
>
> If that change is slow compared to the 10Hz signal, you could use the
> "if in doubt, chuck it out" method (which probably has a fancy
> mathmatical name).
>
> Keep a running average of the pulse rate and use that as your output.
> Then apply a window to that average and if a pulse arrives before the
> beginning of the window, throw it out (it's noise) or if one doesn't
> arrive by the end of the window, make one up (missed pulse).
>
This sounds like a digital phase locked loop.  The output pulse period is
adjusted according to the difference between the position of the next
input pulse and the expected position.  Lets say your current input
frequency is 20Hz (50ms period) and the DPLL is locked.  This means
your output period is also 50ms.  There would expect to find the next
input pulse 50 ms after the previous one.  Divide the areay around the
expected pulse into different regions (A,B,C and D, for instance):

|------- Current output period----|

---
| |                               |
| |                          |  | | |  |
--- ---                        |C |A B|D |
^                                 ^
Input Pulse (N)                   Expected position of pulse (N+1)

If the actual input pulse(N+1) occurs in A or B, you keep the output
pariod unchanged.  If the pulse occurs in C, you decrement your
output period by a certain amount (lets say, Delta) and if it occurs in D
you increment your output period with Delta.  If you see a transition
outside these areas, you ignore it.  If you do not see a transition in
A,B,C or D, then you keep your output period the same.

The choice of A, B, C, D and Delta will determine how fast your PLL can
respond to changes in the input frequency.  It is comparable to the loop
filter in an analogue PLL.  The wider you choose A+C and D+B or the
larger you choose Delta, the higher the maximum input frequency change
rate you would be able to track, but also the more prone the PLL will be
to noise.

Hope this helps
Niki

1998\07\15@050221 by
{Quote hidden}

How about a high order active low-pass filter for the noise.
Count the pulses during a, say, 1s period.

--
Friendly Regards

Tjaart van der Walt
tjaartwasp.co.za

|--------------------------------------------------|
|                WASP International                |
|R&D Engineer : GSM peripheral services development|
|--------------------------------------------------|
|SMS tjaartsms.wasp.co.za  (160 chars max)|
|     http://www.wasp.co.za/~tjaart/index.html     |
|Voice: +27-(0)11-622-8686  Fax: +27-(0)11-622-8973|
|          WGS-84 : 26¡10.52'S 28¡06.19'E          |
|--------------------------------------------------|

Steve asked about the rate of change in the pulse rate.  This is important
because you may need to calculate a window for the next pulse to
occure in.  And if no pulse is there, then you supply a pulse for the
'missing' pulse.

And can you delay your 'clean' output pulse train from the input
'dirty' train?  Also does the output train need to be in micro second
resolution between pulses?

Instead of looking at cleanning up the pulse train, maybe you should
make two tasks out of it.  First, find the time between the clean pulses
on the input.  And the second task would be to output a pulse train
using the time determined by the first task.  This would not be a
faithfull reproduction of the input pulses as it would be delayed
by some amount.

The first thing I would do would be to add an external IC to latch
the incomming pulse.  This would allow the RTC to use the
interupt.

An approach may be to have two running averages.  One
for good pulses and one for all pulses.  And the window for
the good pulses could be some factor of both averages.

The average for all pulses would simply be time between
all pulses.  For every pulse received, the window would move, or track,
toward that time by a small value.  For every pulse that is in the
window the window should move towards that time by a larger value.
At some points its may be necessary to 'seek' and set the window
according to the average time of all pulses.  This would be useful
when starting up.  Read 16 or so pulses and set the window to 1/16
that value.

All of this is under the assumption that it is ok to have the output
pulse train independent of the input pulse train.

And the second task of outputting the pulse is to take the
mid point of the window and use it to output pulses.

It would be nice to have a file of the actural pulse timmings and
try out the ideas in basic on the pc to see how they work.  Or
to use a basic program to simulate the pulse train and try out ideas
on its output.

One important thing I have learned is that it is necessary to
constantly skew the window one direction or the other even
while receiving good signals.  And let the good signals bring
it back on track.  And if there are no good signals then it will
skew until it finds a signal that it thinks is good.

I became aware of this when writting a program to receive
morse code on the computer.  The time for the dots would
increase with every dash received and the time for the dashes
would decrease with every dot received.  When a dot was received,
the dot time would be set to it and when a dash was received,
the dash time would be set to that time.

So if a string of dots were received, the expected time for a dash
would decrease.  In fact it could decrease until it was the same
as a dot's time.  Then when a dot/dash was received, if it was
greater than a dash, it was a dash.  If less than a dot, then it was
a dot.  and if between dot and dash times, then the one it was
closest to.  But the one that it wasn't, was allways pulled towards the
other (the one that it was).  And the one that it was determined to
be, was set to that time.  So after a lot of dots, the first dash would
start it decoding correctly.

Does that make some sense?

Bill C.   billcornutt.com

>The trouble arose from the presence of interfering pulses.  I might have
>missing pulses, say one in every 20 or so.  I might have added pulses,
>added to the stream in a seemingly random fashion.  I might have a pair
>of pulses close together for every pulse that should appear in the
>stream.  I have to look through the interference and pull out the
>fundamental frequency.
>
>I have tried a PLL (digital type, CD4046).  It locks to a clean signal,
>but looses track completely in the presence of interference.

I migt be off track here (Whiskey last night), but here is my idea:

First use a simple pulse stretcher that stretches each pulse to half the
cycle time time of your highest frequency.

Then feed the 4046 with it, and use the internal EOR as phase comparator,
or a mix of both phase comparators.  (In my experience the EOR is better
for asymmetric pulses, but is rather helpless if looses sync, therefor need
help by the other, and also designing the VCO input filter helps.)

The pulse stretcher will swallow pulses close to each other and only
generate one out.  No matter if the first of the pulses was false or real.

It can of course happen that it triggera on single fals pulses distant from
the real ones too, but if not frequent, the PLL will supress them.

Another idea is to feed back the VCO signal to control the timing of the
pulse stretcher, to optimise the timing for the locked frequency.

And/Or-somehow, maybe using the output fron PLL OSC to kill any input every
half cycle to increase suppression of false pulses.

As i am basically a analog guy i would begin to build like this, but it can
probably also be implemented in software somehow.

Interesting problem.  Please tell us how you solve it!

/Morgan
/  Morgan Olsson, MORGANS REGLERTEKNIK, SE-277 35 KIVIK, Sweden \
\  mrtiname.com, ph: +46 (0)414 70741; fax +46 (0)414 70331    /

Nice beginnig, but we have to add something to the below scheme so it dont
lock at half or double frequency.  (really even fout = fin/N or fin*N)

This problem arise because we have such a wide frequency range.

We might also have problem to pull-in fast enough.

/Morgan

{Quote hidden}

/  Morgan Olsson, MORGANS REGLERTEKNIK, SE-277 35 KIVIK, Sweden \
\  mrtiname.com, ph: +46 (0)414 70741; fax +46 (0)414 70331    /

Hi,

> Nice beginnig, but we have to add something to the below scheme so it dont
> lock at half or double frequency.  (really even fout = fin/N or fin*N)
>
> This problem arise because we have such a wide frequency range.
>
> We might also have problem to pull-in fast enough.
>
> /Morgan

Yes, my description is only valid once you are locked.  You also need a
mechanism to get locked and to detect when you have lost lock.  As you
have mentioned, using the DPLL algorithm to get lock, can easily result in
locking to a multiple of the incoming frequency.  One solution is to use
the averaging algorithm described elsewere in this thread to obtain an
initial 'guess' for the DPLL.  You also need a way to detect when you
have lost lock so that you can try to lock again.  You could do this by
maybe counting the number of times you totally miss the expected pulse.
If this goes higher than a threshold you have lost lock.

There are a lot of variables to play around with - the kind of thing that
can keep you busy for months ;-)

Niki

{Quote hidden}

On Tue, 14 Jul 1998, Chris Eddy wrote:

> I have a stream of pulses (real pulses are 1Us wide, but are stretched
> out to whatever I please).  The signal of interest varies from 10 Hz to
> 200 Hz.  I must extract the average overall frequency and generate a new
> stream of pulses that are perfectly cleaned of interference.
>
> The trouble arose from the presence of interfering pulses.  I might have
> missing pulses, say one in every 20 or so.  I might have added pulses,
> added to the stream in a seemingly random fashion.  I might have a pair
> of pulses close together for every pulse that should appear in the
> stream.  I have to look through the interference and pull out the
> fundamental frequency.
>
> I have tried a PLL (digital type, CD4046).  It locks to a clean signal,
> but looses track completely in the presence of interference.
>
> I am tempted to do a FFT.  Problem is, I am not sampling a continuously
> varying wave, but a stream of pulses.  The real data in my case is the
> measurement of time between each subsequent pulse.  Therefore, I cannot
> find any method of implementing an FFT.

You can't use a FFT here, you already have the frequency you want.

imho, you need something like a digital filter with a narrow passband that
corresponds to the max expected 'legal' variation of your input signal,
whose center frequency steers a countinuously running generator.  That is,
if your signal can change by 5 Hz/sec then that will give you the filter
bandwidth. The filter will track the input frequency and disregard noise.

It will also supply pulses when there are no input pulses. I don't know if
such a filter has a name but it seems relatively easy to do with two state
machines (one for missing pulses, one for tracking), and two interrupt
sources (the input signal and a constant programmable clock).

The output frequency will, of course, be an integer multiple of Tcyc on
the processor, no matter what.

The analog way to do this, is an integrator, followed by a VCO, and an
input pulse-driven monostable that turns the output VCO off if there are
no input pulses for some time. Of course, calibrating this will be a 2
hour job (per unit), to be repeated every month or so, unlike the digital
PIC solution ;)

Peter

Hello Chris & PIC.ers,

Is this not the right place to implement a `median filter'?
It has been discussed in the list a number of times & I have put one
to use in filtering very noisy adc signals.
..
Basically, you time the periods between pulses - including the
dud ones.
Sort the timing data in batches of five or other odd no.
(experiment for flavour), a circular buffer is the way to go.
You discard all the data in each batch except the middle value,
thus gate-crashers get slung out and don't affect your
result at all, the way an IIR filter would, etc.
..
Could this do it, or did I miss a point somewhere in your mail?

{Quote hidden}

<snips>
>All ideas welcomed.  Thanks.

>Chris Eddy, PE
>Pioneer Microsystems, Inc.

Best regards,   John
..
email from John Sanderson at
JS Controls, PO Box 1887, Boksburg 1460, Rep. South Africa
Manufacturer & purveyor of laboratory force testing apparatus
and related products and services.
Tel/fax: Johannesburg 893 4154    Cellphone 082 453 4815

Ah, I don't think that this will work, since my third case of trouble is with
more than one pulse per spark event.  In this case, my target period of X may
be split up into x/20 and 19x/20 at most every event.  Instead of one strong
instance of X readings, I would get equal cases of x/20 and 19x/20.  And thus
could not choose the right frequency.  Simply add them together?  Well, I am
not sure that this is going to work under all circumstances.

John Sanderson wrote:

> Hello Chris & PIC.ers,
>
> Is this not the right place to implement a `median filter'?
> It has been discussed in the list a number of times & I have put one
> to use in filtering very noisy adc signals.
> ..

Why don't you just make an integration of the incoming pulses, then an extra
pulse, or a missing one won't make much difference.

Just a thought.

Calvin

Chris,
Stretch the pulse to 1/2 the period of the highest frequency desired.
In your case the max frequency is 200Hz, which has a period of .005
second, so 2.5 milliseconds would be the desired pulse width.

This pulse-stretching will automatically eliminate many of the
pair and added pulses you are encountering. Note that if the
sustained frequency exceeds 400 Hz, then the perceived frequency
will alias and appear to be MUCH lower.

Measure the time from the PREVIOUS_PULSE to the CURRENT_PULSE.
Add this value to the variable CURRENT_16. Decrement the counter
COUNT_16. Replace PREVIOUS_PULSE with CURRENT_PULSE

When COUNT_16 reaches zero, reset it to 16. Take the value in
CURRENT_16 and add it to AVERAGE_16. Divide the result by two,
and use this as the new AVERAGE_16. Reset CURRENT_16 to 0.
The AVERAGE_16 value can be divided by 32 to get the HALF_PERIOD
value which will later be used to produce the output waveform.

The AVERAGE_16 value is prevented from changing too rapidly,
because it is an average of the last TWO sets of 16 readings.
This is equivalent to adding a capacitor to the feedback loop
of an op amp. I have shown the example with 16 samples, but you
could use more or less samples. Less samples will cause the value
to jump around more, but it also makes the acquisition of a value more
rapid. More samples will effectively slow down the response time
to changes, but the average will also be 'smoother'. Experiment
and find out what number of samples work best. I suggest that the
number of samples be related by a power of two, such as 2 4 8 16 32.

You can get the circuit up to speed quickly by initially seeding
the variables with values that are close to the expected initial
values.

The updating is done via the interrupt service routine. The output
waveform generator portion of the program could simply be a loop
that uses the HALF_PERIOD value to determine when to flip/flop the
output. TIMER0 can be used to perform all the timer functions. You would
need a variable PREVIOUS_TIME that would hold the TIMER0 count
present the last time a HALF-PERIOD occured. Adding HALF_PERIOD
to PREVIOUS_TIME would give you the TIMER0 count for the NEXT
flip/flop of the output.

Hope this helps.
Fr. Tom McGahee

----------
{Quote hidden}

Chris Eddy wrote:

> Ah, I don't think that this will work, since my third case of trouble is with
> more than one pulse per spark event.  In this case, my target period of X may
> be split up into x/20 and 19x/20 at most every event.  Instead of one strong
> instance of X readings, I would get equal cases of x/20 and 19x/20.  And thus
> could not choose the right frequency.  Simply add them together?  Well, I am
> not sure that this is going to work under all circumstances.

I prefer uncomplicated solutions. Here's one you could try :

Treat the pulse stream as a simple input. Use an up/down
counter type debouncing routine. Use the current period
between pulses (minus a little bit) as the debounce period.
Your software will only pick up pulses in the 'expected'
window, effectively eliminating noise and double pulses.

I used this technique for bit detection in an rf receiver
where the pulse train length was dependant on the battery
condition of the transmitter.

--
Friendly Regards

Tjaart van der Walt
tjaartwasp.co.za

|--------------------------------------------------|
|                WASP International                |
|R&D Engineer : GSM peripheral services development|
|--------------------------------------------------|
|SMS tjaartsms.wasp.co.za  (160 chars max)|
|     http://www.wasp.co.za/~tjaart/index.html     |
|Voice: +27-(0)11-622-8686  Fax: +27-(0)11-622-8973|
|          WGS-84 : 26¡10.52'S 28¡06.19'E          |
|--------------------------------------------------|

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...