📄 enc_dec_test.m
字号:
clc
clear all
data_in = [1 0 1 0 1 0 0 1]; % must be a x*k (Rate = k/n)
data_in=repmat(data_in,1,30);
%% -----Various Rates------------------------------------------------%
% % K = 5
% Rate = 1/7; constlen = 5; codegen = [35 27 25 27 33 35 37]; puncpat = [1 1 1 1 1 1 1];
%
% % K = 7 (CCSDS)
Rate = 1/2; constlen = 7; codegen = [171 133]; puncpat = [1 1];
% Rate = 2/3; constlen = 7; codegen = [171 133]; puncpat = [1 0];
% Rate = 3/4; constlen = 7; codegen = [171 133]; puncpat = [1 1 0];
% Rate = 5/6; constlen = 7; codegen = [171 133]; puncpat = [1 1 0 1 0];
% Rate = 7/8; constlen = 7; codegen = [171 133]; puncpat = [1 1 1 1 0 1 0];
%
% % K = 7 (Intelsat)
Rate = 1/2; constlen = 7; codegen = [133 171]; puncpat = [1 1];
Rate = 2/3; constlen = 7; codegen = [133 171]; puncpat = [1 0];
Rate = 3/4; constlen = 7; codegen = [133 171]; puncpat = [1 0 1];
% Rate = 5/6; constlen = 7; codegen = [133 171]; puncpat = [1 0 1 0 1];
% Rate = 7/8; constlen = 7; codegen = [133 171]; puncpat = [1 0 0 0 1 0 1];
%
% % K = 9
% Rate = 1/3; constlen = 9; codegen = [557 663 711]; puncpat = [1 1 1];
% Rate = 1/2; constlen = 9; codegen = [753 561]; puncpat = [1 1];
% Rate = 2/3; constlen = 9; codegen = [753 561]; puncpat = [0 1];
%
%
% Rate = 2/3; constlen = [3 3]; codegen = [6 5 1;7 2 5]; puncpat = [1 1 1];
% Rate = 2/3; constlen = [5 4]; codegen = [23 35 0; 0 5 13]; puncpat = [1 1 1];
% Rate = 1/2; constlen = 3; codegen = [7 5]; puncpat = [1 1];
% Rate = 2/3; constlen = 3; codegen = [7 5]; puncpat = [1 0];
%% -----trellis & Convolutional Encoding---------------------------%
trellis = poly2trellis(constlen, codegen); tblen=1;
% [trellis_transition,trellis_output] = trellisgen(constlen,codegen);
u = convenc(data_in,trellis,puncpat); % MATLAB
% u1 = conv_punc(data_in, constlen, codegen, puncpat); % (Rate = 1/n + punc)
u2 = punc_conv(data_in, constlen, codegen, puncpat); % (Rate = k/n+ punc)
%% -----Viterbi Decoding---------------------------------------------%
n=10;
% u(n) = ~u(n); % make Error
w = vitdec(u,trellis,tblen,'trunc','hard',puncpat);
% w1 = vitdecod(u,constlen,codegen); % %(Rate = k/n)
w2 = vit_dec(u,constlen,codegen, puncpat); % (Rate = k/n + punc)
%% Encode BER
[number, ratio] = biterr(u, u2);
disp('Encode BER')
disp(number)
%% MATLAB Decode BER
[number, ratio] = biterr(data_in, w);
disp('MATLAB Decode BER')
disp(number)
%% Function Decode BER
[number, ratio] = biterr(data_in, w2);
disp('Function Decode BER')
disp(number)
%% -----Display output-----------------------------------------------%
% disp('Function decoder output')
% disp(w2)
% disp('MATLAB decoder output')
% disp(w)
% % -----Display input-----------------------------------------------%
% disp('Function encoder output')
% disp(u2)
% disp('MATLAB encoder output')
% disp(u)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -