Verständnisfrage zu Fixed-Point Zahlen

OP Persönliche Seite #3153879
Lesenswert?

Ich möchte Werte im Bereich von -1 bis +1 als Fixed-Point abbilden.

Wenn ich dafür z.B. 8 Bit nehme wären das ja -128 bis 127. Hier ist auch 
schon das Problem. Wenn ich 127 wieder als Gleitkomma interpretiere 
kommen da ja 0,9921875 raus.

Also nehme ich jetzt 9 Bit zum speichern der Werte und nutze nur -128 
bis +128 als Wertebereich. Gibt es da eine bessere Methode?

Und jetzt stehe ich auch noch vor dem Problem, dass ich bei einer 8 Bit 
Zahl mit -128 und 127 durch den Überlauf quasi eine Modulo-Operation 
umsonst bekomme.

Wenn ich 9 Bit nehme möchte ich gerne den Wertebereich auf -128 bis +128 
einschränken. Wie würde man das in VHDL am geschicktesten realisieren?
Gast #3154009
Lesenswert?

What you have to keep in mind is that in fixed point notation the binary 
point remains at a specific place. The bits at the right are the 
fraction, then you have for the first bit 1/2, sencod 1/4 third 1/8 and 
so on from left to right.

1/2 = 0.1000000
1,5 = 1.1000000
0,333 ~ 0.0101010

You always calculate with all the bits and then you can to convert to 
decimal if necessary.

Of course you have to take overflow in account and check if it happens 
and scale accoringly...

A simple test for overflow is: V = A7  B7  (~R7) + (~A7) * (~B7) * R7 
for addition
and V = A7 * (~B7) * (~R7) + (~A7)  B7  R7 for subtraction.
A7, B7 and R7 are the MSBs of the two operand and the result 
respectively. When it gives 1, then there was overflow.

Hope it helps
Gast #3154299
Lesenswert?

Marius S. schrieb:
> Wenn ich 9 Bit nehme möchte ich gerne den Wertebereich auf -128 bis +128
> einschränken. Wie würde man das in VHDL am geschicktesten realisieren?

Naja, einfach mit if then limitieren oder in INT rechnen und den 
Wertebereich passend setzen. Man sollte aber in Erwägung ziehen auf 127 
zu limitieren, da man so Bits spart

----

Simply Limit by IF THEN construct or better use integer values as 
signals. you might also consider to Limit to 127 not be require another 
bit for just one single value
#3154890
Lesenswert?

Meinem Verständnis nach sind 9 bit nicht genug, wenn Du weiter im 
2er-Komplement arbeiten willst UND 1.0 und -1.0 darstellen möchtest.

Also ich würde jetzt denken: 2.8 fixed point und für "10......." und 
"01......." alle Folgestellen auf 0 setzen, also so dass die Zahl 
sozusagen saturiert.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren