Maker Pro
Maker Pro

Digital Sine Wave Generation

S

Scrim

Jan 1, 1970
0
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

I want to redesign it to use nine resistors and a ten shift register stages,
but I havn't been able to work out exactly how the resistor values were
calculated.
The circuit opperation is unusual in that the output (a voltage) is produced
by groups of resistors being connected in parralel to one or other supply
rail and thus acting as a variable potential divider.

By my analysis there are eight (normalised) output voltages generated as
follows:

0
0.217
0.401
0.599
0.783
0.924
1

These are output at equal time intervals, repeating the sequence up, then
down, to generate the sine wave.

After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?

Scrim
 
N

Norm Dresner

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

I want to redesign it to use nine resistors and a ten shift register stages,
but I havn't been able to work out exactly how the resistor values were
calculated.
The circuit opperation is unusual in that the output (a voltage) is produced
by groups of resistors being connected in parralel to one or other supply
rail and thus acting as a variable potential divider.

By my analysis there are eight (normalised) output voltages generated as
follows:

0
0.217
0.401
0.599
0.783
0.924
1

These are output at equal time intervals, repeating the sequence up, then
down, to generate the sine wave.

After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?

Scrim

Assuming your numbers are correct, the first few look like sin(12deg),
sin(24deg), ... But 12 doesn't divide evenly into 90deg so I'd start asking
if you got the numbers right.

Norm
 
T

Tam/WB2TT

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

I want to redesign it to use nine resistors and a ten shift register stages,
but I havn't been able to work out exactly how the resistor values were
calculated.
The circuit opperation is unusual in that the output (a voltage) is produced
by groups of resistors being connected in parralel to one or other supply
rail and thus acting as a variable potential divider.

By my analysis there are eight (normalised) output voltages generated as
follows:

0
0.217
0.401
0.599
0.783
0.924
1

These are output at equal time intervals, repeating the sequence up, then
down, to generate the sine wave.

After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?

Scrim
His sample spacing is 180/8 = 22.5 degrees. You are missing a number in your
table. There should be 7 non zero numbers. Since the voltage is always
positive, if you pick the maximum value as 1, then he is actually generating
(1/2) x (1 + sinx). The values he uses are actually offset from the sample
points. It is getting kind of late here, but my guess is that he is
integrating the area under the curve at 22.5 degree increments, and finding
a pulse height that will produce the same area. This assumes your numbers
are correct, and he did not just interpolating.

Tam
 
S

Scrim

Jan 1, 1970
0
Tam/WB2TT said:
His sample spacing is 180/8 = 22.5 degrees. You are missing a number in your
table. There should be 7 non zero numbers. Since the voltage is always
positive, if you pick the maximum value as 1, then he is actually generating
(1/2) x (1 + sinx). The values he uses are actually offset from the sample
points. It is getting kind of late here, but my guess is that he is
integrating the area under the curve at 22.5 degree increments, and finding
a pulse height that will produce the same area. This assumes your numbers
are correct, and he did not just interpolating.

Tam

Sorry, here is the complete list:
0
0.0757
0.217
0.401
0.599
0.783
0.924
1

I will check my figures, do some more investigating and get back later
today. Thanks for the help so far,

Scrim
 
B

Bill Sloman

Jan 1, 1970
0
Norm Dresner said:
Assuming your numbers are correct, the first few look like sin(12deg),
sin(24deg), ... But 12 doesn't divide evenly into 90deg so I'd start asking
if you got the numbers right.

Norm

It is a long time since I had to solve this problem (more than twenty
years), but IIRR, you can look at it as devising a Finite Impulse
Response filter for the square wave produced by the digital logic.

Essentially, the resistor values are the inverse of the sinc function
(sin(x)/x where x is in radians), where x is phase at each stage of
your shift register.

The problem with this approach is that if your shift register is of
finite length, you get Gibbs oscillation in the frequency response,
which you can get rid of by multiplying the sinc values by a raised
cosine weighing function (Hamming window), which increases the size of
the resistors at the far end of the shift register.

There should be enough names here for a Google search to get you
someplace useful.
 
S

Scrim

Jan 1, 1970
0
Scrim said:
Sorry, here is the complete list:
0
0.0757
0.217
0.401
0.599
0.783
0.924
1

I will check my figures, do some more investigating and get back later
today. Thanks for the help so far,

Scrim
Ok, I seem to have cracked it. The output voltage (V) values I gave are
correct. and they can be calculated within 1% of full scale output using
f(count)= 1/2*(1 - cos(count*22.5 +12.25) ), where count = 0 to 15.

I should now be able to modify this function to work with other size shift
registers and then, I guess, use some large simultaneous equations to work
from that to the resistor values.

Thanks for the help though,

Scrim
 
A

Andrew Holme

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif
After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?


Consider a 6-bit shift register (5 resistors)


Pull up Pull down Angle
-------------- -------------- -----

R1 R2 R3 R2 R1 0
R1 R2 R3 R2 R1 18
R1 R2 R3 R2 R1 36
R1 R2 R3 R2 R1 54
R1 R2 R3 R2 R1 72
R1 R2 R3 R2 R1 90


It's easier if you convert resistance to admittance (A=1/R)


Pull up Pull down Angle Sine
-------------- -------------- ----- ----

A1 A2 A3 A2 A1 0 0
A1 A2 A3 A2 A1 18 0.309
A1 A2 A3 A2 A1 36 0.588
A1 A2 A3 A2 A1 54 e.t.c
A1 A2 A3 A2 A1 72
A1 A2 A3 A2 A1 90


A potential divider formed from admittances = Aup/(Aup+Adown)


A1 = 0.309/2 * (A1+A2+A3+A2+A1)
A1+A2 = 0.588/2 * (A1+A2+A3+A2+A1)
e.t.c.


Choose a value for the sum of admittances.
Your choice sets current consumption and output impedance.

e.g.
Sum = 0.001
A1 = 0.309 / 2 * Sum
A2 = 0.588 / 2 * Sum - A1
A3 = Sum - 2 * A1 - 2 * A2
R1 = 1 / A1 = 6472.5
R2 = 1 / A2 = 7168.5
R3 = 1 / A3 = 2427.2

For a 10-bit shift register, you need 5 admittances.
 
A

Andrew Holme

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?


CORRECTION TO MY PREVIOUS POST
==============================


Consider a 6-bit shift register (5 resistors)


Pull up Pull down Angle
-------------- -------------- -----

R1 R2 R3 R2 R1 0
R1 R2 R3 R2 R1 18
R1 R2 R3 R2 R1 36
R1 R2 R3 R2 R1 54
R1 R2 R3 R2 R1 72
R1 R2 R3 R2 R1 90


It's easier if you convert resistance to admittance (A=1/R)


Pull up Pull down Angle Cosine
-------------- -------------- ----- ------

A1 A2 A3 A2 A1 0 1.000
A1 A2 A3 A2 A1 18 0.951
A1 A2 A3 A2 A1 36 0.809
A1 A2 A3 A2 A1 54 0.588
A1 A2 A3 A2 A1 72 0.309
A1 A2 A3 A2 A1 90 0


A potential divider formed from admittances = Aup/(Aup+Adown)


A1 = 0.309/2 * (A1+A2+A3+A2+A1)
A1+A2 = 0.588/2 * (A1+A2+A3+A2+A1)
e.t.c.


Choose a value for the sum of admittances.
Your choice sets current consumption and output impedance.

e.g.
Sum = 0.001
A1 = 0.309 / 2 * Sum
A2 = 0.588 / 2 * Sum - A1
A3 = Sum - 2 * A1 - 2 * A2
R1 = 1 / A1 = 6472.5
R2 = 1 / A2 = 7168.5
R3 = 1 / A3 = 2427.2

For a 10-bit shift register, you need 5 admittances.
 
A

Allan Herriman

Jan 1, 1970
0
Consider a 6-bit shift register (5 resistors)


Pull up Pull down Angle
-------------- -------------- -----

R1 R2 R3 R2 R1 0
R1 R2 R3 R2 R1 18
R1 R2 R3 R2 R1 36
R1 R2 R3 R2 R1 54
R1 R2 R3 R2 R1 72
R1 R2 R3 R2 R1 90


It's easier if you convert resistance to admittance (A=1/R)


Pull up Pull down Angle Sine
-------------- -------------- ----- ----

A1 A2 A3 A2 A1 0 0
A1 A2 A3 A2 A1 18 0.309
A1 A2 A3 A2 A1 36 0.588
A1 A2 A3 A2 A1 54 e.t.c
A1 A2 A3 A2 A1 72
A1 A2 A3 A2 A1 90


A potential divider formed from admittances = Aup/(Aup+Adown)


A1 = 0.309/2 * (A1+A2+A3+A2+A1)
A1+A2 = 0.588/2 * (A1+A2+A3+A2+A1)
e.t.c.


Choose a value for the sum of admittances.
Your choice sets current consumption and output impedance.

e.g.
Sum = 0.001
A1 = 0.309 / 2 * Sum
A2 = 0.588 / 2 * Sum - A1
A3 = Sum - 2 * A1 - 2 * A2
R1 = 1 / A1 = 6472.5
R2 = 1 / A2 = 7168.5
R3 = 1 / A3 = 2427.2

For a 10-bit shift register, you need 5 admittances.

I was about to post something similar... but I used Y as the symbol
for admittance (actually, G for conductance, since we are using
non-reactive components).

I learned it as:

Impedance, Z
Re(Impedance) = Resistance, R.
Im(Impedance) = Reactance, X

Admittance, Y = 1/Z
Re(Admittance) = Conductance, G
Im(Admittance) = Susceptance, B

Note that (in general),
B not= 1/X and
G not= 1/R

(Not that this affects the resistor values calculated above at all...)

Regards,
Allan.
 
A

Andrew Holme

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

I want to redesign it to use nine resistors and a ten shift register stages,
but I havn't been able to work out exactly how the resistor values were
calculated.
After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?

CORRECTION TO CORRECTION TO MY PREVIOUS POST !!!! Doh!
============================================


Consider a 6-bit shift register (5 resistors)


Pull up Pull down Angle
-------------- -------------- -----

R1 R2 R3 R2 R1 0
R1 R2 R3 R2 R1 36
R1 R2 R3 R2 R1 72
R1 R2 R3 R2 R1 108
R1 R2 R3 R2 R1 144
R1 R2 R3 R2 R1 180


It's easier if you convert resistance to admittance (A=1/R)


Pull up Pull down Angle Cosine Ratio
-------------- -------------- ----- ------ -----

A1 A2 A3 A2 A1 0 1.000 1
A1 A2 A3 A2 A1 36 0.809 0.905
A1 A2 A3 A2 A1 72 0.309 0.655
A1 A2 A3 A2 A1 108 -0.309 0.345
A1 A2 A3 A2 A1 144 -0.809 0.095
A1 A2 A3 A2 A1 180 -1.000 0


Ratio = (cosine+1)/2

A potential divider formed from admittances = Aup/(Aup+Adown)


A1 = 0.095 * (A1+A2+A3+A2+A1)
A1+A2 = 0.345 * (A1+A2+A3+A2+A1)


Choose a value for the sum of admittances.
Your choice sets current consumption and output impedance.


e.g.
Sum = 0.001
a1 = 0.095 * Sum
a2 = 0.345 * Sum - a1
a3 = Sum - 2 * a1 - 2 * a2
R1 = 1 / a1 = 10526.3
R2 = 1 / a2 = 4000
R3 = 1 / a3 = 3225.8


For a 10-bit shift register, you need 5 admittances.
 
T

Tam/WB2TT

Jan 1, 1970
0
Scrim said:
Ok, I seem to have cracked it. The output voltage (V) values I gave are
correct. and they can be calculated within 1% of full scale output using
f(count)= 1/2*(1 - cos(count*22.5 +12.25) ), where count = 0 to 15.

I should now be able to modify this function to work with other size shift
registers and then, I guess, use some large simultaneous equations to work
from that to the resistor values.

Thanks for the help though,

Scrim

I think he has another offset in there to make it easier to build. If you
calculate your 1-cos() terms they should all be non zero. So, it appears he
offset everything by the value of the smallest number to have it go to 0.
Double check me on this, but I think the smallest number you will get is
1 - cos(12.5) = .0237. So, I think the actual equation is
..9763 - cos x
(Did you mean 11.25, instead of 12.25 ?)

This is a neat way of doing it. I built something like it a few years ago,
but I did the sine from 0-90, then from 90-0, and reversed the polarity for
every second iteration. I needed half as many resistors, at the expense of
more logic.

Instead of making the amplitude equal to the cosine at the average angle,
you could also make it equal to the value of the average cosine, or the area
between samples.

Tam
 
F

Fred Bloggs

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

I want to redesign it to use nine resistors and a ten shift register stages,
but I havn't been able to work out exactly how the resistor values were
calculated.
The circuit opperation is unusual in that the output (a voltage) is produced
by groups of resistors being connected in parralel to one or other supply
rail and thus acting as a variable potential divider.

By my analysis there are eight (normalised) output voltages generated as
follows:

0
0.217
0.401
0.599
0.783
0.924
1

These are output at equal time intervals, repeating the sequence up, then
down, to generate the sine wave.

After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?

Scrim

Those values are computed easily once you have the digital weighting
function for the sinewave- it is a digital filtering application- the
example circuit is not a uniform weighting function:
View in a fixed-width font such as Courier.





SHIFT REG
+------------+
| | R1
| B |---/\/\-------+----->VOUT
| 1 | |
| | R2 |
| B |---/\/\-------+
| 2 | |
| | R3 |
| B |---/\/\-------+
| 3 | |
| . | |
| . | |
| . | |
| | RN |
| B |---/\/\-------+
| N |
| |
| B |------+
| N+1| |
| | |
+------------+ |
|
FDBK<----------------+





ITERATIVE COMPUTATION OF R I=1,2,3,..N :
I

Denote Y = 1/R
I I

and Y = Y + Y + ...+ Y
T 1 2 N

and R = 1/Y or R x Y =1
P T P T


When B = Vdd='1' then contribution to VOUT is
I

| 1
VOUT/Vdd| = -------------------------------------------
|B 1+ R x(Y + Y +...Y + Y + ...+ Y )
I I 1 2 I-1 I+1 N




by simple voltage divider rule


- and -



by superposition:
__
\ |
VOUT/Vdd= / VOUT/Vdd|
-- |B
I, B =1 I
I


The computation is nearly complete when you arrange:



| 1
VOUT/Vdd| = -------------------------------------------
|B 1+ R x(Y + Y +...Y + Y + ...+ Y )
I I 1 2 I-1 I+1 N
------------------------------------
R xY
P T



1
= -------------------------------------------
1+ r x (y + y +...y + y + ...+ y )
I 1 2 I-1 I+1 N


where r = R / R and y = Y / Y
I I P K K T



Then since y + y +...y + y + ...+ y = 1 - y it follows
1 2 I-1 I+1 N I



| 1 1
VOUT/Vdd| = ------------------ = --- = y since r x y =1
|B 1+ r x (1 - y ) r I I I
I I I I



|
-or- VOUT/Vdd| = y
|B I
I


|
Then since VOUT/Vdd| = W x SIN (ANGLE )
|B 1 1
1

| |
VOUT/Vdd| + VOUT/Vdd| = W x SIN (ANGLE )
|B |B 2 2
1 2


ETC... - or -

K
__
\ |
/ VOUT/Vdd| = W x SIN (ANGLE )
-- |B K K
I=1 I

W , W ,...= weighting function
1 2

You have by substitution:

y = W x SIN (ANGLE )
1 1 1

y + y = W x SIN (ANGLE )
1 2 2 2

y + y + y = W x SIN (ANGLE )
1 2 3 3 3

ETC...

y + y +... + y = W x SIN(ANGLE )=1
1 2 N N N


From this, it is clear how to solve for ratios y in
I
succession. So that when you fix Y by consideration
T
of loading constraints, then each


1 1
R = - = ------
I Y y x Y
I I T
 
J

Jim Thompson

Jan 1, 1970
0
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif
[snip]
After spending some time using the trig functins on my calculator I havn't
yet been able to find exactly how these values were selected. Any one know
the answer?

Scrim

Those values are computed easily once you have the digital weighting
function for the sinewave- it is a digital filtering application- the
example circuit is not a uniform weighting function:
View in a fixed-width font such as Courier.





SHIFT REG
+------------+
| | R1
| B |---/\/\-------+----->VOUT
| 1 | | [snip]
+------------+ |
|
FDBK<----------------+





ITERATIVE COMPUTATION OF R I=1,2,3,..N :
I

Denote Y = 1/R
I I

and Y = Y + Y + ...+ Y
T 1 2 N

and R = 1/Y or R x Y =1
P T P T


When B = Vdd='1' then contribution to VOUT is
I

| 1
VOUT/Vdd| = -------------------------------------------
|B 1+ R x(Y + Y +...Y + Y + ...+ Y )
I I 1 2 I-1 I+1 N
[snip]
y + y + y = W x SIN (ANGLE )
1 2 3 3 3

ETC...

y + y +... + y = W x SIN(ANGLE )=1
1 2 N N N


From this, it is clear how to solve for ratios y in
I
succession. So that when you fix Y by consideration
T
of loading constraints, then each


1 1
R = - = ------
I Y y x Y
I I T

Show-off ;-)

However, it is refreshing to see math instead of guess-work!

But no surprise coming from Fred!

...Jim Thompson
 
T

Tam/WB2TT

Jan 1, 1970
0
Scrim,

I calculated the coefficients for sin x between 0 and 90 degrees without
regard to how you would build it, using 4 different methods. s(n) is the
sample, and x is the sampling interval. I used 22.5 deg.

1.Kind of dumb. s(n) = sin(nx). gives 0, .3827, .707, .9239.

2. Your method? s(n) = sin( nx + x/2). gives .195, .555, .831, .9808, .9808

3 Average of sin. s(n) = [sin(nx) + sin((n+1)x)]/2. gives .191, .545, .815,
..9619, .9619.

4. Integrated area. s(n) = INTEGRAL [sin nx] {n=m to m+1}
gives .076, .216, .324, .3827, .3827

These don't look at all the same until you normalize them to 1. Then you
get:
2) .1988, .5659, .8473, 1, 1
3) .1986, .5667, .8478, 1, 1
4) .1986, .5644, .8466, 1, 1
Differences are now subtle.

If s(0) is the smallest sample, and s(4) is the biggest, and you want to
scale them so that s(0) is 0 and s(4) is 1, you need to solve the equation
s'(n) = Ks(n) - V, where V is the offset voltage for n=0 and 4:

Ks(0) - V = 0
Ks(4) - V = 1

From the first, V = Ks(0)
So, Ks(4) - Ks(0) = 1, K(s(4) - s(0)) = 1, and K = 1/(s(4) - s(0)). I tried
this for case 2, and it worked. This is not the same as subtracting out s(0)
and then dividing by s(4). Same method should work for V - Kcos

Andrew seems to have a really good way of calculating the resistor values.

Tam
 
A

Andrew Holme

Jan 1, 1970
0
Scrim said:
I'm hoping to use a modification to this circuit from "The Art of
Electronics" but I can't sort out the maths:

http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

I want to redesign it to use nine resistors and a ten shift register stages,

Here's a solution using preferred values (use 1% resistors)

0 1.000 1 0.405 0.012212244 81.9
1 0.940 0.96984631 0.392787756 0.035163756 28.4
2 0.766 0.883022222 0.357624 0.053874 18.6
3 0.500 0.75 0.30375 0.066086244 15.1
4 0.174 0.586824089 0.237663756 0.070327512 14.2 = 12 + 2.2
5 -0.174 0.413175911 0.167336244 0.066086244 15.1 = 10 + 3.9 + 1.2
6 -0.500 0.25 0.10125 0.053874 18.6 = 12 + 5.6 + 1
7 -0.766 0.116977778 0.047376 0.035163756 28.4 = 12 + 8.2 + 8.2
8 -0.940 0.03015369 0.012212244 0.012212244 81.9 = 68 + 10 + 3.9
9 -1.000 0
 
T

Tam/WB2TT

Jan 1, 1970
0
IGNORE THE SECTION BELOW FROM MY PREVIOUS.
It serves no purpose once you go past 180 degrees.
If s(0) is the smallest sample, and s(4) is the biggest, and you want to
scale them so that s(0) is 0 and s(4) is 1, you need to solve the equation
s'(n) = Ks(n) - V, where V is the offset voltage for n=0 and 4:

Ks(0) - V = 0
Ks(4) - V = 1

From the first, V = Ks(0)
So, Ks(4) - Ks(0) = 1, K(s(4) - s(0)) = 1, and K = 1/(s(4) - s(0)). I tried
this for case 2, and it worked. This is not the same as subtracting out s(0)
and then dividing by s(4). Same method should work for V - Kcos

You should be able to scale 1 + cos x easily. Just scale the samples so you
generate 1 + Ks(n), (not K(1 + s(n)). By symmetry, if the largest sample is
made 2, then the smallest will be 0.

Tam
 
S

Scrim

Jan 1, 1970
0
Thanks folks, it will take me a while to soak this all up! I'll be back :)

Scrim
 
S

Scrim

Jan 1, 1970
0
Bill Sloman said:
It is a long time since I had to solve this problem (more than twenty
years), but IIRR, you can look at it as devising a Finite Impulse
Response filter for the square wave produced by the digital logic.

Essentially, the resistor values are the inverse of the sinc function
(sin(x)/x where x is in radians), where x is phase at each stage of
your shift register.

The problem with this approach is that if your shift register is of
finite length, you get Gibbs oscillation in the frequency response,
which you can get rid of by multiplying the sinc values by a raised
cosine weighing function (Hamming window), which increases the size of
the resistors at the far end of the shift register.

There should be enough names here for a Google search to get you
someplace useful.

Thanks Bill. And I thought I'd already solved it!

Scrim
 
S

Scrim

Jan 1, 1970
0
Tam/WB2TT said:
I think he has another offset in there to make it easier to build. If you
calculate your 1-cos() terms they should all be non zero. So, it appears he
offset everything by the value of the smallest number to have it go to 0.
Double check me on this, but I think the smallest number you will get is
1 - cos(12.5) = .0237. So, I think the actual equation is
.9763 - cos x
(Did you mean 11.25, instead of 12.25 ?)

This is a neat way of doing it. I built something like it a few years ago,
but I did the sine from 0-90, then from 90-0, and reversed the polarity for
every second iteration. I needed half as many resistors, at the expense of
more logic.

Instead of making the amplitude equal to the cosine at the average angle,
you could also make it equal to the value of the average cosine, or the area
between samples.

Tam
Hi Tam, I think I folow you, except I made an error saying the offset is
12.25 earlier - it should be 11.25. Following your logic though, I've tried
the new function:

f(x) = 1/2*(0.98078528 - cos(22.5x - 11.25))

Whilst this brings the smallest terms to 0, it also reduces the largest,
which should be 1, from 0.990 to 0.981, so I don't think this works ???

Scrim
 
S

Scrim

Jan 1, 1970
0
Tam/WB2TT said:
Scrim,

I calculated the coefficients for sin x between 0 and 90 degrees without
regard to how you would build it, using 4 different methods. s(n) is the
sample, and x is the sampling interval. I used 22.5 deg.

1.Kind of dumb. s(n) = sin(nx). gives 0, .3827, .707, .9239.

2. Your method? s(n) = sin( nx + x/2). gives .195, .555, .831, .9808, ..9808

3 Average of sin. s(n) = [sin(nx) + sin((n+1)x)]/2. gives .191, .545, ..815,
.9619, .9619.

4. Integrated area. s(n) = INTEGRAL [sin nx] {n=m to m+1}
gives .076, .216, .324, .3827, .3827

These don't look at all the same until you normalize them to 1. Then you
get:
2) .1988, .5659, .8473, 1, 1
3) .1986, .5667, .8478, 1, 1
4) .1986, .5644, .8466, 1, 1
Differences are now subtle.

If s(0) is the smallest sample, and s(4) is the biggest, and you want to
scale them so that s(0) is 0 and s(4) is 1, you need to solve the equation
s'(n) = Ks(n) - V, where V is the offset voltage for n=0 and 4:

Ks(0) - V = 0
Ks(4) - V = 1

From the first, V = Ks(0)
So, Ks(4) - Ks(0) = 1, K(s(4) - s(0)) = 1, and K = 1/(s(4) - s(0)). I tried
this for case 2, and it worked. This is not the same as subtracting out s(0)
and then dividing by s(4). Same method should work for V - Kcos

Andrew seems to have a really good way of calculating the resistor values.

Tam

Hi Tam, I struggled a bit to follow all of your argument, but got the
impression that you were taking the idea from your last post (use an offset
to get the smallest result to 0) and adding a scaling factor to get the
largest result to 1. I tried this and it gives the exact results I obtained
from the original resistor values (3 significant figures) except for one
minor error, so I think, as you say, it works :)
Great stuff!

To sum up, here is the data for counts 0 to 7. This covers all possible
output voltages and saves repeating results:

----------------------------------------------------------------------------
-----------------------------------------
V = the normalised outputs calculated from the resistor values in the
original circuit diagram here :
http://www.scitech.pwp.blueyonder.co.uk/Digital-Sine-Wave-Generatio.gif

F = 0.509795579*(0.98078528 - cos(count*22.5 + 11.25))

Error = (V-F)*100 (gives percentage error relative to full (normalised)
scale).

count V F Error %
0 0 0 0
1 0.0758 0.0761 0.03
2 0.217 0.217 0
3 0.401 0.401 0
4 0.599 0.599 0
5 0.783 0.783 0
6 0.924 0.924 0
7 1.0 1.0 0
----------------------------------------------------------------------------
 
Top