DSPRelated.com
Forums

Fix Point Arithmetic

Started by Salih CALISKAN April 10, 2004
Hello,
 
First off all, I am sory for my bad english.
 
I am new at Fix point arithmetic and I want to use r4fft ( FFT function from dsp62x.lib) on image that I stored in extarnel RAM. My problem is, in documentation, it says all the inputs must be Q15 format. For the fft coefficients, there is no problem because they are in range of -1,1 however the pixel values are out of range (>1). How can I use input values >1 for this function. Should I convert them Q15 format (How??)
 
Any commnet, docmentation or sample code will be appreciated 
 
Thank you in advance,
 
Salih     



Salih-

> First off all, I am sory for my bad english.
>
> I am new at Fix point arithmetic and I want to use r4fft ( FFT function from
> dsp62x.lib) on image that I stored in extarnel RAM. My problem is, in
> documentation, it says all the inputs must be Q15 format. For the fft
coefficients,
> there is no problem because they are in range of -1,1 however the pixel values
are
> out of range (>1). How can I use input values >1 for this function. Should I
> convert them Q15 format (How??)

How can pixel values be out of range? You must have some incredible A/D video
converter.

If you are simply saying they "don't look like fractions" (e.g. gray scale),
then
treat them "in your head" as fractional values, for example 0..0.25 for pixel
values
0..0x0fff.

Similarly, if pixel values are RGB, then perform 3 separate 2-D FFTs...

-Jeff



Salih-

> First off all, I am sory for my bad english.
>
> I am new at Fix point arithmetic and I want to use r4fft ( FFT function from
> dsp62x.lib) on image that I stored in extarnel RAM. My problem is, in
> documentation, it says all the inputs must be Q15 format. For the fft
coefficients,
> there is no problem because they are in range of -1,1 however the pixel values
are
> out of range (>1). How can I use input values >1 for this function. Should I
> convert them Q15 format (How??)

How can pixel values be out of range? You must have some incredible A/D video
converter.

If you are simply saying they "don't look like fractions" (e.g. gray scale),
then
treat them "in your head" as fractional values, for example 0..0.25 for pixel
values
0..0x0fff.

Similarly, if pixel values are RGB, then perform 3 separate 2-D FFTs...

-Jeff



Salih-
> I am sorry I couldn't explain my self in my first email. As I
> said before I am new at Fix Point Arithmetic.>> The pixel values are 8 bit
(0-255).
And the documentation that
> I followed for the Q15 format, don't explain what you should do
> if the value is greater than 1.

Treat them as < 1. I.e. treat them as 0..0.00778 (255/32767).

> For floating point values, you have to multiply them by 32767 ( <<16 )
> to convert them to Q15 format. If I multiply the integer values by
> 32767, the result ,as expected, will be more than 16 bit. Therefore
> my question is, should I convert the pixel values to Q15 format for
> the fft function input. If yes, how? Is there any procedure to
> convert the integers to Q15? Or we simply use integers as it is in
> Q15 format?

You're making too difficult. If you multiply 0.00778 by 32767 then you have...
your
pixel.

-Jeff > Jeff Brower <> wrote:
>
> Salih-
>
> > First off all, I am sory for my bad english.
> >
> > I am new at Fix point arithmetic and I want to use r4fft ( FFT function
> from
> > dsp62x.lib) on image that I stored in extarnel RAM. My problem is, in
> > documentation, it says all the inputs must be Q15 format. For the fft
> coefficients,
> > there is no problem because they are in range of -1,1 however the pixel
> values are
> > out of range (>1). How can I use input values >1 for this function.
> Should I
> > convert them Q15 format (How??)
>
> How can pixel values be out of range? You must have some incredible A/D
> video
> converter.
>
> If you are simply saying they "don't look like fractions" (e.g. gray
> scale), then
> treat them "in your head" as fractional values, for example 0..0.25 for
> pixel values
> 0..0x0fff.
>
> Similarly, if pixel values are RGB, then p erform 3 separate 2-D FFTs...
>
> -Jeff
>




Salih-

> For the fft function, I got the point. Because, it is sum of
> the products (SOP), after scaling the result by dividing 32767,
> we get the coorect result. I mean lets assume the coefficients
> are 0.4 and 0.5, and the pixels are 200 and 210. If we calculate
> SOP and scale the output :
>
> (32767*0.4)*200+(32767*0.5)*210 = 32767(0.4*200+0.5*210)/32767

It should be:

0.4*0.0061 + 0.5*0.0064 + ... <--- floating-point interpretation

13107*200 + 16384*210 + ... <--- Q15 implementation

When u r done with FFT, hopefully u will not need any scaling, and all results
will
be < 1. This will b true if ur pixels are <= 255 and ur FFT size is 256 or
less. If
you can avoid scaling, the SNR (signal-to-noise ratio) of your results will be
improved.

-Jeff > Jeff Brower <> wrote:
>
> Salih-
> > I am sorry I couldn't explain my self in my first email. As I
> > said before I am new at Fix Point Arithmetic.>> The pixel values are 8
> bit (0-255).
> And the documentation that
> > I followed for the Q15 format, don't explain what you should do
> > if the value is greater than 1.
>
> Treat them as < 1. I.e. treat them as 0..0.00778 (255/32767).
>
> > For floating point values, you have to multiply them by 32767 ( <<16 )
> > to convert them to Q15 format. If I multiply the integer values by
> > 32767, the result ,as expected, will be more than 16 bit. Therefore
> > my question is, should I convert the pixel values to Q15 format for
> > the fft function input. If yes, how? Is there any procedure to
> > convert the integers to Q15? Or we simply use integers as it is in
> > Q15 format?
>
> You're maki ng too difficult. If you multiply 0.00778 by 32767 then you
> have... your
> pixel.
>
> -Jeff > > Jeff Brower wrote:
> >
> > Salih-
> >
> > > First off all, I am sory for my bad english.
> > >
> > > I am new at Fix point arithmetic and I want to use r4fft ( FFT
> function
> > from
> > > dsp62x.lib) on image that I stored in extarnel RAM. My problem is, in
>
> > > documentation, it says all the inputs must be Q15 format. For the fft
>
> > coefficients,
> > > there is no problem because they are in range of -1,1 however the
> pixel
> > values are
> > > out of range (>1). How can I use input values >1 for this function.
> > Should I
> > > convert them Q15 format (How??)
> >
> > How can pixel values be out of range? You must have some incredible A/D
>
> > video
> > converter.
> >
> > If you are simply saying they "don't look like fractions" (e.g. gray
> > scale), then
> > treat them "in your head" as fractional values, for example 0..0.25 for
>
> > pixel values
> > 0..0x0fff.
> >
> > Similarly, if pixel values are RGB, then p erform 3 separate 2-D
> FFTs...
> >
> > -Jeff
>




Salih CALISKAN wrote:
>
> Hello,
>
> First off all, I am sory for my bad english.
>
> I am new at Fix point arithmetic and I want to use r4fft ( FFT
> function from dsp62x.lib) on image that I stored in extarnel RAM. My
> problem is, in documentation, it says all the inputs must be Q15
> format. For the fft coefficients, there is no problem because they are
> in range of -1,1 however the pixel values are out of range (>1). How
> can I use input values >1 for this function. Should I convert them Q15
> format (How??)
>
> Any commnet, docmentation or sample code will be appreciated
>
> Thank you in advance,
>
> Salih
>
> ----------------------------------
>
> Note: If you do a simple "reply" with your email client, only the
> author of this message will receive your answer. You need to do a
> "reply all" if you want your answer to be distributed to the entire
> group.
>
> _____________________________________
> About this discussion group:
>
> To Join: Send an email to
>
> To Post: Send an email to
>
> To Leave: Send an email to
>
> Archives: http://www.yahoogroups.com/group/c6x
>
> Other Groups: http://www.dsprelated.com
>
> ---------------------------
> Yahoo! Groups Links
>
> * To
Only twiddle factors should be in Q15. Inputs can be in 8Q8 {255} for a
256 point FFT,
without overflow in a radix4 FFT as a 256 point FFT will be perfomed in
4 stages,
and since each stage is 2 bits of growth, 8 bits input + 8 bits growth
will just
fit in 16 bits.

Regds
JS