首页 > 解决方案 > 在unetstack中使用维特比算法进行卷积解码

问题描述

我曾尝试在 unetstack 中使用 Viterbi 算法实现卷积解码。但是,我面临一些问题。

  1. 数据未发送到节点 2。(arr - MulAgent.groovy 的第 43 行)
  2. 在某些情况下会出错 -

    groovy.lang.MissingMethodException:No signature of method:Script2.send() is applicable for argument types:(java.lang.Integer, java.lang.Integer)
    values: [2,1010]
    // 2, 1010我们给出的输入值在哪里

mul-sim.groovy(打开并要求输入数据的第一个文件)

import org.arl.fjage.Message
import org.arl.unet.*
import org.arl.mac.*
import org.arl.unet.phy.*

import org.arl.fjage.RealTimePlatform

println'''

OUTPUT TABLE
+----+----------+----------+
|    |    0     |    1     |
+----+----------+----------+
| a  | 00(a)    |  11(b)   |  
+----+----------+----------+
| b  | 10(c)    |  01(d)   |  
+----+----------+----------+
| c  | 11(a)    |  00(b)   |  
+----+----------+----------+
| d  | 01(c)    |  10(d)   |  
+----+----------+----------+ '''         
println '''
2-node network to perform sender - receiver operation
-----------------------------------------
Node 1 will send an encoded value to node 2

The agent MulAgent present at node 2, will decode the received data and send the value to node 1  checking

You can interact with node 1 in the console shell. For example, try:

    send <to-address> , <  data>

For example:

    send 2, 1011

When you are done, exit the shell by pressing ^D or entering:

    shutdown
    '''
    platform = RealTimePlatform
    // run simulation forever
    simulate {
         node '1', address: 1, remote: 1101, location: [0, 0, 0], shell: true,  stack: { container ->
       container.shell.addInitrc "${script.parent}/fshrc.groovy"
    }
    node '2', address: 2, remote: 1102, location: [1.km, 0, 0], shell:5102, stack: { container ->
    container.add 'mul', new MulAgent()
    }
    }

MulAgent.groovy( Agent file 

//包含解码码的程序的代理 import org.arl.fjage.Message import org.arl.unet.* import org.arl.mac.*

类 MulAgent 扩展 UnetAgent {

final static int PROTOCOL = Protocol.DATA int received_data int new_data def arr = new int[4][2] def temp = new int[2] def code=new int[4][2] int i int k int j = 0诠释错误位;int column_error = 0 int row_error = 0 int m = 4 int n = 4 int count

void startup() { def phy = agentForService Services.PHYSICAL 订阅主题(phy) }

void processMessage(Message msg) { if (msg instanceof DatagramNtf && msg.protocol == PROTOCOL) { for(i=0;i<2;i++) { temp[i] = msg.data[i] println "接收数据打印在代理中是 ${temp[i]}" }
for(i=0;i<2;i++) arr[j][i] = temp[i]; println "代理中的数组是 ${arr}}" println "代理中打印的接收数据是 ${temp}"

  println "Recieved total data printing in Agent is ${temp}"
   send new DatagramReq(recipient: msg.sender,to: msg.from, protocol: Protocol.MAC, data: arr[j])
   j++

// 开始 /********************************************** ************************/ /* // 使用维特比进行卷积解码 // ------------------ ------------------------ // Step 1:将输入作为编码数据字 // Step 2 子模块计算汉明距离 //
Step 2 : 使用维特比算法解码的代码 */
/************************************************* ******************/代码=arr;int state[]=[0,,0,0,0,0,0,0] //state int mem[]=[0,0,0,0,0,0,0,0,0,0] //内存int path=0; //路径矩阵 //int data[]=[1,1,0,1] int n,l; for (int j=0;j<4;j++) { for(int i=8;i>=0;i--) { mem[i+i]=mem[i]; //移位一位 } for (int i=0;i<8;i++) { state[i]=mem[i]; } //disp(mem); 状态[i]=0;//引入0 mem[i]=0; // 计算汉明距离 int out1=((mem[1]^mem[2]^mem[4]^mem[5]^mem[6]^mem[7]^mem[8])^ (( mem[1]^mem[2]^mem[3]^mem[5]^mem[6]^mem[7]^mem[8])); //disp(out1); //输出状态为0 [i]=1; //引入 1 mem[i]=1; int out2=((mem[1]^mem[2]^mem[4]^mem[5]^mem[6]^mem[7 ]^mem[8])^ ((mem[1]^mem[2]^mem[3]^mem[5]^mem[6]^mem[7]^mem[8]));

int l=(code[j][0]^out1)+(code[j][1]^out)); //与 out1 的汉明距离 int m=(code[j][0]^out2)+(code[j][1]^out2)); //与out2的汉明距离

if(l<m)  {   //consider with minimum hamming distance
   path=path+l;
    state[1]=0;
    mem[1]=0;
    data[j]=0;}
else
 {   path=path+m;
    data[j]=1;
 }




if(l<m)    
  { path=path+l;
    decode[k]=0;}
else if(l>m)
 {   path=path+m;
     decode[k]=1;
 }

println"路径值 =$path" int 代码=数据;}

def codew=new int[4][2] codew=code;//检测0位错误 int correct=0; 诠释检测=0;诠释n; for(i=0;i<2;i++) if(codew[i][j]) codew[i][j]=0;

for(int i=0;i<4;i++)

    if(path!=0) //one error detected
     { if(y==codew) //corrected
      { correct=correct+1;
            detect=detect+1;
         }
        }      
    if(path!=0) //detected
      {  if(y!=codew) //not corrected
          {  detect=detect+1;
          }
        }
   n++;
    if(codew[i][j])
        codew[i][j]=0;
    else
        codew[i][j]=1;

} if(detect==0) println"检测完成" println"$code" else if(detect!=0) println"检测完成" println"$code"

}
}

fshrc.groovy (the received word is encoded and sent for decoding)

import org.arl.unet.* import org.arl.unet.phy.* import org.arl.unet.* import org.arl.unet.phy.* import org.arl.unet.mac.* //import org .arl.unet.nodeinfo.NodeInfo //导入 org.arl.unet.PDU import org.arl.fjage.* //导入静态 org.arl.unet.Services.* //导入静态 org.arl.unet.phy 。身体的。*

订阅物理

send = { addr, value -> println "发送 $value 到节点 $addr" def y= new int[4]; def a=new int[4]; a=[1, 1, 1, 1] y=[0, 0, 0, 0] int i=3 println "$value" int x=value;

而(x!=0) { y[i]=x%10; println "$y" x=x/10; 一世 - ; } def 代码=新的 int[4][2];

/*使用生成器函数编码的码字 g1=1101 g2=1110 */

for(i=0;i<4;i++) {
int bit = y[3-i]; a[3-i] = 位;
代码[i][0] = a[0]^a[1]^a[3]; 代码[i][1] = a[0]^a[1]^a[2]; }

println"4位编码码字:"

//打印码字

println"$代码"

//println "sending ${value[0]} to node $addr "

phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[0])
def txNtf1= receive(TxFrameNtf, 1000)
def rxNtf1 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000)
  if (txNtf1 && rxNtf1 && rxNtf1.from == addr)
    println "Data Received at ${rxNtf.to} from ${rxNtf.from} is: ${rxNtf.data}" 

//println "sending ${value[1]} to node $addr " phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[1]) def txNtf2 = receive(TxFrameNtf, 1000) def rxNtf2 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000) if (txNtf2 && rxNtf2 && rxNtf2.from == addr) println "从 ${rxNtf2.to} 收到的数据来自 ${rxNtf2.from}是:${rxNtf2.data}"

// println "sending ${value[2]} to node $addr " phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[2]) def txNtf3 = receive(TxFrameNtf, 1000) def rxNtf3 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000) if (txNtf3 && rxNtf3 && rxNtf3.from == addr) println "从 ${rxNtf3.to} 收到的数据来自 ${rxNtf3.from}是:${rxNtf3.data}"

//println "sending ${value[3]} to node $addr " phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[3]) def txNtf4 = receive(TxFrameNtf, 1000) def rxNtf4 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000) if (txNtf4 && rxNtf4 && rxNtf4.from == addr) println "从 ${rxNtf4.to} 收到的数据来自 ${rxNtf4.from}是:${rxNtf4.data}"

}


标签: viterbiunetstack

解决方案


推荐阅读