Searching \ for 'Magic Sinewaves demystified' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=sine
Search entire site for: 'Magic Sinewaves demystified'.

Truncated match.
PICList Thread
'Magic Sinewaves demystified'
2000\03\05@114431 by Scott Dattalo

face
flavicon
face
Well, at least partially...

It finally dawned on me yesterday how magic sine waves can be sythesized.
What's frustrating, is that the answer is so simple that it's obvious; so
obvious that it's been overlooked in the discussions we had off and on for
the last couple of years (at least by me). Lancaster is probably a
chuckling lurker :).

There are probably a few ways to go about it, but this is the one I tried.
Imagine how you'd go about synthesizing a sine wave if you had an A/D
converter. The most common way is to produce `N' samples for one sine wave
cycle and repeatedly write these to an A/D converter. The sine wave
frequency is determined by the rate at which the samples are written to
the A/D converter.

Now imagine replacing the A/D converter with a PWM generator that has the
same resolution. So for example, if you had a 12-bit A/D converter the PWM
generator would be capable of producing 4095 (2^12 - 1) different duty
cycles. Theoretically, the low-pass filtered output of the A/D converter
and the PWM are the same. Practically however, it's difficult to design a
filter that would have the proper cut-off characteristics. So to ease the
filter requirements, the PWM synthesized sine wave is usually made to be a
much higher frequency than the frequency at which samples are written to
the A/D converter.

Now when we, or at least I, begin to think about `magic sine waves' the
idea that the pwm frequency can be reduced is forgotten. Furthermore, we
constrain ourselves to the low-resolution 8 or 10 bit pwm generators that
are available in the various pic's. What the magic sine wave algorithm
does, AFAICT, is find a suitable time discretization for a high
resolution PWM synthesized sine wave.

So, there are two parts to the synthesis. Part 1 invovles finding the high
resolution PWM representation of the sine wave. Part 2 involves finding an
optimum way to make time discrete. The first part is easy and the attached
octave (or matlab) program will do this. The second part can be determined
using brute force search techniques. I don't have an elegant solution
though, but hopefully some others have some insight.


Scott

PS, this octave program is meant to be tool and otherwise not too useful
(in other words, I don't bother to explain hardly anything...)

% `magic'sine wave synthesis
%   The purpose of this program is to find an optimum pulse stream
% that when low pass filtered will produce a sine wave. The optimization
% criterion is to minimize the harmonics for a given number of pulses.


% by  T. Scott Dattalo 04MAR00
clear;
clg;
pulses = 32;

T = 1;              % Period
f = 1/T;            % fundamental frequency

tp = T/pulses;      % Time window for each pulse

t = [0:(pulses-1)]/pulses;
sine_samples = sin(2*pi*f * t);

ts = zeros(1,4*(pulses-1));
p = ts;

% create a pwm sine wave with edges based on floating point
% numbers:

for i=1:pulses

 ts(4*i) = t(i);
 ts(4*i+1) = t(i);
 ts(4*i+2) = t(i) + (1 + sine_samples(i))/2 * tp + 1000*eps;
 ts(4*i+3) = ts(4*i+2);
 p(4*i+0) = 0;
 p(4*i+1) = 1;
 p(4*i+2) = 1;
 p(4*i+3) = 0;

end

% Now calculate the harmonic content
harmonics = 20*pulses;
mag = zeros(1:harmonics);
ph  = zeros(1:harmonics);
phase = [0:(pulses-1)] * T/(pulses);
N = 1000;                 %Number of samples
sqwave = zeros(1:N);
u = [1:N]/N * T;          %Time vector

for n=1:harmonics
 w = n*2*pi/T;

 m=2;
 for m=1:(pulses)
   tau = (1 + sine_samples(m))/2*tp;
   d = tau/T;
   sqwave = sqwave + 2*sin(n*pi*d)/(n*pi)*cos(w*(u-tau/2-phase(m)));
   mag(n) = mag(n) + 2*sin(n*pi*d)/(n*pi)*cos(w*phase(m));
   ph(n) = ph(n) + cos(w*phase(m));
 end

end

sqwave = sqwave + 0.5 + 2;
dc = sum(sine_samples);
mag(2) = 0;
ti = sprintf('PWM Synthesis');
title(ti)
subplot(111)
%plot(t,sine_samples)
%subplot(212)
% plot the harmonics:
plot([0:harmonics-1]/pulses,abs(mag))
% uncomment to plot the square wave train re-synthesized from its
% harmonics
%plot(ts,p,u,sqwave)

2000\03\06@072604 by Andrew Kunz

flavicon
face
Scott,

You mean D/A converter, not A/D, right?  Otherwise, I'm confused.

Andy

2000\03\06@083018 by Scott Dattalo

face
flavicon
face
On Mon, 6 Mar 2000, Andrew Kunz wrote:

> You mean D/A converter, not A/D, right?  Otherwise, I'm confused.

D/A of course - sorry.


The octave (matlab) code posted yesterday had a bug in the harmonic
calculation. That's been fixed. In addition, I wrote another similar
octave program that will analyze an ascii string of 0's and 1's. Like the
other program, it plots the square wave that has been reconstructed from
its harmonics and it plots the magnitudes of the first few harmonics.
Here's a screen shot of a 12-bit string, "010110100000", produced by the
program:

http://www.dattalo.com/ms1.gif

and the programs:

http://www.dattalo.com/ms.m
http://www.dattalo.com/ms2.m


Scott

2000\03\06@115039 by Grif\ w. keith griffith

flavicon
face
<x-flowed>At 10:44 AM 3/5/00 -0600, you wrote..
>It finally dawned on me yesterday how magic sine waves can be sythesized.

Major math snip:::

Scott:  doesn't your code produce an analog output?  I was of the opinion
the whole reason for the Magic part of the synthesis was using saturated
switching at a much higher freq than the final output and stuffing it thru
a low pass filter, getting a somewhat usable, higher power sine wave
output?  Or did I just learn something this early in the week???  ( that
would be good,,, then I wouldn't have to work as hard the rest of the week!)


'Grif'   N7IVS

</x-flowed>

2000\03\06@120514 by jamesnewton

face picon face
What language are these programs written in?

I am flagging these emails for follow up in a week or so (I'm crunched at
the moment) but I'm interested in a general purpose magic sinwave routine
code generator for the PIC.

---
James Newton spam_OUTjamesnewtonTakeThisOuTspamgeocities.com 1-619-652-0593
http://techref.massmind.org NEW! FINALLY A REAL NAME!
Members can add private/public comments/pages ($0 TANSTAAFL web hosting)


{Original Message removed}

2000\03\06@132106 by Scott Dattalo

face
flavicon
face
On Mon, 6 Mar 2000, "Grif" w. keith griffith wrote:

> At 10:44 AM 3/5/00 -0600, you wrote..
> >It finally dawned on me yesterday how magic sine waves can be sythesized.
>
> Major math snip:::
>
> Scott:  doesn't your code produce an analog output?  I was of the opinion
> the whole reason for the Magic part of the synthesis was using saturated
> switching at a much higher freq than the final output and stuffing it thru
> a low pass filter, getting a somewhat usable, higher power sine wave
> output?  Or did I just learn something this early in the week???  ( that
> would be good,,, then I wouldn't have to work as hard the rest of the week!)


True, the ultimate objective is to produce an analog output. However, the
goal with the so called 'magic sinewaves' is to find the MINIMUM number of
switch transitions. The resulting bit stream is filtered such that a sine
wave is produced. The reason for minimizing the transitions is because
some switches, particularly those associated with high power applications
like in AC inverters, require a significant amount of energy to switch or
cannot be efficiently switched at high frequencies. As an example, you may
have a sine wave synthesis circuit where you want to drive the gate of a
MOSFET directly from a pic I/O pin. Pic's have fairly beefy outputs,
however they're very weak when compared to real MOSFET drivers. But given
enough time, the PIC I/O can switch a MOSFET (assuming of course that Voh
is above Vgs threshold - i.e. logic level Vgs MOSFETs may be required). If
you attempted to drive the MOSFET at too high of frequency with this pic
I/O pin, then chances are that it will never switch!

In addition, if you can use harmonic cancellation, then the constraints on
the analog filter may be relaxed. PWM generated waveforms relax the filter
constraints by maximizing the switching frequency. If the PWM carrier is
100 times the sinewave you're trying to generate, then you're analog
filter is much easier to design. There aren't any harmonics (to an
approximation) between the sine wave frequency you're generating and the
carrier frequency of the PWM.

Magic sine waves explicitly remove these harmonics by strategically
placing the pulses (or edges). The pulses, when viewed individually,
contain harmonics at the fundamental (of the sine wave being generated)
and at all integer multiples above. But when the pulses are taken
together, the 2nd, 3rd and so on harmonics are cancelled. The number of
harmonics cancelled depends on the quantization of time for the edges. For
example, in the previous post, I had a graph of a 12-bit pulse stream
010110100000. The second and third harmonics were exactly cancelled, but
there is a 4th and 5th harmonic present. Doubling the number of pulses to
24 allows a pulse stream to be created that will cancel the 4th harmonic.
In general, if you have a pulse stream containing n! pulses, then it's
possible to exactly cancel the first n harmonics. However, n! grows rather
quickly. It's simply not practical to attempt to cancel the first 10
harmonics (after the fundamental) by creating a pulse stream containing
10! or 3,628,800 pulses.

Consequently, if you wish to cancel the first 10 harmonics but with a
pulse stream containing only a 1000 pulses, you're not going to achieve
your goal. However, you may discover a particular stream that exactly
cancels the 2nd, 3rd, and 4th, and attenuates the 5th through 10th
harmonics by 20dB. From that you may design an appropriate analog filter.

AFAIK, there is no way to apriori determine the appropriate length of the
pulse stream to achieve some required harmonic profile. I think
Lancaster's contribution to this technology is to discover certain lengths
that perform well - or at least better than pulses streams that are
slightly shorter or longer. What I'm playing around with is a way you can
study the characteristics of one stream versus another.

Scott

2000\03\06@163855 by Wagner Lipnharski

picon face
Considering the sine wave PWM generated, I wonder about the totally
unpredictable harmonics from the combination of several different pulse
width along the stream.  Square waves are terrible to deal to avoid
harmonics, except when you know exactly the fundamental fo's and the
harmonics composition, otherwise, as a sine wave generator with variable
frequency, it is a real pain. The most comprehensible approach to avoid
them is using PWM cycles in the order of several MHz with prime numbers
as the base for level control, so they will not repeat or cause
alliasing.

Of course, a high "Q" active filter would be the best solution to avoid
harmonics, but again, or the fo is fixed or the active filter is
programmable too, what increase the cost. In this case, the D/A solution
(16 bits at least) turns to be much more economically attractive.

There is another technique that I call "Rolling Triangles" (nothing to
do with Rolling Stones...:), that is;  A triangle face is flat, as flat
is a digital signal, or a linear ramp generated by a constant current
circuit.  Rolling a Triangle, means that your program would set the
triangle face angle according to the sine value, or signal rotational
angle, and this is done by controlling charging current.  Suppose you
slice a 90¡ angle in 90 triangles, equally distributed in rotation, 1¡
per triangle, you would have the first quadrant of your sine-wave.  To
reduce the abrupt angle change between one triangle and another, several
other small triangles are inserted at the transition, you can think as
interpolation.

I use to say that the biggest mistake people do when looking at a sine
wave, is thinking about sine(x) functions, because it is related to a
flat point of view of who is laid on the floor. According to the wheel
point of view, it is just a plain and pure rotation, so the triangle
explanation makes effect. The interaction of those triangles with a
common panel (the floor, and the witness eyesight) we are able to see
only a bi-plane sinewave, when other polarization in different
dimensions are not allowed, as the magnetic and electric fields
modulating a base electrical signal. It wouldn't be nice to be able to
see this multidimensional sine wave interacting with several other
signals?

I first used the expression "Rolling Triangles" when produced a 3 phase
60Hz sine-wave, based on programmable constant current generators, and
high speed processors integrating more than 50 thousands small triangles
per cycle.  I was never able to do it with PWM, even with oscillators
close to MHz.

Later on I found out that changing the 60¡ angle of each triangle
vertice and connect thousands in a net style, it was possible to draw
and plot practically *any* 3 dimensional electrical surface
representation.

Isn't interesting how many different ways you can do the same thing?  I
use to say that there are several ways to skin a cat, you can really be
a winner if you end up with very few scratches...

Wagner.

Scott Dattalo wrote:

[some snip below]
{Quote hidden}

2000\03\06@165758 by David VanHorn

flavicon
face
<x-flowed>At 04:37 PM 3/6/00 -0500, you wrote:
>Considering the sine wave PWM generated, I wonder about the totally
>unpredictable harmonics from the combination of several different pulse
>width along the stream.  Square waves are terrible to deal to avoid
>harmonics, except when you know exactly the fundamental fo's and the
>harmonics composition, otherwise, as a sine wave generator with variable
>frequency, it is a real pain. The most comprehensible approach to avoid
>them is using PWM cycles in the order of several MHz with prime numbers
>as the base for level control, so they will not repeat or cause
>alliasing.


If you used a boxcar integrator, clocked at 2X, then you could get rid of
all the evens anyway.
I'm still looking for a way to nuke the odds.
(I know it's all odds in your app)

</x-flowed>

2000\03\06@172323 by David VanHorn
flavicon
face
<x-flowed>Actually, I am looking for a generalized technique that will let me strip
odd harmonics.
I have an application that's using the boxcar as I described, both to
indicate distortion level, and to subtract said distortion from a signal,
but the odd harmonics have me stumped.

I use one boxcar to take the signal, but of course it also passes the 2H,
3H, 4H... right on up, though past the 4th it's pretty well damped since
it's an eight cap boxcar :)  The second grabs the 2h and 4h components
perfectly, but I have no simple answer for 3h and 5h. (Maybe I only need
3h, but you get the idea.)

</x-flowed>

2000\03\06@203311 by Scott Dattalo

face
flavicon
face
On Mon, 6 Mar 2000, David VanHorn wrote:

> Actually, I am looking for a generalized technique that will let me strip
> odd harmonics.
> I have an application that's using the boxcar as I described, both to
> indicate distortion level, and to subtract said distortion from a signal,
> but the odd harmonics have me stumped.
>
> I use one boxcar to take the signal, but of course it also passes the 2H,
> 3H, 4H... right on up, though past the 4th it's pretty well damped since
> it's an eight cap boxcar :)  The second grabs the 2h and 4h components
> perfectly, but I have no simple answer for 3h and 5h. (Maybe I only need
> 3h, but you get the idea.)

If you had a square wave with a 50% duty cycle, there are no even
harmonics. Furthermore, the relative magnitude of the harmonics are
inversely proportional to their harmonic numbers. If you vary the duty
cycle to say 33%, you'll have no 3rd,6th, 9th harmonic, but some of the
evens will pop up. I don't think there's a way to arbitrarily kill the odd
harmonics. But you can do (at least) two things: vary the pulse width of
individual pulses and vary the number of pulses. The plot:

http://www.dattalo.com/ms1.gif

cancels the 2nd and 3rd harmonics. You could say that it consists of three
pulses; one twice as wide as the other. (But the program generating it had
4 bits for those 3 pulses...).

I don't have time right now to explain, but as I mentioned earlier, it's
possible to exactly cancel the first N harmonics. However, the number of
'time slots' or quantized positions at which the pulse edges may occur is
of the order of N! (factorial). There is technique that involves examining
the phases of the harmonics of the individual pulses. I found that pulses
can be collected into groups that totally cancel one another at a given
harmonic number. The smallest group I experimented with is just a pair.
For example, for the second harmonic, the pulses are grouped in pairs. One
pulse is 180 degrees out of phase with the other. The pairs for the second
harmonic are two pulses separated by one pulse. For the third harmonic,
the pulses are separated by two pulses.

2nd harmonic suppressed:
010100000000
000010100000

3rd harmonic suppressed:
010010000000
000100100000

Total pulse stream:
010110100000

So the objective is to discover the pairs that cancel at a given harmonic
and then to find a set of pulses that will have complete coverage for each
harmonic. I've done this for 24 pulses, but beyond that it gets pretty
hairy...

Scott

2000\03\07@025109 by David VanHorn

flavicon
face
>
>
> If you had a square wave with a 50% duty cycle, there are no even
> harmonics. Furthermore, the relative magnitude of the harmonics are
> inversely proportional to their harmonic numbers. If you vary the duty
> cycle to say 33%, you'll have no 3rd,6th, 9th harmonic, but some of the
> evens will pop up. I don't think there's a way to arbitrarily kill the odd
> harmonics. But you can do (at least) two things: vary the pulse width of
> individual pulses and vary the number of pulses. The plot:


No, it's a problem of receiving a waveform that's synchronus to what I'm
doing,
but the waveshape is essentially random.
It may have any population of harmonics, but I'm only interested in the
fundamental, and whatever processing I do to it has to preserve the phase over
frequency. It can introduce an absolute shift, as long as it's constant.
(hence
the boxcar filter),

2000\03\07@062440 by Nikolai Golovchenko

flavicon
face
Hi Scott,

I never heard of "magic sinewaves" before, so I can be wrong. Anyway,
if I understand correctly, there are two goals in generating the pulse
sequence:
1) Minimize switching
2) Attenuate higher harmonics

I can't understand why you choose PWM to achieve this!

Okay, PWM has small number of transitions - two per PWM period.

Now harmonics. They appear as a result of PWM conversion and can be
thought of as quantization error. To reduce the quantization effect
the PWM resolution (and therefore frequency) must be increased.

The problem is: If you want to reduce errors(or harmonics), you have
to increase PWM frequency. On the other hand, increased PWM frequency
increases the number of transitions per unit of time. So these two
goals conflict with each other, don't they?

I can see another approach. A scheme to minimize quantization errors,
also known as "Scenix PWM".
               --------------
0..1 -----      | 1     +--- |
-----|+  |---o--|       |    |--o-------------
  --|+  |   |  | 0 ----+    |  |
  | -----   |  |       1    |  |
  |         |  --------------  |
  |         |   Quantizer      |
  |         |                  |
  |         -------  -----------
  |               |  |
  |             --------
  |             | +  - |
  |             |      |
  |    -------  --------
  |    |  -1 |      |
  -----| Z   |-------
       -------

Switching is determined by sampling frequency. Choose what you need or
can afford. In any case, the system is trying to eliminate
quantization error at every sample (unlike PWM), which leads to a
higher attenuation of harmonics at the same clock frequency. The
benefit is that you don't have to worry about pulse position, it's
done automatically. The noise is minimal at fundamental harmonic
frequency and increases with frequency. Probably there is a better
feedback variant (noise shaping filter) but this is the simplest and
the only one I know <G>.

Nikolai


On Monday, March 06, 2000 Scott Dattalo wrote:
{Quote hidden}

2000\03\07@093711 by Scott Dattalo

face
flavicon
face
On Tue, 7 Mar 2000, Nikolai Golovchenko wrote:

> Hi Scott,
>
> I never heard of "magic sinewaves" before, so I can be wrong. Anyway,
> if I understand correctly, there are two goals in generating the pulse
> sequence:
> 1) Minimize switching
> 2) Attenuate higher harmonics
>
> I can't understand why you choose PWM to achieve this!
>
> Okay, PWM has small number of transitions - two per PWM period.

Recall though that if you're generating a sinewave using PWM that there
are many PWM cycles for one period of the sinewave. In fact, the more the
better. The reason is because it becomes easier for an analog filter to
remove the PWM carrier frequency while passing the sinewave.

Now in some applications you want to minimize the number of transitions
because the switching losses are a significant factor. If you were to
limit yourself to say only two transitions per cycle, i.e. a square wave,
to generate or synthesize a sinewave then an analog filter would have a
whole lot of work to do. If you made the duty cycle 50% then the even
harmonics are suppressed and your analog filter would need to attenuate
the odds. But the third harmonic is so close to the fundamental that it's
difficult to effectively filter it without detrimentally affecting the
fundamental.

So the next step may be to say, well, I'm going to try two pulses per sine
wave cycle. If you study this case, you'll discover that it's possible to
suppress either the 2nd or the 3rd but not both (at least that's my
observation). So then you say, well, how about three pulses? It turns out
that this can be done: http://www.dattalo.com/ms1.gif. But the 4th and 5th
harmonics are fairly significant - almost as big as the fundamental. Now
to suppress the 4th and the 5th and so on harmonics requires more and more
pulses.


{Quote hidden}

<they hardly were the ones to first invent this...>

{Quote hidden}

But it is interesting to look at from this perspective (as opposed to
looking at an algorithm).

Scott

2000\03\07@141828 by Scott Dattalo

face
flavicon
face
On Tue, 7 Mar 2000, David VanHorn wrote:

> No, it's a problem of receiving a waveform that's synchronus to what I'm
> doing,
> but the waveshape is essentially random.
> It may have any population of harmonics, but I'm only interested in the
> fundamental, and whatever processing I do to it has to preserve the phase over
> frequency. It can introduce an absolute shift, as long as it's constant.
> (hence
> the boxcar filter),

?

What's your application? I don't understand the concept of 'constant phase
over frequency', when there's only one frequency involved. If there's a
frequency band then it does make some sense (but I tend to think in terms
of group delays [and bessel filters]). Are you building a tone decoder?
What's the bandwidth and center Frequency? Or are you building a PLL?

Scott

2000\03\07@154817 by Dan Michaels

flavicon
face
Scott wrote:
>
>Recall though that if you're generating a sinewave using PWM that there
>are many PWM cycles for one period of the sinewave. In fact, the more the
>better. The reason is because it becomes easier for an analog filter to
>remove the PWM carrier frequency while passing the sinewave.
>

Speaking of sinewaves generated via PWM, I once had the brilliant
idea I could use the PWM generated by a PIC73, along with some data
stored in EEPROM, to add cheapo voice output to an embedded system.
It was gonna be called the "Tiny Talker" [or maybe Tiny Skwauker].

You would probably have to limit the highest voice frequencies to
1-2 Khz or so, but it would probably sound as good as early skwauky
devices, and would cost you next to nothing to add to the embedded
system.

The fundamental frequency of 7-bit PWM on a 20Mhz PIC is 156 Khz.
That would give you 78 samples on a 2 Khz sinewave. Stick on a nice
1 Khz low-pass filter, and the PWM fundamental would be down about
44 dB.  [I think - the first thing you forget is all that EE math].

Think this could work?

Toodle Pip - (is that how it goes?)
- Dan Michaels
Oricom Technologies
http://www.sni.net/~oricom
==========================

2000\03\07@162730 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>What's your application? I don't understand the concept of 'constant phase
>over frequency', when there's only one frequency involved. If there's a
>frequency band then it does make some sense (but I tend to think in terms
>of group delays [and bessel filters]). Are you building a tone decoder?

Nope.  I'm switching an array of antennas, creating a phase shift on the RF
carrier, which is demodulated, and used to give a vector to the
transmitter. The problem is that the recovered waveform is rather
non-sinusoidal, so it has noise, plus odd products of the fundamental.

>What's the bandwidth and center Frequency? Or are you building a PLL?

It almost hasn't got one. The center frequency is entirely programmable,
and will shift during operation.
The current boxcar is equivalent to a filter with a center frequency
settable anywhere from 200hZ to 8kHz, with a bandwidth of about 1/2 Hz. The
boxcar passes higher harmonics fairly well, so I have a second boxcar
running at twice the speed, which causes the fundamental to drop out. This
output is inverted and summed with the first boxcar, giving me an output
that only has the fundamental, and odd harmonics.

Due to using boxcars, I can even make radical shifts in switching frequency
during operation, since the phase response of the boxcars is linear (they
are clocked right along with the antenna switching)

Say 10 "spins" at 200 hz, followed by 10 at 8000, and then 10 at 2000, or
set the switching speed per "revolution" according to a PN generator's
output, so that there is no way to modulate the transmitted carrier so as
to disturb my aquisition of the signal.


-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMWeBYFlGDz1l6VWEQJRHQCeMNf79D+BPSAherGgrdl6r1kLr/EAn1EK
kVLcsp/wAgdm+UI8KLRg5BVB
=o3+H
-----END PGP SIGNATURE-----

2000\03\07@163330 by Andrew Kunz

flavicon
face
Who you doing phased array for?  .....akunzKILLspamspam@spam@tdipower.com

Andy

2000\03\08@034822 by Graeme Zimmer

flavicon
face
Hi Dave,

> Nope.  I'm switching an array of antennas, creating a phase shift on the
RF
> carrier, which is demodulated, and used to give a vector to the
> transmitter. The problem is that the recovered waveform is rather
> non-sinusoidal, so it has noise, plus odd products of the fundamental.

An excellent application for a PIC! A Doppler Direction Finder....

I trust that you have seen the original "DopplerScant" article from about 15
years ago?
(was it QST or HR?).

It was the first time that I saw mention of a Commutating Filter......
Strangely they seem to be rarely used today...

I would have a copy here somewhere if you want....

............... Zim

2000\03\08@063005 by paulb

flavicon
face
David VanHorn wrote:

> Due to using boxcars, I can even make radical shifts in switching
> frequency during operation, since the phase response of the boxcars is
> linear (they are clocked right along with the antenna switching)

 These are in fact digital implementations, are they not?

> Say 10 "spins" at 200 hz, followed by 10 at 8000, and then 10 at 2000,
> or set the switching speed per "revolution" according to a PN
> generator's output, so that there is no way to modulate the
> transmitted carrier so as to disturb my aquisition of the signal.

 Somehow, compensating for the phase shift in the IF and detector has
always worried me about that proposal.  How do you propose to do that?
--
 Cheers,
       Paul B.

2000\03\08@130428 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>An excellent application for a PIC! A Doppler Direction Finder....

Well... Actually it's not exactly a pic.. It's an AVR project (8 MHz
AVR8535), but this part of the project is certainly applicable to both worlds.
(he said, edging twoard the door)

>I trust that you have seen the original "DopplerScant" article from about 15
>years ago? (was it QST or HR?).

Ancient history. It was a masterpice in it's time, but not anymore.

>It was the first time that I saw mention of a Commutating Filter......

That's what they called it, AofE calls it a boxcar integrator, which I
think is more descriptive.

It works like this:  I use one timer's int to step the antennas (eight of
them, could be four, could be more)
On switching from antenna X to antenna X+1, there is some phase shift
imposed on the carrier.
Although this is a step function, the receiver integrates it to some
degree, resulting in something between a pulse, and a level shift on the
audio output (a purist would tap the discriminator, I have a 10.7 MHz IF
input)
Over one scan cycle, you get a number of phase shifts, which are exactly in
sync with the antenna switching.
The boxcar integrator connects eight capacitors to the signal line, through
a high resistance, each for 1/8 of the scan cycle.
If you do this a lot, then the integrator averages up a waveform that
represents the phase shifts, which in a perfect world, would be a sine
wave. Unfortunately, there are reflections from odd angles, so you end up
with something rather less than a sine.

My device runs a second boxcar twice as fast, which averages up all the
even hamonic content of the waveform, which I level detect, and compare to
the level of the fundamental plus evens, (two ADC channels) which tells me
how "clean" the waveform is.  I then invert the even hamonic waveform, and
add it to the main, which gets rid of the evens pretty nicely.
Unfortunately, the third and to some degree the fifth, sail right on through.

After that is done, the signal is fed to an MF-6 filter, which is clocked
synchronusly with the antennas, and this filter effectively converts the
remaining waveform into a sine. At this point, I detect the level again,
and the zero crossings for phase information.

The original "dopplescant" and all it's clones run somewhere between 200
and 400 scans/sec, and do almost nothing to "clean up" the signal, relying
mostly on "eyeball integration".

I can vary my scan rate, even during aquisition, since all the filters are
clocked from the scan rate.
My low end is 200 Hz, for practical reasons, and high is 7812 Hz, because
of the divisor limitations of the timer I'm using to divide the 8 MHz proc
clock. 4 MHz is as fast as I can get to, and by the time I divide that down
for the MF-6 and the antenna steppers, we end up at 7812 scans/second.

The "dopplescant" simply lights the appropriate LED when it has a signal,
and lets you worry about everything else.
The other microprocessor units out there, average the data incorrectly, by
simply averaging the most recent sample with the average of the previous
samples. IOW:   90,90,90,.....90,90,90,270 = 180  in that system.
Obviously wrong, but that's what they do, and the nature of the system is
that you do get "wild" bearings fairly often, when a reflection is
momentarily stronger than the true signal path.

On each sample int (zero crossing ^ of the recovered sine), I take the 8
bit sample data, correct for an absolute offset, and current vehicle
heading (vampired from compass data or GPS if compass is not available),
and store it in an array of 16 samples.  If the harmonic content is too
high, or the amplitude too low, then the sample is skipped. Then the sample
is converted from radial form to polar form, which makes the rest easier.
(trust me)

Every 16th sample, I run vector calculus on the lot, to properly average
the bearing, though at this level it's simpler, since the radius is all
"1". The result is stored in another array of 16.

Each time that array fills, I run the vector calc again, this time with
vector and radius to worry about, and derive a "raw" bearing (though it's
hardly raw) and a supersample, which is stored in another array of 16.

That process is repeated again, allowing me to produce a good output on 16
scans, and superb output if the carrier stays present for 16^4 scans. (8
seconds at 7812 Hz)

For both the "raw" and the cooked samples, I convert back to radial, which
now gives me both a vector and a radius, and the radius indicates the
quality of the bearing.  Without running the math on it (approximate)
90,90,90,90,90,90,90,90,90,270 = something like 94 degrees, with a radius
of 0.9 or something similar.
You see the difference?
If the samples were really ratty, then you might have samples all over the
map, and I would still derive a bearing, but the radius would be a lot
closer to zero, indicating that I'm not very sure of my bearing.  The
radius information is used by the PC application to indicate confidence.

Each sample output is tagged with the current GPS location and heading
information, and put in my outbound sample buffer.

In the background, I am serving as half of a stat mux, taking data from
four serial ports, and two internal "virtual" ports, and creating variable
length packets to be sent out another serial port at 38400 baud, to a PC
application, which tears this stream apart, and sees all the data as
separate inputs again (important for laptops, which generally have only one
serial port!)

On the downstream side, I grab the data from the pc, parse the packets, and
output each channel's data to it's respective port, real or virtual. I also
manage handshaking on each port, signalling the host app through a command
channel, which ports can accept additional data. I also handle the cases
where packets were sent before I said "enough" by putting them in the
"holding bin" until the port frees up. (Command channel packets are not
queued, they are jammed into the flow as soon as the current packet
completes, since they are time sensitive)

In my spare time, I vampire the GPS and compass NMEA inputs for the
information I need, and apply that as corrections to the sampling, so that
you can take an accurate bearing while driving in a circle for example.

One final weakness of the original "dopplescant" was that you could
transmit a tone that was exactly at the antenna switching speed, and
confuse it pretty easily. Finding the exact tone was a little difficult,
but that's the only hard part.  My unit normally operates at the 7800 Hz
rate (for fast aquisition) but if it has trouble getting a bearing, it will
start hopping scan rates, according to the output of a PN generator
(internal background task) so the effect is similar to spread spectrum, in
that your jamming signal is spread, but my antenna scanning is always in
sync, so your jamming dissapears.

The display unit talks to the main board by SPI link, (low speed) and has
another AVR processor that presents the "raw" and "cooked" data on a ring
of bi-color LEDs, (tricky multiplexing, I'm using two lead leds) and a
bargraph, and sends me the state of three buttons that I use to configure
and control the system.

The PC application takes my datastream, and puts it on a moving map, with
you at the center, plots each bearing from the point where it was taken.
It also talks to other systems, through an RF data link, and plots their
reported bearings on the map, from wherever they were taken, and indicates
their current position, course, and speed as well.

So, if you decide to get on the ham bands without a licence, or make a
nuisance of yourself, you better be able to outrun me, because every time
you transmit, I'm going to know EXACTLY where you are, moving or not. It
only takes me about 2mS to grab a bearing that's better than any other
doppler unit on the market (more precise) and the longer the signal, the
more accurate I get.

The end market for this thing is serious hams like me, and certain
governmental bodies that have similar interests.
There is also a market for tracking tornadoes, as they emit significant RF
noise. I have already shown that I can accurately DF broadband noise
sources with this rig.

The really fun part is the vector math, which involves a square root
calculation for every 16 incoming samples, as part of an ISR. (The sqrt is
eleven lines of code)

Now, if you'll all don the blindfolds, and stand against the wall please? :)

But, I'm still looking for a reasonable way to remove the odd harmonics,
like the 2x boxcar does the evens.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMa/94FlGDz1l6VWEQIb9ACg5qcujxeGyHdjHgxzK2it1X/R98sAn3fu
6lHZvFzJ7n6C9HVey7u55rtN
=D59g
-----END PGP SIGNATURE-----

2000\03\08@131052 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>  Somehow, compensating for the phase shift in the IF and detector has
>always worried me about that proposal.  How do you propose to do that?
>--
>  Cheers,
>        Paul B.


It's a constant offset. Just tune in a known transmitter (NWS on 162.5-ish)
and enter the true bearing, or point the vehicle at the transmitter, and
tell it to calibrate. It sweeps up the possible sample rates, and enters an
offset value for each scan rate, so even the group delay in the audio
circuits is taken care of.

I do accept audio input as from a speaker jack, but I prefer, and have the
circuitry for, a 10.7 MHz IF input, into my own demod, so as to eliminate
most of the variables.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMbBn4FlGDz1l6VWEQJoTQCdEgBqz4NGeIi7OQXTld0nRnHcwXEAn3aJ
pzJFMRwFmdv8w3+ExEwJgLsg
=b828
-----END PGP SIGNATURE-----

2000\03\08@155737 by paulb

flavicon
face
David VanHorn wrote:

> It's a constant offset. Just tune in a known transmitter (NWS on
> 162.5-ish) and enter the true bearing, or point the vehicle at the
> transmitter, and tell it to calibrate.  It sweeps up the possible
> sample rates, and enters an offset value for each scan rate, so even
> the group delay in the audio circuits is taken care of.

 The delay between altering scan rate and beginning to take readings
was my concern.  It would matter if you were truly using a spread
spectrum approach but as it seems you are just swapping frequencies and
allowing a substantial number of "sweeps" at each, this apparently is
diluted out.
--
 Cheers,
       Paul B.

2000\03\08@161445 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>  The delay between altering scan rate and beginning to take readings
>was my concern.  It would matter if you were truly using a spread
>spectrum approach but as it seems you are just swapping frequencies and
>allowing a substantial number of "sweeps" at each, this apparently is
>diluted out.

I have a holdoff for the MF-6 to stabilize at the new clock, so it ignores
scans for a short while after each hop.

If I didn't have the MF-6 in there, then each sweep could be at a different
rate, but yes, the group delay of the receiver would become important, and
somewhat difficult to calibrate to. Maybe not, I haven't tried that.
I was thinking about an SS approach earlier (months) but didn't think it
would be that useful, and it prevents me from using the MF-6, which
definitely helps clean things up.
(Nice chip that!)

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMbsXoFlGDz1l6VWEQI3IwCeK7UoWEAXld9WKoGG0nV9N8x9WGwAoKOh
CUQjMS7aOr+qbE3Mqb9rrmSs
=qutQ
-----END PGP SIGNATURE-----

2000\03\08@171142 by paulb

flavicon
face
David VanHorn wrote:

> using the MF-6, which definitely helps clean things up.

 I thought the MF-6 was simply a switched-capacitor "boxcar" filter
like you are already using for the primary filter?  How does it reject
harmonics?
--
 Cheers,
       Paul B.

2000\03\08@231550 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>  I thought the MF-6 was simply a switched-capacitor "boxcar" filter
>like you are already using for the primary filter?  How does it reject
>harmonics?

I'm not really sure of the internals, but it's outputting a nice clean sine.
It's clocked a lot faster, 50x (actually 64X in my application) rather than
8x.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMdPOoFlGDz1l6VWEQKu+ACgoCT3QnOKQJ6aO861Wr8C7HSQioUAoIov
MBxW3BWFo5RKXa6m7LaT3jOb
=EwMY
-----END PGP SIGNATURE-----

2000\03\09@084059 by Graeme Zimmer

flavicon
face
Hi,

>   I thought the MF-6 was simply a switched-capacitor "boxcar" filter
> like you are already using for the primary filter?  How does it reject
> harmonics?

Switched capacitor filters are analogous to conventional multi oppamp
filters such as Biquad or State Variable.

They merely use the switched capacitor as a (sort of) digitally variable
resistor.

They don't respond to harmonics.

The Commutating Filter is a completely different beast, which DOES respond
to harmonics.

Personally, I think that Box Car Integrator is the wrong term for
these.......

cheers ............. Zim

2000\03\09@091810 by paulb

flavicon
face
Graeme Zimmer wrote:

> Switched capacitor filters are analogous to conventional multi oppamp
> filters such as Biquad or State Variable.

 Ah yes!  Now I recall.  A bit vague of me.

 I recall when a local magazine published a telephone modem using
switched capacitor filters, quite a while ago.  Had a bit of a bad
reputation which I take to indicate the difficulty of taming such a
beast implemented in discrete components with switching frequencies
floating about...

 In a single IC; a much better proposition.
--
 Cheers,
       Paul B.

2000\03\09@120729 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>The Commutating Filter is a completely different beast, which DOES respond
>to harmonics.
>
>Personally, I think that Box Car Integrator is the wrong term for
>these.......


Well, that's what AofE calls them..

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMf/KoFlGDz1l6VWEQJ24QCg0GIZrNL8ieoqAhQqq/f5w+RnbVQAoJFV
m4YhhFRcFjtzvK5/+zszxQ28
=sfEX
-----END PGP SIGNATURE-----

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