利用crc演算法計算誤位元速率和誤位元率,研究此演算法的效能曲線。
crc.h
#pragma once
#include#includeclass crc16 ;
crc.cpp
#include"crc16.h"
//多項式除法
int crc16::polynomial_division(int* data_in, int stop)
} while (first_position <= stop) ;
generate[first_position] = 1;
generate[first_position + 1] = 1;
generate[first_position + 14] = 1;
generate[first_position + 16] = 1;
for (int j = 0; j < 1040; j++)
else
} for (first_position = 0; first_position < 1040; first_position++)
} }return first_position;
}//編碼過程
void crc16::crc_enc(int* data_in, int* data_out, int len)
int stop = 1023;
polynomial_division(data_in, stop);
for (int k = 0; k < 16; k++)
}//差錯檢驗
bool crc16::error_detect(int* det_in, int& error_dec)
int stop = 1023;
int first_position = polynomial_division(data, stop);
if (first_position != 1040)
return 0;
}//以概率p出錯(過bsc通道)
bool crc16::code_random(int* data, double p)
} if (flag == 1)
return 1;
return 0;
}
main.cpp
#include#include#include#include#include "crc16.h"
using namespace std;
int main()
//原始碼進行crc編碼生成校驗碼,原始碼+校驗碼儲存於data_out
crc16::crc_enc(data_in, data_out, len);
cout << endl << "the generated checksum is as follows: " << endl;
for (int k = 1024; k < 1040; k++)
cout << endl;
//進行測試
double p[5] = ; //出錯概率
for (int k = 0; k < 4; k++)
//過bsc通道
if (crc16::code_random(data, p[k]))
error++;
//差錯檢驗
if (!crc16::error_detect(data, error_dec))
//漏檢檢驗
if (i != 1040)
}} cout << "there are a number of examples of real errors " << error << endl;
cout << "there are a total of samples for detecting errors " << error_dec << endl;
cout << "there are a total of missing samples " << m << endl;
cout << "the error rate is " << (double)(error / temp) << endl;
if (error != 0)
} system("pause");
return 0;
}
實驗結果如下:
CRC解碼(解碼並刪除迴圈冗餘校驗)
1 blk,err nrcrcdecode blkcrc,poly blk,err nrcrcdecode blkcrc,poly 檢查輸入資料blkcrc中是否存在crc錯誤。該函式假定輸入資料報括與多項式poly相關的crc奇偶校驗位。該函式返回blk,這是輸入blkcrc的資料部分。該函式還返...
CRC校驗和CRC各種演算法
crc校驗和crc各種演算法 1 簡介 crc即 迴圈冗餘校驗碼 cyclic redundancy check 是資料通訊領域中最常用的一種查錯校驗碼,其特徵是資訊字段和校驗欄位的長度可以任意選定。迴圈冗餘檢查 crc 是一種資料傳輸檢錯功能,對資料進行多項式計算,並將得到的結果附在幀的後面,接收...
CRC演算法原理
演算法原理 假設資料傳輸過程中需要傳送15位的二進位制資訊g 101001110100001,這串二進位製碼可表示為代數多項式g x x 14 x 12 x 9 x 8 x 7 x 5 1,其中g中第k位的值,對應g x 中x k的係數。將g x 乘以x m,既將g後加m個0,然後除以m階多項式h ...