# Conventional channel coding/decoding

I am trying to understand the algorithms of channel coding. Regarding the conventional channel which is, for me, the easiest one to implement, I have a question regarding the output of its decoder.

When using encoder whose rate is 1/2, the output of the decoder is half of its input, for example:

constlen = 7;  codegen = [171 133];
tblen = 32;     % traceback length
trellis = poly2trellis(constlen, codegen);

X = randi([0 1], 1024,1);        %The data to encdoe
Y = convenc(X, trellis);        %Performing of coding
Y_dec = vitdec(Y, trellis, tblen, 'cont', 'hard');  %The decoder


As you see, in last line, Y_dec is of length 1024. However, its input Y has a length of 2048. What I need is to show the whole corrected outputs, I mean I need to have the output Y_dec of length 2048 which includes the data and the redundancy. Is that feasible?

EDIT:

Following Dilip's feedback, I could get back it as below:

constlen = 7;  codegen = [171 133];
tblen = 32;     % traceback length
trellis = poly2trellis(constlen, codegen);

X = randi([0 1], 1024,1);        %The data to encdoe
Y = convenc(X, trellis);        %Performing of coding
Y_dec = vitdec(Y, trellis, tblen, 'cont', 'hard');  %The decoder
Y2 = convenc(Y_dec(1+tblen:end), trellis);
Y3 = Y(1:end-2*tblen) - Y2;     % This is Zero


But as you see, it means that a part of code word can be found which is Y2 = Y(1:end-2*tblen). however the code word size is $$2048$$, so is there a way to get all the codeword?

• You may be thinking of systematic codes, which this convolutional code is not. For a systematic block code (like Reed Solomon) you do recover all the coded bits: the data plus the redundancy. Jul 20 '20 at 18:45
• @P2000 I tried using LDPC with ofdm, which is also systematic , but I didn't get good results. do you have an example code which is using LDPC with OFDM ? Jul 21 '20 at 4:01
• That sounds like a different question. Perhaps you could post it. 802.11n/ac/ax uses OFDM with LDPC. Jul 21 '20 at 4:57
• OK .. thank you Jul 21 '20 at 5:03

Yes, it is possible to determine the path that the Viterbi algorithm found through the trellis. Just apply the encoding algorithm to what you are calling Y_dec and you will get the corresponding codeword of length $$2048$$. You can then compare it to Y, the transmitted codeword, to see where the channel made errors.

Additional notes: If the data to be transmitted 1024 information bits and the code to be used is a half-rate $$(2,1)$$ convolutional code with constraint length $$7$$, then the convolutional codeword produced by the convolutional encoder is $$2060 = 2048+12 = (2\times 1024) + 2\times 6$$ bits long where the extra $$12$$ bits are produced by the encoder as zeroes are pumped into the $$6$$-bit-long data buffer as the buffer empties out. I don't speak MATLABian gobbledygook at all and so don't know what Y_dec(1+tblen:end) means, or indeed why tblen is involved at all. If Y = convenc(X, trellis) produces a codeword vector Y of 2060 bits, then Y_dec = vitdec(Y, trellis, tblen, 'cont', 'hard') should produce X again. I don't see where there was any noise involved and so the Viterbi decoder should just zoom through the trellis following the same path as the encoder so that Y_dec should equal X. If there is noise, then Y_dec should be the same as X in most of the 1024 bits except for some bursts of errors in that span. In this case, convenc(Y_dec, trellis) will not be the same as Y, but in the absence of any channel errors, Y_dec=X and convenc(Y_dec, trellis)=convenc(X, trellis)=Y.

• Thank you for your feedback, when I do encoding for the whole 'Y_dec', I don't get the same codeword 'Y' , but when I did it as I added above, I can get it. However, it's not the whole codeword. So, is there a way to get back the whole codeword? Jul 21 '20 at 3:49
• Hi Dilip. but when I use the encoder 'Y = convenc(X, trellis)' with variable $X$ of length $1024$, it gives the codeword whose length is $2048$, it's not $2060$; for that I delete the first $32$ bits. Jul 22 '20 at 11:55
• Wait for a MATLAB expert (there are many on this forum) to respond. You need to figure out what options you need to give to vitenc or something similar to get a terminated convolutional code. Jul 22 '20 at 14:41

That is the whole point of decoding: to get the original sequence back, if possible. So, this is doing exactly what you'd want. In many decoders (such as the Viterbi), the transmitted code bit sequence is never explicitly recovered anywhere.

As Dilip's answer shows: You can, however, determine the original transmit sequence by re-encoding the decoded bits.

Now, the only purpose of that (far as I can think of) would be to compare that with the receive signal in order to e.g. update a phase error or frequency error estimate. But, that's not subject of channel coding.

• Not sure why the downvote. Marcus makes a good point. Moreover, recovering the transmitted sequence is part of decision directed equalizer adaptation, and unfortunately it does not come free with convolutional codes. Jul 21 '20 at 5:03
• @P2000 I agree with you. Marcus always help. I upvoted his answer Jul 21 '20 at 5:16
• Hi Marcus, What you mean that's not subject of channel coding? ... You can that's not feasible ? Jul 23 '20 at 13:39
• no, channel estimation is not the scope of channel coding. Jul 23 '20 at 14:22