Digital sine wave generation

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,

Reply to
Mochuelo
Loading thread data ...

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.

Reply to
Tim Shoppa

The SW4024 family of inverters made by Xantrex

formatting link
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.

Reply to
The Phantom

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.

Reply to
Tim Shoppa

Where did you find the waveforms (URL)?

Reply to
The Phantom

Figure 18 in

formatting link

The little bippy peak on top might be there to satisfy some specific class of load. I am not an AC inverter guru but my understanding is that certain loads only care about a couple aspects of the input waveform and not all.

Tim.

Reply to
Tim Shoppa

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)

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.

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,

Reply to
Mochuelo

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.

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.

Reply to
Tim Shoppa

How do you calculate the sum-of-squares error?

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.

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

Reply to
The Phantom

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.

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.

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.

Reply to
Tim Shoppa

Ok, this clears up some confusion I had. It sounds like you're saying that you took the difference between the value of sin(pi/16) and the output of the network and squared it, did the same for the the other 15 points and added up the squares. I did things a little differently. I integrated the square of the difference between the sine function and the step value from the network for all 16 intervals (actually I did 8 and multiplied by 2), whereas you only took the values at the midpoint of the intervals. Do I properly understand what you did?

What did you take to be the rail voltage for calculating the output of the network? I took it to be 2 volts, so that the sine function I was approximating was just the standard mathematical sine with an offset of 1.

And, in the interest of seeing if I can duplicate your results, what did you get for the sum-of-squares of the two resistor sets in your first post?

In your previous post, you said: "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."

What I'm wondering is whether you just stopped when you hit the 30.1K, etc. set, or if you checked all the E96 values. Your comment makes it sound like you didn't check them all.

I also checked all the E192 values, and didn't find anything better than your set.

Where I said "slightly modify", I was thinking that one could put 57 ohm resistors in series with the 16.2K and 60 ohms in series with the 12.4K to partly satisfy that obsession. It does pull down the magnitude of that 5th harmonic quite a bit. :-)

Reply to
The Phantom

I rescaled the rail voltage so that for each resistor combination, the sum-of-squares would be minimized. This means that it was less than the peak of the sine. If I got sin(7*pi/16) right, then it'd be 0.9807 for example. I think this step is necessary to make heads or tails of the least-squares minimization; otherwise you aren't really minimizing the harmonics but some other measure that's off by 2 percent.

Checked all of them. Like I said, the resistor range of 3:1 means that there you'll have to go out of the decade for some of them.

Interesting data point, thanks!

Note that the output impedance of a typical HC shift register (e.g. HC595) is in the 40-60 ohm region for small currents, Vcc of 5V, and 25 deg C and this makes the decade scale I chose for

57.6K/30.9K/23.7K/22.1K a particular sweet spot. It looks like it helps elsewhere too!

Tim.

Reply to
Tim Shoppa

No doubt letting a computer do an exhaustive search for you would be easiest.

When I did it (with 5% values) I plotted the standard values on a log scale, then the ratios on the same log scale on a different piece of paper and slid it along the standard values plot looking for a best fit.

Reply to
bogax

I've done an exhaustive search on two consecutive decades of the E96 series, looking at the spectral contents of the resulting signal, and the best[*] combination is yours, {115 124 162 301}. Congratulations :-). It took 5.2 hours on my AMD XP @ 1800, with Matlab v7.

[*] Criterium:

- The maximum |S(f)| is located in the bin f=1/(16*Tclk). I will call this |S(f_1)|.

- The ratio |S(f_1)|/|S(f_worst)| is maximum, where f_worst=k*f_1 and k is the value out of {2,3,4... 14} for which |S(f_worst)| is highest.

- I considered only combinations for which Ra

Reply to
Mochuelo

Could you post the next best 2 or 3 that you found? Also, you might search the E192 series; let the computer run while you're in bed. :-)

Reply to
The Phantom

Thank you :-).

Reply to
Tim Shoppa

The problem is that, for memory reasons, the program recorded new information only when it found a combination better than the best one so far. So, the last row is meaningful (it is the combination or one of the combinations that yield the best result, with the restrictions mentioned), but the second to last is not, because it depends on the search path. There is no guarantee that it is the second best combination.

My last rows were:

[ Ra Rb Rc Rd] SFDR14 : har3 har5 har7 har9 har11 har13

... [ 100 105 140 249] -53.95 : -54.4 -76.6 -54.0 -56.1 -83.4

-67.0 [ 100 105 140 255] -55.11 : -66.4 -62.9 -55.1 -57.3 -69.7

-79.0 [ 100 105 140 261] -56.28 : -61.0 -56.3 -56.4 -58.6 -63.0

-73.6 [ 100 107 140 261] -61.21 : -72.7 -61.2 -69.0 -71.1 -68.0

-85.3 [ 102 110 143 267] -64.05 : -67.8 -64.1 -79.5 -81.6 -70.8

-80.4 [ 115 124 162 301] -68.20 : -106.7 -68.2 -82.3 -84.4 -75.0

-119.3

So, it did find one other combination (besides Tim's) better than the one in AOE (which has -61.9 dB), but maybe there are more. In fact, there may be more than one combination with -68.20 dB, but my program only showed the first one it found. If I rerun the program with a "

Reply to
Mochuelo

Hmmm... what do you call common sense? The solution of a system of equations? I wouldn't call it that way. Besides, that system of equations minimizes one thing, which is the LSE, and I didn't want to assume anything about the LSE.

Frankly, can you find out the ratios doing only very few calculations? How?

I guess you meant 192^4 = 1.4*10^9. No, I "only" swept 5.8*10^7 combinations.

I know, but I didn't want to start assuming any ratios, and especially ratios that were found with a goal in the time domain. I wanted to look only at the frequency domain.

Best,

Reply to
Mochuelo

Since the wave would likely be filtered by an analog filter, I think a good criterion would be to attenuate the successive harmonics by a 6 dB/octave rolloff and compute the total power in the first 14 harmonics as attenuated, the minimum of this power being the goal. And then attenuate by 12 dB/octave, 18 dB/octave, etc. What fun! :-)

Reply to
The Phantom

I made a dumb programming error, and missed some, including an ultra cherry one.

Here are several from the E192 series that are quite good. I only show the first 5 values; the last 3 are mirrors of the first 3, of course.

Series THD Att. of 3rd and 5th, dB

40.7K 22.1K 16.9K 15.6K 11.307170939% -123 -75 27.7K 15.0K 11.5K 10.6K 11.30717522% -81 -79 40.2K 21.8K 16.7K 15.4K 11.307174038% -80 -76 25.8K 14.0K 10.7K 9.88K 11.30717007% -81 -77

----------------------------------------------------------------------

The theoretical best distortion is 11.3071522645%, so we see that some of these are getting pretty good.

The first one above beats the 30.1K 16.2K 12.4K 11.5K series with respect to all the harmonics through the 13th; I didn't check any more.

I found these by starting at the beginning of the E192 series of values and comparing the theoretical ratios wanted with the four closest from the E192 series, computing the mean square sum of the ratios of each theoretical value to the E192 value, and looking for small results. I did it on a hand calculator in about 5 minutes (5 minutes after the program was written and debugged; that took an hour!)

Reply to
The Phantom

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.