在unetstack中使用维特比算法进行卷积解码

时间:2019-04-11 04:23:49

标签: viterbi unetstack

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

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

    groovy.lang.MissingMethodException:方法的无签名:Script2.send()适用于参数类型:(java.lang.Integer,java.lang.Integer)
      值:[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 

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

MulAgent类扩展了UnetAgent {

最终静态整数PROTOCOL = Protocol.DATA   整数接收数据   int new_data   def arr =新的int [4] [2]   def temp =新的int [2]   def code =新int [4] [2]   我   整数k   整数j = 0   int error_bit;   int column_error = 0   int row_error = 0   整数m = 4   整数n = 4   整数计数

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

void processMessage(消息消息){     如果(DatagramNtf的msg实例&& 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++

//开始   / ***************************************************** ****************** /   / * /   / 使用维特比 /进行卷积解码   / ------------------------------------------ /   / 步骤1:将输入作为编码后的数据字 /   / 步骤2:子模块计算汉明距离 /
  /
步骤2:使用维特比算法解码的代码* /
  / ***************************************************** ****************** / code = arr; int state [] = [0,,0,0,0,0,0,0] //状态 int mem [] = [0,0,0,0,0,0,0,0,0,0] //内存 int path = 0; //路径矩阵 // int数据[] = [1,1,0,1] int n,l; 对于(int j = 0; j <4; j ++)      {for(int i = 8; i> = 0; i--)      {mem [i + i] = mem [i]; //移动一位      }     为(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 =(代码[j] [0] ^ out1)+(代码[j] [1] ^ out)); //与out1的汉明距离    int m =(代码[j] [0] ^ out2)+(代码[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“路径值= $路径”  整数代码=数据;   }

def codew =新int [4] [2] codew = code; //检测0位错误 整数正确= 0; int detect = 0; int 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;

}    如果(检测== 0)        println“检测完成”        println“ $ code”   否则if(detect!= 0)       println“检测完成”        println“ $ code”

}
}

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

导入org.arl.unet。* 导入org.arl.unet.phy。* 导入org.arl.unet。* 导入org.arl.unet.phy。* 导入org.arl.unet.mac。* //导入org.arl.unet.nodeinfo.NodeInfo //导入org.arl.unet.PDU 导入org.arl.fjage。* //导入静态org.arl.unet.Services。* //导入静态org.arl.unet.phy.Physical。*

订阅者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] 整数i = 3 println“ $ value” int x = value;

while(x!= 0)   {     y [i] = x%10;     println“ $ y”     x = x / 10;     一世 - ;     } def code = new int [4] [2];

/ *使用生成器功能编码的代码字                                 g1 = 1101                                 g2 = 1110 * /

for(i = 0; i <4; i ++) {
    整数位= 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“ $ code”

//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“向节点$ addr发送$ {value [1]}”     phy <<新的DatagramReq(发送至:addr,协议:Protocol.DATA,数据:code [1])     def txNtf2 =接收(TxFrameNtf,1000)     def rxNtf2 = receive({it instanceof RxFrameNtf && it.from == addr},5000)       如果(txNtf2 && rxNtf2 && rxNtf2.from == addr)         

println“从$ {rxNtf2.from}在$ {rxNtf2.to}接收到的数据是:$ {rxNtf2.data}”

// println“将$ {value [2]}发送到节点$ addr”     phy << new DatagramReq(收件人:addr,协议:Protocol.DATA,数据:code [2])     def txNtf3 =接收(TxFrameNtf,1000)     def rxNtf3 = receive({it instanceof RxFrameNtf && it.from == addr},5000)       如果(txNtf3 && rxNtf3 && rxNtf3.from == addr)         

println“从$ {rxNtf3.from}在$ {rxNtf3.to}接收到的数据是:$ {rxNtf3.data}”

// println“向节点$ addr发送$ {value [3]}”     phy << new DatagramReq(收件人:addr,协议:Protocol.DATA,数据:code [3])     def txNtf4 =接收(TxFrameNtf,1000)     def rxNtf4 = receive({it instanceof RxFrameNtf && it.from == addr},5000)       如果(txNtf4 && rxNtf4 && rxNtf4.from == addr)         

println“从$ {rxNtf4.from}在$ {rxNtf4.to}处接收的数据是:$ {rxNtf4.data}”

}


0 个答案:

没有答案