SISO decoder for a general (n,n-1) SPC code(补充章节3)

前言:

           前面讲了SPC(3,2) 这里扩展一下到SPC(n,n-1)

发送的数据长度为n-1,经过SPC编码形成长度为n的

codeword.

目录

   1: 总体流程

   2:简化算法

   3: code


一 总体流程

前面知道

intrinsic LLR

    L_i = \frac{2}{\sigma^2}r_i

   L_i = L_i+L_{ext,i}

主要还是在计算extrinsic LLR ,在SPC(3,2)中,以L1为例

    sign(L_{ext,1})=sign(L_2)sign(L_3)

    |L_{ext,1}|=f(f(L_2)+f(L_3)) \approx min(|L_2|,|L_3|)

    f(x)=|log tan\frac{|x|}{2}|

 同理我们可以得到

   sign(L_{ext,1})=sign(L_2)sign(L_3)...sign(L_n)

   |L_{ext,1}|=min\begin{Bmatrix} |L_2|,|L_3|,...|L_n| \end{Bmatrix}

更为通用的是:

  L_{ext,i}=sign(L_1)sign(L_2)...sign(L_{i-1})sign(L_{i+1})..sign(L_{i})min\begin{Bmatrix} L_1,L_2,...L_{i-1},L_{i+1},..L_{n} \end{Bmatrix}

证明方法: 通过数学归纳法,参考SPC(3,2),它依然是一个tanh 函数连乘 

 


二 简化算法

   2.1 符号计算

    sgn= sgn(L_1)sgn(L_2)...sgn(L_n)

    sgn(L_i)=sgn(L_i)*sgn

   sgn=1: 对应c=0,奇偶校验成功,保持L_i不变

   sgn=-1:  对应c=1, 奇偶校验失败,L_i  Flip

 2.2 大小计算

      跟SPC(3,2)一样,这里可以用一种更加简单的方法,不需要每次重新划分自己

 

   


三 code 

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 10 09:23:37 2022

@author: chengxf2
"""
import numpy as np

"""
AWGN: QPSK 调制后,加入噪声,这里假设发送的都是1(0->1)
args
   std: 标准差
   mu:  均值
   n: 样本个数
"""
def sendmessage(mu=0,sigma=1.0,n=6):
    
    #np.random.seed(5)
    s = 1.0+ np.random.normal(mu, sigma, n)
    #sr = 1+std*np.random.randn(1,n)
    print("\n step1 发送数据: ", s)
    return s
    


'''
获取channel LLR, intrinsic
args
   rList: 来自信道本身的LLR
   sigma: 方差
   n: 样本个数
'''
def getIntrLLR(rList, sigma,n=6):
    
    left = 2.0/sigma
    llrList = []
    for r in rList:
        llr = np.round(left*r,2)
        llrList.append(llr)
        
    print("\n step2  intrinsic llr ",llrList)
    return llrList

'''
获得符号函数
arg
  llr: 似然比
return
   符号
'''
def  sign(llr):
    if llr>0:
        return 1
    else:
        return -1


'''
获得符号,hardDecsion 过程
args 
   llrList
return
    sgn: 总体的sign
    sgnList: 每个的sign
'''
def getSign(llrList):
    sgn = 1
    sgnList = []
    for llr in llrList:
        sgn_i = sign(llr)
        sgnList.append(sgn_i)
        sgn = sgn*sign(llr)
    print("\n step3  get sign",sgn,"\t sgnList ",sgnList)
    return sgn,sgnList

'''
找到最小值,以及位置, 找到次小值
'''
def minimum(llrList):
    
    
    #llrList.sort()
    print("\n step4 minimum",llrList)
    
    n = len(llrList)
    min1 = llrList[0]
    min2 = llrList[0]
    minpos = 0
   
    
    for i in range(1,n):
        llr = llrList[i]
        if llr<min1:
            min1 = llr
            minpos = i
        else:
            min2 = llr #保证min2 肯定比min1 大就行了
    #print("\n min1: %4.2f  minpos: %d"%(min1,minpos))
    
    for j in range(n):
        llr = llrList[j]
        if j==minpos:
            continue
        
        if llr<min2:
            min2 = llr
    print("\n min1: %4.2f  minpos: %d  min2: %4.2f "%(min1,minpos,min2))
    return min1,min2, minpos
        
    
def getextrinsic(sgn, sgnList,min1,min2, minpos):
       n = len(sgnList)
       sgn_extrinsic = np.multiply(sgn, sgnList)
       print("\n sgn_extrinsic ",sgn_extrinsic,)
       
       extrinsicLLR =[]
       
       for i in range(n):
           if i == minpos:
               llr = min2
           else:
               llr = min1
           extrinsicLLR.append(llr)
           
       extLLR = np.multiply(sgn_extrinsic, extrinsicLLR)
       print("\n extLLR ",extLLR)
       return extLLR
       


'''
更新llr
'''       
def updateLLR(intrinsicLLR, extrinsicLLR):

     llr = intrinsicLLR+extrinsicLLR
     print("\n llr ",llr)        
        
        
        
        
    
        

if __name__ =="__main__":
    
    sigma = 0.8**2
    
    s = sendmessage(0, sigma, 6)
    intLLR = getIntrLLR(s, sigma)
    sgn,sgnList = getSign(intLLR)
    absLLR = np.abs(intLLR)
    min1,min2, minpos =minimum(absLLR)
    
    extLLR =getextrinsic(sgn,sgnList,min1,min2, minpos)
    
    updateLLR(intLLR, extLLR)

   

 

 

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 10 08:44:34 2022

@author: chengxf2
"""
#-*-coding:utf-8-*-
"""
python绘制标准正态分布曲线
"""
# ==============================================================
import numpy as np
import math
import matplotlib.pyplot as plt


def gd(x, mu=0, sigma=1.0):
  """生成数据

  Argument:
    x: array
      输入数据(自变量)
    mu: float
      均值
    sigma: float
    方差
  """
  
  left = 1 / (np.sqrt(2 * math.pi) * np.sqrt(sigma))
  right = np.exp(-(x - mu)**2 / (2 * sigma))
  return left * right


if __name__ == '__main__':
  # 自变量
  x = np.arange(-4, 5, 0.1)
  # 因变量(不同均值或方差)
  y_1 = gd(x, 0, 2.0)
  y_2 = gd(x, 0, 1.0)
  y_3 = gd(x, 0, 5.0)
  y_4 = gd(x, 0, 0.2)

  # 绘图
  plt.plot(x, y_1, color='green')
  plt.plot(x, y_2, color='blue')
  plt.plot(x, y_3, color='yellow')
  plt.plot(x, y_4, color='red')
  # 设置坐标系
  plt.xlim(-5.0, 5.0)
  plt.ylim(-0.2, 1)
  #由于axes会获取到四个轴,而我们只需要两个轴,所以我们需要把另外两个轴隐藏,把顶部和右边轴的颜色设置为none,将不会显示
  ax = plt.gca()
  ax.spines['right'].set_color('none')
  ax.spines['top'].set_color('none')
  ax.xaxis.set_ticks_position('bottom')
  ax.spines['bottom'].set_position(('data', 0))
  ax.yaxis.set_ticks_position('left')
  ax.spines['left'].set_position(('data', 0))

  plt.legend(labels=['$\mu = 0, \sigma^2=2.0$', '$\mu = 0, \sigma^2=1.0$', '$\mu = 0, \sigma^2=5.0$', '$\mu = 0, \sigma^2=0.2$'])
  plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值