# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# comm.ViterbiDecoder System object

Package: comm

Decode convolutionally encoded data using Viterbi algorithm

## Description

The `ViterbiDecoder` object decodes input symbols to produce binary output symbols. This object can process several symbols at a time for faster performance. This object processes variable-size signals; however, variable-size signals cannot be applied for erasure inputs.

To decode input symbols and produce binary output symbols:

1. Define and set up your Viterbi decoder object. See Construction.

2. Call `step` to decode input symbols according to the properties of `comm.ViterbiDecoder`. The behavior of `step` is specific to each object in the toolbox.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`H = comm.ViterbiDecoder` creates a Viterbi decoder System object, `H`. This object uses the Viterbi algorithm to decode convolutionally encoded input data.

`H = comm.ViterbiDecoder(Name,Value)` creates a Viterbi decoder object, `H`, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (`Name1`,`Value1`,...,`NameN`,`ValueN`).

`H = comm.ViterbiDecoder(TRELLIS,Name,Value)` creates a Viterbi decoder object, `H`. This object has the `TrellisStructure` property set to `TRELLIS` and the other specified properties set to the specified values.

## Properties

 `TrellisStructure` Trellis structure of convolutional code Specify the trellis as a MATLAB® structure that contains the trellis description of the convolutional code. The default is the result of ```poly2trellis(7, [171 133])```. Use the `istrellis` function to verify whether a structure is a valid trellis. `InputFormat` Input format Specify the format of the input to the decoder as `Unquantized` | `Hard` | `Soft`. The default is `Unquantized`. When you set this property to `Unquantized`, the input must be a real vector of double- or single-precision soft values that are unquantized. The object considers negative numbers to be `1`s and positive numbers to be `0`s. When you set this property to `Hard`, the input must be a vector of hard decision values, which are `0`s or `1`s. The data type of the inputs can be double-precision, single-precision, logical, 8-, 16-, and 32-bit signed integers. You can also use 8-, 16-, and 32-bit unsigned integers. When you set this property to `Soft`, the input requires a vector of quantized soft values represented as integers between 0 and . The data type of the inputs can be double-precision, single-precision, logical, 8-, 16-, and 32-bit signed integers. You can also use 8-, 16-, and 32-bit unsigned integers. Alternately, you can specify the data type as an unsigned and unscaled fixed point object (fi) with a word length equal to the word length that you specify in the `SoftInputWordLength` property. The object considers negative numbers to be `0`s and positive numbers to be `1`s. `SoftInputWordLength` Soft input word length Specify the number of bits to represent each quantized soft input value as a positive, integer scalar value. The default is `4` bits. This property applies when you set the `InputFormat` property to `Soft`. `InvalidQuantizedInputAction` Action when input values are out of range Specify the action the object takes when input values are out of range as `Ignore` | `Error`. The default is `Ignore`. Set this property to `Error` so that the object generates an error when the quantized input values are out of range. This property applies when you set the `InputFormat` property to `Hard` or `Soft`. `TracebackDepth` Traceback depth Specify the number of trellis branches to construct each traceback path as a numeric, integer scalar value. The default is `34`. The traceback depth influences the decoding accuracy and delay. The number of zero symbols that precede the first decoded symbol in the output represent a decoding delay. When you set the `TerminationMethod` property to `Continuous`, the decoding delay consists of `TracebackDepth` zero symbols or `TracebackDepth`$×$K zero bits for a rate K/N convolutional code. When you set the `TerminationMethod` property to `Truncated` or `Terminated`, there is no output delay. In this case, `TracebackDepth` must be less than or equal to the number of symbols in each input. As a general estimate, a typical `TracebackDepth` property value is approximately two to three times (k – 1)/(1 – r), where k is the constraint length of the code and r is the code rate [1]. For example: A rate `1/2` code has a `TracebackDepth` of 5(k – 1).A rate `2/3` code has a `TracebackDepth` of 7.5(k – 1).A rate `3/4` code has a `TracebackDepth` of 10(k – 1).A rate `5/6` code has a `TracebackDepth` of 15(k – 1). `TerminationMethod` Termination method of encoded frame Specify the termination method as `Continuous` | `Truncated` | `Terminated`. The default is `Continuous`. In `Continuous` mode, the object saves the internal state metric at the end of each frame for use with the next frame. The object treats each traceback path independently. In `Truncated` mode, the object treats each frame independently. The traceback path starts at the state with the best metric and always ends in the all-zeros state. In `Terminated` mode, the object treats each frame independently, and the traceback path always starts and ends in the all-zeros state. `ResetInputPort` Enable decoder reset input Set this property to true to enable an additional `step` method input. The default is `false`. When the reset input is a nonzero value, the object resets the internal states of the decoder to initial conditions. This property applies when you set the `TerminationMethod` property to `Continuous`. `DelayedResetAction` Reset on nonzero input via port Set this property to true to delay resetting the object output. The default is false. When you set this property to true, the reset of the internal states of the decoder occurs after the object computes the decoded data. When you set this property to false, the reset of the internal states of the decoder occurs before the object computes the decoded data. This property applies when you set the `ResetInputPort` property to true. `PuncturePatternSource` Source of puncture pattern Specify the source of the puncture pattern as `None` | `Property`. The default is `None`. When you set this property to `None`, the object assumes no puncturing. Set this property to `Property` to decode punctured codewords based on a puncture pattern vector specified via the `PuncturePattern` property. `PuncturePattern` Puncture pattern vector Specify puncture pattern to puncture the encoded data. The default is `[1; 1; 0; 1; 0; 1]`. The puncture pattern is a column vector of `1`s and `0`s. The `0`s indicate the position to insert dummy bits. The puncture pattern must match the puncture pattern used by the encoder. This property applies when you set the `PuncturePatternSource` property to `Property`. `ErasuresInputPort` Enable erasures input Set this property to `true` to specify a vector of erasures as a `step` method input. The default is `false`. The erasures input must be a double-precision or logical, binary, column vector. This vector indicates which symbols of the input codewords to erase. Values of `1` indicate erased bits. The decoder does not update the branch metric for the erasures in the incoming data stream. The lengths of the `step` method erasure input and the `step` method data input must be the same. When you set this property to `false`, the object assumes no erasures. `OutputDataType` Data type of output Specify the data type of the output as `Full precision` | ```Smallest unsigned integer``` | `double` | `single` | `int8` | `uint8` | `int16` | `uint16` | `int32` | `uint32` | `logical`. The default is `Full precision`. When the input signal is an integer data type, you must have a Fixed-Point Designer™ user license to use this property in ```Smallest unsigned integer``` or `Full precision` mode.

## Methods

 clone Create Viterbi decoder object with same property values getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs from step method isLocked Locked status for input attributes and nontunable properties release Allow property value and input characteristics changes reset Reset states of the Viterbi decoder object step Decode convolutionally encoded data using Viterbi algorithm

## Examples

expand all

Transmit a convolutinally encoded 8-DPSK modulated bit stream through an AWGN channel. Then, demodulate and decode using a Viterbi decoder.

Create the necessary System objects.

```hConEnc = comm.ConvolutionalEncoder; hMod = comm.DPSKModulator('BitInput',true); hChan = comm.AWGNChannel('NoiseMethod', ... 'Signal to noise ratio (SNR)',... 'SNR',10); hDemod = comm.DPSKDemodulator('BitOutput',true); hDec = comm.ViterbiDecoder('InputFormat','Hard'); hError = comm.ErrorRate('ComputationDelay',3,'ReceiveDelay', 34); ```

Process the data using the following steps:

1. Generate random bits

2. Convolutionally encode the data

3. Apply DPSK modulation

4. Pass the modulated signal through AWGN

5. Demodulate the noisy signal

6. Decode the data using a Viterbi algorithm

7. Collect error statistics

```for counter = 1:20 data = randi([0 1],30,1); encodedData = step(hConEnc, data); modSignal = step(hMod, encodedData); receivedSignal = step(hChan, modSignal); demodSignal = step(hDemod, receivedSignal); receivedBits = step(hDec, demodSignal); errors = step(hError, data, receivedBits); end ```

Display the number of errors.

```errors(2) ```
```ans = 3 ```

Encode and decode a sequence of bits using a convolutional encoder and a Viterbi decoder with a defined puncture pattern. Verify that the input and output bits are identical

Define a puncture pattern matrix and reshape it into vector form for use with the Encoder and Decoder objects.

```pPatternMat = [1 0 1;1 1 0]; pPatternVec = reshape(pPatternMat,6,1); ```

Create convolutional encoder and a Viterbi decoder in which the puncture pattern is defined by `pPatternVec`.

```ENC = comm.ConvolutionalEncoder(... 'PuncturePatternSource','Property', ... 'PuncturePattern',pPatternVec); DEC = comm.ViterbiDecoder('InputFormat','Hard', ... 'PuncturePatternSource','Property',... 'PuncturePattern',pPatternVec); ```

Create an error rate counter with the appropriate receive delay.

```ERR = comm.ErrorRate('ReceiveDelay',DEC.TracebackDepth); ```

Encode and decode a sequence of random bits.

```dataIn = randi([0 1],600,1); dataEncoded = step(ENC,dataIn); dataOut = step(DEC,dataEncoded); ```

Verify that there are no errors in the output data.

```errStats = step(ERR,dataIn,dataOut); errStats(2) ```
```ans = 0 ```

## Algorithms

This object implements the algorithm, inputs, and outputs described on the Viterbi Decoder block reference page. The object properties correspond to the block parameters, except:

## References

[1] Moision, B., "A Truncation Depth Rule of Thumb for Convolutional Codes," Information Theory and Applications Workshop, pp. 555–557, 2008.