DSPRelated.com
Forums

Sine Lookup Table with Linear Interpolation

Started by rickman March 16, 2013
On 3/20/2013 8:03 PM, josephkk wrote:
> On Mon, 18 Mar 2013 19:53:17 -0400, rickman<gnuarm@gmail.com> wrote: > >> >>>> No, not quite right. There is a LUT with points spaced at 90/255 degrees >>>> apart starting at just above 0 degrees. The values between points in the >>>> table are interpolated with a maximum deviation near the center of the >>>> interpolation. Next to 90 degrees the interpolation is using the maximum >>>> interpolation factor which will result in a value as close as you can >>>> get to the correct value if the end points are used to construct the >>>> interpolation line. 90 degrees itself won't actually be represented, but >>>> rather points on either side, 90&#4294967295;delta where delta is 360&#4294967295; / 2^(n+1) >>>> with n being the number of bits in the input to the sin function. >>>> >>> >>> i read this over a couple times and cannot grok it quite. need to be >>> more explicit (mathematically, or with C or pseudocode) with what your >>> operations are. >> >> It is simple, the LUT gives values for each point in the table, precise >> to the resolution of the output. The sin function between these points >> varies from close to linear to close to quadratic. If you just >> interpolate between the "exact" points, you have an error that is >> *always* negative anywhere except the end points of the segments. So it >> is better to bias the end points to center the linear approximation >> somewhere in the middle of the real curve. Of course, this has to be >> tempered by the resolution of your LUT output. >> >> If you really want to see my work it is all in a spreadsheet at the >> moment. I can send it to you or I can copy some of the formulas here. >> My "optimization" is not nearly optimal. But it is an improvement over >> doing nothing I believe and is not so hard. I may drop it when I go to >> VHDL as it is iterative and may be a PITA to code in a function. >> >> >>>>> if you assume an approximate quadratic behavior over that short segment, >>>>> you can compute the straight line where the error in the middle is equal >>>>> in magnitude (and opposite in sign) to the error at the end points. >>>>> that's a closed form solution, i think. >>>> >>>> Yes, it is a little tricky because at this point we are working with >>>> integer math (or technically fixed point I suppose). >>> > > Hmm. I would like to take a crack at simpson's rule interpolation for > this to measure error budget. I may not be timely but this is > interesting. joseph underscore barrett at sbcglobal daht cahm
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. -- Rick
On 3/21/2013 12:18 AM, glen herrmannsfeldt wrote:
> In comp.dsp josephkk<joseph_barrett@sbcglobal.net> wrote: > > (snip, someone wrote) >>> I'm not sure this would be easier. The LUT an interpolation require a >>> reasonable amount of logic. This requires raising X to the 5th power >>> and five constant multiplies. My FPGA doesn't have multipliers and this >>> may be too much for the poor little chip. I suppose I could do some of >>> this with a LUT and linear interpolation... lol > >> No multipliers(?); ouch. My Simpson's rule method may fit but it will >> need a trapezoidal strip out of a full Wallace tree multiplier. Preferably >> three (speed issue, that may not be that big for you). How do you do the >> linear interpolation without a multiplier? > > The LUT is indexed by the high (4) bits of the input and the low bits > to interpolate with. So it is, pretty much, 16 different interpolation tables > which, in other words, is multiply by table lookup.
That is the poor man's LUT approach where the resources are precious. It requires a "coarse" table using the high and mid bits of the input and a second table indexed by the high and low bits of the input for a correction. I have a 512x18 LUT available and in fact, it is dual ported for simultaneous access if needed. This by itself gives pretty good results. The linear approximation would be done with a serial/parallel Booth's two technique using n clock cycles where n is the number of bits in the multiplier. I've got some time for each sample and expect to share the hardware between two channels. -- Rick
On 3/21/13 6:20 PM, rickman wrote:
> On 3/21/2013 12:18 AM, glen herrmannsfeldt wrote:
...
>> >> The LUT is indexed by the high (4) bits of the input and the low bits >> to interpolate with. So it is, pretty much, 16 different interpolation >> tables >> which, in other words, is multiply by table lookup. > > That is the poor man's LUT approach where the resources are precious. It > requires a "coarse" table using the high and mid bits of the input and a > second table indexed by the high and low bits of the input for a > correction.
that's sorta the case for even the middle-class man's LUT and interpolation. you're always splitting a continuous-time parameter (however many bits are used to express it) into an integer part (that selects the set of samples used in the interpolation) and a fractional part (that defines how this set of samples are to be combined to be the interpolated value). -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On 3/21/2013 1:14 PM, John Larkin wrote:
> On Wed, 20 Mar 2013 20:53:13 -0700, josephkk > <joseph_barrett@sbcglobal.net> wrote: > >> On Sun, 17 Mar 2013 17:22:59 -0700, John Larkin >> <jjlarkin@highNOTlandTHIStechnologyPART.com> wrote: >> >>> >>>> I don't think you are clear on this. The table and linear interp are as >>>> good as they can get with the exception of one or possibly two lsbs to >>>> minimize the error in the linear interp. These is no way to correct for >>>> this by adding a second harmonic, etc. Remember, this is not a pure >>>> table lookup, it is a two step approach. >>> >>> Why can't some harmonic component be added to the table points to improve >>> downstream distortion? Of course, you'd need a full 360 degree table, not a >>> folded one. >> >> How do you get that? All harmonics would be within the 90 degree table. > > Second?
Actually this would not work for anything except odd harmonics. The way the table is folded they have to be symmetrical about the 90 degree point as well as the X axis at 0 and 90 degrees. Odd harmonics would do this if they are phased correctly. I don't think it would be too useful that way.
>> Harmonic phase shifts is a different matter though, that would take >> careful characterization of production quantities of the final product, >> $$$$$. > > Of course you'd have to null each harmonic for gain and phase, > preferably on each production unit, but it wouldn't be difficult or > expensive *if* you had a distortion analyzer with the required PPM > performance. We regularly do automated calibrations, polynomial curve > fits and such, more complex than this.
Might as well use a separate table for the nulling, it would be much simpler. -- Rick
rickman wrote:
> On 3/21/2013 1:14 PM, John Larkin wrote: > >> On Wed, 20 Mar 2013 20:53:13 -0700, josephkk >> <joseph_barrett@sbcglobal.net> wrote: >> >>> On Sun, 17 Mar 2013 17:22:59 -0700, John Larkin >>> <jjlarkin@highNOTlandTHIStechnologyPART.com> wrote: >>> >>>> >>>>> I don't think you are clear on this. The table and linear interp >>>>> are as >>>>> good as they can get with the exception of one or possibly two lsbs to >>>>> minimize the error in the linear interp. These is no way to >>>>> correct for >>>>> this by adding a second harmonic, etc. Remember, this is not a pure >>>>> table lookup, it is a two step approach. >>>> >>>> >>>> Why can't some harmonic component be added to the table points to >>>> improve >>>> downstream distortion? Of course, you'd need a full 360 degree >>>> table, not a >>>> folded one. >>> >>> >>> How do you get that? All harmonics would be within the 90 degree >>> table. >> >> >> Second? > > > Actually this would not work for anything except odd harmonics. The way > the table is folded they have to be symmetrical about the 90 degree > point as well as the X axis at 0 and 90 degrees. Odd harmonics would do > this if they are phased correctly. I don't think it would be too useful > that way. > > >>> Harmonic phase shifts is a different matter though, that would take >>> careful characterization of production quantities of the final product, >>> $$$$$. >> >> >> Of course you'd have to null each harmonic for gain and phase, >> preferably on each production unit, but it wouldn't be difficult or >> expensive *if* you had a distortion analyzer with the required PPM >> performance. We regularly do automated calibrations, polynomial curve >> fits and such, more complex than this. > > > Might as well use a separate table for the nulling, it would be much > simpler. >
What ever happen to the good old days of generating sine waves via digital instead of using these DDS chips that no one seems to know exactly how they do it? Well, that seems to be the picture I am getting. ---- You need an incremintor (32 bit) for example, a phase accumulator (32 bits) and lets say a 12 bit DAC. All this does is generate a +/- triangle reference via the phase accumulator. The 31th bit would be the sign which indicates when to start generating decal instead of acel, in the triangle output. Using integers as your phase acc register, this will naturally wrap around. THe idea is to keep summing with the incriminator, which has been initially calculated verses the update time (sample) and desired freq. Now since the DAC is only 12 bits, you use the MSB's as the ref for the DAC and the LSB (20 bits) for the fixed point integer math to get the needed precision. Now that we have a nice triangle wave that can be past to a hybrid log amp, the rest is trivial. Actually, today I was looking at one of our circuits that seem to be generating trapezoid on the (-) peak instead of sine and that was a log amp. Seems the transistor in the feed back failed some how and it most likely has been like that for a long time, no one never noticed it before... And on top of that, years ago I've made sinewave oscillators from the RC point of a 555 timer that drove a log amp designed to give rather clean sinewaves. Jamie
On Mar 22, 1:09&#4294967295;am, Jamie
<jamie_ka1lpa_not_valid_after_ka1l...@charter.net> wrote:
> rickman wrote: > > On 3/21/2013 1:14 PM, John Larkin wrote: > > >> On Wed, 20 Mar 2013 20:53:13 -0700, josephkk > >> <joseph_barr...@sbcglobal.net> &#4294967295;wrote: > > >>> On Sun, 17 Mar 2013 17:22:59 -0700, John Larkin > >>> <jjlar...@highNOTlandTHIStechnologyPART.com> &#4294967295;wrote: > > >>>>> I don't think you are clear on this. &#4294967295;The table and linear interp > >>>>> are as > >>>>> good as they can get with the exception of one or possibly two lsbs to > >>>>> minimize the error in the linear interp. &#4294967295;These is no way to > >>>>> correct for > >>>>> this by adding a second harmonic, etc. &#4294967295;Remember, this is not a pure > >>>>> table lookup, it is a two step approach. > > >>>> Why can't some harmonic component be added to the table points to > >>>> improve > >>>> downstream distortion? Of course, you'd need a full 360 degree > >>>> table, not a > >>>> folded one. > > >>> How do you get that? &#4294967295; All harmonics would be within the 90 degree > >>> table. > > >> Second? > > > Actually this would not work for anything except odd harmonics. &#4294967295;The way > > the table is folded they have to be symmetrical about the 90 degree > > point as well as the X axis at 0 and 90 degrees. &#4294967295;Odd harmonics would do > > this if they are phased correctly. &#4294967295;I don't think it would be too useful > > that way. > > >>> Harmonic phase shifts is a different matter though, that would take > >>> careful characterization of production quantities of the final product, > >>> $$$$$. > > >> Of course you'd have to null each harmonic for gain and phase, > >> preferably on each production unit, but it wouldn't be difficult or > >> expensive *if* you had a distortion analyzer with the required PPM > >> performance. We regularly do automated calibrations, polynomial curve > >> fits and such, more complex than this. > > > Might as well use a separate table for the nulling, it would be much > > simpler. > > &#4294967295; What ever happen to the good old days of generating sine waves via > digital instead of using these DDS chips that no one seems to know > exactly how they do it? Well, that seems to be the picture I am getting. > ---- > &#4294967295; &#4294967295;You need an incremintor (32 bit) for example, a phase accumulator (32 > bits) and lets say a 12 bit DAC. > > &#4294967295; &#4294967295;All this does is generate a +/- triangle reference via the phase > accumulator. The 31th bit would be the sign which indicates when to > start generating decal instead of acel, in the triangle output. > > &#4294967295; &#4294967295;Using integers as your phase acc register, this will naturally wrap > around. THe idea is to keep summing with the incriminator, which has > been initially calculated verses the update time (sample) and desired freq. > > &#4294967295; &#4294967295;Now since the DAC is only 12 bits, you use the MSB's as the ref for > the DAC and the LSB (20 bits) for the fixed point integer math to get > the needed precision. > > &#4294967295; Now that we have a nice triangle wave that can be past to a hybrid log > amp, the rest is trivial. > > &#4294967295; Actually, today I was looking at one of our circuits that seem to be > generating trapezoid on the (-) peak instead of sine and that was a > log amp. Seems the transistor in the feed back failed some how and > it most likely has been like that for a long time, no one never noticed > it before... > > &#4294967295; &#4294967295;And on top of that, years ago I've made sinewave oscillators from the > RC point of a 555 timer that drove a log amp designed to give rather > clean sinewaves. > > 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
langwadt@fonz.dk wrote:
> On Mar 22, 1:09 am, Jamie > <jamie_ka1lpa_not_valid_after_ka1l...@charter.net> wrote: > >>rickman wrote: >> >>>On 3/21/2013 1:14 PM, John Larkin wrote: >> >>>>On Wed, 20 Mar 2013 20:53:13 -0700, josephkk >>>><joseph_barr...@sbcglobal.net> wrote: >> >>>>>On Sun, 17 Mar 2013 17:22:59 -0700, John Larkin >>>>><jjlar...@highNOTlandTHIStechnologyPART.com> wrote: >> >>>>>>>I don't think you are clear on this. The table and linear interp >>>>>>>are as >>>>>>>good as they can get with the exception of one or possibly two lsbs to >>>>>>>minimize the error in the linear interp. These is no way to >>>>>>>correct for >>>>>>>this by adding a second harmonic, etc. Remember, this is not a pure >>>>>>>table lookup, it is a two step approach. >> >>>>>>Why can't some harmonic component be added to the table points to >>>>>>improve >>>>>>downstream distortion? Of course, you'd need a full 360 degree >>>>>>table, not a >>>>>>folded one. >> >>>>>How do you get that? All harmonics would be within the 90 degree >>>>>table. >> >>>>Second? >> >>>Actually this would not work for anything except odd harmonics. The way >>>the table is folded they have to be symmetrical about the 90 degree >>>point as well as the X axis at 0 and 90 degrees. Odd harmonics would do >>>this if they are phased correctly. I don't think it would be too useful >>>that way. >> >>>>>Harmonic phase shifts is a different matter though, that would take >>>>>careful characterization of production quantities of the final product, >>>>>$$$$$. >> >>>>Of course you'd have to null each harmonic for gain and phase, >>>>preferably on each production unit, but it wouldn't be difficult or >>>>expensive *if* you had a distortion analyzer with the required PPM >>>>performance. We regularly do automated calibrations, polynomial curve >>>>fits and such, more complex than this. >> >>>Might as well use a separate table for the nulling, it would be much >>>simpler. >> >> What ever happen to the good old days of generating sine waves via >>digital instead of using these DDS chips that no one seems to know >>exactly how they do it? Well, that seems to be the picture I am getting. >>---- >> You need an incremintor (32 bit) for example, a phase accumulator (32 >>bits) and lets say a 12 bit DAC. >> >> All this does is generate a +/- triangle reference via the phase >>accumulator. The 31th bit would be the sign which indicates when to >>start generating decal instead of acel, in the triangle output. >> >> Using integers as your phase acc register, this will naturally wrap >>around. THe idea is to keep summing with the incriminator, which has >>been initially calculated verses the update time (sample) and desired freq. >> >> Now since the DAC is only 12 bits, you use the MSB's as the ref for >>the DAC and the LSB (20 bits) for the fixed point integer math to get >>the needed precision. >> >> Now that we have a nice triangle wave that can be past to a hybrid log >>amp, the rest is trivial. >> >> Actually, today I was looking at one of our circuits that seem to be >>generating trapezoid on the (-) peak instead of sine and that was a >>log amp. Seems the transistor in the feed back failed some how and >>it most likely has been like that for a long time, no one never noticed >>it before... >> >> And on top of that, years ago I've made sinewave oscillators from the >>RC point of a 555 timer that drove a log amp designed to give rather >>clean sinewaves. >> >>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
In comp.dsp robert bristow-johnson <rbj@audioimagination.com> wrote:
> On 3/21/13 6:20 PM, rickman wrote:
(snip, I wrote)
>>> The LUT is indexed by the high (4) bits of the input and the low bits >>> to interpolate with. So it is, pretty much, 16 different interpolation >>> tables >>> which, in other words, is multiply by table lookup.
>> That is the poor man's LUT approach where the resources are precious. It >> requires a "coarse" table using the high and mid bits of the input and a >> second table indexed by the high and low bits of the input for a >> correction.
You could instead index one ROM with eight bits, giving the interpolation size (delta y) and then index another ROM with that, and the low for data bits. That would allow closer matching of the interpolation slope to the actual data. Seems to me that someone started selling MOS ROMs and then designed some ready to sell.
> that's sorta the case for even the middle-class man's LUT and > interpolation. you're always splitting a continuous-time parameter > (however many bits are used to express it) into an integer part (that > selects the set of samples used in the interpolation) and a fractional > part (that defines how this set of samples are to be combined to be the > interpolated value).
One would have to go through the numbers to see how much difference it makes. This was before the EPROM. They final mask layer was generated from the data file from the user (in large enough quantities to make it worthwhile) or for the special case ROMs in the data book. -- glen
On Thu, 21 Mar 2013 18:45:02 -0400, rickman <gnuarm@gmail.com> wrote:

>On 3/21/2013 1:14 PM, John Larkin wrote: >> On Wed, 20 Mar 2013 20:53:13 -0700, josephkk >> <joseph_barrett@sbcglobal.net> wrote: >> >>> On Sun, 17 Mar 2013 17:22:59 -0700, John Larkin >>> <jjlarkin@highNOTlandTHIStechnologyPART.com> wrote: >>> >>>> >>>>> I don't think you are clear on this. The table and linear interp are as >>>>> good as they can get with the exception of one or possibly two lsbs to >>>>> minimize the error in the linear interp. These is no way to correct for >>>>> this by adding a second harmonic, etc. Remember, this is not a pure >>>>> table lookup, it is a two step approach. >>>> >>>> Why can't some harmonic component be added to the table points to improve >>>> downstream distortion? Of course, you'd need a full 360 degree table, not a >>>> folded one. >>> >>> How do you get that? All harmonics would be within the 90 degree table. >> >> Second? > >Actually this would not work for anything except odd harmonics. The way >the table is folded they have to be symmetrical about the 90 degree >point as well as the X axis at 0 and 90 degrees. Odd harmonics would do >this if they are phased correctly. I don't think it would be too useful >that way.
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.
> > >>> Harmonic phase shifts is a different matter though, that would take >>> careful characterization of production quantities of the final product, >>> $$$$$. >> >> Of course you'd have to null each harmonic for gain and phase, >> preferably on each production unit, but it wouldn't be difficult or >> expensive *if* you had a distortion analyzer with the required PPM >> performance. We regularly do automated calibrations, polynomial curve >> fits and such, more complex than this. > >Might as well use a separate table for the nulling, it would be much >simpler.
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. -- John Larkin Highland Technology, Inc jlarkin at highlandtechnology dot com http://www.highlandtechnology.com Precision electronic instrumentation Picosecond-resolution Digital Delay and Pulse generators Custom laser drivers and controllers Photonics and fiberoptic TTL data links VME thermocouple, LVDT, synchro acquisition and simulation
On Thu, 21 Mar 2013 20:21:57 -0500, Jamie
<jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> wrote:

>rickman wrote: >> On 3/21/2013 1:14 PM, John Larkin wrote: >> >>> On Wed, 20 Mar 2013 20:53:13 -0700, josephkk >>> <joseph_barrett@sbcglobal.net> wrote: >>> >>>> On Sun, 17 Mar 2013 17:22:59 -0700, John Larkin >>>> <jjlarkin@highNOTlandTHIStechnologyPART.com> wrote: >>>> >>>>> >>>>>> I don't think you are clear on this. The table and linear interp >>>>>> are as >>>>>> good as they can get with the exception of one or possibly two lsbs to >>>>>> minimize the error in the linear interp. These is no way to >>>>>> correct for >>>>>> this by adding a second harmonic, etc. Remember, this is not a pure >>>>>> table lookup, it is a two step approach. >>>>> >>>>> >>>>> Why can't some harmonic component be added to the table points to >>>>> improve >>>>> downstream distortion? Of course, you'd need a full 360 degree >>>>> table, not a >>>>> folded one. >>>> >>>> >>>> How do you get that? All harmonics would be within the 90 degree >>>> table. >>> >>> >>> Second? >> >> >> Actually this would not work for anything except odd harmonics. The way >> the table is folded they have to be symmetrical about the 90 degree >> point as well as the X axis at 0 and 90 degrees. Odd harmonics would do >> this if they are phased correctly. I don't think it would be too useful >> that way. >> >> >>>> Harmonic phase shifts is a different matter though, that would take >>>> careful characterization of production quantities of the final product, >>>> $$$$$. >>> >>> >>> Of course you'd have to null each harmonic for gain and phase, >>> preferably on each production unit, but it wouldn't be difficult or >>> expensive *if* you had a distortion analyzer with the required PPM >>> performance. We regularly do automated calibrations, polynomial curve >>> fits and such, more complex than this. >> >> >> Might as well use a separate table for the nulling, it would be much >> simpler. >> > What ever happen to the good old days of generating sine waves via >digital instead of using these DDS chips that no one seems to know >exactly how they do it? Well, that seems to be the picture I am getting.
We know how to do it. We do DDS ourselves, with an FPGA and a DAC. It's really pretty simple. -- John Larkin Highland Technology, Inc jlarkin at highlandtechnology dot com http://www.highlandtechnology.com Precision electronic instrumentation Picosecond-resolution Digital Delay and Pulse generators Custom laser drivers and controllers Photonics and fiberoptic TTL data links VME thermocouple, LVDT, synchro acquisition and simulation