mirror of
https://github.com/romanz/amodem.git
synced 2026-02-25 00:31:08 +08:00
Use linear regression in sigproc
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import sigproc
|
||||
import itertools
|
||||
import common
|
||||
import config
|
||||
import numpy as np
|
||||
import random
|
||||
|
||||
|
||||
def test_qam():
|
||||
q = sigproc.QAM(common.symbols)
|
||||
q = sigproc.QAM(config.symbols)
|
||||
r = random.Random(0)
|
||||
m = q.bits_per_symbol
|
||||
bits = [tuple(r.randint(0, 1) for j in range(m)) for i in range(1024)]
|
||||
@@ -16,12 +16,10 @@ def test_qam():
|
||||
assert decoded == bits
|
||||
|
||||
|
||||
def test_drift():
|
||||
fc = 10e3
|
||||
df = 1.23
|
||||
f = fc + df
|
||||
x = np.cos(2 * np.pi * f / common.Fs * np.arange(common.Fs))
|
||||
S = sigproc.extract_symbols(x, fc)
|
||||
S = np.array(list(S))
|
||||
df_ = sigproc.drift(S) / common.Tsym
|
||||
assert abs(df - df_) < 1e-5, (df, df_)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user