Converting from floating point to fixed point.

10 ビュー (過去 30 日間)
ON
ON 2022 年 9 月 27 日
移動済み: Walter Roberson 2022 年 9 月 27 日
How can i convert from floating point to two's complement? I need to convert a vector of filter coefficients from Filter Designer but I do not know how.

採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 27 日
The Fixed Point Toolbox fi() can be used to create a variety of fixed point formats.
If you need to match a particular hardware fixed point format for a dsp then we would need to know the details of the representation.
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 27 日
移動済み: Walter Roberson 2022 年 9 月 27 日
format long g
BitsAfterDecimalPoint = 12;
Value = -0.0126842654631061924064283630286809057
Value =
-0.0126842654631062
encoded = int16(Value * 2^BitsAfterDecimalPoint)
encoded = int16
-52
decoded = double(encoded) / 2^BitsAfterDecimalPoint
decoded =
-0.0126953125
abs(Value - decoded)
ans =
1.10470368938076e-05
There is a limit to how much precision you can get with 16 bits...
BitsAfterDecimalPoint = 16;
encoded = int16(Value * 2^BitsAfterDecimalPoint)
encoded = int16
-831
decoded = double(encoded) / 2^BitsAfterDecimalPoint
decoded =
-0.0126800537109375
abs(Value - decoded)
ans =
4.21175216869241e-06

サインインしてコメントする。

その他の回答 (1 件)

ON
ON 2022 年 9 月 27 日
I need to convert for example -0.0126842654631061924064283630286809057 into a 16 bit signed value.
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 27 日
int16(Value * 2^BitsAfterDecimalPoint)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by