(2,1,2)卷积码译码器的JAVA实现
发布日期:2022-04-04 06:36:29
浏览次数:20
分类:博客文章
本文共 5369 字,大约阅读时间需要 17 分钟。
本人编写。
package Veteribi;import java.util.ArrayList;public class Veterbi { public static void decoder(StringBuffer received) { // 记录四种状态的路径 StringBuffer route1 = new StringBuffer("0000"); // x00 StringBuffer route2 = new StringBuffer("0011"); // x10 StringBuffer route3 = new StringBuffer("1110"); // x01 StringBuffer route4 = new StringBuffer("1101"); // x11 StringBuffer realway1 = new StringBuffer("00"); StringBuffer realway2 = new StringBuffer("01"); StringBuffer realway3 = new StringBuffer("10"); StringBuffer realway4 = new StringBuffer("11"); System.out.println("接收到的数据长度为: " + received.length()); System.out.println("接收到的数据为 : " + received); int [] distance = {0,0,0,0,0};; //记录4种状态的最小码距 int length = received.length(); distance[0] = 0; distance[1] += (route1.charAt(0)^received.charAt(0) ) + (route1.charAt(1)^received.charAt(1)) + (route1.charAt(2)^received.charAt(2)) +(route1.charAt(3)^received.charAt(3)) ; distance[2] += (route2.charAt(0)^received.charAt(0) ) + (route2.charAt(1)^received.charAt(1)) + (route2.charAt(2)^received.charAt(2)) +(route2.charAt(3)^received.charAt(3)) ; distance[3] += (route3.charAt(0)^received.charAt(0) ) + (route3.charAt(1)^received.charAt(1)) + (route3.charAt(2)^received.charAt(2)) +(route3.charAt(3)^received.charAt(3)) ; distance[4] += (route4.charAt(0)^received.charAt(0) ) + (route4.charAt(1)^received.charAt(1)) + (route4.charAt(2)^received.charAt(2)) +(route4.charAt(3)^received.charAt(3)) ; int i; System.out.println(); for(i=4 ; i< length ; i++) { int temp1=distance[1]; int temp2=distance[2]; int temp3=distance[3]; int temp4=distance[4]; System.out.println("i =" + i + "最短路径分别为:" + temp1 + temp2 + temp3 +temp4); String copy1 = route1.toString(); String copy2 = route2.toString(); String copy3 = route3.toString(); String copy4 = route4.toString(); String copyway1 = realway1.toString(); String copyway2 = realway2.toString(); String copyway3 = realway3.toString(); String copyway4 = realway4.toString(); /* 选择下一跳最短码距的路径 */ // jump to S1 // 1/000 --> 1/00 // 3/001 --> 1/11 if( temp1 + ('0' ^ received.charAt(i) ) + ('0' ^received.charAt(i+1)) > temp3 + ('1' ^ received.charAt(i) ) + ( '1'^received.charAt(i+1)) ) { route1.replace(0, i, copy3); route1.append("11"); realway1.replace(0, i/2, copyway3); realway1.append("0"); distance[1] = temp3 + ('1' ^ received.charAt(i) ) + ( '1'^received.charAt(i+1)) ; } else { route1.replace(0, i, copy1); route1.append("00"); realway1.replace(0, i/2,copyway1); realway1.append("0"); distance[1] =temp1 + ('0' ^ received.charAt(i) ) + ('0' ^received.charAt(i+1)) ; } System.out.println("此时i = " + i + " ,路径1的原码:" + route1 + " ,路径1的译码结果:" + realway1); // jump to S2 // 1/100 --> 2/10 // 3/101 --> 2/00 if( temp1 + ( '1' ^ received.charAt(i) ) + ( '1' ^ received.charAt(i+1)) > temp3 + ( '0' ^ received.charAt(i) ) + ( '0' ^ received.charAt(i+1)) ) { route2.replace(0, i , copy3); route2.append("00"); realway2.replace(0, i/2, copyway3); realway2.append("1"); distance[2] = temp3 + ( '0' ^ received.charAt(i) ) + ( '0' ^ received.charAt(i+1)) ; } else { route2.replace(0, i , copy1); route2.append("11"); realway2.replace(0, i/2, copyway1); realway2.append("1"); distance[2] = temp1 + ( '1' ^ received.charAt(i) ) + ( '1' ^ received.charAt(i+1)); } System.out.println("此时i = " + i + " ,路径2的原码:" + route2 + " ,路径2的译码结果:" + realway2); //jump to S3 // 2/010 --> 3/10 // 4/011 --> 3/01 if( temp2 + ('1' ^ received.charAt(i)) + ('0' ^ received.charAt(i+1)) > temp4 + ('0' ^ received.charAt(i)) + ('1' ^ received.charAt(i+1)) ) { route3.replace(0, i, copy4); route3.append("01"); realway3.replace(0, i/2, copyway4); realway3.append("0"); distance[3] =temp4 + ('0' ^ received.charAt(i)) + ('1' ^ received.charAt(i+1)) ; } else { route3.replace(0, i, copy2); route3.append("10"); realway3.replace(0, i/2, copyway2); realway3.append("0"); distance[3] =temp2 + ('1' ^ received.charAt(i)) + ('0' ^ received.charAt(i+1)) ; } System.out.println("此时i = " + i + " ,路径3的原码:" + route3 + " ,路径3的译码结果:" + realway3); //jump to S4 // 2/101 --> 4/01 // 4/111 --> 4/10 if( temp2 + ('0' ^ received.charAt(i)) + ('1' ^ received.charAt(i+1)) > temp4 + ('1' ^ received.charAt(i)) + ('0' ^ received.charAt(i+1)) ) { route4.replace(0, i, copy4); route4.append("10"); realway4.replace(0, i/2, copyway4); realway4.append("1"); distance[4] = temp4 + ('1' ^ received.charAt(i)) + ('0' ^ received.charAt(i+1)) ; } else { route4.replace(0, i, copy2); route4.append("01"); realway4.replace(0, i/2, copyway2); realway4.append("1"); distance[4] = temp2 + ('0' ^ received.charAt(i)) + ('1' ^ received.charAt(i+1)) ; } System.out.println("此时i = " + i + " ,路径4的原码:" + route4 + " ,路径4的译码结果:" + realway4); ++i; } System.out.println(received.length() + "bit的最短距离分别是" + distance[1] + " " + distance[2] + " " + distance[3] + " " + distance[4]); } }
转载地址:https://www.cnblogs.com/l20902/p/10610884.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年03月19日 03时53分15秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
java io封装_Java程序员开发面试宝典之Java IO篇
2019-04-21
java反射测试方法_Java反射知识重拾
2019-04-21
摩托罗拉v3java_拆一代超薄经典手机-摩托罗拉V3
2019-04-21
k近邻算法python解读_机器学习(K-近邻算法)Python的基础知识
2019-04-21
java timer并发_Java并发编程笔记之Timer源码分析
2019-04-21
java声明变量保存性别_java第二次课变量第一次上机
2019-04-21
js装修计算器java代码_JavaScript代码实现简单计算器
2019-04-21
功夫传人java_PAT L2-020 功夫传人【BFS】
2019-04-21
联机侠控制台JAVA_联机侠控制台常见问题 | 我的世界 | MC世界侠
2019-04-21
2018转行的java学习_2018java平均工资,想转行学java的快点上车
2019-04-21
java 常用数据库_java连接常用数据库
2019-04-21
有什么可以替换php,php替换函数是什么
2019-04-21
java静态方法是不是成员方法,Java静态变量与静态方法与成员变量成员方法的区别...
2019-04-21