Skip to main content

Trellis

Struct Trellis 

Source
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

Source

pub fn n_states(&self) -> usize

Number of states $2^{K-1}$.

Source

pub fn constraint(&self) -> u32

Constraint length $K$ (memory $K - 1$).

Source

pub fn n_out(&self) -> usize

Coded bits per input bit $n$ (at least 1).

Source

pub fn next(&self) -> &[[usize; 2]]

next()[s][u]: the state after input u in state s.

Source

pub fn out(&self) -> &[[u32; 2]]

out()[s][u]: the coded bits of the branch, the first output in the most significant position.

Source

pub fn tail(&self) -> &[u8] ⓘ

tail()[s]: the input that drives state s towards zero (0 for feed-forward codes).

Source

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.

Source

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.

Source

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)?);
Source

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.

Source

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);

Trait Implementations§

Source§

impl Clone for Trellis

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Trellis

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Trellis

Source§

impl PartialEq for Trellis

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Trellis

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.