Maker Pro
Maker Pro

Sine Lookup Table with Linear Interpolation

J

Jamie

well the DDS chips work just like you describe, an accumulator
but instead of generating a triangle and shaping it, the MSBs index a
sinewave table going to a DAC

you can do with one quadrant of sine table, with MSB-1 you can
chose 2nd,4rd quadrant, invert the bits indexing the sinewave (makes
the index count "in reverse")

MSB choose 1st,2nd or 3rd,4th quadrant, for 3rd and 4th negate the
sinewave output

-Lasse
Well I kind of figure that was the operation taking place since I've
made circuits like that via RS485 but I used a log amp instead. Using
a single quadrant is all you need and you can get very detailed with
the linear to sin translations.

Many of these DDS FG's seem to show that anything other than a sine
wave, forces them to reduce output BW. I can only assume this due to a
bottle neck from the uC to the chip to update pattern configuration via
SPI or C2I.. I guess a parallel version would make a vast improvement.

Jamie
 
S

Spehro Pefhany

On Thu, 21 Mar 2013 21:38:39 -0500, the renowned Jamie

..
Many of these DDS FG's seem to show that anything other than a sine
wave, forces them to reduce output BW. I can only assume this due to a
bottle neck from the uC to the chip to update pattern configuration via
SPI or C2I.. I guess a parallel version would make a vast improvement.

Jamie

Compare the bandwidth of a sine wave of frequency f vs. a sawtooth of
the same frequency.


Best regards,
Spehro Pefhany
 
M

Martin Brown

If I could measure the THD accurately, I'd just blast in a corrective harmonic
adder to the table for each of the harmonics. That could be scientific or just
iterative. For the 2nd harmonic, for example, add a 2nd harmonic sine component
into all the table points, many of which wouldn't even change by an LSB, to null
out the observed distortion. Gain and phase, of course.


Our experience is that the output amplifiers, after the DAC and lowpass filter,
are the nasty guys for distortion, at least in the 10s of MHz. Lots of
commercial RF generators have amazing 2nd harmonic specs, like -20 dBc. A table
correction would unfortunately be amplitude dependent, so it gets messy fast.

Is it really "pure" second harmonic distortion or a tiny mismatch in the
gain bandwidth product of the power amplifier that could be tweaked out
by a small change in the digital amplitude of the negative cycle?
 
J

Jerry Avins

(snip, ending on CORDIC)



I once thought I pretty well understood binary CORDIC, but it
is also used in decimal on many pocket calculators. I never got
far enough to figure out how they did that.

The hp35 used CORDIC to compute trig functions. Its basic math
operations were BDC, using decimal arithmetic. Most CORDIC
implementations skip "irrelevant" rotations, so the scale of the result
isn't constant for all inputs. To get sine, the hp35 computed both sine
and cosine (little extra cost for getting both) which had the same
scale, then divided to get the cotangent-- the scale factors cancel.
1/sqrt(cot(x)^2 + 1) = sin(x). Since the arithmetic functions were all
in place, it was the fastest way to the result.

So what does "simple" really mean?

Jerry
 
G

glen herrmannsfeldt

(snip, I wrote)
The hp35 used CORDIC to compute trig functions. Its basic math
operations were BDC, using decimal arithmetic. Most CORDIC
implementations skip "irrelevant" rotations, so the scale of the result
isn't constant for all inputs.

The usual binary explanation is that you rotate one way or the other,
such that the scale is constant. Then multiply (once) to correct
for that scale, or for any other scale you want the result to have.
To get sine, the hp35 computed both sine
and cosine (little extra cost for getting both) which had the same
scale, then divided to get the cotangent-- the scale factors cancel.
1/sqrt(cot(x)^2 + 1) = sin(x). Since the arithmetic functions were all
in place, it was the fastest way to the result.

Does sound better than convert to binary followed by binary CORDIC.
If you really aren't in a hurry, you can do 0 to 9 rotations for
each digit.
So what does "simple" really mean?

Sometimes it means no divide and few mutliplies.

I think I have previously noted the Integer Cosine Transform for when
you need to do something like FFT, but with minimal multiplies.
(And when you have lots of processing power for the inverse.)
Designed for the CDP1802, which doesn't have a multiply.

Integer cosine site:jpl.nasa.gov

into google should find it.

-- glen
 
R

Robert Baer

Jerry said:
The hp35 used CORDIC to compute trig functions. Its basic math
operations were BDC, using decimal arithmetic. Most CORDIC
implementations skip "irrelevant" rotations, so the scale of the result
isn't constant for all inputs. To get sine, the hp35 computed both sine
and cosine (little extra cost for getting both) which had the same
scale, then divided to get the cotangent-- the scale factors cancel.
1/sqrt(cot(x)^2 + 1) = sin(x). Since the arithmetic functions were all
in place, it was the fastest way to the result.

So what does "simple" really mean?

Jerry
Someone pointed out that i quoted sqrt(50) incorrectly at 6 digits;
the actual table in CRC shows 7.071068 which is seven digits, definitely
better than the puny 4 digits that was bandied about.
 
J

Jamie

Spehro said:
On Thu, 21 Mar 2013 21:38:39 -0500, the renowned Jamie

.



Compare the bandwidth of a sine wave of frequency f vs. a sawtooth of
the same frequency.


Best regards,
Spehro Pefhany

Something tells me that not all DDS chips are created equal.

Jamie
 
J

josephkk

Oh, I thought you were talking about using Simpsom's rule as part of the
interpolation. You are talking about using it to estimate the integral
of the error. Great idea! I'll shoot you an email.

I was talking about using it for interpolation.

?-)
 
J

josephkk

Just looking at a sine at F and one at 2F, it's obvious that the 90
degree folded table can't make the 2F component. The 2nd harmonic has
to change sign between 0-90 degrees and 90-180 but can't if the same
90 degree table is used.


It's really about the same, but I guess if the main table is heavily
interpolated, it would make sense to have a little distortion table
off to the side, maybe even with its own DAC.

The table is always valid. The only difference in frequency is the phase
accumulator stepping rate. That is why a DDS is "tunable".

?-)
 
J

josephkk

I can't say I follow what you mean about Simpson's rule interpolation.
Interpolation is used to derive Simpson's Rule, but I don't see a way to
use an integral for obtaining an interpolation. Isn't Simpson's Rule
about approximating integrals? What am I missing?

In many ways it is just an estimator with somewhat less than second order
complexity for function sections of greater than second order complexity.
It is useful in integration because it reduces error and complexity for
reasonably smooth functions. Its value for interpolating within a segment
comes from there.

?-)
 
B

Ben Bradley

I'm lurking in this thread, and it's great (a better s/n than I
expected for such a long thread), until I got to this URL:
...
It is a lot of document for just two pages. Try this link to see the
short version...

arius.com/foobar/1972_National_MOS_Integrated_Circuits_Pages_273-274.pdf

PLEASE put the http:// thing at the start of any URL - it triggers
most software (such as this Free Agent) to make the URL clickable:

http://arius.com/foobar/1972_National_MOS_Integrated_Circuits_Pages_273-274.pdf
 
J

josephkk

The email bounced.

Hmmm. Not sure just what happened. Can you see the headers of this news
post?

Plus after getting into my books again i think i can explain just how to
do it without fussing with a spreadsheet.

It is a matter of weighting the coefficients (and using more cardinal
points).

For a section of table spanning 5 (or just 3) cardinal points; we take the
sub-interval centered on the 'nearest' cardinal point. (semi open segment,
-2^n to +2^n-1; where 2*2^n-1 is the number of interpolated points.) For
5 cardinal points this point gets maximum weight call it 1/2. The two
points to either side get weighted 1/4 each, and the two outermost
cardinal points get weighted 1/8 each. For three cardinal points just
eliminate the outer two. Then the rest of your interpolator tool should
do the rest.

?-)
 
R

rickman

Hmmm. Not sure just what happened. Can you see the headers of this news
post?

Yes, and the email address is exactly what I used. Here it is with the
address slightly munged.

<joseph_barrett at sbcglobal.com>:
Sorry, I wasn't able to establish an SMTP connection. (#4.4.1)
I'm not going to try again; this message has been in the queue too long.

Plus after getting into my books again i think i can explain just how to
do it without fussing with a spreadsheet.

The spread sheet isn't important, but I don't have an image of what you
are talking about below.

It is a matter of weighting the coefficients (and using more cardinal
points).

For a section of table spanning 5 (or just 3) cardinal points; we take the
sub-interval centered on the 'nearest' cardinal point. (semi open segment,
-2^n to +2^n-1; where 2*2^n-1 is the number of interpolated points.) For
5 cardinal points this point gets maximum weight call it 1/2. The two
points to either side get weighted 1/4 each, and the two outermost
cardinal points get weighted 1/8 each. For three cardinal points just
eliminate the outer two. Then the rest of your interpolator tool should
do the rest.

One of the things I have realized is that with the table size I am
using, the curve segments that I am interpolating become very good
matches to a straight line to within 18 bits. I have a 512 entry table
and interestingly enough, there is this give and take between the range
of the interpolation and the non-linearity of the curve at that point.

The part of the quarter sine table that has the highest step size is at
zero where the linearity is near dead on. The part of the table that
has the worst approximation to linear is at 90 degrees where the step
size is near zero. I think in an 18 bit table the step is just one
count! So there is not much improvement to be had over simple linear
interpolation. In fact, I can't say there is much of an improvement by
offsetting any of the end point.

If the word width increases from 18 bits, then perhaps there might be
some advantage to other methods. But even an 18 bit table gives a 19
bit result when the sine bit is added. That is way down there in the
noise really. I am looking at a software version and to keep from going
to double precision I might just drop the extra bit and limit the signed
result to 18 bits. This is in a custom processor in an FPGA. 18 bits
comes from the memory size in the block RAMs. We'll see. The
difference is only near the end of the code section and *something* has
to be sent out to the CODEC even if the extra bits are just noise in the
DAC, 24 bits, 90 dB SINAD. Why so many bits you have to wonder...
 
Top