Closed londumas closed 3 years ago
The sizes are message_bits.shape = (100000,)
and decoded_soft.shape = (100004,)
. This is very strange.
Taking all but the last 4 bits gives a very bad result of ~ 0.5 error, indeed the bits after the first few are very different.
I simply replaced by:
NumErr, BER_soft[cntr] = BER_calc(message_bits, decoded_soft[:-4]) # bit-error ratio (soft decision)
NumErr, BER_hard[cntr] = BER_calc(message_bits, decoded_hard[:-4]) # bit-error ratio (hard decision)
It gives very poor results:
Soft decision:
0.498325
Hard decision:
0.49850700000000003
Uncoded message:
0.008961
np.mean(np.abs(message_bits[:10]-decoded_soft[:10]))
0.0
np.mean(np.abs(message_bits[:100]-decoded_soft[:100]))
0.0
np.mean(np.abs(message_bits[:1000]-decoded_soft[:1000]))
0.368
Fixed in PR https://github.com/veeresht/CommPy/pull/92
I do not know where the hexadecimal matrix came from np.array([[0o171, 0o133]])
, but it produces a wrong looking modulation.
The bits are only encoded into the bottom symbols.
import numpy as np
import commpy.channelcoding.convcode as cc
import commpy.modulation as modulation
import matplotlib.pyplot as plt
###
N = 124
###
M = 4
modem = modulation.PSKModem(M)
###
message_bits = np.random.randint(0, 2, N)
modulated_uncoded = modem.modulate(message_bits)
plt.errorbar(np.real(modulated_uncoded),np.imag(modulated_uncoded),fmt='o',label='modulated+uncoded')
###
generator_matrix = np.array([[5, 7]])
trellis = cc.Trellis(np.array([M]), generator_matrix)
coded_bits = cc.conv_encode(message_bits, trellis)
modulated = modem.modulate(coded_bits)
plt.errorbar(np.real(modulated)+0.05,np.imag(modulated)+0.05,fmt='o',label='modulated+coded matrix [5, 7]')
###
generator_matrix = np.array([[0o171, 0o133]])
trellis = cc.Trellis(np.array([M]), generator_matrix)
coded_bits = cc.conv_encode(message_bits, trellis)
modulated = modem.modulate(coded_bits)
plt.errorbar(np.real(modulated)-0.05,np.imag(modulated)-0.05,fmt='o',label='modulated+coded matrix [0o171, 0o133]')
###
plt.xlabel('I')
plt.ylabel('Q')
plt.legend()
plt.grid()
plt.show()
size mismatch in channel coding README