Create PN sequence generator object
h = commsrc.pn
h = commsrc.pn(property1,value1,...)
h = commsrc.pn creates
a default PN sequence generator object h, and is
equivalent to the following:
H = commsrc.pn('GenPoly', [1 0 0 0 0 1 1], ... 'InitialStates', [0 0 0 0 0 1], ... 'CurrentStates', [0 0 0 0 0 1], ... 'Mask', [0 0 0 0 0 1], ... 'NumBitsOut', 1)
H = commsrc.pn('GenPoly', [1 0 0 0 0 1 1], ... 'InitialStates', [0 0 0 0 0 1], ... 'CurrentStates', [0 0 0 0 0 1], ... 'Shift', 0, ... 'NumBitsOut', 1)
h = commsrc.pn(property1,value1,...) creates
a PN sequence generator object, h, with properties
you specify as property/value pairs.
A PN sequence generator has the properties shown on the following table. All properties are writable except for the ones explicitly noted otherwise.
|GenPoly||Generator polynomial vector array of bits; must be descending order|
|InitialStates||Vector array (with length of the generator polynomial order) of initial shift register values (in bits)|
|CurrentStates||Vector array (with length of the generator polynomial order) of present shift register values (in bits)|
|NumBitsOut||Number of bits to output at each |
A mask vector of binary 0 and 1 values is used to specify which shift register state bits are XORed to produce the resulting output bit value.
Alternatively, a scalar shift value may be used to specify an equivalent shift (either a delay or advance) in the output sequence.
'GenPoly' property values specify the
shift register connections. Enter these values as either a binary
vector or a vector of exponents of the nonzero terms of the generator
polynomial in descending order of powers. For the binary vector representation,
the first and last elements of the vector must be 1. For the descending-ordered
polynomial representation, the last element of the vector must be
0. For more information and examples, see the LFSR SSRG Details section
of this page.
A PN sequence generator is equipped with the following methods.
Generate [NumBitsOut x 1] PN sequence generator values
CurrentStates values to the
Get the actual or equivalent
Get the actual or equivalent
Make an independent copy of a
Display PN sequence generator object properties
Every time this property is set, it will reset the entire object.
In addition to changing the polynomial values,
'Mask' will be set to their default values
'NumBitsOut' will remain the same), and no warnings
will be issued.
Every time this property is set, it will also set
generate method produces a pseudorandom
noise (PN) sequence using a linear feedback shift register (LFSR).
The LFSR is implemented using a simple shift register generator (SSRG,
or Fibonacci) configuration, as shown below.
All r registers in the generator update
their values at each time step according to the value of the incoming
arrow to the shift register. The adders perform addition modulo 2.
The shift register is described by the
(generator polynomial), which is a primitive binary polynomial in z,
The coefficient gk is 1 if there is a connection
from the kth register, as labeled in the preceding diagram, to the
adder. The leading term gr and the constant
term g0 of the
must be 1 because the polynomial must be primitive.
You can specify the Generator polynomial parameter using either of these formats:
A vector that lists the coefficients of the polynomial in descending order of powers. The first and last entries must be 1. Note that the length of this vector is one more than the degree of the generator polynomial.
A vector containing the exponents of z for
the nonzero terms of the polynomial in descending order of powers.
The last entry must be
[1 0 0 0 0 0 1 0 1] and
2 0] represent the same polynomial, p(z) = z8 +
z2 + 1.
The Initial states parameter is a vector specifying the initial values of the registers. The Initial states parameter must satisfy these criteria:
All elements of the Initial states vector must be binary numbers.
The length of the Initial states vector must equal the degree of the generator polynomial.
At least one element of the Initial states vector must be nonzero in order for the block to generate a nonzero sequence. That is, the initial state of at least one of the registers must be nonzero.
For example, the following table indicates two sets of parameter values that correspond to a generator polynomial of p(z) = z8 + z2 + 1.
|Quantity||Example 1||Example 2|
|Degree of generator polynomial||8, which is ||8|
Output mask vector (or scalar shift value) shifts the starting point of the output sequence. With the default setting for this parameter, the only connection is along the arrow labeled m0, which corresponds to a shift of 0. The parameter is described in greater detail below.
You can shift the starting point of the PN sequence with Output mask vector (or scalar shift value). You can specify the parameter in either of two ways:
An integer representing the length of the shift
A binary vector, called the mask vector, whose length is equal to the degree of the generator polynomial
The difference between the block's output when you set Output mask vector (or scalar shift value) to 0, versus a positive integer d, is shown in the following table.
|T = 0||T = 1||T = 2||...||T = d||T = d+1|
|Shift = 0||x0||x1||x2||...||xd||xd+1|
|Shift = d||xd||xd+1||xd+2||...||x2d||x2d+1|
Alternatively, you can set Output mask vector (or
scalar shift value) to a binary vector, corresponding to
a polynomial in z, mr-1zr-1 +
mr-2zr-2 + ... +
m1z + m0, of degree
at most r-1. The mask vector corresponding to a shift of d is the
vector that represents m(z) = zd modulo
g(z), where g(z) is the
generator polynomial. For example, if the degree of the generator
polynomial is 4, then the mask vector corresponding to d = 2 is
1 0 0], which represents the polynomial m(z) = z2.
The preceding schematic diagram shows how Output mask vector
(or scalar shift value) is implemented when you specify
it as a mask vector. The default setting for Output mask
vector (or scalar shift value) is
You can calculate the mask vector using the Communications Toolbox™ function
If you want to generate a sequence of the maximum possible length for a fixed degree, r, of the generator polynomial, you can set Generator polynomial to a value from the following table. See Proakis, John G., Digital Communications, Third edition, New York, McGraw Hill, 1995 for more information about the shift-register configurations that these polynomials represent.
|r||Generator Polynomial||r||Generator Polynomial|
|18||37||[37 12 10 2 0]|
|19||38||[38 6 5 1 0]|
|20||39||[39 8 0]|
|40||47||[47 14 0]|
|41||48||[48 28 27 1 0]|
|42||49||[49 9 0]|
|43||50||[50 4 3 2 0]|
|44||51||[51 6 3 1 0]|
|45||52||[52 3 0]|
|46||53||[53 6 2 1 0]|
Set up a PN sequence generator. Define the polynomial in binary vector format or exponential vector format.
This figure defines a PN sequence generator with a generator polynomial .
Define this PN sequence generator as follows:
h1 = commsrc.pn('GenPoly', [1 0 0 0 0 1 1], 'Mask', [1 1 0 1 0 1]); h2 = commsrc.pn('GenPoly', [1 0 0 0 0 1 1], 'Shift', 22); mask2shift ([1 0 0 0 0 1 1],[1 1 0 1 0 1])
ans = 22
Alternatively, you can input
GenPoly as the exponents of z for the nonzero terms of the polynomial in descending order of powers:
h = commsrc.pn('GenPoly', [6 1 0], 'Mask', [1 1 0 1 0 1])
h = GenPoly: [1 0 0 0 0 1 1] InitialStates: [0 0 0 0 0 1] CurrentStates: [0 0 0 0 0 1] Mask: [1 1 0 1 0 1] NumBitsOut: 1
commsrc.pn is used to output pseudorandom data streams.
Construct a PN object.
h = commsrc.pn('Shift',0);
Output 10 PN bits.
ans = 10×1 1 0 0 0 0 0 1 0 0 0
Output 10 more PN bits.
ans = 10×1 0 1 1 0 0 0 1 0 1 0
Reset the object to the initial shift register state values.
Output 4 PN bits.
ans = 4×1 1 0 0 0
commsrc.pn object is copied, its states are also copied. Subsequent outputs from the copied object are likely to be different from the initial outputs from the original object.
Construct a PN object and output a sequence from it.
h = commsrc.pn('Shift', 0); set(h, 'NumBitsOut', 5); generate(h)
ans = 5×1 1 0 0 0 0
Make a copy of
h. Generate a sequence from the copied object. Because the copy was made after the state of
h changed, the initial sequence generated by
g is different from the initial sequence generated from
ans = 5×1 0 1 0 0 0
g is reset, it generates the same sequence that
ans = 5×1 1 0 0 0 0