




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上这是我搜集整理的一个关于卷积编码和Viterbi译码的Matlab程序,现在把它们放在这里,希望对需要的人有些帮助。卷积编码程序: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;% ch
2、eck to see if extra zero padding is necessaryif rem(length(msg), k0) 0 msg = msg, zeros(size(1:k0-rem(length(msg),k0);endn = length(msg)/k0; % 把输入比特按k0分组,n为所得的组数。% check the size of matrix gif rem(size(g, 2), k0) 0 error(Error, g is not of the right size.);end% determine L and n0L = size(g, 2)/k0;n0
3、 = 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);enduu = reshape(u1, L*k0, n+
4、L-1);% determine the outputoutput = reshape(rem(g*uu, 2), 1, n0*(L+n-1);len_tal = n0*(L + n - 1);% write the output to the encodetextresult = fopen(encodetext, w);for i = 1:n0*(L+n -1) fwrite(result, output(i), bit1);endfclose(result);Viterbi译码程序:function decoder_output, survivor_state, cumulated_me
5、tric = viterbi(channel_output, decodetext)ticG= 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;k = 1;frr = fopen(channel_output, r);msg, len = fread(frr, ubit1);channel_output = msg;n = size(G,1);% check the sizesif rem(size(G, 2), k) = 0 error(channel_output not of the right siz
6、e);endL = size(G, 2)/k;number_of_states = 2(L-1)*k);% generate state transition matrix, output matrix, and input matrixfor j = 0:number_of_states - 1 for i = 0:2k-1 next_state, memory_contents = nxt_stat(j,i, L, k); input(j+1, next_state + 1) = i; branch_output = rem(memory_contents*G, 2); nextstate
7、(j+1, i+1) = next_state; output(j+1, i+1) = bin2deci(branch_output); endend% add the extra zero, ensure the length of channel_output is integral% times to n.if rem(len, n)0 channel_output = channel_output, zeros(size(n-rem(len, n):-1:1);endstate_metric = zeros(number_of_states, 2);depth_of_trellis =
8、 length(channel_output)/n;channel_output_matrix = reshape(channel_output, n, depth_of_trellis);survivor_state = zeros(number_of_states, depth_of_trellis + 1);% start decoding of non-tail channel outputsfor i = 1:depth_of_trellis-L+1 flag = zeros(1, number_of_states); if i state_metric(j+1,1). + bran
9、ch_metric) | flag(nextstate(j+1, l+1) + 1) = 0) state_metric(nextstate(j+1,l+1)+1, 2) = state_metric(j+1, 1) + branch_metric; suvivor_state(nextstate(j+1,l+1) + 1, i+1) = j; flag(nextstate(j+1, l+1) + 1) = 1; end end end state_metric = state_metric(:, 2:-1:1);end% start decoding of the tail channel-
10、outputsfor i = depth_of_trellis - L + 2:depth_of_trellis flag = zeros(1, number_of_states); last_stop = number_of_states/(2(i - depth_of_trellis+L-2)*k); for j = 0:last_stop - 1 branch_metric = 0; binary_output = deci2bin(output(j + 1, 1), n); for r = 1:n branch_metric = branch_metric + metric(chann
11、el_output_matrix(r, i), binary_output(r); end if(state_metric(nextstate(j+1, l+1) + 1, 2)state_metric(j+1,1). + branch_metric) | flag(nextstate(j+1, 1) + 1) = 0) state_metric(nextstate(j+1,1)+1, 2) = state_metric(j+1, 1) + branch_metric; suvivor_state(nextstate(j+1,1) + 1, i+1) = j; flag(nextstate(j
12、+1, 1) + 1) = 1; end end state_metric = state_metric(:, 2:-1:1);end% generate the decode output from the optimal pathstate_sequence = zeros(1, depth_of_trellis + 1);state_sequence(1, depth_of_trellis) = survivor_state(1, depth_of_trellis+1);for i = 1:depth_of_trellis state_sequence(1, depth_of_trell
13、is-i+1) = suvivor_state(state_sequence(1, depth_of_trellis+2-i). +1), depth_of_trellis - i+2);enddecoder_output_matrix = zeros(k, depth_of_trellis -L+1);for i = 1:depth_of_trellis - L + 1 dec_output_deci = input(state_sequence(1, i)+1, state_sequence(1, i+1)+1); dec_output_bin = deci2bin(dec_output_
14、deci, k); decoder_output_matrix(:,i) = dec_output_bin(k:-1:1);enddecoder_output = reshape(decoder_output_matrix, 1, k*(depth_of_trellis-L+1);cumulated_metric = state_metric(1, 1);% write the output to the encodetextresult = fopen(decodetext, w);for i = 1:k*(depth_of_trellis-L+1) fwrite(result, decod
15、er_output(i), bit1);endfclose(result);toc%*%function distance = metric(x,y)if x = y distance = 0;else distance = 1;end%*%function next_state, memory_contents = nxt_stat(current_state, input, L, k)binary_state = deci2bin(current_state, k*(L-1);binary_input = deci2bin(input, k);next_state_binary = binary_input, binary_state(1:(L-2)*k);next_state = bin2deci(next_state_binary);mem
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 解析卷-人教版八年级物理上册第4章光现象综合测试试题(解析版)
- 难点解析人教版八年级物理上册第5章透镜及其应用单元测试试卷(详解版)
- 难点解析人教版八年级物理上册第5章透镜及其应用同步练习练习题(含答案解析)
- 2025年中小学学生体质健康评价与运动技能达标考核试卷
- 2025年工业废气VOCs治理催化剂性能考核试卷
- 2025年计算机技术与软件专业技术资格(中级)《软件设计师》AI语音交互系统开发模拟考核试卷
- 难点解析-人教版八年级物理上册第5章透镜及其应用单元测试试题(含详细解析)
- 考点解析人教版八年级上册物理光现象《光的直线传播》章节测试试题(含详细解析)
- 考点解析人教版八年级物理上册第5章透镜及其应用专题攻克试卷(详解版)
- 难点解析-人教版八年级物理上册第6章质量与密度-质量定向训练试题(详解)
- 社区眼科知识培训课件
- 银行从业资格2025年法律法规模考训练冲刺试卷(含答案)
- 2025年宁夏中考英语试卷附答案
- 第11课西汉建立和“文景之治”课件-七年级历史上册新教材
- 2025年成考英语试卷及答案
- 2025年上海市大数据中心工作人员公开招聘考试参考题库及答案解析
- 容貌焦虑讲解课件
- 2025年东营市专业技术人员继续教育公共服务平台公需课-题目and答案
- 隔爆水棚替换自动隔爆装置方案及安全技术措施
- cice考试题库及答案
- 2025年广州市海珠区华洲街道招聘雇员(4人)笔试备考试题含答案详解(综合题)
评论
0/150
提交评论