fix drift correction demo

This commit is contained in:
Roman Zeyde
2014-07-20 13:21:56 +03:00
parent 48e8b13e53
commit 048e52574a

View File

@@ -2,43 +2,22 @@ import numpy as np
import pylab
import common
import sigproc
import loop
def main():
f0 = 10e3
_, x = common.load(file('recv_10kHz.pcm', 'rb'))
x = x[100:]
t = np.arange(0.1*common.Fs) * common.Ts
f = common.Fc * (1 + 10e-6)
x = np.sin(2*np.pi*f*t)
fl = loop.FreqLoop(iter(x), [common.Fc])
S = []
Y = []
S = []
gain = common.Nsym / (2*np.pi)
for s, in fl:
y = np.round(s)
if abs(y) > 0:
err = -np.angle(s / y) * gain
S.append([err])
fl.sampler.offset += 0.5*err
prefix = 100
symbols = loop.FreqLoop(x, [f0])
for s, in symbols:
S.append(s)
if len(S) > prefix:
symbols.correct(s, np.mean(S[:prefix]))
Y.append([
symbols.correction * (f0 / common.Nsym),
])
S = np.array(S)
pylab.figure()
pylab.subplot(121)
circle = np.exp(2j*np.pi*np.linspace(0, 1, 1001))
pylab.plot(S.real, S.imag, '.', circle.real, circle.imag, ':')
pylab.grid('on')
pylab.axis('equal')
Y = np.array(Y)
a = 0.01
pylab.subplot(122)
pylab.plot(list(sigproc.lfilter([a], [1, a-1], Y)), '-')
pylab.grid('on')
if __name__ == '__main__':
main()
pylab.show()
S = np.array(S)
pylab.plot(S)
pylab.show()