Advanced maths

Binary convolutional code calculator with trellis encoding and Viterbi decoding

Encode a short binary stream with polynomial shift-register taps, or decode its zero-terminated trellis using exact hard-decision Viterbi search.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Encode a short binary stream with polynomial shift-register taps, or decode its zero-terminated trellis using exact hard-decision Viterbi search.

THE FORMULAc_j(t)=parity(g_j AND register(t)); D_t(s)=min over predecessor branches of D_(t−1)(s_prev)+Hamming(branch output,received block).

A worked example

For memory2 and tap masks[7,5], message1011 followed by two zero-tail bits encodes as11 10 00 01 01 11. Decoding111000010111 returns message1011 with Hamming distance0.

Good to know

Binary rate1/r feed-forward encoders with r2–3, memory1–5 and at most200 information bits; zero start and zero-tail termination stated explicitly. Hard-decision Hamming metric initially, exact Viterbi dynamic programming, tie counts and selected path. Validate generator taps and catastrophic/common-factor conditions. No soft-decision, punctured or tail-biting decoder silently implied.

Memory distinguishes a convolutional code

A convolutional encoder forms each output block from the current input bit and a fixed number of previous bits. Its memory means the same current bit can produce different outputs in different states. A trellis records the finite memory state at every time step, allowing paths that share a state to merge even though their earlier input histories differed.

This is different from treating one fixed-length message as an arbitrary linear block codeword. The stream, shift-register convention and termination rule define which paths are legal. The calculator supports a small binary feed-forward model, with one input bit producing r output bits. It does not infer an encoder from a received sequence or claim that every noisy sequence identifies its original sender’s message.

The terminated encoder path returns to the zero state0121320Input: 1 0 1 1 | 0 0 tail; output: 11 10 00 01 01 11
Scroll across to see the full diagram.
For memory2 and tap masks[7,5], message1011 followed by two zero-tail bits encodes as11 10 00 01 01 11. Decoding111000010111 returns message1011 with Hamming distance0.

Compare this with the Linear code syndrome decoding calculator with all nearest codewords. Encode a bit stream using polynomial shift-register taps and decode a terminated trellis by minimum path metric. Existing finite block-code nearest-word decoding and Reed–Solomon polynomial evaluation do not expose memory states, termination or a convolutional trellis.

Interpret taps and state bits explicitly

A nonzero integer tap mask names the binary coefficients of one generator polynomial. Bit0 multiplies the current input, bit1 the previous input, and subsequent bits older memory positions. The register used for an output is formed by shifting the old state left and inserting the current bit at the least-significant position; output bits are parities selected by the masks.

Declare the memory separately and keep every tap within that register width. The generator list fixes the output order within each coded block. Reversing mask bits, reversing transmitted output order or using a different shift convention creates a different encoder unless the rest of the interpretation is changed consistently. The displayed state/output trace should make these conventions checkable.

Start and terminate at the zero state

The supported frame starts with every memory bit zero. Encoding appends exactly the declared number of zero input bits after the information message, flushing the register back to zero. Those tail outputs are transmitted and belong to the received frame when decoding. They add overhead and must not be discarded before the trellis endpoint condition is enforced.

This model is not tail biting, in which the starting state is chosen to equal an unknown ending state, and it is not an unterminated streaming decoder with a guessed traceback delay. A received length must be divisible by the number of generator masks. It must also contain enough time steps for the zero tail. Endpoint and tail conventions are part of the valid path set, not cosmetic reporting choices.

Decode by dynamic programming

For each time step and each register state, retain the minimum accumulated Hamming distance among paths reaching that state. An incoming branch adds the number of differing bits between its predicted coded block and the received block. Future costs depend on the current state, so a more expensive path to the same state can be discarded without losing the best complete hard-decision decode.

Traceback records a predecessor for a selected best path. If several paths attain the same metric, the page must report the tie convention rather than imply unique recovery. A minimum-distance path is optimal under the stated Hamming metric, but it need not be the originally transmitted path when too many errors occur. No channel-error probability is calculated merely from that path metric.

Check the default encoded frame

Use tap masks7 and5, representing binary111 and101, with memory two. Starting from state zero, information bits1011 and tail00 produce six coded blocks:11,10,00,01,01 and11. The register returns to zero after the final tail bit, matching the termination requirement. The concatenated transmitted frame is111000010111.

With that same frame supplied noiselessly, the selected terminated path has accumulated Hamming distance zero and recovers information bits1011 after removing the two tail inputs. Changing one received bit creates a different metric comparison; it should not be repaired by comparing only with the displayed example message. The decoder searches its full legal trellis independently of the encoding demonstration.

Validate the generator convention

Zero masks, masks beyond the declared memory width and incompatible input lengths should be rejected. The implementation also needs an explicit policy for catastrophic or common-factor generator choices. A common polynomial factor can create problematic encoders, so a simple-looking tap list should not automatically be described as a production-quality error-correcting code.

All polynomial arithmetic for tap validation is over the binary field, where addition is exclusive-or. Integer gcd is not the relevant common-factor test. If noncatastrophic generator choices are required by the implementation, unsupported masks should produce a clear error. Hard decisions, puncturing, soft metrics and recursive feedback are separate capabilities and must not be implied by a generic Viterbi label.

Verify the returned path

Re-encode the decoded information bits with the same zero tail and compare every output block with the received frame. Their total Hamming distance must equal the reported optimum metric. Independently enumerating all messages for a short frame gives a strong reference check for the dynamic program, including ties and start/end states.

The small memory and frame limits bound both the state count and traceback storage. This calculator explains finite trellis encoding and exact bounded hard-decision decoding; it is not a real-time communications implementation, a cryptographic primitive or a performance estimate for a particular radio link. Preserve the tap order, state convention and termination rule whenever exporting a result.

A few questions, answered

Are zero-tail outputs part of the received frame?

Yes. The decoder expects the coded outputs generated while the appended zeros flush the state back to zero.

Does minimum distance prove the original message was recovered?

No. It identifies an optimum path under the stated hard-decision model; enough noise can make a different message closer.

What does tap bit0 mean?

It selects the current input bit; higher mask bits select progressively older memory positions.

Does this support soft-decision or tail-biting decoding?

No. The initial scope is zero-start, zero-tail binary feed-forward encoding with Hamming branch metrics.

Find your calculator

Start typing to explore the library.