def test_fec_conv_puncture(self): yp_test = [0., 0., 0., 1., 0., 1., 1., 0., 0., 1., 1., 0., 0., 0., 0., 1., 1., 0., 1., 0., 0., 0., 1., 0.] cc1 = fec_conv.fec_conv() x = np.random.randint(0, 2, 20) state = '00' y, state = cc1.conv_encoder(x, state) yp = cc1.puncture(y, ('110', '101')) npt.assert_almost_equal(yp_test, yp)
def test_fec_conv_viterbi_decoder(self): cc1 = fec_conv.fec_conv() x = np.random.randint(0,2,20) state = '00' y, state = cc1.conv_encoder(x, state) z_test = [ 0., 0., 1., 1., 1., 1., 0., 0., 0., 0., 0.] yn = dc.cpx_AWGN(2 * y - 1, 5, 1) yn = (yn.real + 1) / 2 * 7 z = cc1.viterbi_decoder(yn) npt.assert_almost_equal(z_test, z)
def test_fec_conv_conv_encoder(self): cc1 = fec_conv.fec_conv() x = np.random.randint(0, 2, 20) state = '00' y_test, state_test = (np.array([ 0., 0., 0., 0., 1., 1., 0., 1., 1., 0., 1., 0., 0., 1., 1., 1., 0., 0., 0., 0., 0., 0., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0., 1., 1., 1., 0., 1., 1., 1., 1.]), '10') y, state = cc1.conv_encoder(x, state) npt.assert_almost_equal(y_test, y) self.assertEqual(state_test, state)
def test_fec_conv_depuncture(self): zdpn_test = [-0.18077499, 0.24326595, -0.43694799, 3.5, 3.5, 7.41513671, -0.55673726, 7.77925472, 7.64176133, 3.5, 3.5, -0.09960601, -0.50683017, 7.98234306, 6.58202794, 3.5, 3.5, -1.0668518, 1.54447404, 1.47065852, -0.24028734, 3.5, 3.5, 6.19633424, 7.1760269, 0.89395647, 7.69735877, 3.5, 3.5, 1.29889556, -0.31122416, 0.05311373, 7.21216449, 3.5, 3.5, -1.37679829] cc1 = fec_conv.fec_conv() x = np.random.randint(0, 2, 20) state = '00' y, state = cc1.conv_encoder(x, state) yp = cc1.puncture(y, ('110', '101')) ypn = dc.cpx_AWGN(2 * yp - 1, 8, 1) ypn = (ypn.real + 1) / 2 * 7 zdpn = cc1.depuncture(ypn, ('110', '101'), 3.5) # set erase threshold to 7/2 npt.assert_almost_equal(zdpn_test, zdpn)
import numpy as np import sk_dsp_comm.sigsys as ss import scipy.signal as signal import scipy.special as special import sk_dsp_comm.digitalcom as dc import sk_dsp_comm.fec_conv as fec #Como siempre gracias stackoverflow #https://stackoverflow.com/questions/10321978/integer-to-bitfield-as-a-list def bitfield(n): return [int(digit) for digit in '{0:04b}'.format(n)] cc1 = fec.fec_conv(('1111001', '1011011')) #Generamos el arreglo con todos los datos necesarios en formato de bits. #En nuestro testbench tenemos desde 0 a 15, de a 4 bits. int_array = np.arange(0, 16) #Nos quedamos con los ultimos 4 bits o sea los menos significativos bit_array = np.array([bitfield(item) for item in int_array]) bit_array = bit_array.reshape(bit_array.size, 1) #Aca todo perfectamente serializado. Siendo el orden de envio MSb FIRST+ # Cadena a enviar 0x0 0x0 ........................0xE 0xF # Cadena a enviar 0000 0001 1110 1111 y, state = cc1.conv_encoder(bit_array, '0000000') y = np.array(y, dtype=np.int8) y = y.reshape(y.size // 4, 4)[:, ::-1]
def test_fec_conv_Nstates(self): G = ('111', '101') cc = fec_conv.fec_conv(G) self.assertEqual(4, cc.Nstates)
def test_fec_conv_inst(self): cc1 = fec_conv.fec_conv(('101', '111'), Depth=10) # decision depth is 10
import numpy as np from sk_dsp_comm import fec_conv from sk_dsp_comm import digitalcom as dc np.random.seed(100) cc = fec_conv.fec_conv() print(cc.Nstates) import matplotlib.pyplot as plt import numpy as np from sk_dsp_comm import fec_conv as fc SNRdB = np.arange(2,12,.1) Pb_uc = fc.conv_Pb_bound(1/2,5,[1,4,12,32,80,192,448,1024],SNRdB,2) Pb_s = fc.conv_Pb_bound(1/2,5,[1,4,12,32,80,192,448,1024],SNRdB,1) plt.figure(figsize=(5,5)) plt.semilogy(SNRdB,Pb_uc) plt.semilogy(SNRdB,Pb_s) plt.axis([2,12,1e-7,1e0]) plt.xlabel(r'$E_b/N_0$ (dB)') plt.ylabel(r'Symbol Error Probability') #plt.legend(('Uncoded BPSK','R=1/2, K=5, Soft'),loc='best') plt.grid(); plt.show()