def receive_prefix(symbols): S = common.take(symbols, len(train.prefix))[:, config.carrier_index] sliced = np.round(S) if pylab: pylab.figure() show.constellation(S, sliced, 'Prefix') bits = np.array(np.abs(sliced), dtype=int) if any(bits != train.prefix): raise ValueError('Incorrect prefix') log.info('Prefix OK') nonzeros = np.array(train.prefix, dtype=bool) pilot_tone = S[nonzeros] phase = np.unwrap(np.angle(pilot_tone)) / (2 * np.pi) indices = np.arange(len(phase)) a, b = sigproc.linear_regression(indices, phase) freq_err = a / (config.Tsym * config.Fc) last_phase = a * indices[-1] + b log.debug('Current phase on carrier: %.3f', last_phase) expected_phase, = set(np.angle(sliced[nonzeros]) / (2 * np.pi)) log.debug('Excepted phase on carrier: %.3f', expected_phase) sampling_err = (last_phase - expected_phase) * config.Nsym log.info('Frequency error: %.2f ppm', freq_err * 1e6) log.info('Sampling error: %.2f samples', sampling_err) return freq_err, sampling_err
def test_linreg(): x = np.array([1, 3, 2, 8, 4, 6, 9, 7, 0, 5]) a, b = 12.3, 4.56 y = a * x + b a_, b_ = sigproc.linear_regression(x, y) assert abs(a - a_) < 1e-10 assert abs(b - b_) < 1e-10