卷积码编码与Viterbi译码的MATLAB仿真研究
- 格式:pdf
- 大小:2.33 MB
- 文档页数:15


1、卷积编码和Viterbi解码的原理参见tutorial,代码编写都是基于该文档进行
网址:
或者附带的pdf文件
2、Convolutional Encoding采用Matlab自带的编码程序;可以在Matlab安装目
录下的通信工具箱中找到
3、测试程序testV对比了uncoded system & (2,1,2)卷积码经维特比解码后误码率
和信噪比曲线图,也可以采用别的卷积编码生成矩阵
4、由于无法压缩上传,故把代码放在一个word文档中,可将其中各子程序分
别复制出来保存为M。
注意有可能某些注释在doc文件中换行了,需要修改为注释
5、代码很少用matlab内部函数和工具箱,除某些参考网上设计外其余皆为自己
编写并测试通过,可修改其内容实现其他功能。
卷积码的编解码Matlab仿真摘要卷积码是一种性能优越的信道编码。
它的编码器和译码器都比较容易实现,同时它具有较强的纠错能力。
随着纠错编码理论研究的不断深入,卷积码的实际应用越来越广泛。
本文简明地介绍了卷积码的编码原理和译码原理。
并在SIMULINK模块设计中,完成了对卷积码的编码和译码以及误比特统计整个过程的模块仿真。
最后,通过在仿真过程中分别改变卷积码的重要参数来加深理解卷积码的这些参数对卷积码的误码性能的影响。
经过仿真和实测,并对测试结果作了分析。
得出了以下三个结论:(1)当改变卷积码的码率时,系统的误码性能也将随之发生变化。
(2)对于码率一定的卷积码,当约束长度N 发生变化时,系统的误码性能也会随之发生变化。
(3)回溯长度也会不同程度上地影响误码性能。
关键词:卷积码;码率;约束长度;回溯长度目录论文总页数:21页1 引言 (1)1.1 课题背景 (1)1.2 国内外研究现状 (1)1.3 本课题的意义 (1)1.4 本课题的研究方法 (1)2 卷积码的基本概念 (2)2.1 信道 (2)2.2 纠错编码 (2)2.3 卷积码的基本概念 (2)2.4 卷积码编码的概念 (2)2.4.1 卷积编码 (2)2.4.2 卷积码的树状图 (3)2.4.3 卷积码的网格图 (4)2.4.4 卷积码的解析表示 (5)3 卷积码的译码 (6)3.1 卷积码译码的概述 (6)3.2 卷积码的最大似然译码 (6)3.3 VITEBI 译码的关键步骤 (7)3.3.1 输入与同步单元 (7)3.3.2 支路量度计算 (7)3.3.3 路径量度的存储与更新 (7)3.3.4 信息序列的存储与更新 (8)3.3.5 判决与输出单元 (8)4 结论 (9)4.1 卷积码的仿真 (9)4.1.1 SIMULINK仿真模块的参数设置以及重要参数的意义 (9)4.2 改变卷积码的参数仿真以及结论 (12)4.2.1 不同回溯长度对卷积码性能的影响 (12)4.2.2 不同码率对卷积码误码性能的响 (14)4.2.3 不同约束长度对卷积码的误码性能影响 (15)结论 (17)参考文献 (18)致谢.................................................... 错误!未定义书签。
BUPT卷积码编码及Viterbi译码班级:07114学号:070422姓名:吴希龙指导老师:彭岳星邮箱:FusionBupt@1. 序言卷积码最早于1955年由Elias 提出,稍后,1957年Wozencraft 提出了一种有效地译码方法即序列译码。
1963年Massey 提出了一种性能稍差但是比较实用的门限译码方法,使得卷积码开始走向实用化。
而后1967年Viterbi 提出了最大似然译码算法,它对存储级数较小的卷积码很容易实现,被称作Viterbi 译码算法,广泛的应用于现代通信中。
2. 卷积码编码及译码原理2.1 卷积码编码原理卷积码是一种性能优越的信道编码,它的编码器和解码器都比较易于实现,同时还具有较强的纠错能力,这使得它的使用越来越广泛。
卷积码一般表示为(n,k,K)的形式,即将k 各信息比特编码为n 个比特的码组,K 为编码约束长度,说明编码过程中相互约束的码段个数。
卷积码编码后的n 各码元不经与当前组的k 个信息比特有关,还与前K-1个输入组的信息比特有关。
编码过程中相互关联的码元有K*n 个。
R=k/n 是编码效率。
编码效率和约束长度是衡量卷积码的两个重要参数。
典型的卷积码一般选n,k 较小,但K 值可取较大(>10),以获得简单而高性能的卷积码。
卷积码的编码描述方式有很多种:冲激响应描述法、生成矩阵描述法、多项式乘积描述法、状态图描述,树图描述,网格图描述等。
2.1.1 卷积码解析表示法卷积码的解析表示发大致可以分为离散卷积法,生成矩阵法,码多项式法。
下面以离散卷积为例进行说明。
卷积码的编码器一般比较简单,为一个具有k 个输入端,n 个输出端,m 级移位寄存器的有限状态有记忆系统。
下图所示为(2,1,7)卷积码的编码器。
若输入序列为u =(u 0u 1u 2u 3……),则对应两个码字序列c ①=(c 0①c 1①c 2①c 3①……)和c ②=(c 0②c 1②c 2②c 3②……)相应的编码方程可写为c ①=u ∗g ①,c ②=u ∗g ②,c=(c ①,c ②)。
%%---------------------------------------testViterbi.m--------------------------------------------------------------%% %%% Annotated by Quan Xu on Nov. 22, 2011clear all;clc;close;delete *.mat;EsNodB = 0:1:10;EsNo = 10.^(EsNodB/10);N_samples = 100;N_bits = 512;for k = 1 : length(EsNodB)for m = 1 : N_samples% noise powerWGNPower = 1/EsNo(k); % for uncoded systemWGNPower1 = 2/EsNo(k); % for 1/2 convolutional coded system% random messagemsg = randint(1,N_bits);% unencode datab = msg;% Encode data bitstrel = poly2trellis(3,[7 5]); % Define trellisb1 = convenc(msg,trel); % Encode% modulatex = 1 - 2*b;x1 = 1 - 2*b1;% AWGN channelh = ones(size(x));h1 = ones(size(x1));% Gaussian noise generationw = sqrt(WGNPower/2)*(randn(size(x)) + sqrt(-1)*randn(size(x)));w1 = sqrt(WGNPower1/2)*(randn(size(x1)) + sqrt(-1)*randn(size(x1)));% recieved signalsy = h.*x + w;y1 = h1.*x1 + w1;% demodulate uncoded dataoutUncod = uncode(y,h);% Soft-decision viterbi decodingoutVit1 = simeudistVit(trel, y1);errrate(m) = mean(abs(outUncod-msg));errrate1(m) = mean(abs(outVit1-msg));end % for mber(k) = mean(errrate)ber1(k) = mean(errrate1)end % for ksemilogy(EsNodB,ber,'k',EsNodB,ber1,'-r');grid onaxis([1 10 10^-5 1])xlabel('10log(Eb/No)')ylabel('BER')title('AWGN channel viterbi decoder');h = legend('uncoded', '[2,1,2]convolutional encoding');set(h,'Interpreter','none')save conViterbi.mat;% EOF%%---------------------------------------- testViterbi.m ------------------------------------------------------%%%% Calulating Euclidean distance%% (x-y).^2 --> xy ; since x = +1 or -1; y is the same for every branch%% Annotated by Quan Xu on Nov. 22, 2011function dist = simEudist(x,y)leth = length(x);realx = real(x);realy = real(y);dist = 0;for i=1:lethdist = dist + realx(i)*realy(i);end% EOF%%----------------------------------------simEudist.m ------------------------------------------------------%%%%----------------------------------------uncode.m ------------------------------------------------------%% %% Annotated by Quan Xu on Nov. 22, 2011%% demodulating the uncoded datafunction unOut = uncode(y,h)for l = 1 : length(y)llr(l) = abs(y(l)+h(l))^2 - abs(y(l)-h(l))^2;x_hat(l) = sign(llr(l));b_hat(l) = (1-x_hat(l))/2;end % for lunOut = b_hat;% EOF%%----------------------------------------uncode.m ------------------------------------------------------%%%%% Annotated by Quan Xu on Nov. 22, 2011function enc = trellis2enc( trl ),% put the trellis structure into a more user friendly mannerenc.k = log2( trl.numInputSymbols ); % number of inputsenc.n = log2( trl.numOutputSymbols ); % numbor of outputsenc.r = enc.k / enc.n; % code rateenc.ksym = trl.numInputSymbols; % number of possible input combinationsenc.nsym = trl.numOutputSymbols; % number of possible output combinationsenc.stat = trl.numStates; % number of encoder states% forward transitions:enc.next.states = trl.nextStates + 1; % NEXT statesenc.next.output = trl.outputs; % NEXT outputsfor i = 1:enc.ksym, % NEXT (binary) outputsenc.next.binout( :,:,i ) = 1 - 2*de2bi( oct2dec( trl.outputs(:,i) ), enc.n, 'left-msb' );end% store possible binary outputs and inputs:enc.inp = de2bi( oct2dec( [0:enc.ksym-1] ), enc.k, 'left-msb' ); % all possible binary inputsenc.out = de2bi( oct2dec( [0:enc.nsym-1] ), enc.n, 'left-msb' ); % all possible binary outputsenc.bininp = 2*enc.inp-1;return;%%----------------------------------------trellis2enc.m ------------------------------------------------------%%%%% This function could be found in C:\Program Files\MATLAB\R2008b\toolbox\comm\comm\convenc.m%%% Annotated by Quan Xu on Nov. 22, 2011function varargout = convenc(msg, trellis, varargin)% Typical error checking.error(nargchk(2,4,nargin,'struct'));nvarargin = nargin - 2;% Set defaultspunctVec = [];initialstate = 0;switch (nvarargin)case 1if ~isempty(varargin{1})if isscalar(varargin{1})initialstate = varargin{1};elsepunctVec = varargin{1};endendcase 2[punctVec, initialstate] = deal(varargin{:});endif nargout > 2error('comm:convenc:TooManyOutputArg','Too many output arguments.');end% check trellisif ~istrellis(trellis),error('comm:convenc:InvalidTrellis','Trellis is not valid.');end% Get info out of trellis structurek = log2(trellis.numInputSymbols);n = log2(trellis.numOutputSymbols);outputs = oct2dec(trellis.outputs);% Check msgif ~isempty(msg)msg_dim = size(msg);if ~( isnumeric(msg) || islogical(msg) ) || ...length(msg_dim)>2 || ...min(msg_dim)>1error('comm:convenc:InvalidMsg','The input message must be a logical or numeric vector.');endoutLog = islogical(msg); % for output data typemsg = double(msg); % for proper numerical operationif max(max(msg < 0)) || ...max(max(~isfinite(msg))) || ...~isreal(msg) || ...max(max(floor(msg) ~= msg)) || ...max(max(msg)) > 1error('comm:convenc:InputNotBinary','The input message must contain only binary values.');endif mod(length(msg), k) ~=0error('comm:convenc:InvalidMsgLength',['Length of the input message must be a multiple of the ' ...'number of bits in an input symbol.']);end% Get message orientationif msg_dim(1)>1msg_flip = 1;msg=msg';elsemsg_flip = 0;endend% Check Puncture vectorif ~isempty(punctVec)% Validity checkif ~( isnumeric(punctVec) || islogical(punctVec) ) || ...length(size(punctVec)) > 2 || ...~( isvector(punctVec) && ~isscalar(punctVec) ) || ...max(max(~isfinite(punctVec))) || ...~isreal(punctVec)error('comm:convenc:InvalidPuncPat', ['The puncture pattern parameter',...' must be a vector of real or logical values.']);end% Binary value checkif any(punctVec~=0 & punctVec~=1)error('comm:convenc:PuncPatNotBinary', ...['The puncture pattern parameter must be a binary vector of 1''s ',...'and 0''s only.']);end% Length checksif length(punctVec) < nerror('comm:convenc:InvalidPuncPatLength',...['The puncture pattern parameter length must be at least the ',...'number of bits in an output symbol.']);endif mod((length(msg)/k)*n, length(punctVec)) ~=0error('comm:convenc:InvalidCodeLengthPunc', ...['The input message length divided by the base code rate must be an',...'\ninteger multiple of the length of the puncture pattern parameter.']);endend% Check initial stateif ~isnumeric(initialstate) || ...~isscalar(initialstate) || ...max(max(initialstate < 0)) || ...max(max(~isfinite(initialstate))) || ...~isreal(initialstate) || ...max(max(floor(initialstate) ~= initialstate)) || ...max(max(initialstate)) > trellis.numStates-1error('comm:convenc:InvalidInitialState',['The initial state must be an integer scalar between 0 and ' ...'(TRELLIS.numStates-1). See POLY2TRELLIS.']);end% Return if input message is emptyif isempty(msg)varargout{1} = [];varargout{2} = initialstate;return;end% Actual call to core function 'convcore.c'[code, fstate] = ...convcore(msg,k,n,trellis.numStates,outputs,trellis.nextStates,initialstate);if ~isempty(punctVec)% Expand punctVec if neededif length(code) ~= length(punctVec)pVec = punctVec(:);bb = pVec(:, ones(1, length(code)/length(punctVec))); % repeatpunctVec = bb(:); % vector end% Puncture the encoded outputcode(~logical(punctVec)) = [];end% Change code back to same orientation as input MSGif msg_flipcode=code';end% Set output data type to logical if appropriateif outLog, code = logical(code); end;% Set outputsvarargout = {code, fstate};% [EOF]%%----------------------------------------convenc.m ------------------------------------------------------%%%%----------------------------------------simeudistVit.m ------------------------------------------------------%% %% Using the simplified Euclidean distance%% trellis2enc transfer the Matlab trellis to be user-friendly form%% input arguments%% trel : matlab trellis structure%% y : received symbols from the channel%% output%% decVit : decoding bits%% Annotated by Quan Xu on Nov. 22, 2011function decVit = simeudistVit(trel, y);enc = trellis2enc( trel );% some parametersk = enc.k;n = enc.n;r = enc.r;ksym = enc.ksym;nsym = enc.nsym;numStat = enc.stat;states = enc.next.states;outputs = enc.next.binout;leth = length(y)/n;%Input table; for decoding with current state and previous statedecodBit = 2*ones(numStat); %Row numbers represent current states plus 1 while columns represent next states plus 1for i=1:numStatfor j=1:2nxt = states(i,j);decodBit(i,nxt) = j-1;end %jend %i%---------------caculating path metric array &surviving predecessor states array initial value numMem = log2(numStat); % Memories of the encoder: number of branches before constructing four statespm = zeros(1,numStat);pmtmp = pm;surpred = zeros(numStat,leth);inipred = [1 zeros(1,numStat-1)];initmp = inipred;for i = 1:numMemiy = zeros(1,n);for p = 1:niy(p) = y((i-1)*n+p);endfor j = 1:numStatif initmp(j) == 1ininxt0 = states(j,1);pm(ininxt0) = pmtmp(j)+simEudist(outputs(j,:,1),iy);surpred(ininxt0,i) = j;inipred(ininxt0) = 1;ininxt1 = states(j,2);pm(ininxt1) = pmtmp(j)+simEudist(outputs(j,:,2),iy);surpred(ininxt1,i) = j;inipred(ininxt1) =1;endend %jinitmp = inipred;pmtmp = pm;end %i%----caculating path metric array &surviving predecessor states...%...array initial value% indiceid = zeros(2*numStat, 2);for i = 1:2*numStatid(i,1) = mod(i-1,numStat)+1;id(i,2) = floor((i-1)/numStat)+1;end %i% decode beginningfor i=numMem+1:leth;iy = zeros(1,n);for p = 1:niy(p) = y((i-1)*n+p);endfor s = 1:numStat;d1=simEudist(outputs(id(2*s-1,1),:,id(2*s,2)),iy); % The previous two states could be caculated with left-shift of current ..d2=simEudist(outputs(id(2*s,1),:,id(2*s,2)),iy); % ... state then plus 0&1, for theoutputs, these two indices should plus another 1if (pmtmp(id(2*s-1,1))+d1)>(pmtmp(id(2*s,1))+d2);pm(s)=pmtmp(id(2*s-1,1))+d1;surpred(s,i) = id(2*s-1,1);elsepm(s)=pmtmp(id(2*s,1))+d2;surpred(s,i) = id(2*s,1);endendpmtmp = pm;end%find the path having minimum accumulated metricminMetr = [1 pm(1)];for i=1:numStat;if pm(i) > minMetr(2);minMetr(2)= pm(i); % the minimum metric of the last branch in trellisminMetr(1)=i; % the last state of selected pathendenddecVit = 2*ones(1,leth);cs = minMetr(1);for j=leth:-1:1;ps = surpred(cs,j);if ps ==0disp('error');enddecVit(j) = decodBit(ps,cs);cs = ps;end%EOF%%----------------------------------------simeudistVit.m ------------------------------------------------------%%。