循环码(7,3)码
- 格式:doc
- 大小:788.88 KB
- 文档页数:16
一循环码循环码最大的特点就是码字的循环特性,所谓循环特性是指:循环码中任一许用码组经过循环移位后,所得到的码组仍然是许用码组。
如(7,3)循环码的全部码字在整数运算中,有模n运算。
例如,在模2运算中,有1+1=2≡0(模2),1+2=3≡1(模2),2×3=6≡0(模2)等。
因此,若一个整数m可以表示为:则在模n运算下,有m≡p(模n),也就是说,在模n运算下,一整数m等于其被n除所得的余数。
在码多项式运算中也有类似的按模运算法则。
若一任意多项式F(x)被一个n次多项式N(x)除,得到商式Q(x)和一个次数小于n的余式R(x),也就是:则可以写为:F(x)≡R(x)(模N(x))2 计算x4+x2+1除以x3+1的值可得:一个长度为n的循环码,它必为按模()运算的一个余式。
三、循环码的生成多项式及生成矩阵(全0码字除外)称为生成多项式,用g(x)表示。
可以证明生成多项式g(x)具有以下特性(1)g(x)是一个常数项为1的r=n-k次多项式(首一多项式);(2)g(x)是的一个因式;(3)该循环码中其它码多项式都是g(x)的倍式生成矩阵G(x)可以表示成为:n=7,k=3,r=4。
可以看到,其生成多项式可以用第1码字构造:生成多项式g(x)是的一个因式,其次g(x)是一个r次因式。
因此,就可以先对进行因式分解,找到它的r次因式。
下面仍以(7,3)循环码为例进行分析。
要从上式中找到r=n-k次的因子。
不难看出,这样的因子有两个,即:3 这里h(x)称为监督多项式例如,对于(7,3)循环码,若选用 ,信息码110时,则:上式相当于这时的编码输出为 1100101二 卷积码(Convolutional Code )的编码卷积码记为(n ,k ,m )卷积码的纠错能力随着N 的增加而增大,在编码器复杂程度相同的情况下,卷积码的性能优于分组码。
码约束(长)度N =m +1码率Rate :k/n卷积码的编码一个简单的(2,1,2)卷积码(码率Rate :k/n=1/2,约束长度N=2+1=3)11)(1)(1)(23*37++=⇒++=+=x x x h x x x g x x h ⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=⇒⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎣⎡++++++++=00011010011010011010011010001)(23134245356H x x x x x x x x x x x xH树图篱笆图。
实验报告学科:通信原理(二)题目:数字信号基带传输系统仿真实验设备:安有matlab仿真软件的计算机学院:光电信息与通信工程学院系别:通信工程学号:姓名:指导教师:一、实验目的与要求1. 学习并理解信道编码的根本目的、技术要求与基本目标等基本概念;2. 掌握循环码、miller码的物理涵义、数学基础及检纠错原理;3. 掌握循环码、miller码的码型特点、检纠错能力、编译码方法及基本技术;4. 学会使用MATLAB 实现循环码及miller码的编译码及检纠错模拟与分析。
二、实验仪器与设备1. 安装了matlab程序的计算机 1 台三、实验原理(一)循环码循环码是线性分组码的一个重要子集,是目前研究得最成熟的一类码,它有许多特殊的代数性质,例如,循环码中任一许用码组经过循环移位后,所得到的码组仍然是许用码。
循环码A= a n−1+a n−2+…+a 1+a 0可以表示为如下的码多项式:1.生成多项式g (x)定义:若一个循环码的所有码字多项式都是一个次数最低的、非零的、首一多项式g (x)的倍式,则称g (x)为生成该码,并称g (x) 为该码的生成元或生成多项式。
可以证明生成多项式g (x)具有以下特性:(1)g (x) 是一个常数项为1 的r=n −k 次多项式;(2)g (x) 是x n+1 的一个因式;(3)该循环码中其它码多项式都是g (x)的倍式。
为了保证构成的生成矩阵G的各行线性不相关,通常用g (x) 来构造生成矩阵。
因此,一旦生成多项式g (x) 确定以后,该循环码的生成矩阵就可以确定。
设则有:2.监督多项式h(x)定义:若g (x) 是(n,k) 循环码的生成多项式,则有x n+1= g (x )h (x) 。
其中,h(x) 是k 次多项式,称为监督多项式。
也称校验多项式。
监督矩阵可表示为:其中:3.伴随式发送码C(x) 通过含噪信道时,会因各种扰而产生误码。
例如发送码为:00000000001111111111接收码为:01101001001111001001产生错误序列:01101001000000110110可见,发生了两个长度分别为7和5的突发差错,其错误图样分别为1101001 和11011。
课程设计班 级: 通信09—4 姓 名: 宋蕾 学 号: 0906030421 指导教师: 刘玉珍 成 绩:原理数字 课程设计报告电子与信息工程学院通信工程系循环码产生电路设计1. 引言在线性分组码中,有一种重要的码称为循环码(cycil code)。
循环码是在严密的代数学理论基础上建立起来的。
这种编码和解码设备都不太复杂,而且检(纠)错的能力较强。
循环码是线性分组码中最重要的一种子类,是目前研究得比较成熟的一类码。
循环码具有许多特殊的代数性质,这些性质有助于按照要求的纠错能力系统地构造这类码,并且简化译码算法,并且目前发现的大部分线性码与循环码有密切关系。
循环码还有易于实现的特点,很容易用带反馈的移位寄存器实现其硬件。
simulink 是matlab 中的一种可视化仿真工具, 是一种基于matlab 的框图设计环境,是实现动态系统建模、仿真和分析的一个软件包,被广泛应用于线性系统、非线性系统、数字控制及数字信号处理的建模和仿真中。
simulink 可以用连续采样时间、离散采样时间或两种混合的采样时间进行建模,它也支持多速率系统,也就是系统中的不同部分具有不同的采样速率。
为了创建动态系统模型,Simulink 提供了一个建立模型方块图的图形用户接口(GUI) ,这个创建过程只需单击和拖动鼠标操作就能完成,它提供了一种更快捷、直接明了的方式,而且用户可以立即看到系统的仿真结果。
2. 设计要求(1)用simulink 对系统建模。
(2)写出其生成多项式(自定)。
(3)对所设计的系统性能进行仿真分析。
(4)对其应用举例阐述。
3. 设计原理3.1 循环码的循环性循环码除了具有线性码的一般性质外,还具有循环性。
循环性是指任一码组循环一位(即将最右端的一个码元移至左端,或反之)以后,仍为该码中的一个码组。
在表1中给出一种(7,3)循环码的全部码组。
由此表可以直观看出这种码的循环型。
例如,表中的第2码组向右移一位即得到第5码组;第6码组向右移一位即得到第7码组。
实验、循环码编译码系统一、 实验目的:1、熟悉循环码的编译码原理;2、掌握Quartus Ⅱ开发软件的运用,在该软件下熟练的运用多种输入方式完成各种电路设计的要求;3、初步掌握VHDL 语言,能够运用该语言编写简单的程序,完成设计要求;4、熟悉对PLD 的下载和仿真,学会观察测试结果的正确性;5、学会运用各方面知识,设计并实现一个系统。
二、 实验要求:使用Quartus Ⅱ软件,用m 序列发生器作为信号源设计循环码编译码,速率可自定,并在实验箱上调试出编码和译码波形,比较信号源和译码后的信号波形。
三、实验设备:Quartus II 软件、Modelsim 软件、FPGA 实验箱、微机1台、示波器1台四、实验原理:1、 循环码的编码循环码最大的特点就是码字的循环特性,所谓循环特性是指:循环码中任一许用码组经过循环移位后,所得到的码组仍然是许用码组。
若(1n a - 2n a -…… 1a 0a )为一循环码组,则(2n a - 3n a -……0a 1n a -)、(3n a - 4n a -……1n a - 2n a -)、……还是许用码组。
也就是说,不论是左移还是右移,也不论移多少位,仍然是许用的循环码组。
表1-2给出了一种(7,3)循环码的全部码字。
可以将循环码码组用代数多项是来表示,这个多项式被称为码多项式,对于表1-2中的任一码组可以表示为:654326543210()A x a x a x a x a x a x a x a =++++++ (1-4)表1-2一种(7,3)循环码的全部码字在码多项式运算中采用按模运算法则。
若一任意多项式F (x )被一个n 次多项式N (x )除,得到商式Q (x )和一个次数小于n 的余式R (x ),也就是:()()()()()F x R x Q x N x N x =+ (1-5) 则可以写为:F (x )≡R (x )(模N (x ))。
这时,码多项式系数仍按模2运算,即只取值0和1,假设:计算x 4+x 2+1除以x 3+1的值可得:422331111x x x x x x x ++++=+++ (1-6)循环码的生成多项式和生成矩阵:(全0码字除外)称为生成多项式,用g (x )表示。
******************实践教学*******************兰州理工大学计算机与通信学院2014年秋季学期计算机通信课程设计题目:(7,3)循环码编译码软件设计专业班级:姓名:学号:指导教师:成绩:摘要随着计算机通信的日益发展,传输数据的场合越来越多。
串行数据的差错检验是保证数据传输正确的必要手段,而循环码是差错码中最常用的一种编码。
循环码是线性分组码中最重要的一种子类,它除了具有分组码的线性外,还具有循环性,其码字结构一般用符号(n,k)表示,其中,n是该码组中的码元数,k是信息码元位数,r=n-k是监督码元位数。
循环码具有许多特殊的代数性质,这些性质有助于按照要求的纠错能力系统地构造这类码,能简化译码算法,并且目前发现的大部分线性码与循环码有密切关系。
已有循环码编译码系统大多以标准逻辑器件(如中小规模TTL系列、CMOS系列)按传统数字系统设计方法设计而成,其主要缺点是逻辑规模小、功耗大、可靠性低。
随着大规模、超大规模集成电路的发展,以及电子设计自动化水平的提高,这种制约正在被逐渐消除。
本文通过C 语言平台运行所编写的程序,观察了在输入信息码情况下输出对应的编码结果以及相反的译码功能。
通过多组的对比验证了该(7,4)循环码的编译码程序的正确性。
最后,在程序运行的过程中进步分析循环码的编译码原理,并通过比较仿真模型与理论计算的性能,证明了仿真模型的可行性。
关键词:循环码;编码;译码;程序仿真目录前言 (1)1、目的及意义 (2)2、设计原理 (3)2.1循环码的介绍 (3)2.1.1循环码的定义 (3)2.1.2循环码的特点 (3)2.1.3循环码的多项式表示 (4)2.1.4(n,k)循环码的生成多项式 (4)2.1.5循环码的生成矩阵和一致校验矩阵 (6)2.2循环码编码原理 (8)2.2.1多项式除法电路 (8)2.3循环码译码原理 (9)3、设计结果及分析 (11)3.1程序运行结果 (11)3.2运行结果理论分析 (14)3.3软件可行性分析 (15)4、总结 (16)附录 (17)参考文献 (22)前言数字信号在传输过程中,由于受到干扰的影响,码元波形将变坏。
8.5 循环码循环码是线性分组码中最重要的一个子类码,它的基本特点是编码电路及伴随式解码电路简单易行;循环码代数结构具有很多有用的特性,便于找到有效解码方法。
因此在实际差错控制系统中所使用的线性分组码,几乎都是循环码。
下面将介绍循环码的多项式表示及其性质,同时简介几种重要的循环码,CRC、BCH和R-S 码等。
8.5.1 循环码的描述1. 码多项式及其运算通式表示为:(8-69)于是称与为“同余”式,即[模](8-70)如:则[模] 即能被整除利用这一运算原理,我们可对一个码字进行移位表示:如:的多项式表示为:使码组向左移2位(循环)则有对应多项式然后以去除得:这一结果表明,以作除法运算(称模)后,即与为同余因此,(模)应注意,利用这种同余式表示,必须加注(模),否则就不明确在什么条件下得到的这一同余关系式。
2.循环码的构成循环码的构成突出特点是只要是该码中的一个许用码组——码字,通过循环位其结果则可包括全部个非全0码字,如上面介绍的(7,3)分组码,从信码位0 0 1构成的码字(0011101)开始逐一向左(或者向右)移一位,可得其余6个码字:(0111010)、(1110100)、(1101001)、(1010011)、(0100111)、(1001110)。
若把这些码字写成码多项式,都具有同一个移位运算模式,并设(0011101)对应的码多项式,于是,有:(模)(8-71)这样,就构成了(7,3)循环码,如表8-4。
从表8-4看出,循环得到的(7,3)码,仍为系统码,信息码组均在表中码字的高位(左方)。
表8-4 (7,3)循环码移位(7,3)码码多项式(模)0 0 0 1 1 1 0 11 0 1 1 1 0 1 02 1 1 1 0 1 0 03 1 1 0 1 0 0 14 1 0 1 0 0 1 15 0 1 0 0 1 1 16 1 0 0 1 1 1 08.5.2 循环码生成多项式与生成矩阵1. 生成多项式由表8-4构成个非全0码字多项式的过程与结果看,我们从开始进行逐一循环,并以模运算,该码字正是信码组中最低位为1,对应码字多项式,在全部非全0码字中,它的最高位阶次也最低,并等于,即最高次项为,随后一系列码字都源于它的移位而形成,因此称其为生成多项式,即(8-72)然后再从的因式分解来进一步分析(8-73)我们可以将三个既约多项式因式任意组合成两个因式,可有(8-74)如:(8-75)(8-76)其中可以组合为二因式中包含最高次为4次的情况有两种,即展开式的第4及第5两组,都可以作为阶次最高为4的即(8-77)(8-78)在展开式中选用了其中一个(组合)因式为后,余下一个因式,则称其为循环码的监督多项式,如式(8-74)生成多项式与相应监督多项式乘积等于多项式。
functionvarargout = Hamming(varargin)% HAMMING M-file for Hamming.fig% HAMMING, by itself, creates a new HAMMING or raises the existing % singleton*.%% H = HAMMING returns the handle to a new HAMMING or the handle to % the existing singleton*.%% HAMMING('CALLBACK',hObject,eventData,handles,...) calls thelocal% function named CALLBACK in HAMMING.M with the given input arguments. %% HAMMING('Property','Value',...) creates a new HAMMING or raises the % existing singleton*. Starting from the left, property value pairs are% applied to the GUI before Hamming_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application% stop. All inputs are passed to Hamming_OpeningFcn via varargin. %% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help Hamming% Last Modified by GUIDE v2.5 07-Jan-2008 20:22:48% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @Hamming_OpeningFcn, ...'gui_OutputFcn', @Hamming_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);ifnargin&&ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endifnargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before Hamming is made visible.functionHamming_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to Hamming (see VARARGIN)% Choose default command line output for Hamminghandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes Hamming wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. functionvarargout = Hamming_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties. function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as a double% --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)chose=get(handles.popupmenu1,'value');if chose==1;clc;msg=str2num(get(handles.edit1,'string'))%信息产生code=encode(msg,7,4);%汉明编码rcv=decode(code,7,4);%汉明译码set(handles.edit2,'string',num2str(code));set(handles.edit3,'string',num2str(rcv));elsek=str2num(get(handles.edit1,'string'));code1=encode(k,7,3,'cyclic/binary');rcv1=decode(code1,7,3,'cyclic/binary');set(handles.edit2,'string',num2str(code1));set(handles.edit3,'string',num2str(rcv1));endfunction edit7_Callback(hObject, eventdata, handles)% hObject handle to edit7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit7 as text% str2double(get(hObject,'String')) returns contents of edit7 as a double% --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles)% hObject handle to edit7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit8 as text% str2double(get(hObject,'String')) returns contents of edit8 as a double% --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit9_Callback(hObject, eventdata, handles)% hObject handle to edit9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit9 as text% str2double(get(hObject,'String')) returns contents of edit9 asa double% --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles)% hObject handle to edit9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit10_Callback(hObject, eventdata, handles)% hObject handle to edit10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit10 as text% str2double(get(hObject,'String')) returns contents of edit10 as a double% --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles)% hObject handle to edit10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit15_Callback(hObject, eventdata, handles)% hObject handle to edit15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit15 as text% str2double(get(hObject,'String')) returns contents of edit15 as a double% --- Executes during object creation, after setting all properties. function edit15_CreateFcn(hObject, eventdata, handles)% hObject handle to edit15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)chose=get(handles.popupmenu1,'value');if chose==1;[H,G,N,K]=hammgen(3); %产生H和G矩阵for i=1:2^Kfor j=K:-1:1if rem(i-1,2^(-j+K+1))>=2^(-j+K)U(i,j)=1;elseU(i,j)=0;endendendC=rem(U*G,2);A=str2num(get(handles.edit7,'string'));[r,l]=size(A);E=[0 0 0 0 0 0 0;0 0 0 0 0 0 1;0 0 0 0 0 1 0;0 0 0 0 1 0 0;0 0 0 1 0 00;0 0 1 0 0 0 0;0 1 0 0 0 0 0;1 0 0 0 0 0 0]; %%%%%求校正子,然后将其转化成十进制数S=rem(A*H',2);Sx=bi2de(S,'left-msb');%%%%下面是(7,4)码检错for i=1:rswitch(Sx)case 0disp=('此接收码字没错')case 1disp=('注意:此接收码字的第3位有错,请纠正')case 2disp=('注意:此接收码字的第2位有错,请纠正')case 4disp=('注意:此接收码字的第1位有错,请纠正')case 3disp=('注意:此接收码字的第5位有错,请纠正')case 5disp=('注意:此接收码字的第7位有错,请纠正')case 6disp=('注意:此接收码字的第4位有错,请纠正')case 7disp=('注意:此接收码字的第6位有错,请纠正')endendset(handles.edit8,'string',disp);%%%下面为在知道哪位出错的情况下,进行纠正for i=1:rswitch(Sx)case 0B(i,:)=A(i,:)+E(1,:);case 1B(i,:)=A(i,:)+E(6,:);case 2B(i,:)=A(i,:)+E(7,:);case 4B(i,:)=A(i,:)+E(8,:);case 3B(i,:)=A(i,:)+E(4,:);case 5B(i,:)=A(i,:)+E(2,:);case 6B(i,:)=A(i,:)+E(5,:);case 7B(i,:)=A(i,:)+E(3,:);endendB=rem(B,2);set(handles.edit9,'string',num2str(B));elsegenpoly=cyclpoly(7,3);[p,g]=cyclgen(7,genpoly);c=str2num(get(handles.edit7,'string'));s=rem(p*c',2);Sx=s(1,1)+s(2,1)*2+s(3,1)*4+s(4,1)*8;switch(Sx)case 0set(handles.edit8,'string','此接收碼无错');set(handles.edit9,'string',num2str(c));case 1if c(1,1)==0c(1,1)=1;elsec(1,1)=0endset(handles.edit8,'string','注意:此接收码字的第一位有错,请纠正');set(handles.edit9,'string',num2str(c));case 2if c(1,2)==0c(1,2)=1;elsec(1,2)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第二位有错,请纠正');case 4if c(1,3)==0c(1,3)=1;elsec(1,3)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第三位有错,请纠正');case 8if c(1,4)==0c(1,4)=1;elsec(1,4)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第四位有错,请纠正');case 13if c(1,5)==0c(1,5)=1;elsec(1,5)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第五位有错,请纠正');case 7if c(1,6)==0c(1,6)=1;elsec(1,6)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第六位有错,请纠正');case 14if c(1,7)==0c(1,7)=1;elsec(1,7)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第七位有错,请纠正');case{3,5,6,9,10,11,12,15}set(handles.edit8,'string','注意:此接收码字有错');set(handles.edit9,'string','注意:无法纠正无法判别错在哪位'); endend% --- Executes on selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu1% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end。
******************实践教学*******************兰州理工大学计算机与通信学院2014年秋季学期计算机通信课程设计题目:(7,3)循环码编译码软件设计专业班级:姓名:学号:指导教师:成绩:摘要随着计算机通信的日益发展,传输数据的场合越来越多。
串行数据的差错检验是保证数据传输正确的必要手段,而循环码是差错码中最常用的一种编码。
循环码是线性分组码中最重要的一种子类,它除了具有分组码的线性外,还具有循环性,其码字结构一般用符号(n,k)表示,其中,n是该码组中的码元数,k是信息码元位数,r=n-k是监督码元位数。
循环码具有许多特殊的代数性质,这些性质有助于按照要求的纠错能力系统地构造这类码,能简化译码算法,并且目前发现的大部分线性码与循环码有密切关系。
已有循环码编译码系统大多以标准逻辑器件(如中小规模TTL系列、CMOS系列)按传统数字系统设计方法设计而成,其主要缺点是逻辑规模小、功耗大、可靠性低。
随着大规模、超大规模集成电路的发展,以及电子设计自动化水平的提高,这种制约正在被逐渐消除。
本文通过C 语言平台运行所编写的程序,观察了在输入信息码情况下输出对应的编码结果以及相反的译码功能。
通过多组的对比验证了该(7,4)循环码的编译码程序的正确性。
最后,在程序运行的过程中进步分析循环码的编译码原理,并通过比较仿真模型与理论计算的性能,证明了仿真模型的可行性。
关键词:循环码;编码;译码;程序仿真目录前言 (1)1、目的及意义 (2)2、设计原理 (3)2.1循环码的介绍 (3)2.1.1循环码的定义 (3)2.1.2循环码的特点 (3)2.1.3循环码的多项式表示 (4)2.1.4(n,k)循环码的生成多项式 (4)2.1.5循环码的生成矩阵和一致校验矩阵 (6)2.2循环码编码原理 (8)2.2.1多项式除法电路 (8)2.3循环码译码原理 (9)3、设计结果及分析 (11)3.1程序运行结果 (11)3.2运行结果理论分析 (14)3.3软件可行性分析 (15)4、总结 (16)附录 (17)参考文献 (22)前言数字信号在传输过程中,由于受到干扰的影响,码元波形将变坏。
functionvarargout = Hamming(varargin)% HAMMING M-file for Hamming.fig% HAMMING, by itself, creates a new HAMMING or raises the existing % singleton*.%% H = HAMMING returns the handle to a new HAMMING or the handle to % the existing singleton*.%% HAMMING('CALLBACK',hObject,eventData,handles,...) calls thelocal% function named CALLBACK in HAMMING.M with the given input arguments. %% HAMMING('Property','Value',...) creates a new HAMMING or raises the % existing singleton*. Starting from the left, property value pairs are% applied to the GUI before Hamming_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application% stop. All inputs are passed to Hamming_OpeningFcn via varargin. %% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help Hamming% Last Modified by GUIDE v2.5 07-Jan-2008 20:22:48% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @Hamming_OpeningFcn, ...'gui_OutputFcn', @Hamming_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);ifnargin&&ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endifnargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before Hamming is made visible.functionHamming_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to Hamming (see VARARGIN)% Choose default command line output for Hamminghandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes Hamming wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. functionvarargout = Hamming_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties. function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as a double% --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)chose=get(handles.popupmenu1,'value');if chose==1;clc;msg=str2num(get(handles.edit1,'string'))%信息产生code=encode(msg,7,4);%汉明编码rcv=decode(code,7,4);%汉明译码set(handles.edit2,'string',num2str(code));set(handles.edit3,'string',num2str(rcv));elsek=str2num(get(handles.edit1,'string'));code1=encode(k,7,3,'cyclic/binary');rcv1=decode(code1,7,3,'cyclic/binary');set(handles.edit2,'string',num2str(code1));set(handles.edit3,'string',num2str(rcv1));endfunction edit7_Callback(hObject, eventdata, handles)% hObject handle to edit7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit7 as text% str2double(get(hObject,'String')) returns contents of edit7 as a double% --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles)% hObject handle to edit7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit8 as text% str2double(get(hObject,'String')) returns contents of edit8 as a double% --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit9_Callback(hObject, eventdata, handles)% hObject handle to edit9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit9 as text% str2double(get(hObject,'String')) returns contents of edit9 asa double% --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles)% hObject handle to edit9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit10_Callback(hObject, eventdata, handles)% hObject handle to edit10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit10 as text% str2double(get(hObject,'String')) returns contents of edit10 as a double% --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles)% hObject handle to edit10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit15_Callback(hObject, eventdata, handles)% hObject handle to edit15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit15 as text% str2double(get(hObject,'String')) returns contents of edit15 as a double% --- Executes during object creation, after setting all properties. function edit15_CreateFcn(hObject, eventdata, handles)% hObject handle to edit15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)chose=get(handles.popupmenu1,'value');if chose==1;[H,G,N,K]=hammgen(3); %产生H和G矩阵for i=1:2^Kfor j=K:-1:1if rem(i-1,2^(-j+K+1))>=2^(-j+K)U(i,j)=1;elseU(i,j)=0;endendendC=rem(U*G,2);A=str2num(get(handles.edit7,'string'));[r,l]=size(A);E=[0 0 0 0 0 0 0;0 0 0 0 0 0 1;0 0 0 0 0 1 0;0 0 0 0 1 0 0;0 0 0 1 0 00;0 0 1 0 0 0 0;0 1 0 0 0 0 0;1 0 0 0 0 0 0]; %%%%%求校正子,然后将其转化成十进制数S=rem(A*H',2);Sx=bi2de(S,'left-msb');%%%%下面是(7,4)码检错for i=1:rswitch(Sx)case 0disp=('此接收码字没错')case 1disp=('注意:此接收码字的第3位有错,请纠正')case 2disp=('注意:此接收码字的第2位有错,请纠正')case 4disp=('注意:此接收码字的第1位有错,请纠正')case 3disp=('注意:此接收码字的第5位有错,请纠正')case 5disp=('注意:此接收码字的第7位有错,请纠正')case 6disp=('注意:此接收码字的第4位有错,请纠正')case 7disp=('注意:此接收码字的第6位有错,请纠正')endendset(handles.edit8,'string',disp);%%%下面为在知道哪位出错的情况下,进行纠正for i=1:rswitch(Sx)case 0B(i,:)=A(i,:)+E(1,:);case 1B(i,:)=A(i,:)+E(6,:);case 2B(i,:)=A(i,:)+E(7,:);case 4B(i,:)=A(i,:)+E(8,:);case 3B(i,:)=A(i,:)+E(4,:);case 5B(i,:)=A(i,:)+E(2,:);case 6B(i,:)=A(i,:)+E(5,:);case 7B(i,:)=A(i,:)+E(3,:);endendB=rem(B,2);set(handles.edit9,'string',num2str(B));elsegenpoly=cyclpoly(7,3);[p,g]=cyclgen(7,genpoly);c=str2num(get(handles.edit7,'string'));s=rem(p*c',2);Sx=s(1,1)+s(2,1)*2+s(3,1)*4+s(4,1)*8;switch(Sx)case 0set(handles.edit8,'string','此接收碼无错');set(handles.edit9,'string',num2str(c));case 1if c(1,1)==0c(1,1)=1;elsec(1,1)=0endset(handles.edit8,'string','注意:此接收码字的第一位有错,请纠正');set(handles.edit9,'string',num2str(c));case 2if c(1,2)==0c(1,2)=1;elsec(1,2)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第二位有错,请纠正');case 4if c(1,3)==0c(1,3)=1;elsec(1,3)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第三位有错,请纠正');case 8if c(1,4)==0c(1,4)=1;elsec(1,4)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第四位有错,请纠正');case 13if c(1,5)==0c(1,5)=1;elsec(1,5)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第五位有错,请纠正');case 7if c(1,6)==0c(1,6)=1;elsec(1,6)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第六位有错,请纠正');case 14if c(1,7)==0c(1,7)=1;elsec(1,7)=0endset(handles.edit9,'string',num2str(c));set(handles.edit8,'string','注意:此接收码字的第七位有错,请纠正');case{3,5,6,9,10,11,12,15}set(handles.edit8,'string','注意:此接收码字有错');set(handles.edit9,'string','注意:无法纠正无法判别错在哪位'); endend% --- Executes on selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu1% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end。
10.1 已知码集合中有8个码组为(000000)、(001110)、(010101)、(011011)、(100011)、(101101)、(110110)、(111000),求该码集合的最小码距。
解 因为该码集合中包含全零码组(000000),所以对于线性分组码,最小码距等于除全零码外的码组的最小重量,即3min =d 。
10.2 上题给出的码集合若用于检错,能检出几位错码?若用于纠错,能纠正几位错码?若同时用于检错与纠错,问纠错、检错的能力如何?解 只用于检错时,由条件:最小码距1min +≥e d ,求出2=e ,即能检出2位错码。
只用于纠错时,由12min +≥t d ,可得1=t ,既能纠正1位错码。
同时用于检错与纠错,且3min =d 时,无法满足下列条件⎩⎨⎧>++≥te e t d 1m i n故该码不能同时用于检错与纠错。
10.4 已知(7,3)码的生成矩阵为⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=001110101001111001110G列出所有许用码组,并求监督矩阵。
解 分别将信息段(000)、(001)、(010)、(011)、(100)、(101)、(110)和(111)代入式A =m G ,得到许用码组如下 0000000 0011101 0100111 0111010 1001110 1010011 1101001 1110100生成矩阵G 为典型阵,有⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=110101111110Q 所以⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡==011110111101TQ P监督矩阵[]⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡==0110001110001011101001011000r I P H 10.5 已知一个(7,4)系统汉明码监督矩阵如下:⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=110100101110101110100H 试求:(1) 生成矩阵G ;(2) 当输入信息序列()101101011010=m 时,求输出码序列A=? (3) 若译码器输入()1001001B =,请计算校正子S ,并指出可能的错误图样。
8-1 某码字的集合为 00000000 1000111 0101011 0011101 1101100 1011010 0110110 1110001求:(1)该码字集合的最小汉明距离;(2)根据最小汉明距离确定其检错和纠错能力。
解:(1)通过两两比较每个码字,可知该码字集的最小汉明距离为4;(2)因为检错能力与最小码距的关系为:1min +=e d ,所以检错能力为3141min =-=-=d e又因为纠错能力与最小码距的关系为:12min +=t d ,所以纠错能力为5.121421min =-=-=d t取整后可得,纠错能力为1=t 。
8-2 已知二进制对称信道的差错率为210-=P 。
(1)(5,1)重复码通过此信道传输,不可纠正错误的出现概率是多少?(2)(4,3)偶校验码通过此信道传输,不可检出错误的出现概率是多少?解: (1)当(5,1)重复码发生3个或3个以上的错误时不可纠正,此时不可纠正的错误出现的概率为()()()60555144523351085.9111-⨯≈-+-+-=P P C P P C P P C P e (2)当(4,3)偶校验码发生偶数个错误时这些错误不可检出,这些错误出现的概率为()()4044422241088.511-⨯≈-+-=P P C P P C P e8-3 等重码是一种所有码字具有相同汉明重量的码,请分析等重码是否线性码?解:因为该码字集中所有的码字均有相同的码重,因此全零码字不包括在内,而线性码在输入信息位均为零时,输出也全为零,因此一定包含全零码。
因此等重码不是线性码。
8-4 对于一个码长为15,可纠正2个随机错误的线性分组码,需要多少个不同的校正子?至少需要多少位监督码元?解:对于一个码长为15的线性码,1个及2个随机错误的图样数为120215115=+C C所以至少需要121个校正子因为12712120631272151156=-<=+<=-C C所以至少需要7位监督码元。
循环码的概念及性质:循环码是线性分组码中最重要的一种子类,是目前研究得比较成熟的一类码。
循环码具有许多特殊的代数性质,这些性质有助于按照要求的纠错能力系统地构造这类码,并且简化译码算法,并且目前发现的大部分线性码与循环码有密切关系。
循环码还有易于实现的特点,很容易用带反馈的移位寄存器实现其硬件。
正是由于循环码具有码的代数结构清晰、性能较好、编译码简单和易于实现的特点,因此在目前的计算机纠错系统中所使用的线性分组码几乎都是循环码。
它不仅可以用于纠正独立的随机错误,而且也可以用于纠正突发错误。
在描述循环码之前,先看以下例子。
设(7,4)汉明码C的生成矩阵和校验矩阵为:于是可以得到相应的16个码组:(1000101)(0001011)(0010110)(0101100)(1011000)(0110001)(1100010)(0100111)(1001110)(0011101)(0111010)(1110100)(1101001)(1010011)(1111111)(0000000)由上述这些码组可以看到,如果是C的码组,则它的左右移位都是C的码组,具有这种特性的线性分组码称为循环码。
循环码具有以下一些性质:1、封闭性(线性性)。
任何许用码组的线性和还是许用码组。
由此性质可以知:线性码都包含全零码。
且最小码重就是最小码距。
2、循环性。
任何许用的码组循环移位后的码组还是许用码组。
循环码可以用多项式来表示。
为了用代数理论的方法研究循环码的特性,我们经常将循环码表示成码多项式的形式:通常将码的码多项式定义如下:其中,D、。
这里,GF(2)表示2元域,在GF(2)内只有两种元素0,1,且0、1满足如下的加法和乘法运算规则:1+1=0、1+0=1、0+1=1、0+0=0;1×1=1、1×0=0、0×0=0、0×1=0。
例如(1011000)码的多项式表示为循环码的生成多项式:(返回)循环码完全由其码长n和生成多项式构成。
循环码(7,3)码(生成多项式1)(234+++=x x xx g )摘要:本报告详细给出了循环码的定义以及由生成多项式求解生成矩阵和系统生成矩阵的过程,并在Matlab 环境下写出了循环码的编码器和解码器代码,实现了编码和译码功能。
分析和讨论了 此码发现错误、纠正错误的能力,并讨论了其与线性分组码、Hamming 码等信道编码的区别与联系。
关键字:循环码 编码 译码 检错 纠错 Matlab信道编码:信道编码又称差错控制编码或纠错编码,它是提高信息传输可靠性的有效方法之一。
一类一类信道编码是对传输信号的码型进行变换,使之更适合于信道特性或满足接收端对恢复信号的要求,从而减少信息的损失;另一类信道编码是在信息序列中人为的增加冗余位,使之具有相关特性,在接收端利用相关性进行检错或纠错,从而达到可靠通信的目的。
1.1、循环码循环码是线性分组码中一个重要的分支。
它的检、纠错能力较强,编码和译码设备并不复杂,而且性能较好,不仅能纠随机错误,也能纠突发错误。
循环码是目前研究得最成熟的一类码,并且有严密的代数理论基础,故有许多特殊的代数性质,这些性质有助于按所要求的纠错能力系统地构造这类码,且易于实现,所以循环码受到人们的高度重视,在FEC 系统中得到了广泛应用。
1.1.1、循环码定义定义:一个线性分组码,若具有下列特性,则称为循环码。
设码字 )(0121c c c c c n n ⋅⋅⋅=-- (1.1.1) 若将码元左移一位,得())(10121--⋅⋅⋅=n n c c c c c (1.1.2)()1c也是一个码字。
由于(k n ,)线性分组码是n 维线性空间n V 中的一个k 维子空间,因此()k n ,循环码是n 维线性空间n V 中的一个k 维循环子空间。
注意:循环码并非由一个码字的全部循环移位构成。
1.1.2、循环码的特点循环码有两个数学特征: (1)线性分组码的封闭型;(2)循环性,即任一许用码组经过循环移位后所得到的码组仍为该许用码组集合中的一个码组。
即若()0121a a a a n n ⋅⋅⋅--为一循环码组,则()1032---⋅⋅⋅n n n a a a a 、()2143----⋅⋅⋅n n n n a a a a 、……还是许用码组。
也就是说,不论是左移还是右移,也不论移多少位,仍然是许用的循环码组。
表1.1-1列出了某(7,3)循环码的全部码组。
码组 信息位监督位码组信息位监督位编号 编号10000000510011102001110161010011301001117110100141111811116a 5a 4a 3a 2a 1a 0a 6a 5a 4a 3a 2a 1a 0a表1.1-1(7,3)循环码组 以3号码组(0100111)为例,左移循环一位变成5号码组(1001110),依次左移一位构成的状态图如图1.1-2所示。
11101000100111011101000111011001110101001111010013号 5号2号4号8号 7号 6号图1.1-1(7,3)循环码中的循环圈可见除全零码组外,不论循环右移或左移,移多少位,其结果均在该循环码组的集合中(全零码组自己构成独立的循环圈)。
1.1.3、码多项式为了用代数理论研究循环码,可将码组用多项式表示,循环码组中各码元分别为多项式的系数。
长度为n的码组()0121a a a a A n n ⋅⋅⋅=--用码多项式表示则为012211)(a x a x a x a x A n n n n +⋅⋅⋅++=---- (1.1.3)式中,x 的幂次是码元位置的标记。
若把一个码组左移i位后的码组记为),,,,(121)(i n i n i n i n i a a a a A -+-----⋅⋅⋅=,其码多项式为i n i n n i n n i n i a x a x a x a x A -+-------++⋅⋅⋅++=12211)()( (1.1.4) )()(x A i 可以根据)(x A x i 按模1+n x 运算得到,即 )1mod()()()(+≡ni i x x A x x A (1.1.5)或)()1)(()()(x A x x Q x A x i n i ++= (1.1.6)式中,)(x Q 为)(x A x i 除以1+n x 的商式,而)()(x A i 等于)(x A A i⋅被1+n x 除得之余式。
以码组1011100为例,若将此码左移两位,则由式(1.1.6)可得 )()1)(()()2(723462x A x x Q x x x x x ++=+++易有其余式为x x x x x A i +++=456)()( ,对应的码组为1110010,它与直接对码组进行循环左移的结果相同。
码多项式之间可以进行代数运算,在二元码中遵循模2运算的规则。
根据线性码的封闭性,任意两码字经模运算后仍为本码组中的码字。
1.1.4、生成多项式(n,k )循环码码组集合中(全“0”码除外)幂次最低的多项式(n-k )阶称为生成多项式)(x g 。
它是能整除1+nx 且常数项为1的多项式,具有唯一性。
集合中其他码多项式,都是按模(1+nx )运算下)(x g 的倍式,即可以由多项式)(x g 产生循环码的全部码组。
假设信息码多项式为)(x m ,则对应的循环码多项式为)()()(x g x m x A = (1.1.7) 式中,)(x m 为次数不大于1-k 的多项式,共有k2个(k n ,)循环码组。
考查表1.1-1,其中4=-k n 阶的多项式只有编号为2的码组(0011101),所以表中所示(7,3)循环码组的生成多项式1)(234+++=x x x x g ,并且该码组集合中的任何码多项式)(x A 都可由信息位乘以生成多项式得到)1mod()()()(0121+++⋅⋅⋅++=--nk k x x g m m m m x A (1.1.8)式中,)(0121m m m m k k ⋅⋅⋅--为信息码元。
对于(7,k )循环码,17+x 的因式分解为)1)(1)(1(12337+++++=+x x x x x x (1.1.9) 由该式可以构成表1.1-2所示几种(7,k )循环码。
表1.1-2 (7,3)循环码的生成多项式从表1.1-2中可以看出,即使n,k 均已确定,也可能由多种生成多项式供选择,选用的多项式不同,产生出的循环码组也不同。
1.1.5、生成矩阵根据各码组集合中生成多项式的唯一性,可以构造生成矩阵G 。
由于g (x )的次数为k n -,则)(,),(),(1x g x x xg x g k -⋅⋅⋅都是码多项式,(7,k) g(x)(7,1) (7,3) (7,4) (7,6))1)(1(323++++x x x x )1)(1()1)(1(323++++++x x x x x x或11323++++x x x x 或1+x而且线性无关,因此以这k 各多项式对应的码组作为k 行就能构成该循环码的生成矩阵,因此循环码的生成矩阵多项式可以写成⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎣⎡=-)()()()(1x g x g x x g x x G k (1.1.10) 以生成多项式1)(234+++=x x x x g 构造)(x G ,相应的矩阵形式为⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡+++++++++=⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=1)()()()(23434524562x x x x x x x x x x x x g x g x x g x x G (1.1.11)则G 为g(x)升幂排列时的G 为⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=101110001011100010111G (1.1.12)对式(1.1.12)作线性变换,整理成典型形式的生成矩阵⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=101110011100100111001G (1.1.13)若信息码元与式(1.1.13)相乘,得到的就是系统循环码。
1.1.6、监督多项式与监督矩阵如前所述,在(n ,k )循环码中,由于g(x)能除尽,因此1+nx 可分解成g(x)和其他因式的乘积,记为)()(1x h x g x n=+即可写成)(1)(x g x x h n +=(1.1.14) 由于g(x)是常数项为1的r 次多项式,所以h(x)必为k 次多项式。
称h(x)为监督多项式或一致校验多项式,与式(1.1.10)给出的G(x)相对应,监督矩阵多项式可表示为⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎣⎡=-)()()()(***1x h x xh x h x x H r (1.1.15) 式中,)(*x h 式h(x)的逆多项式。
由式(1.1.14)可知,前述生成多项式的g(x)的一致校验多项式为1)(23++=x x x h ,所以其一致校验矩阵(监督矩阵)为⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=1011000010110000101100001011)(X H (1.1.16)1.1.7、系统循环码循环码也可以构成为系统循环码。
为方便系统码的构造,将消息多项式和码式都记为高位在前,即),,,,(0121m m m m m k k ⋅⋅⋅=--的消息多项式为m(x),1110)(--+++=k k x m x m m x m又设码式的高幂次部分等于m(x),即)()()(111110x p x m x x c x c x c x c c x c k n n n k n k n k n k n +⋅=++++++=---+-+--- k n r x p -=<∂)(其中p(x)称为校验位多项式,由于码式是生成式的倍式,所以))((mod 0)()()()(x g x g x a x m x x p kn ==+-))()(mod ()(x g x m x x p r⋅-= 因此循环码的系统码码式为 ))]((mod )([)()(x g x m x x m xx c rr-= (1.1.17)将循环码的系统码构造步骤总结为(1)多项式乘))(()(x m x x m x rr =(2)多项式求模(余式) )())())(mod ((x p x g x m x r=(3)多项式减)()())((x c x p x m x r =- 如果令)(x m 为单项式1+r x ,1,,1,0-=k ir x p x p x g x a xi i r <∂+=+)(),()()(1ir ii x x p x c ++=)()( 那么容易看到,)(x c i 对应的向量i c ,1,,1,0-=k i 是线性无关的,从而得到循环码系统码的生成矩阵s G 为⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=------1000100011,11,10,11,111101,00100r k k k r r s p p p p p p p p p G(1.1.18)故由式(1.1.18)可以求得前述(7,3)循环码系统码的生成矩阵为⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=101110011100100111001s G1.1.8、循环码的编码1. 利用生成多项式g(x)实现编码:如上所述,但循环码的生成多项式g(x)确定时,码就完全确定了。