quantize
固定小数点数の量子化
構文
説明
例
量子化する入力 fi の値を定義します。
x_BP = fi(pi)
x_BP =
3.1416
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13
numerictype オブジェクトを使用
語長が 8 ビットで小数部の長さが 4 ビットの符号付き固定小数点データ型を指定する numerictype オブジェクトを作成します。
ntBP = numerictype(1,8,4);
定義した numerictype オブジェクト ntBP を使用して、入力 x_BP を 2 進小数点でスケーリングされた固定小数点データ型に量子化します。
yBP1 = quantize(x_BP,ntBP)
yBP1 =
3.1250
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
入力で数値型プロパティを指定
yBP2 = quantize(x_BP,1,8,4)
yBP2 =
3.1250
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
傾きとバイアスでスケーリングされた固定小数点データ型を指定する numerictype オブジェクトを作成します。
ntSB = numerictype('Scaling','SlopeBias',... 'SlopeAdjustmentFactor',1.8,... 'Bias',1,... 'FixedExponent',-12);
量子化する入力 fi の値を定義します。
x_BP = fi(pi)
x_BP =
3.1416
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13
定義した numerictype ntSB を使用して、入力 x_BP を傾きとバイアスでスケーリングされた固定小数点データ型に量子化します。
ySB1 = quantize(x_BP, ntSB)
ySB1 =
3.1415
DataTypeMode: Fixed-point: slope and bias scaling
Signedness: Signed
WordLength: 16
Slope: 0.000439453125
Bias: 1
量子化する入力 fi の値を定義します。
x_SB = fi(rand(5,3),numerictype('Scaling','SlopeBias','Bias',-0.125))
x_SB =
0.8147 0.0975 0.1576
0.8750 0.2785 0.8750
0.1270 0.5469 0.8750
0.8750 0.8750 0.4854
0.6324 0.8750 0.8003
DataTypeMode: Fixed-point: slope and bias scaling
Signedness: Signed
WordLength: 16
Slope: 3.0517578125e-5
Bias: -0.125
numerictype オブジェクトを使用
語長が 8 ビットで小数部の長さが 4 ビットの 2 進小数点でスケーリングされた符号付き固定小数点データ型を指定する numerictype オブジェクト ntBP を作成します。
ntBP = numerictype(1,8,4);
定義した numerictype ntBP を使用して、入力 x_SB を 2 進小数点でスケーリングされた固定小数点データ型に量子化します。さらに、最も近い値に丸め、オーバーフローで飽和させます。
yBP1 = quantize(x_SB,ntBP,'Nearest','Saturate')
yBP1 =
0.8125 0.1250 0.1875
0.8750 0.2500 0.8750
0.1250 0.5625 0.8750
0.8750 0.8750 0.5000
0.6250 0.8750 0.8125
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
入力で数値型プロパティを指定
yBP2 = quantize(x_SB,1,8,4,'Nearest','Saturate')
yBP2 =
0.8125 0.1250 0.1875
0.8750 0.2500 0.8750
0.1250 0.5625 0.8750
0.8750 0.8750 0.5000
0.6250 0.8750 0.8125
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
量子化する入力 fi の値を定義します。
x_SB = fi(rand(5,3),numerictype('Scaling','SlopeBias','Bias',-0.125))
x_SB =
0.8147 0.0975 0.1576
0.8750 0.2785 0.8750
0.1270 0.5469 0.8750
0.8750 0.8750 0.4854
0.6324 0.8750 0.8003
DataTypeMode: Fixed-point: slope and bias scaling
Signedness: Signed
WordLength: 16
Slope: 3.0517578125e-5
Bias: -0.125
傾きとバイアスでスケーリングされた固定小数点データ型を指定する numerictype オブジェクトを作成します。
ntSB = numerictype('Scaling','SlopeBias', ... 'SlopeAdjustmentFactor',1.8,'Bias',... 1,'FixedExponent',-12);
定義した numerictype ntSB を使用して、入力 x_SB を傾きとバイアスでスケーリングされた固定小数点データ型に量子化します。さらに、正方向に丸めます。
ySB2 = quantize(x_SB,ntSB,'Ceiling')ySB2 =
0.8150 0.0978 0.1580
0.8752 0.2789 0.8752
0.1272 0.5469 0.8752
0.8752 0.8752 0.4854
0.6326 0.8752 0.8005
DataTypeMode: Fixed-point: slope and bias scaling
Signedness: Signed
WordLength: 16
Slope: 0.000439453125
Bias: 1
量子化する入力の値を定義します。
xInt = int8(-16:4:16)
xInt = 1×9 int8 row vector
-16 -12 -8 -4 0 4 8 12 16
numerictype オブジェクトを使用
語長が 8 ビットで小数部の長さが 4 ビットの 2 進小数点でスケーリングされた符号付き固定小数点データ型を指定する numerictype オブジェクトを作成します。
ntBP = numerictype(1,8,4);
定義した numerictype ntBP を使用して、入力 xInt を 2 進小数点でスケーリングされた固定小数点データ型に量子化します。
yBP1 = quantize(xInt,ntBP,'Zero')yBP1 =
0 4 -8 -4 0 4 -8 -4 0
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
量子化された出力の範囲を表示します。
range(yBP1)
ans =
-8.0000 7.9375
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
最初の 2 つの値と最後の 3 つの値は、出力型の表現可能な範囲の外にあるためラップされています。
入力で数値型プロパティを指定
yBP2 = quantize(xInt,1,8,4,'Zero')yBP2 =
0 4 -8 -4 0 4 -8 -4 0
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4
量子化する入力の値を定義します。
xInt = int8(-16:4:16)
xInt = 1×9 int8 row vector
-16 -12 -8 -4 0 4 8 12 16
傾きとバイアスでスケーリングされた固定小数点データ型を指定する numerictype オブジェクトを作成します。
ntSB = numerictype('Scaling','SlopeBias', ... 'SlopeAdjustmentFactor',1.8,'Bias',... 1,'FixedExponent',-12);
定義した numerictype ntSB を使用して、入力 xInt を傾きとバイアスでスケーリングされた固定小数点データ型に量子化します。
ySB = quantize(xInt,ntSB,'Round','Saturate')
ySB =
-13.4000 -11.9814 -7.9877 -3.9939 -0.0002 3.9936 7.9873 11.9811 15.3996
DataTypeMode: Fixed-point: slope and bias scaling
Signedness: Signed
WordLength: 16
Slope: 0.000439453125
Bias: 1
量子化された出力の範囲を表示します。
range(ySB)
ans =
-13.4000 15.3996
DataTypeMode: Fixed-point: slope and bias scaling
Signedness: Signed
WordLength: 16
Slope: 0.000439453125
Bias: 1
最初の値と最後の値は、出力型の表現可能な範囲の制限にあるため飽和しています。
入力引数
量子化する入力データ。以下として指定します。
組み込みの符号付きまたは符号なしの整数
2 進小数点でスケーリングされた固定小数点
fi傾きとバイアスでスケーリングされた固定小数点
fi
fi double と fi single は入力として許容されますが、量子化されずに関数 quantize を通過します。
データ型: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
複素数のサポート: あり
固定小数点データ型を記述する numerictype オブジェクト。
量子化に使用する丸め手法。次のいずれかとして指定します。
'Ceiling'— 許容される次の量子化値に切り上げます。'Convergent'— 許容される最も近くの量子化値に丸めます。許容される最も近い 2 つの量子化値のちょうど中間にある数値は、丸め後の最下位ビットが 0 になる場合のみ上方に丸められます。'Floor'— 許容される次の量子化値に切り下げます。'Nearest'— 許容される最も近くの量子化値に丸めます。許容される最も近くの 2 つの量子化値の中間にある値は、切り上げられます。'Round'— 許容される最も近くの量子化値に丸めます。許容される最も近くの 2 つの量子化値の中間にある値は、絶対値に切り上げられます。'Zero'— 許容される次の量子化値まで、負の数は切り上げ、正の数は切り下げます。
データ型: char
オーバーフロー時のアクション。次の値のいずれかとして指定します。
'Saturate'— オーバーフローは飽和されます。量子化するデータの値が数値型プロパティで指定される表示可能な数字の最大値から最小値までの範囲の外にある場合、これらの値は、どちらに近いかにより、表示可能な最大値または最小値のどちらかの値に量子化されます。
'Wrap'— オーバーフローはラップされます。量子化するデータの値が数値型プロパティで指定される表示可能な数字の最大値から最小値までの範囲の外にある場合、これらの値は、表示可能な最小値に関連するモジュラー演算を使用し、指定された範囲内に戻るようにラップされます。
データ型: char
量子化された固定小数点数の符号属性。1 (符号付き) または 0 (符号なし) として指定します。
データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
出力データの格納整数値の語長 (ビット)。
量子化値の小数部の長さ。スカラー整数として指定します。
データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
バージョン履歴
R2006a より前に導入quantize は推奨されません。代わりに cast、zeros、ones、eye、または subsasgn を使用してください。quantize を削除する予定はありません。
R2013a 以降では、代わりに cast、zeros、ones、eye、または subsasgn を使用してください。関数 cast、zeros、ones、eye、および subsasgn では、fi オブジェクトに加えて他のデータ型も量子化でき、量子化の型情報を個別の入力引数としてではなくオブジェクトにカプセル化できます。
非推奨 | 推奨 |
|---|---|
x_BP = fi(pi); ntBP = numerictype(1,8,4); yBP = quantize(x_BP,ntBP) yBP =
3.1250
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4 |
x_BP = fi(pi);
ntBP = fi([],1,8,4);
yBP = cast(x_BP,'like',ntBP)yBP =
3.1250
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 4 |
参考
fi | numerictype | cast | zeros
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)