Accelerating the pace of engineering and science

# comm.Scrambler System object

Package: comm

Scramble input signal

## Description

The Scrambler object scrambles a scalar or column vector input signal.

To scramble the input signal:

1. Define and set up your scrambler object. See Construction.

2. Call step to scramble the input signal according to the properties of comm.Scrambler. The behavior of step is specific to each object in the toolbox.

## Construction

H = comm.Scrambler creates a scrambler System object™, H. This object scrambles the input data using a linear feedback shift register that you specify with the Polynomial property.

H = comm.Scrambler(Name,Value) creates a scrambler 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.Scrambler(N,POLY,COND,Name,Value) creates a scrambler object, H. This object has the CalculationBase property set to N, the Polynomial property set to POLY, the InitialConditions property set to COND, and the other specified properties set to the specified values.

## Properties

 CalculationBase Range of input data Specify calculation base as a positive, integer, scalar value. Set the calculation base property to one greater than the number of input values. The step method input and output integers are in the range [0, CalculationBase–1]. The default is 4. Polynomial Linear feedback shift register connections Specify the polynomial that determines the shift register feedback connections. The default is [1 1 1 0 1]. You can specify the generator polynomial as a numeric, binary vector that lists the coefficients of the polynomial in order of ascending powers of z–1, where p(z–1) = 1 + p1z-1 + p2z-2 + ... is the generator polynomial. The first and last elements must be 1. Alternatively, you can specify the generator polynomial as a numeric vector. This vector must contain the exponents of z–1 for the nonzero terms of the polynomial, in order of ascending powers of z–1. In this case, the first vector element must be 0. For example, both [1 0 0 0 0 0 1 0 1] and [0 -6 -8] specify the same polynomial $p\left({z}^{-1}\right)=1+{z}^{-6}+{z}^{-8}$. InitialConditionsSource Source of initial conditions Specify the source of the InitialConditions property as either Property or Input port. If set to Input port, the initial conditions are provided as an input argument to the step function. The default value is Property. InitialConditions Initial values of linear feedback shift register Specify the initial values of the linear feedback shift register as an integer row vector with values in [0 CalculationBase–1]. The default is [0 1 2 3]. The length of this property vector must equal the order of the Polynomial property vector. This property is available when InitialConditionsSource is set to Property. ResetInputPort Scrambler state reset port Specify the creation of an input port that is used to reset the state of the scrambler. If ResetInputPort is true, the scrambler is reset when a nonzero input argument is provided to the step function. The default value is false. This property is available when InitialConditionsSource is set to Property.

## Methods

 clone Create scrambler 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 scrambler object step Scramble input signal

## Examples

expand all

### Scramble and Descramble Data

Scramble and descramble 8-ary data using comm.Scrambler and comm.Descrambler System objects™ having a calculation base of 8.

Create scrambler and descrambler objects while specifying the generator polymomial and initial conditions using name-value pairs.

```N = 8;
hSCR = comm.Scrambler(N,[1 0 1 1 0 1 0 1], ...
[0 3 2 2 5 1 7]);
hDSCR = comm.Descrambler(N,[1 0 1 1 0 1 0 1], ...
[0 3 2 2 5 1 7]);
```

Scramble and descramble random integers and verify that the descrambled output matches the initial data

```data = randi([0 N-1],5,1);
scrData = step(hSCR,data);
deScrData = step(hDSCR,scrData);
[data scrData deScrData]
```
```ans =

6     7     6
7     5     7
1     7     1
7     0     7
5     3     5

```

### Scramble and Descramble Data With Changing Initial Conditions

Scramble and descramble quaternary data while changing the initial conditions between step calls.

Create scrambler and descrambler System objects™. Set the InitialConditionsSource property to Input port to be able to set the initial conditions as an argument to the step function.

```N = 4;
hSCR = comm.Scrambler(N,[1 0 0 1],'InitialConditionsSource','Input port');
hDSCR = comm.Descrambler(N,[1 0 0 1],'InitialConditionsSource','Input port');
```

Allocate memory for errVec.

```errVec = zeros(10,1);
```

Scramble and descramble random integers while changing the initial conditions, initCond, each time the loop executes. Use the symerr function to determine if the scrambling and descrambing operations result in symbol errors.

```for k = 1:10
initCond = randperm(3)';
data = randi([0 N-1],5,1);
scrData = step(hSCR,data,initCond);
deScrData = step(hDSCR,scrData,initCond);
errVec(k) = symerr(data,deScrData);
end
```

Examine errVec to verify that the output from the descrambler matches the original data.

```errVec
```
```errVec =

0
0
0
0
0
0
0
0
0
0

```

## Algorithms

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