Scramble input signal
The comm.Scrambler object scrambles a scalar or column vector input signal.
This schematic shows the scrambler operation. The adders operate modulo N, where N is the value specified by the CalculationBase property.
At each time step, the input causes the contents of the registers to shift sequentially. Using the Polynomial property, you specify the on or off state for each switch in the scrambler.
To scramble an input signal:
comm.Scrambler object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects? (MATLAB).
scrambler = comm.Scrambler
scrambler = comm.Scrambler(base,poly,cond)
scrambler = comm.Scrambler(___,Name,Value)
creates a scrambler
object™. This object scrambles the input data by using a linear feedback shift register
that you specify with the Polynomial property.
scrambler = comm.Scrambler
creates the scrambler object with the CalculationBase property set to
scrambler = comm.Scrambler(
base, the Polynomial property set to
poly, and the InitialConditions property set to
comm.Scrambler(8,'1 + z^-2 + z^-3 + z^-5 + z^-7',[0 3 2 2 5 1 7])sets the calculation base to
8, and the scrambler polynomial and initial conditions as specified.
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).
CalculationBase— Range of input data
Range of input data used in the scrambler for modulo operations, specified as a
nonnegative integer. The input and output of this object are integers from
Polynomial— Connections for linear feedback shift registers
'1 + z^-1 + z^-2 + z^-4'(default) | character vector | integer vector | binary vector
Connections for linear feedback shift registers in the scrambler, specified as a
character vector, integer vector, or binary vector. The
property defines if each switch in the scrambler is on or off. Specify the polynomial as:
A character vector, such as
'1 + z^-6 + z^-8'. For more details on
specifying polynomials in this way, see Character Representation of
An integer vector, such as
[0 -6 -8], listing the scrambler
coefficients in order of descending powers of
p(z-1) = 1 +
p2z-2 + ...
A binary vector, such as
[1 0 0 0 0 0 1 0 1], listing the powers of
z that appear in the polynomial that have a coefficient of 1. In this
case, the order of the scramble polynomial is one less than the binary vector
'1 + z^-6 + z^-8',
[0 -6 -8], and
[1 0 0 0 0 0 1 0 1] all represent this polynomial:
p(z-1) = 1 + z-6 + z-8
InitialConditionsSource— Initial conditions source
InitialConditions— Initial conditions of scrambler registers
[0 1 2 3](default) | nonnegative integer vector
Initial conditions of scrambler registers when the simulation starts, specified as a
nonnegative integer vector. The length of
InitialConditions must equal
the order of the Polynomial property. The vector element
values must be integers from
0 to CalculationBase –
This property is available when InitialConditionsSource
is set to
ResetInputPort— Scrambler state reset port
scrambledOut = scrambler(signal)
scrambledOut = scrambler(signal,initcond)
scrambledOut = scrambler(signal,reset)
scrambles the input signal. The output is the same data type and length as the input vector.
scrambledOut = scrambler(
signal— Input signal
Input signal, specified as a column vector.
scrambledOut = scrambler([0 1 1 0 1])
initcond— Initial register conditions
Initial scrambler register conditions when the simulation starts, specified as a
nonnegative integer column vector. The length of
initcond must equal the
order of the Polynomial property. The vector
element values must be integers from
0 to CalculationBase –
scrambledOut = scrambler(signal,[0 1 1 0]) corresponds to
possible initial register states for a scrambler with a polynomial order of
4 and a calculation base of
reset— Reset initial state of scrambler
Reset the initial state of the scrambler when the simulation starts, specified as a
scalar. When the value of
reset is nonzero, the object is reset before
it is called.
scrambledOut = scrambler(signal,0) scrambles the input signal
without resetting the scrambler states.
To use an object function, specify the
object as the first input argument. For
example, to release system resources of a System
Scramble and descramble 8-ary data using
comm.Descrambler System objects™ having a calculation base of 8.
Create scrambler and descrambler objects, specifying the calculation base, polynomial, and initial conditions using input arguments. The scrambler and descrambler polynomials are specified with different but equivalent data formats.
N = 8; scrambler = comm.Scrambler(N,'1 + z^-2 + z^-3 + z^-5 + z^-7', ... [0 3 2 2 5 1 7]); descrambler = comm.Descrambler(N,[1 0 1 1 0 1 0 1], ... [0 3 2 2 5 1 7]);
Scramble and descramble random integers. Display the original data, scrambled data, and descrambled data sequences.
data = randi([0 N-1],5,1); scrData = scrambler(data); deScrData = descrambler(scrData); [data scrData deScrData]
ans = 5×3 6 7 6 7 5 7 1 7 1 7 0 7 5 3 5
Verify that the descrambled data matches the original data.
ans = logical 1
Scramble and descramble quaternary data while changing the initial conditions between function calls.
Create scrambler and descrambler System objects having a calculation base of 4. Set the
InitialConditionsSource property to
'Input port' so you can set the initial conditions as an argument to the object.
N = 4; scrambler = comm.Scrambler(N,'1 + z^-3','InitialConditionsSource','Input port'); descrambler = comm.Descrambler(N,'1 + z^-3','InitialConditionsSource','Input port');
Preallocate memory for the error vector which will be used to store errors output by the
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 descrambling operations result in symbol errors.
for k = 1:10 initCond = randperm(3)'; data = randi([0 N-1],5,1); scrData = scrambler(data,initCond); deScrData = descrambler(scrData,initCond); errVec(k) = symerr(data,deScrData); end
errVec to verify that the output from the descrambler matches the original data.
errVec = 10×1 0 0 0 0 0 0 0 0 0 0
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).