Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Generate orthogonal variable spreading factor (OVSF) code from set of orthogonal codes

Spreading Codes

The OVSF Code Generator block generates an OVSF code from a set of orthogonal codes. OVSF codes were first introduced for 3G communication systems. OVSF codes are primarily used to preserve orthogonality between different channels in a communication system.

OVSF codes are defined as the rows of an N-by-N matrix, C_{N},
which is defined recursively as follows. First, define C_{1} = [1].
Next, assume that C_{N} is defined and let
C_{N}(k) denote the kth row of C_{N}. Define
C_{2N} by

$${C}_{2N}=\left[\begin{array}{cc}{C}_{N}(0)& {C}_{N}(0)\\ {C}_{N}(0)& -{C}_{N}(0)\\ {C}_{N}(1)& {C}_{N}(1)\\ {C}_{N}(1)& -{C}_{N}(1)\\ \mathrm{...}& \mathrm{...}\\ {C}_{N}(N-1)& {C}_{N}(N-1)\\ {C}_{N}(N-1)& -{C}_{N}(N-1)\end{array}\right]$$

Note that *C*_{N }is only defined for
*N* a power of 2. It follows by induction that the rows of
*C*_{N }are orthogonal.

The OVSF codes can also be defined recursively by a tree structure, as shown in the following figure.

If [C] is a code length 2^{r} at depth r in the tree, where
the root has depth 0, the two branches leading out of C are labeled by the sequences [C
C] and [C -C], which have length 2^{r+1}. The codes at depth r
in the tree are the rows of the matrix C_{N}, where N =
2^{r}.

Note that two OVSF codes are orthogonal if and only if neither code lies on the path
from the other code to the root. Since codes assigned to different users in the same
cell must be orthogonal, this restricts the number of available codes for a given cell.
For example, if the code C_{41} in the tree is assigned to a user,
the codes C_{10}, C_{20},
C_{82}, C_{83}, and so on, cannot be
assigned to any other user in the same cell.

You specify the code the OVSF Code Generator block outputs by two parameters in
the block's dialog: the **Spreading factor**, which is the length
of the code, and the **Code index**, which must be an integer in
the range [0, 1, ... , N - 1], where N is the spreading factor. If the code appears
at depth r in the preceding tree, the **Spreading factor** is
2^{r}. The **Code index** specifies how
far down the column of the tree at depth r the code appears, counting from 0 to
*N* - 1. For C_{N, k} in the preceding
diagram, *N* is the **Spreading factor** and
*k* is the **Code index**.

You can recover the code from the **Spreading factor **and the
**Code index** as follows. Convert the **Code
index** to the corresponding binary number, and then add 0s to the
left, if necessary, so that the resulting binary sequence
*x*_{1}
*x*_{2} ...
*x*_{r} has length
*r*, where *r* is the logarithm base 2 of the
**Spreading factor**. This sequence describes the path from the
root to the code. The path takes the upper branch from the code at depth
*i* if x_{i} = 0, and the lower branch if
x_{i} = 1.

To reconstruct the code, recursively define a sequence of codes
C_{i} for as follows. Let C_{0} be the
root [1]. Assuming that C_{i} has been defined, for
*i* < *r*, define
C_{i+1} by

$${C}_{i+1}=\{\begin{array}{ll}{C}_{i}{C}_{i}\hfill & \text{if}{x}_{i}=0\hfill \\ {C}_{i}(-{C}_{i})\hfill & \text{if}{x}_{i}=1\hfill \end{array}$$

The code C_{N} has the specified **Spreading
factor** and **Code index**.

For example, to find the code with **Spreading factor**
`16`

and **Code index**
`6`

, do the following:

Convert 6 to the binary number 110.

Add one 0 to the left to obtain 0110, which has length 4 = log

_{2}16.Construct the sequences C

_{i}according to the following table.i x _{i}C _{i}0 C _{0}= [1]1 0 C _{1}= C_{0}C_{0}= [1] [1]2 1 C _{2}= C_{1}-C_{1}= [1 1] [-1 -1]3 1 C _{3}= C_{2}-C_{2}= [1 1 -1 -1] [-1 -1 1 1]4 0 C _{4}= C_{3}C_{3}= [1 1 -1 -1 -1 -1 1 1] [1 1 -1 -1 -1 -1 1 1]

The code C_{4 }has **Spreading factor**
`16`

and **Code index**
`6`

.

**Spreading factor**Positive integer that is a power of 2, specifying the length of the code.

**Code index**Integer in the range [0, 1, ... , N - 1] specifying the code, where N is the

**Spreading factor**.**Sample time**The time between each sample of the output signal. Specify as a nonnegative real scalar.

**Samples per frame**The number of samples per frame in one column of the output signal. Specify as a positive integer scalar.

### Note

The time between output updates is equal to the product of

**Samples per frame**and**Sample time**. For example, if**Sample time**and**Samples per frame**equal one, the block outputs a sample every second. If**Samples per frame**is increased to 10, then a 10-by-1 vector is output every 10 seconds. This ensures that the equivalent output rate is not dependent on the**Samples per frame**parameter.**Output data type**The output type of the block can be specified as an

`int8`

or`double`

. By default, the block sets this to`double`

.**Simulate using**Select the simulation mode.

`Code generation`

On the first model run, simulate and generate code. If the structure of the block does not change, subsequent model runs do not regenerate the code.

If the simulation mode is

`Code generation`

, System objects corresponding to the blocks accept a maximum of nine inputs.`Interpreted execution`

Simulate model without generating code. This option results in faster start times but can slow subsequent simulation performance.