mirror of
https://github.com/romanz/amodem.git
synced 2026-04-23 06:46:27 +08:00
replace extract_symbols into frequency demultiplexer
This commit is contained in:
@@ -212,16 +212,15 @@ def demodulate(symbols, filters, freqs, sampler):
|
|||||||
|
|
||||||
|
|
||||||
def receive(signal, freqs, gain=1.0):
|
def receive(signal, freqs, gain=1.0):
|
||||||
signal = sigproc.FreqLoop(signal, freqs)
|
symbols = sigproc.Demux(signal, freqs)
|
||||||
signal.sampler.gain = gain
|
symbols.sampler.gain = gain
|
||||||
symbols = iter(signal)
|
|
||||||
|
|
||||||
freq_err, offset_err = receive_prefix(symbols)
|
freq_err, offset_err = receive_prefix(symbols)
|
||||||
signal.sampler.offset -= offset_err
|
symbols.sampler.offset -= offset_err
|
||||||
signal.sampler.freq -= freq_err
|
symbols.sampler.freq -= freq_err
|
||||||
|
|
||||||
filters = train_receiver(symbols, freqs)
|
filters = train_receiver(symbols, freqs)
|
||||||
data_bits = demodulate(symbols, filters, freqs, signal.sampler)
|
data_bits = demodulate(symbols, filters, freqs, symbols.sampler)
|
||||||
return itertools.chain.from_iterable(data_bits)
|
return itertools.chain.from_iterable(data_bits)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy import linalg
|
from numpy import linalg
|
||||||
import itertools
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
from . import sampling
|
from . import sampling
|
||||||
from . import common
|
from . import common
|
||||||
@@ -60,19 +62,21 @@ class QAM(object):
|
|||||||
yield self._dec[S]
|
yield self._dec[S]
|
||||||
|
|
||||||
|
|
||||||
class FreqLoop(object):
|
class Demux(object):
|
||||||
def __init__(self, src, freqs):
|
def __init__(self, src, freqs):
|
||||||
interp = sampling.Interpolator()
|
interp = sampling.Interpolator()
|
||||||
self.sampler = sampling.Sampler(src, interp)
|
self.sampler = sampling.Sampler(src, interp)
|
||||||
self.gens = []
|
self.filters = [exp_iwt(-f, Nsym) / (0.5*Nsym) for f in freqs]
|
||||||
|
self.filters = np.array(self.filters)
|
||||||
samplers = itertools.tee(self.sampler, len(freqs))
|
|
||||||
for freq, generator in zip(freqs, samplers):
|
|
||||||
gen = extract_symbols(generator, freq)
|
|
||||||
self.gens.append(gen)
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return common.izip(*self.gens)
|
return self
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
frame = common.take(self.sampler, Nsym)
|
||||||
|
return np.dot(self.filters, frame)
|
||||||
|
|
||||||
|
__next__ = next
|
||||||
|
|
||||||
|
|
||||||
class MODEM(object):
|
class MODEM(object):
|
||||||
@@ -111,13 +115,6 @@ def coherence(x, freq):
|
|||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
def extract_symbols(x, freq, offset=0):
|
|
||||||
Hc = exp_iwt(-freq, Nsym) / (0.5*Nsym)
|
|
||||||
|
|
||||||
for _, symbol in common.iterate(x, Nsym):
|
|
||||||
yield np.dot(Hc, symbol)
|
|
||||||
|
|
||||||
|
|
||||||
def linear_regression(x, y):
|
def linear_regression(x, y):
|
||||||
''' Find (a,b) such that y = a*x + b. '''
|
''' Find (a,b) such that y = a*x + b. '''
|
||||||
x = np.array(x)
|
x = np.array(x)
|
||||||
|
|||||||
Reference in New Issue
Block a user