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

📄 cnv_encd.m

📁 信道编码中的卷积码的编译码Matlab仿真程序。有资源大家共享才是真的好
💻 M
字号:
%卷积编码程序
function [output, len_tal] = cnv_encd(secrettext, encodetext)

g = [0 0 1 0 0 1 0 0; 0 0 0 0 0 0 0 1; 1 0 0 0 0 0 0 1; 0 1 0 0 1 1 0 1];

k0 = 1;

% 读入文本文件并计算文件长度
frr = fopen(secrettext, 'r');
[msg, len] = fread(frr, 'ubit1');
msg = msg';
% check to see if extra zero padding is necessary
if rem(length(msg), k0) > 0
    msg = [msg, zeros(size(1:k0-rem(length(msg),k0)))];
end

n = length(msg)/k0;          % 把输入比特按k0分组,n为所得的组数。

% check the size of matrix g
if rem(size(g, 2), k0) > 0
    error('Error, g is not of the right size.');
end

% determine L and n0
L = size(g, 2)/k0;
n0 = size(g, 1);

% add extra zeros,以保证编码器是从全0开始,并回到全0状态。
u = [zeros(size(1:(L-1)*k0)), msg, zeros(size(1:(L-1)*k0))];

% generate uu, a matrix whose columns are the contents of conv. encoder at
% various clock cycles.
u1 = u(L*k0: -1 :1);
for i = 1:n+L-2
    u1 = [u1, u((i+L)*k0:-1:i*k0+1)];
end

uu = reshape(u1, L*k0, n+L-1);

% determine the output
output = reshape(rem(g*uu, 2), 1, n0*(L+n-1));
len_tal = n0*(L + n - 1);

% write the output to the encodetext
result = fopen(encodetext, 'w');
for i = 1:n0*(L+n -1)
    fwrite(result, output(i), 'bit1');
end

fclose(result);

⌨️ 快捷键说明

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