* Re: floating point to fixed point conversion
2006-02-21 22:15 floating point to fixed point conversion riya1012
@ 2006-02-21 23:49 ` Jeffrey R. Carter
2006-02-21 23:51 ` Keith Thompson
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Jeffrey R. Carter @ 2006-02-21 23:49 UTC (permalink / raw)
riya1012@gmail.com wrote:
> I need some help from you. I am doing a DSP project and for that I need
> to do some C coding for the conversion of sample data which is in
> floating point representation to fixed point representation.
This is c.l.ada. We're for engineering SW in Ada, not for "C coding".
> the sample data is in floating point like
> 0.224128
> 2.299965
> 0.448350
> -1.779926
> My DSP algorithm is implemented in C and is supposed to be using fixed
> point representation.
> The above data is intended to be converted to fixed integer format.I
> request you to help me out regarding this conversion.I will be very
> glad if u give me some hints or algorithms for this conversion.
I have no idea how to convert floating-point values to fixed point in C, and
this does not seem to be the right place to be asking about that. As far as I
know, C does not have fixed-point types. Ada does; yet another reason to use
Ada. If you get a useful answer about C coding here, it will be pure luck. I
suggest you try c.l.c.
If I'm misinterpreting your question, and this does have something to do with
Ada, perhaps you can rephrase it in a manner that makes that clear.
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: floating point to fixed point conversion
2006-02-21 22:15 floating point to fixed point conversion riya1012
2006-02-21 23:49 ` Jeffrey R. Carter
@ 2006-02-21 23:51 ` Keith Thompson
2006-02-22 0:51 ` Keith Thompson
2006-02-22 11:01 ` stuart clark
2006-02-22 14:25 ` Peter Hermann
3 siblings, 1 reply; 6+ messages in thread
From: Keith Thompson @ 2006-02-21 23:51 UTC (permalink / raw)
riya1012@gmail.com writes:
> I need some help from you. I am doing a DSP project and for that I need
> to do some C coding for the conversion of sample data which is in
> floating point representation to fixed point representation.
> the sample data is in floating point like
> 0.224128
> 2.299965
> 0.448350
> -1.779926
> My DSP algorithm is implemented in C and is supposed to be using fixed
> point representation.
> The above data is intended to be converted to fixed integer format.I
> request you to help me out regarding this conversion.I will be very
> glad if u give me some hints or algorithms for this conversion.
Um, why are you asking about C coding in comp.lang.ada?
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: floating point to fixed point conversion
2006-02-21 23:51 ` Keith Thompson
@ 2006-02-22 0:51 ` Keith Thompson
0 siblings, 0 replies; 6+ messages in thread
From: Keith Thompson @ 2006-02-22 0:51 UTC (permalink / raw)
Keith Thompson <kst-u@mib.org> writes:
> riya1012@gmail.com writes:
>> I need some help from you. I am doing a DSP project and for that I need
>> to do some C coding for the conversion of sample data which is in
>> floating point representation to fixed point representation.
>> the sample data is in floating point like
[snip]
>
> Um, why are you asking about C coding in comp.lang.ada?
As well as comp.arch.embedded, comp.lang.c, comp.graphics.algorithms,
comp.arch.arithmetic, and comp.dsp.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: floating point to fixed point conversion
2006-02-21 22:15 floating point to fixed point conversion riya1012
2006-02-21 23:49 ` Jeffrey R. Carter
2006-02-21 23:51 ` Keith Thompson
@ 2006-02-22 11:01 ` stuart clark
2006-02-22 14:25 ` Peter Hermann
3 siblings, 0 replies; 6+ messages in thread
From: stuart clark @ 2006-02-22 11:01 UTC (permalink / raw)
Not sure if this is what you are after but an example from a real IDD,
where floats are represented as 16 bit signed integers, the 16th bit is
the sign bit.
Eg from a real life navigational computer IDD
magnetic heading = +/-180 degrees.
bits to use = 15, the 16th bit the sign bit
pass integers across an interface, which are then converted to floats
using a known scaling factor.
scaling factor = 180 / (2^15 ) = 0.005493....
we define the integer value of 1 = 0.005493.... and we call this value
the LSB.
>From basics where 15 bits can represent a max value of 2^15 -1 we now
have max value of 180 - LSB (iw 2^15 =180 and 1 =LSB)
therefore to send 180 - LSB across an interface what integer value do
you need = 180 / scaling factor = (180 - 0.005493..) / 0.005493 =
32767 (the old 2^15-1) = 0x7FFF
90 degrees = 90 / 0.005493 = 16383.5 = 0x3FFF
but note there is an accuracy loss as
0x3FFF * 0.005493 = 89.997
Thats hows its done in real life, hope it helps!
Stuart Clark
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: floating point to fixed point conversion
2006-02-21 22:15 floating point to fixed point conversion riya1012
` (2 preceding siblings ...)
2006-02-22 11:01 ` stuart clark
@ 2006-02-22 14:25 ` Peter Hermann
3 siblings, 0 replies; 6+ messages in thread
From: Peter Hermann @ 2006-02-22 14:25 UTC (permalink / raw)
riya1012@gmail.com wrote:
> hello guys,
>
> I need some help from you. I am doing a DSP project and for that I need
> to do some C coding for the conversion of sample data which is in
> floating point representation to fixed point representation.
> the sample data is in floating point like
> 0.224128
> 2.299965
> 0.448350
> -1.779926
> My DSP algorithm is implemented in C and is supposed to be using fixed
> point representation.
> The above data is intended to be converted to fixed integer format.I
> request you to help me out regarding this conversion.I will be very
> glad if u give me some hints or algorithms for this conversion.
>
with ada.text_io,ada.integer_text_io,system;
procedure fixed_riya is
type data is delta 0.000_001 range -9.9 .. 9.9;
for data'size use 32;
feld : constant array(positive range <>) of data :=(
0.224128, 2.299965, 0.448350, -1.779926, 1.0, 1.5);
fel2 : array(feld'range) of integer;
for fel2'address use feld'address;
begin
ada.text_io.put_line("starting program fixed_riya");
for x in fel2'range loop
ada.integer_text_io.put(fel2(x),base=>10);
ada.integer_text_io.put(fel2(x),base=>2,width=>32);
ada.text_io.put_line(data'image(feld(x)));
end loop;
--starting program fixed_riya
-- 235015 2#111001011000000111# 0.224128
-- 2411688 2#1001001100110010101000# 2.299965
-- 470129 2#1110010110001110001# 0.448350
-- -1866387 -2#111000111101010010011#-1.779925
-- 1048576 2#100000000000000000000# 1.000000
-- 1572864 2#110000000000000000000# 1.500000
--ada.integer_text_io.put(data'aft); -- giving 6
end fixed_riya; --20060222ph
--
--Peter.Hermann@ihr.uni-stuttgart.de (+49)0711-685-87244
--Nobelstr.19 Raum 0.030, D-70569 Stuttgart IHR Hoechstleistungsrechnen
--http://www.ihr.uni-stuttgart.de/ Fax 0711-89238279
^ permalink raw reply [flat|nested] 6+ messages in thread