⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.c

📁 无线通讯中使用的一种揪错算法,rs 1.0 揪错能力可配置 能纠正 (冗余长度)/2-1 个错误
💻 C
字号:
/* Example use of Reed-Solomon library  * * (C) Universal Access Inc. 1996 * * This same code demonstrates the use of the encodier and  * decoder/error-correction routines.  * * We are assuming we have at least four bytes of parity (NPAR >= 4). *  * This gives us the ability to correct up to two errors, or  * four erasures.  * * In general, with E errors, and K erasures, you will need * 2E + K bytes of parity to be able to correct the codeword * back to recover the original message data. * * You could say that each error 'consumes' two bytes of the parity, * whereas each erasure 'consumes' one byte. * * Thus, as demonstrated below, we can inject one error (location unknown) * and two erasures (with their locations specified) and the  * error-correction routine will be able to correct the codeword * back to the original message. * */ #include <stdio.h>#include <stdlib.h>#include "ecc.h" unsigned char msg[20] ;unsigned char codeword[256]; int main ( ){	int erasures[16];	int nerasures = 0;	/* Initialization the ECC library */	initialize_ecc ();	/* ************** */	/* Encode data into codeword, adding NPAR parity bytes */	memcpy(msg,"\01\02\03x123 hj\10\xfa\0??",16);	encode_data(msg, 15, codeword);	printf("Encoded data is: \"%s\"\n", codeword);#define ML (sizeof (msg) + NPAR)	codeword[0]=0;	codeword[1]=0;	codeword[7]=0;	codeword[8]=0;	codeword[9]=0;	codeword[13]=0;	printf("with some errors: \"%s\"\n", codeword);	/* We need to indicate the position of the erasures.	Eraseure		 positions are indexed (1 based) from the end of the message... */	erasures[nerasures++] = ML-17;	erasures[nerasures++] = ML-19;	/* Now decode -- encoded codeword size must be passed */	decode_data(codeword, ML);	/* check if syndrome is all zeros */	if (check_syndrome () != 0) {		correct_errors_erasures (codeword, ML, nerasures, erasures);		printf("Corrected codeword: \"%s\"\n", codeword);	}	exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -