前言:
前面讲了SPC(3,2) 这里扩展一下到SPC(n,n-1)
发送的数据长度为n-1,经过SPC编码形成长度为n的
codeword.
目录
1: 总体流程
2:简化算法
3: code
一 总体流程
前面知道
intrinsic LLR
主要还是在计算extrinsic LLR ,在SPC(3,2)中,以L1为例
同理我们可以得到
更为通用的是:
证明方法: 通过数学归纳法,参考SPC(3,2),它依然是一个tanh 函数连乘
二 简化算法
2.1 符号计算
sgn=1: 对应c=0,奇偶校验成功,保持不变
sgn=-1: 对应c=1, 奇偶校验失败, 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()