Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Conversion from fixed point to floating point and vise versa

Status
Not open for further replies.

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
convert fixed point to floating point

Asslamo 3likom

How to convert from fixed point Q15 to floating point and vise versa in C

Salam
Hossam Alzomor
www(.)i-g(.)org
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,863
convert fixed point to float

If you are using Microchip Mplab C30 compiler, if you look in the header file, 'dsp.h' you will find the following functon prototypes:
Code:
extern fractional Float2Fract (         /* Converts float into fractional */
   float aVal                           /* float value in range [-1, 1) */
);
extern float Fract2Float (        /* Converts fractional into float */
   fractional aVal                /* fract value in range {-1, 1-2^-15} */
);

You will find the functions in the dsp\src directory.
 

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
fixed point to float

Thanks btbass

But My question is How it can be implemented in C.
I am not using Mplab C30 compiler

Salam
Hossam Alzomor
www(.)i-g(.)org
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,863
q15 conversion

Here are the functions in C from the Microchip lib.
 

    alzomor

    Points: 2
    Helpful Answer Positive Rating

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
fixed to float conversion

Hi

A Good and simple way to:
Convert from Fixed point to Flaoting point.
Just divide by the full scale of integer represented in the no of bits representing fixed point and type cast the result to float
example
a: fixed point represented in Q15 formate
b:floating point representation of a

b= (float) (a/(2^15-1))

Conversion from float to fixed:
a=(int) (b*(scale))
scale depends on the max value of floating point values being converted and fixed point formate result.



Salam
Hossam Alzomor
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top