メインコンテンツ

crcGenerate

CRC 符号ビットを生成し、それらを入力データに付加

R2024a 以降

説明

codeword = crcGenerate(msg,crcCfg) は、指定された CRC 構成オブジェクトに基づいて入力メッセージの CRC チェックサムを生成します。関数は、入力メッセージに CRC チェックサムを追加します。詳細については、アルゴリズムを参照してください。

すべて折りたたむ

長さ 6 の 2 つのメッセージ ワードを生成します。

x = logical([1 0 1 1 0 1 0 1 1 1 0 1]');

3 ビット CRC 発生器を使用してメッセージ ワードを符号化します。

cfgObj = crcConfig(Polynomial='z^3 + 1',ChecksumsPerFrame=2);
codeword = crcGenerate(x,cfgObj);

各コードワードに 1 のビット エラーを追加します。

errorPattern = randerr(2,9,1).';
codewordWithError = xor(codeword,errorPattern(:));

エラーの有無にかかわらずメッセージを復号化します。crcDetect 関数は、codeword については、送信されたメッセージ ワードにエラーがないことを報告し、codewordWithError については、送信されたメッセージ ワードの両方にエラーがあることを報告します。

[tx,err] = crcDetect(codeword,cfgObj);
[tx1,err1] = crcDetect(codewordWithError,cfgObj);
disp(err)
   0
   0
disp(err1)
   1
   1

ITU-T Recommendation X-25 [1] の Section 2.2.7.4 に記載されているように、Appendix I、I.1 の Example 2 の入力データと期待されるフレーム チェック シーケンス (FCS) を使用して CRC-16-CCITT 発生器を適用します。ここで、アドレス = B、F = 1 とします。

番号なしの ACK (UA) の応答フレームを作成します。

Address = [1 0 0 0 0 0 0 0];
UA = [1 1 0 0 1 1 1 0];
input = [Address UA]';
expectedChecksum = [1 1 0 0 0 0 0 1 1 1 1 0 1 0 1 0]'; % Expected FCS
checksumLength = 16;

crcCfg = crcConfig( ...
    Polynomial='X^16 + X^12 + X^5 + 1', ...
    InitialConditions=1, ...
    DirectMethod=true, ...
    FinalXOR=1);
crcSeq = crcGenerate(input,crcCfg);
checkSum =  crcSeq(end-checksumLength+1:end);

計算されたチェックサムを期待されるチェックサムと比較します。

isequal(expectedChecksum,checkSum)
ans = logical
   1

参考文献

[1] ITU Telecommunication Standardization Sector. Series X: Data Networks and Open System Communication. Public Data Networks – Interfaces, 1997.

802.11™-2016[1] の Section 21.3.10.3 に示されている例の CRC-8 チェックサムを生成し、その結果を期待される CRC と比較します。

802.11-2016 の CRC 計算に準拠した CRC 構成オブジェクトを作成します。生成多項式を z8+z2+z+1 に設定します。初期条件を 1 に設定します。直接法を使用するようにアルゴリズムを設定します。最終 XOR を 1 に設定します。

crc8 = crcConfig(Polynomial=[8 2 1 0], ...
    InitialConditions=1, ...
    DirectMethod=true, ...
    FinalXOR=1)
crc8 = 
  crcConfig with properties:

           Polynomial: [8 2 1 0]
    InitialConditions: 1
         DirectMethod: 1
    ReflectInputBytes: 0
     ReflectChecksums: 0
             FinalXOR: 1
    ChecksumsPerFrame: 1

802.11-2016 規格の Section 21.3.10.3 の例に従って、1 つの入力フレームを処理します。この例では、入力ビット ストリーム {m0, ... m22} は {1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1} で、期待される CRC チェックサム {c7, ... c0} は {0 0 0 1 1 1 0 0} です。

x = [1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1]';
expectedChecksum = [0 0 0 1 1 1 0 0]';
checksumLength = length(expectedChecksum);

生成された CRC チェックサムを予想されるチェックサムと比較します。

codeword = crcGenerate(x,crc8);
checksum = codeword(end-checksumLength+1:end);
isequal(checksum,expectedChecksum)
ans = logical
   1

参考文献

[1] IEEE® 802.11™-2016. IEEE Standard for Information Technology — Local and Metropolitan Area Networks — Specific Requirements — Part 11: Wireless LAN MAC and PHY Specifications.

入力引数

すべて折りたたむ

入力メッセージ。列ベクトルまたは行列内のバイナリ値として指定します。

データ型: double | int8 | logical

CRC 構成。crcConfig オブジェクトとして指定します。

データ型: crcConfig object

出力引数

すべて折りたたむ

出力コードワード。入力 msg と同じデータ型と列数をもつ列ベクトルまたは行列内のバイナリ値として返されます。出力 codeword には、生成されたチェックサムが追加された入力 msg が含まれます。msg を行列として入力すると、追加されたチェックサムは列ごとに個別に計算されます。

出力フレームの長さは N + C × P ビットです。ここで、N は入力 msg の列の長さ、C はフレームあたりのチェックサムの数 (crcCfg.ChecksumsPerFrame)、P は生成多項式 (crcCfg.Polynomial) の次数です。

アルゴリズム

すべて折りたたむ

参照

[1] Sklar, Bernard. Digital Communications: Fundamentals and Applications. Englewood Cliffs, NJ: Prentice-Hall, 1988.

[2] Wicker, Stephen B. Error Control Systems for Digital Communication and Storage. Upper Saddle River, NJ: Prentice Hall, 1995.

拡張機能

すべて展開する

C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。

バージョン履歴

R2024a で導入