0
votes

I have written a code in order to calculate the twiddle factors for FFT in C. Now, I want to convert it from floating point to fixed point so that I can test it on a DSP processor. I want to calculate the twiddle factors respectively such :

1) Cos(2*pi*k/N)-jSin(2*pi*k/N) where k goes from 0..N/3-1 and N =1536.

How can I get the answer back in Fixed point(lets say Q15 format)

1
I checked that one as well but its not related to my question because we have to deal with sin and cos :)IO8aHcyKS1y gst4CCbfI
Ok - perhaps you should edit your question and title to make the problem more specific.Roger Rowland

1 Answers

1
votes

A Q15 number has 15 fraction bits. Most likely, it has additional bit that is either an integer bit or a sign bit. (This would be evident from context or from additional documentation not supplied in the question.) Let’s suppose the additional bit is an integer bit, and the value is unsigned.

If the 16 bits have the value x when interpreted as an unsigned integer, then they have the value x/215 when interpreted as a Q15. Obviously, to convert the Q15 value x/215 to the integer value x, you simply multiply by 215.

So, given some value y, which may be a cosine or sine for one of your twiddle factors, you can convert it to the integer that you will store in the 16 bits by multiplying by 215, as with the code y*32768, and converting from floating-point to integer. However, the conversion from floating-point to integer truncates toward zero, so 33.9 becomes 33. If you round to the nearest integer instead, there is less error in general. You can do this with nearbyint(y*32768).

There are some problems:

  • If your Q15 is unsigned, you cannot represent negative values, but some of the twiddle factors are negative.
  • If your Q15 is signed, it presumably does not have an integer bit, so the largest value it can represent is 32767/32768. However, some of the twiddle factors are +1 or –1, so they cannot be represented. There may be ways to work around this by handling those twiddle factors specially.
  • It is conceivable that your Q15 uses 32767 as a scale instead of 32768, since this would allow it both to be signed and to handle +1 and –1. I think this is uncommon, but I mention it since neither of the above is completely satisfactory. In this case, you would use 32767 in place of 32768 in the conversion. (Pixel intensities are commonly stored this way; their scaled values range from 0 to 255 to represent intensities from 0 to 1.)