pub struct Trellis { /* private fields */ }Expand description
The trellis of a rate-$1/n$ binary convolutional code, built by
Trellis::feedforward or Trellis::recursive (its fields are read through
getters, so that the tables always agree with the constraint length and the number
of outputs).
Implementations§
Source§impl Trellis
impl Trellis
Sourcepub fn constraint(&self) -> u32
pub fn constraint(&self) -> u32
Constraint length $K$ (memory $K - 1$).
Sourcepub fn out(&self) -> &[[u32; 2]]
pub fn out(&self) -> &[[u32; 2]]
out()[s][u]: the coded bits of the branch, the first output in the most
significant position.
Sourcepub fn tail(&self) -> &[u8] ⓘ
pub fn tail(&self) -> &[u8] ⓘ
tail()[s]: the input that drives state s towards zero (0 for feed-forward
codes).
Sourcepub fn feedforward(constraint: u32, generators: &[u32]) -> Result<Trellis>
pub fn feedforward(constraint: u32, generators: &[u32]) -> Result<Trellis>
The feed-forward code of constraint length constraint with the generators
generators (octal digits written as integers, e.g. 0o133).
§Errors
comnum_core::Error::Config for a constraint length outside 1 to 24 or no generator.
Sourcepub fn recursive(
constraint: u32,
feedback: u32,
forward: u32,
) -> Result<Trellis>
pub fn recursive( constraint: u32, feedback: u32, forward: u32, ) -> Result<Trellis>
The recursive systematic code with the feedback polynomial feedback and the
feed-forward polynomial forward (octal, e.g. 0o13, 0o15): outputs the input
bit, then the parity bit.
§Errors
comnum_core::Error::Config for a constraint length outside 1 to 24.
Sourcepub fn recursive_parities(
constraint: u32,
feedback: u32,
forwards: &[u32],
) -> Result<Trellis>
pub fn recursive_parities( constraint: u32, feedback: u32, forwards: &[u32], ) -> Result<Trellis>
The recursive systematic code with the feedback polynomial feedback and several
feed-forward polynomials forwards (octal, the most significant bit the current
register input $w_{t} = u_{t} \oplus \dots$): outputs the input bit, then one parity
bit per polynomial, in their order (Trellis::recursive is the case of one
polynomial); the constituent codes of the turbo codes of CCSDS 131.0-B (Sec. 6.3)
have up to three.
§Errors
comnum_core::Error::Config for a constraint length outside 1 to 24, no
polynomial, or more than 31 outputs.
§Examples
use comnum_fec::conv::Trellis;
// the 16-state code of CCSDS rate 1/6, encoder a: G0 = 10011, G1, G2, G3
let t = Trellis::recursive_parities(5, 0o23, &[0o33, 0o25, 0o37])?;
assert_eq!((t.n_states(), t.n_out()), (16, 4));
assert_eq!(Trellis::recursive_parities(4, 0o13, &[0o15])?, Trellis::recursive(4, 0o13, 0o15)?);Sourcepub fn encode(&self, bits: &[u8], terminate: bool) -> Vec<u8> ⓘ
pub fn encode(&self, bits: &[u8], terminate: bool) -> Vec<u8> ⓘ
Encode bits from state 0; with terminate, append the $K - 1$ tail inputs that
return to state 0. Returns the coded bits.
Sourcepub fn encode_tail_biting(&self, bits: &[u8]) -> Result<Vec<u8>>
pub fn encode_tail_biting(&self, bits: &[u8]) -> Result<Vec<u8>>
Encode bits with tail biting: the register starts in the state that its last
$K - 1$ inputs leave it in, so that the path ends in the state it starts from and
no tail is sent (the code of LTE, TS 36.212 Sec. 5.1.3.1). Returns the $n$ coded
bits of every input bit.
§Errors
comnum_core::Error::Config for a recursive code (its state depends on more than
the last $K - 1$ inputs); comnum_core::Error::Shape for fewer than $K - 1$ bits.
§Examples
use comnum_fec::conv::{Trellis, viterbi_tail_biting};
let t = Trellis::feedforward(7, &[0o133, 0o171, 0o165])?; // the code of LTE
let bits: Vec<u8> = (0..40).map(|i| ((i * 5) % 7 < 3) as u8).collect();
let c = t.encode_tail_biting(&bits)?;
assert_eq!(c.len(), 3 * 40); // no tail
let llr: Vec<f64> = c.iter().map(|&b| if b == 0 { 2.0 } else { -2.0 }).collect();
assert_eq!(viterbi_tail_biting(&t, &llr, 4)?, bits);