1

I have generated a sine wave using a 257-point look-up table that covers only one quadrant (4th quadrant). The entries in the table are in fixed point format (Q1.15) [o,.....,-32768]. linear interpolation is used for finding unknown values in the table. I came across an example in which linear interpolation is implemented and used the same logic. The index and delta are calculated as:

x -> phase in Q1.15 entries in look up table = 2^8 + 1 = 257

n = 8;
if (x > 0) 
{
    sign_flag = 1;
    x = ~(x);
  }
if (x < -16384)
 {
    x = -32768 - x;
  }
  x = ~(x);
index = x >> (14-n);
delta = (x & ((1 << (14 - n)) - 1)) << (1 + n);
z = table[index];
y = ((table[index+1] - table[index]) * delta) >> 15;
y = z + y;`
  1. what is the logic behind index and delta ?
  2. If delta is calculated using x (phase) in float, how to calculate delta without using shift operation?
mjack34
  • 11
  • 2
  • "[o,.....,-32768]" is unclear. Do you mean that Q1.15 can encode values [-1.0 to +(1.0 - 1/32768.0)] or [something else](https://en.wikipedia.org/wiki/Q_(number_format)#Characteristics)? – chux - Reinstate Monica Dec 20 '22 at 09:09
  • @chux-ReinstateMonica - values in my quadrature look up table are [0,-201,-402,-603,.......,-32768] ; total 257 values. The values in the table are generated using 0x8000 * (-sin((2*pi*i)/1024)) , i=0,1,2,.....,256 – mjack34 Dec 20 '22 at 11:29
  • mjack34, Is this a homework problem? – chux - Reinstate Monica Dec 20 '22 at 12:32
  • @chux-ReinstateMonica - No, it is not a homework problem. LUT are commonly used while working with microcontrollers. My goal is to generate a sine wave using LUT in both fixed point as well as floating point values and investigate the differences between fixed point and floating point values – mjack34 Dec 20 '22 at 12:52
  • @njuffa - what will be the expression for delta if x is float? – mjack34 Dec 20 '22 at 13:22
  • @mjack34 Multiply the argument `x` with an appropriate constant `c`, then `index = int (x * c)`, and `delta = x * c - index`, where `delta` in [0, 1). – njuffa Dec 20 '22 at 18:56

0 Answers0