微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

维特比解码器 k=4

如何解决维特比解码器 k=4

在 k=3 格子图中,我使用此代码将距离相加并选择最短的距离

tmpPrevstate=[]
    for a in range(4): 
        if tmpdist[0,2 * a + 0] <= tmpdist[0,2 * a + 1]:
            cumdist[a] = tmpdist[0,2 * a + 0]
            tmpPrevstate.append((a % 2) * 2 + 0)
        else:
            cumdist[a] = tmpdist[0,2 * a + 1]
            tmpPrevstate.append((a % 2) * 2 + 1)
    prevstate.append(tmpPrevstate)

我将范围设置在 0~3 之间,因为 K=3 状态图中有 4 个状态 但是在 k=4 环境中,Diagram 中有 8 个状态,因此我将范围更改为 0~7,但是此解码器无法正常工作

在此之下,是我的整个编解码器代码

 import numpy as np

def Encoder(data):
data = np.append(data,[0,0])#shift Register
dataSize = np.shape(data)[0] #(64,)
shiftReg = [0,0] #k=4
encoded_bit = np.zeros((2,dataSize)

for i in range(dataSize):
    shiftReg[3] = shiftReg[2]
    shiftReg[2] = shiftReg[1]
    shiftReg[1] = shiftReg[0]
    shiftReg[0] = data[i]
    encoded_bit[0,i] = np.logical_xor(np.logical_xor(shiftReg[0],shiftReg[1]),np.logical_xor(shiftReg[2],shiftReg[3]))
    encoded_bit[1,shiftReg[2]),shiftReg[3])
return encoded_bit

def ViterbiDecoder(encoded_bit):
ref_out = np.zeros((2,16))
ref_out[0,:] = [0,1,1]
ref_out[1,0]
dataSize = np.shape(encoded_bit)[1] 
cumdist = [0,100,100] 

prevstate = []
for i in range(dataSize):
    tmpData = np.tile(encoded_bit[:,i].reshape(2,1),(1,16))
    dist = np.sum(np.abs(tmpData - ref_out),axis=0) 
    tmpdist = np.tile(cumdist,2)) + dist

    tmpPrevstate=[]
    for a in range(8): 
        if tmpdist[0,2 * a + 1]
            tmpPrevstate.append((a % 2) * 2 + 1)
    prevstate.append(tmpPrevstate)
    state_index = np.argmin(cumdist)
   

decoded_bit=[]
for b in range(dataSize-1,-1,-1):
    decoded_bit.append(int(state_index/2))
    state_index = prevstate[b][state_index]
data_size = np.shape(decoded_bit)[0]
decoded_bit = np.flip(decoded_bit)[0:data_size - 4]
return decoded_bit

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。