def symbol_recovery_24(xdi, xdq):
angles = numpy.where(xdi >= 0, numpy.arctan2(xdq, xdi), numpy.arctan2(-xdq, -xdi))
theta = (signal.convolve(angles, smooth)) [-len(xdi):]
xr = (xdi + 1j * xdq) * numpy.exp(-1j * theta)
bi = (numpy.real(xr) >= 0) + 0
# pll parameters
period = 24
halfPeriod = period / 2
corr = period / 24.
phase = 0
res = []
pin = 0
stats = {0: 0, 1: 1}
oddity = 0
latestXrSquared = [0]*8
lxsIndex = 0
theta = [0]
shift = 0
# pll, system model, error calculation, estimate update
for i in range(1, len(bi)):
if bi[i-1] != bi[i]:
if phase < halfPeriod-2:
phase += corr
elif phase > halfPeriod+2:
phase -= corr
if phase >= period:
phase -= period
latestXrSquared[lxsIndex] = (xdi[i] + 1j * xdq[i])**2
lxsIndex += 1
if lxsIndex >= len(latestXrSquared):
lxsIndex = 0
th = shift + cmath.phase(sum(latestXrSquared)) / 2
if abs(th - theta[-1]) > 2:
if th < theta[-1]:
shift += math.pi
th += math.pi
else:
shift -= math.pi
th -= math.pi
theta.append(th)
oddity += 1
if oddity == 2:
oddity = 0
yp = (xdi[i] + 1j * xdq[i])
ypp = cmath.exp(-1j * th) * yp
# bit decode
nin = 1 * (ypp.real > 0)
stats[nin] += 1
res.append(pin ^ nin)
pin = nin
phase += 1
return res
评论列表
文章目录