mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 05:36:42 +08:00
fix training scaling factor
This commit is contained in:
@@ -7,14 +7,14 @@ log = logging.getLogger(__name__)
|
|||||||
Fs = 32e3
|
Fs = 32e3
|
||||||
Ts = 1.0 / Fs
|
Ts = 1.0 / Fs
|
||||||
|
|
||||||
frequencies = (1 + np.arange(1)) * 1e3
|
frequencies = (1 + np.arange(2)) * 1e3
|
||||||
carrier_index = 0
|
carrier_index = 0
|
||||||
Fc = frequencies[carrier_index]
|
Fc = frequencies[carrier_index]
|
||||||
Tc = 1.0 / Fc
|
Tc = 1.0 / Fc
|
||||||
|
|
||||||
symbols = np.array([complex(x, y)
|
symbols = np.array([complex(x, y)
|
||||||
for x in np.linspace(-1, 1, 4)
|
for x in np.linspace(-1, 1, 8)
|
||||||
for y in np.linspace(-1, 1, 4)]) / np.sqrt(2)
|
for y in np.linspace(-1, 1, 8)]) / np.sqrt(2)
|
||||||
|
|
||||||
Tsym = 1e-3
|
Tsym = 1e-3
|
||||||
Nsym = int(Tsym / Ts)
|
Nsym = int(Tsym / Ts)
|
||||||
|
|||||||
11
recv.py
11
recv.py
@@ -78,20 +78,19 @@ def receive_prefix(symbols):
|
|||||||
|
|
||||||
def train_receiver(symbols, freqs):
|
def train_receiver(symbols, freqs):
|
||||||
filters = {}
|
filters = {}
|
||||||
full_scale = len(freqs)
|
scaling_factor = len(freqs) # to avoid saturation
|
||||||
training = np.array(train.equalizer)
|
training = np.array(train.equalizer)
|
||||||
expected = full_scale * training
|
|
||||||
if pylab:
|
if pylab:
|
||||||
pylab.figure()
|
pylab.figure()
|
||||||
|
|
||||||
for i, freq in enumerate(freqs):
|
for i, freq in enumerate(freqs):
|
||||||
S = take(symbols, i, len(expected))
|
S = take(symbols, i, len(training))
|
||||||
|
|
||||||
filt = sigproc.train(S, expected)
|
filt = sigproc.train(S, training * scaling_factor)
|
||||||
filters[freq] = filt
|
filters[freq] = filt
|
||||||
|
|
||||||
S = list(filt(S))
|
S = list(filt(S))
|
||||||
y = np.array(S)
|
y = np.array(S) / scaling_factor
|
||||||
if pylab:
|
if pylab:
|
||||||
pylab.subplot(HEIGHT, WIDTH, i+1)
|
pylab.subplot(HEIGHT, WIDTH, i+1)
|
||||||
show.constellation(y, 'Train: $F_c = {}Hz$'.format(freq))
|
show.constellation(y, 'Train: $F_c = {}Hz$'.format(freq))
|
||||||
@@ -100,7 +99,7 @@ def train_receiver(symbols, freqs):
|
|||||||
if not all(train_result == training):
|
if not all(train_result == training):
|
||||||
raise ValueError('#{} training failed on {} Hz'.format(i, freq))
|
raise ValueError('#{} training failed on {} Hz'.format(i, freq))
|
||||||
|
|
||||||
noise = y - expected
|
noise = y - training
|
||||||
Pnoise = sigproc.power(noise)
|
Pnoise = sigproc.power(noise)
|
||||||
log.info('%10.1f kHz: Noise sigma=%.4f, SNR=%.1f dB',
|
log.info('%10.1f kHz: Noise sigma=%.4f, SNR=%.1f dB',
|
||||||
freq/1e3, Pnoise**0.5, 10*np.log10(1/Pnoise))
|
freq/1e3, Pnoise**0.5, 10*np.log10(1/Pnoise))
|
||||||
|
|||||||
Reference in New Issue
Block a user