veeresht / CommPy

Digital Communication with Python
http://veeresht.github.com/CommPy
BSD 3-Clause "New" or "Revised" License
551 stars 179 forks source link

MAP decoder for convolutional codes #97

Closed postrou closed 3 years ago

postrou commented 3 years ago

In the README it is stated, that there is a MAP decoder for convolutional codes, based on BCJR. But I can't find it. Only the one for turbo codes. Did I miss it?

BastienTr commented 3 years ago

I'm not sure as I'm not a BCJR specialist but I think that this looks like the MAP BCJR decoder for convolutionnal codes:

https://github.com/veeresht/CommPy/blob/5dba9a496835313fec7076407daddcbc702dfa09/commpy/channelcoding/turbo.py#L163-L167

The BCJR turbo code is just below: https://github.com/veeresht/CommPy/blob/5dba9a496835313fec7076407daddcbc702dfa09/commpy/channelcoding/turbo.py#L254-L259

However, I don't know why this convolutionnal decoder is in the turbo file.

postrou commented 3 years ago

But map_decode needs two encoder outputs as its inputs: sys_symbols and non_sys_symbols, and conv_encode gives only one output. Also in the original article about BCJR I haven't found anything about multiple inputs to decoder.

BastienTr commented 3 years ago

Let' have a look to the doc: https://github.com/veeresht/CommPy/blob/5dba9a496835313fec7076407daddcbc702dfa09/commpy/channelcoding/turbo.py#L166-L178

My understanding is that the decoder is designed for systematic convolutional code with rate 1/2. sys_symbol corresponds to the systematic part and non_sys_symbols to the other ones. This can be checked with the following code.

import numpy as np
import commpy.channelcoding as cc
from numpy.testing import assert_equal

treillis = cc.convcode.Trellis(np.array(2, ndmin=1), np.array((1, 7), ndmin=2))
message = np.random.choice((0, 1), 10000)
coded = cc.convcode.conv_encode(message, treillis, 'cont')
decoded = cc.turbo.map_decode(coded[::2], coded[1::2], treillis, chan.noise_std**2, np.zeros_like(coded[::2]))

assert_equal(decoded[1], message)

BTW do you think that this code should be added in commpy as a test file?

postrou commented 3 years ago

Thanks! Yes, I think, it should be added.