Maker Pro
Maker Pro

Digital sine wave generation

M

Mochuelo

Jan 1, 1970
0
As far as I know, minimizing sum-of-squares gives the same result as
minimizing THD.


If the minimization processis such that you can make the error as
small as you want, yes. Otherwise, not necessarily.

We are clearly in the latter case, since our delta t is fixed
(period/16) and we are choosing resistors from a set of standard
values.

In cases like this one, you may find that the set of resistors that
minimizes the THD is not the same as the set of resistors that
minimizes the sum of squared errors. Since the good criterium is
spectrum based, it doesn't make much sense wasting effort doing LSE.
LSE can provide a good starting point to be used in an iterative
algorithm that minimizes harmonic contents.

Best,
 
T

Tim Shoppa

Jan 1, 1970
0
Mochuelo said:
If the minimization processis such that you can make the error as
small as you want, yes. Otherwise, not necessarily.

We are clearly in the latter case, since our delta t is fixed
(period/16) and we are choosing resistors from a set of standard
values.

In cases like this one, you may find that the set of resistors that
minimizes the THD is not the same as the set of resistors that
minimizes the sum of squared errors. Since the good criterium is
spectrum based, it doesn't make much sense wasting effort doing LSE.
LSE can provide a good starting point to be used in an iterative
algorithm that minimizes harmonic contents.

If you get the LSE "perfect" with the 16-step/7-resistor design, then
the first fourteen harmonics are ZERO.

Higher harmonics are NON-ZERO, actually pretty large, and (as long as
you're limiting yourself to 7 resistors and equal-spaced steps and want
the first 14 harmonics to be zero) you have NO CONTROL of them
because... you've only got 16 fixed-spacing steps!

Any real analysis has to include the effect of the low-pass filter that
follows our primitive DDS. My decoupling (saying "first we get rid of
the first 14 harmonics in synthesis to make the work of the low-pass
filter easier") may indeed be primitive and not a good decoupling.

If you have any reference to real designs or published literature that
do DDS-like (e.g. equally spaced steps) or other numerically-controlled
oscillator sine-wave synthesis and do NOT simply choose sin(phase) for
equal phase spacing, I'm very interested. DDS has become very popular
over the past decade or so but none of the published designs or chips
I've seen use anything but sin(phase) for equally-spaced phase in their
lookup table.

I'm not completely disinterested in designs that use diode-limiting on
triangle waves (you will note that these often do use non-equal spaced
steps) but I'm convinced that I'm already doing better than all of
those. I'm also convinced that I do much better than
8038's/XR-2206's/etc (which are essentially "slope and trip-point
synthesizers")

Don's "Magic Sine Waves" seem interesting but there's a lot more steps
going on in his PWM than his accounting says there are :). And I'm
working with fairly conventional microprocessors and logic so his
methods run out of steam real quick above a kHz or so (whereas the
16-step-7-resistor thingy is good to several MHz, a place that magic
sine waves will not go).

Tim.
 
T

The Phantom

Jan 1, 1970
0
If you get the LSE "perfect" with the 16-step/7-resistor design, then
the first fourteen harmonics are ZERO.

Higher harmonics are NON-ZERO, actually pretty large, and (as long as
you're limiting yourself to 7 resistors and equal-spaced steps and want
the first 14 harmonics to be zero) you have NO CONTROL of them
because... you've only got 16 fixed-spacing steps!

Any real analysis has to include the effect of the low-pass filter that
follows our primitive DDS. My decoupling (saying "first we get rid of
the first 14 harmonics in synthesis to make the work of the low-pass
filter easier") may indeed be primitive and not a good decoupling.

If you have any reference to real designs or published literature that
do DDS-like (e.g. equally spaced steps) or other numerically-controlled
oscillator sine-wave synthesis and do NOT simply choose sin(phase) for
equal phase spacing, I'm very interested. DDS has become very popular
over the past decade or so but none of the published designs or chips
I've seen use anything but sin(phase) for equally-spaced phase in their
lookup table.

The SW4024 family of inverters made by Xantrex
http://www.xantrex.com/web/id/45/p/1/pt/18/product.asp
generates a waveform that is a stepped sine approximation. The amplitude
of the steps varies with load, so the timing and number of steps is varied
to keep the complete waveform approximately 120 VAC. The way the THD
varies with the number of steps is surprising.
 
T

Tim Shoppa

Jan 1, 1970
0
The said:
The SW4024 family of inverters made by Xantrex
http://www.xantrex.com/web/id/45/p/1/pt/18/product.asp
generates a waveform that is a stepped sine approximation. The amplitude
of the steps varies with load, so the timing and number of steps is varied
to keep the complete waveform approximately 120 VAC. The way the THD
varies with the number of steps is surprising.

Maybe I should've written "that do sine wave synthesis and do a good
job" :). Admittedly their load is a lot more reactive than mine...

I'm surprised at their published waveform, too. With those big pips at
the top and bottom of each sine wave, it's looking more like a triangle
than a sine! By my calculation that amplitude of that pip should be a
percent or two, and it's looking more like 15 percent in their
published curve!

In that respect it looks a little bit like the distortion that comes
out of an 8038 etc. (although I know that uses an entirely different
method.)

Tim.
 
T

The Phantom

Jan 1, 1970
0
Maybe I should've written "that do sine wave synthesis and do a good
job" :). Admittedly their load is a lot more reactive than mine...

I'm surprised at their published waveform, too. With those big pips at
the top and bottom of each sine wave, it's looking more like a triangle
than a sine! By my calculation that amplitude of that pip should be a
percent or two, and it's looking more like 15 percent in their
published curve!

Where did you find the waveforms (URL)?
 
M

Mochuelo

Jan 1, 1970
0
If you get the LSE "perfect" with the 16-step/7-resistor design, then
the first fourteen harmonics are ZERO.

The even harmonics are of course zero, by construction, but the odd
ones are not, unless you call "8*10^-4" zero (and having assigned the
value "1" to the fundamental).

With the AOE values {57.6 30.9 23.7 22.1 23.7 30.9 57.6}:
harmonic[ 0] : 0.0000000000 (-234.4 dB)
harmonic[ 1] : 1.0000000000 ( 0.0 dB) Fundamental
harmonic[ 2] : 0.0000000000 (-319.7 dB)
harmonic[ 3] : 0.0005555000 ( -65.1 dB) <-- not zero
harmonic[ 4] : 0.0000000000 (-335.2 dB)
harmonic[ 5] : 0.0008047148 ( -61.9 dB) <-- not zero
harmonic[ 6] : 0.0000000000 (-344.6 dB)
harmonic[ 7] : 0.0001848441 ( -74.7 dB) <-- not zero
harmonic[ 8] : 0.0000000000 (-335.2 dB)
harmonic[ 9] : 0.0001437676 ( -76.8 dB) <-- not zero
harmonic[10] : 0.0000000000 (-349.0 dB)
harmonic[11] : 0.0003657795 ( -68.7 dB) <-- not zero
harmonic[12] : 0.0000000000 (-344.7 dB)
harmonic[13] : 0.0001281923 ( -77.8 dB) <-- not zero
harmonic[14] : 0.0000000000 (-336.6 dB)
harmonic[15] : 0.0666666676 ( -23.5 dB) <-- large
harmonic[16] : 0.0000000000 (-669.5 dB)
harmonic[17] : 0.0588235305 ( -24.6 dB) <-- large
harmonic[18] : 0.0000000000 (-338.8 dB)
harmonic[19] : 0.0000877105 ( -81.1 dB) etc
harmonic[20] : 0.0000000000 (-349.1 dB)
....

With your values {30.1 16.2 12.4 11.5 12.4 16.2 30.1}:
harmonic[ 0] : 0.0000000000 (-228.8 dB)
harmonic[ 1] : 1.0000000000 ( 0.0 dB) Fundamental
harmonic[ 2] : 0.0000000000 (-323.8 dB)
harmonic[ 3] : 0.0000046094 (-106.7 dB) <-- not zero
harmonic[ 4] : 0.0000000000 (-328.6 dB)
harmonic[ 5] : 0.0003879629 ( -68.2 dB) <-- not zero
harmonic[ 6] : 0.0000000000 (-331.2 dB)
harmonic[ 7] : 0.0000764662 ( -82.3 dB) <-- not zero
harmonic[ 8] : 0.0000000000 (-341.2 dB)
harmonic[ 9] : 0.0000594737 ( -84.5 dB) <-- not zero
harmonic[10] : 0.0000000000 (-335.7 dB)
harmonic[11] : 0.0001763468 ( -75.1 dB) <-- not zero
harmonic[12] : 0.0000000000 (-338.2 dB)
harmonic[13] : 0.0000010637 (-119.5 dB) <-- not zero
harmonic[14] : 0.0000000000 (-340.7 dB)
harmonic[15] : 0.0666666676 ( -23.5 dB) <-- large
harmonic[16] : 0.0000000000 (-655.0 dB)
harmonic[17] : 0.0588235305 ( -24.6 dB) <-- large
harmonic[18] : 0.0000000000 (-342.9 dB)
harmonic[19] : 0.0000007278 (-122.8 dB) etc
harmonic[20] : 0.0000000000 (-342.6 dB)
....
Better, but not perfect.

Intuitively speaking, you can't cause (other than by chance) n perfect
independent zeros with m adjustable variables, being n>m. m equals 4,
for you. If the value of each variable can be chosen from a set with a
_finite_ number of possible values, as is your case (if you want to
use standard E96 values), the situation can only be worse.

What I was saying is that, assuming that your choice minimizes the sum
of squared errors (which I haven't checked), in general, there may be
a _different_ choice that causes the THD to be lower than in your
case. If I have time I will try to find an example to prove this.

Higher harmonics are NON-ZERO, actually pretty large, and (as long as
you're limiting yourself to 7 resistors and equal-spaced steps and want
the first 14 harmonics to be zero) you have NO CONTROL of them
because... you've only got 16 fixed-spacing steps!

Any real analysis has to include the effect of the low-pass filter that
follows our primitive DDS. My decoupling (saying "first we get rid of
the first 14 harmonics in synthesis to make the work of the low-pass
filter easier") may indeed be primitive and not a good decoupling.

If you have any reference to real designs or published literature that
do DDS-like (e.g. equally spaced steps) or other numerically-controlled
oscillator sine-wave synthesis and do NOT simply choose sin(phase) for
equal phase spacing, I'm very interested. DDS has become very popular
over the past decade or so but none of the published designs or chips
I've seen use anything but sin(phase) for equally-spaced phase in their
lookup table.

I'm not completely disinterested in designs that use diode-limiting on
triangle waves (you will note that these often do use non-equal spaced
steps) but I'm convinced that I'm already doing better than all of
those. I'm also convinced that I do much better than
8038's/XR-2206's/etc (which are essentially "slope and trip-point
synthesizers")

Don's "Magic Sine Waves" seem interesting but there's a lot more steps

I don't like using the word "magic" for non-magic things. For the same
reason, delta-sigma modulation could be called magic modulation, the
fast Fourier transform could be called the magic transform, etc. For
me, it is like saying "this is so complex that it has to be called
'magic.'" It is ok if I'm talking to a 10-year old kid, but not if I'm
talking to engineers.

going on in his PWM than his accounting says there are :). And I'm
working with fairly conventional microprocessors and logic so his
methods run out of steam real quick above a kHz or so (whereas the
16-step-7-resistor thingy is good to several MHz, a place that magic
sine waves will not go).

If you need to work with low ratios (clock/output_f), maybe you can
run a long simulation to find the optimum sequence of 0s and 1s (and
even the values of resistors, if you want to work with more than two
levels) that produce the signal with the spectral contents that you
want. Just brute force would work (for low ratios), but a minimization
algorithm would help.

Best,
 
T

Tim Shoppa

Jan 1, 1970
0
Mochuelo said:
The even harmonics are of course zero, by construction, but the odd
ones are not, unless you call "8*10^-4" zero (and having assigned the
value "1" to the fundamental).

Well, the odd ones would be zero IF we got all the resistor ratios
perfect. I generally don't get to pick values that aren't standard E96,
but with 0.01% E96 values available off-the-shelf maybe it'd be good to
use some series combinations.
With the AOE values {57.6 30.9 23.7 22.1 23.7 30.9 57.6}:
harmonic[ 0] : 0.0000000000 (-234.4 dB)
harmonic[ 1] : 1.0000000000 ( 0.0 dB) Fundamental
harmonic[ 2] : 0.0000000000 (-319.7 dB)
harmonic[ 3] : 0.0005555000 ( -65.1 dB) <-- not zero
harmonic[ 4] : 0.0000000000 (-335.2 dB)
harmonic[ 5] : 0.0008047148 ( -61.9 dB) <-- not zero
harmonic[ 6] : 0.0000000000 (-344.6 dB)
harmonic[ 7] : 0.0001848441 ( -74.7 dB) <-- not zero
harmonic[ 8] : 0.0000000000 (-335.2 dB)
harmonic[ 9] : 0.0001437676 ( -76.8 dB) <-- not zero
harmonic[10] : 0.0000000000 (-349.0 dB)
harmonic[11] : 0.0003657795 ( -68.7 dB) <-- not zero
harmonic[12] : 0.0000000000 (-344.7 dB)
harmonic[13] : 0.0001281923 ( -77.8 dB) <-- not zero
harmonic[14] : 0.0000000000 (-336.6 dB)
harmonic[15] : 0.0666666676 ( -23.5 dB) <-- large
harmonic[16] : 0.0000000000 (-669.5 dB)
harmonic[17] : 0.0588235305 ( -24.6 dB) <-- large
harmonic[18] : 0.0000000000 (-338.8 dB)
harmonic[19] : 0.0000877105 ( -81.1 dB) etc
harmonic[20] : 0.0000000000 (-349.1 dB)
...

With your values {30.1 16.2 12.4 11.5 12.4 16.2 30.1}:
harmonic[ 0] : 0.0000000000 (-228.8 dB)
harmonic[ 1] : 1.0000000000 ( 0.0 dB) Fundamental
harmonic[ 2] : 0.0000000000 (-323.8 dB)
harmonic[ 3] : 0.0000046094 (-106.7 dB) <-- not zero
harmonic[ 4] : 0.0000000000 (-328.6 dB)
harmonic[ 5] : 0.0003879629 ( -68.2 dB) <-- not zero
harmonic[ 6] : 0.0000000000 (-331.2 dB)
harmonic[ 7] : 0.0000764662 ( -82.3 dB) <-- not zero
harmonic[ 8] : 0.0000000000 (-341.2 dB)
harmonic[ 9] : 0.0000594737 ( -84.5 dB) <-- not zero
harmonic[10] : 0.0000000000 (-335.7 dB)
harmonic[11] : 0.0001763468 ( -75.1 dB) <-- not zero
harmonic[12] : 0.0000000000 (-338.2 dB)
harmonic[13] : 0.0000010637 (-119.5 dB) <-- not zero
harmonic[14] : 0.0000000000 (-340.7 dB)
harmonic[15] : 0.0666666676 ( -23.5 dB) <-- large
harmonic[16] : 0.0000000000 (-655.0 dB)
harmonic[17] : 0.0588235305 ( -24.6 dB) <-- large
harmonic[18] : 0.0000000000 (-342.9 dB)
harmonic[19] : 0.0000007278 (-122.8 dB) etc
harmonic[20] : 0.0000000000 (-342.6 dB)
...
Better, but not perfect.

I didn't mean to confuse things: all I ever meant to claim was that my
E96 values were better than those in AOE. And I think they're the best
you can get with E96 values... they happen to be several times better
than the next-best combination. (Sort of like how 355/113 is a
surprisingly good approximation to pi...)

I always wrote "perfect" in quotes because I was using it in the same
idealized sense (ignoring E96 limitiations) that the text in AOE uses.

It is actually a bit surprisng that by choosing appropriate E96
resistor values (2% between each step approximately) that you can get
the largest of the first fourteen harmonics down to 0.03% of the
fundamental. And the third harmonic (probably the most important for
real-world non-brick-wall low-pass filters) comes out at 0.0004% of the
fundamental.

Thank you for running the Fourier analysis, BTW. It's reassuring to see
that a factor of four better in sum-of-squares really does translate
into all the harmonics being 6dB or more down. I'll try to trundle
through the other E96 combinations and see if any happen to be
particularly better at getting the third and fifth down way low,
probably at the expense of picking up some strength in the seventh,
ninth, etc.

Tim.
 
T

The Phantom

Jan 1, 1970
0
Mochuelo said:
The even harmonics are of course zero, by construction, but the odd
ones are not, unless you call "8*10^-4" zero (and having assigned the
value "1" to the fundamental).

Well, the odd ones would be zero IF we got all the resistor ratios
perfect. I generally don't get to pick values that aren't standard E96,
but with 0.01% E96 values available off-the-shelf maybe it'd be good to
use some series combinations.
With the AOE values {57.6 30.9 23.7 22.1 23.7 30.9 57.6}:
harmonic[ 0] : 0.0000000000 (-234.4 dB)
harmonic[ 1] : 1.0000000000 ( 0.0 dB) Fundamental
harmonic[ 2] : 0.0000000000 (-319.7 dB)
harmonic[ 3] : 0.0005555000 ( -65.1 dB) <-- not zero
harmonic[ 4] : 0.0000000000 (-335.2 dB)
harmonic[ 5] : 0.0008047148 ( -61.9 dB) <-- not zero
harmonic[ 6] : 0.0000000000 (-344.6 dB)
harmonic[ 7] : 0.0001848441 ( -74.7 dB) <-- not zero
harmonic[ 8] : 0.0000000000 (-335.2 dB)
harmonic[ 9] : 0.0001437676 ( -76.8 dB) <-- not zero
harmonic[10] : 0.0000000000 (-349.0 dB)
harmonic[11] : 0.0003657795 ( -68.7 dB) <-- not zero
harmonic[12] : 0.0000000000 (-344.7 dB)
harmonic[13] : 0.0001281923 ( -77.8 dB) <-- not zero
harmonic[14] : 0.0000000000 (-336.6 dB)
harmonic[15] : 0.0666666676 ( -23.5 dB) <-- large
harmonic[16] : 0.0000000000 (-669.5 dB)
harmonic[17] : 0.0588235305 ( -24.6 dB) <-- large
harmonic[18] : 0.0000000000 (-338.8 dB)
harmonic[19] : 0.0000877105 ( -81.1 dB) etc
harmonic[20] : 0.0000000000 (-349.1 dB)
...

With your values {30.1 16.2 12.4 11.5 12.4 16.2 30.1}:
harmonic[ 0] : 0.0000000000 (-228.8 dB)
harmonic[ 1] : 1.0000000000 ( 0.0 dB) Fundamental
harmonic[ 2] : 0.0000000000 (-323.8 dB)
harmonic[ 3] : 0.0000046094 (-106.7 dB) <-- not zero
harmonic[ 4] : 0.0000000000 (-328.6 dB)
harmonic[ 5] : 0.0003879629 ( -68.2 dB) <-- not zero
harmonic[ 6] : 0.0000000000 (-331.2 dB)
harmonic[ 7] : 0.0000764662 ( -82.3 dB) <-- not zero
harmonic[ 8] : 0.0000000000 (-341.2 dB)
harmonic[ 9] : 0.0000594737 ( -84.5 dB) <-- not zero
harmonic[10] : 0.0000000000 (-335.7 dB)
harmonic[11] : 0.0001763468 ( -75.1 dB) <-- not zero
harmonic[12] : 0.0000000000 (-338.2 dB)
harmonic[13] : 0.0000010637 (-119.5 dB) <-- not zero
harmonic[14] : 0.0000000000 (-340.7 dB)
harmonic[15] : 0.0666666676 ( -23.5 dB) <-- large
harmonic[16] : 0.0000000000 (-655.0 dB)
harmonic[17] : 0.0588235305 ( -24.6 dB) <-- large
harmonic[18] : 0.0000000000 (-342.9 dB)
harmonic[19] : 0.0000007278 (-122.8 dB) etc
harmonic[20] : 0.0000000000 (-342.6 dB)
...
Better, but not perfect.

I didn't mean to confuse things: all I ever meant to claim was that my
E96 values were better than those in AOE. And I think they're the best
you can get with E96 values... they happen to be several times better
than the next-best combination. (Sort of like how 355/113 is a
surprisingly good approximation to pi...)

How do you calculate the sum-of-squares error?
I always wrote "perfect" in quotes because I was using it in the same
idealized sense (ignoring E96 limitiations) that the text in AOE uses.

It is actually a bit surprisng that by choosing appropriate E96
resistor values (2% between each step approximately) that you can get
the largest of the first fourteen harmonics down to 0.03% of the
fundamental. And the third harmonic (probably the most important for
real-world non-brick-wall low-pass filters) comes out at 0.0004% of the
fundamental.

Did you just do an exhaustive search, starting at the beginning of the
E96 series? I can't find any other sets that are as good. The only one
that even comes close is:

Q1: 34.8K
Q2: 18.7K
Q3: 14.3K
Q4: 13.3K
Q5: 14.3K
Q6: 18.7K
Q7: 34.8K

The attenuations of the harmonics are:

3rd -97 dB
5th -65 dB
7th -74 dB
9th -76 dB
11th -71 dB
13th -109 dB

Even better however, is to slightly modify your values to:

Q1: 30.1K
Q2: 16.257K
Q3: 12.46K
Q4: 11.5K
Q5: 12.46K
Q6: 16.257K
Q7: 30.1K

Then the attenuations are:

3rd -108 dB
5th -87.5 dB
7th -80.7 dB
9th -82.9 dB
11th -94.4 dB
13th -121 dB

You're going to have some good tempco resistors to hold that kind of
suppression of the harmonics. And, of course, I didn't take into account
the output resistance of the gates, etc.
Thank you for running the Fourier analysis, BTW.

I got the same numbers he did; we each must have got it right, or we made
exactly the same mistake!
 
T

Tim Shoppa

Jan 1, 1970
0
The said:
How do you calculate the sum-of-squares error?

It was just the sum of the squares of the deviation between the
synthesized voltage and the actual value of sin(phase) for each of the
phases pi/16, 3*pi/16, etc.

There are many many tools and techniques for minimizing sum-of-squares
error. I just sort of use it by default, without thinking, in any sort
of fitting etc. In many cases it is not the correct error to minimize,
but it's almost always the easiest fit, so a lot of us use it as a
measure without any real justification.
Did you just do an exhaustive search, starting at the beginning of the
E96 series?

Sort-of. I knew the "perfect" resistor ratios, and would choose a
"base" E96 value, look up the nearest E96 choices for the other 3
resistors, and then use those. Yeah, this isn't the best if the perfect
value comes exactly between two E96 choices, but then those
combinations are not going to be the best of the bunch either.

Because the ideal resistor values span a roughly 3:1 range I allowed
two adjacent decades of E96 values.
Even better however, is to slightly modify your values to:

Q1: 30.1K
Q2: 16.257K
Q3: 12.46K
Q4: 11.5K
Q5: 12.46K
Q6: 16.257K
Q7: 30.1K

The "perfect" ratios are to 8 digits (normalized to R1=100K):

R1: 100K
R2: 54.1195982K
R3: 41.4213457K
R4: 38.2683326K

With E96 resistors available off-the-shelf with 0.01% tolerances these
days, somebody who was really obsessed with this could probably find
some series or parallel combinations that hit these to an obscene
number of digits.

But... it's sort of like 355/113 being a surprisingly good
approximation to pi. Yeah, you can tell me that 52163/16604 is better,
but it's not better by much!

Tim.
 
Top