Main Content


Generate OVSF code


The OVSFCode object generates an orthogonal variable spreading factor (OVSF) code from a set of orthogonal codes. OVSF codes were first introduced for 3G communication systems. They are primarily used to preserve orthogonality between different channels in a communication system.

To generate an OVSF code:

  1. Define and set up your OVSF code object. See Construction.

  2. Call step to generate an OVSF code according to the properties of comm.OVSFCode. The behavior of step is specific to each object in the toolbox.


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.


H = comm.OVSFCode creates an orthogonal variable spreading factor (OVSF) code generator System object, H. This object generates an OVSF code.

H = comm.OVSFCode(Name,Value) creates an OVSF code generator 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).



Length of generated code

Specify the length of the generated code as an integer scalar value with a power of two. The default is 64.


Index of code of interest

Specify the index of the desired code from the available set of codes that have the spreading factor specified in the SpreadingFactor property. This property must be an integer scalar in the range 0 to SpreadingFactor1. The default is 60.

OVSF codes are defined as the rows of an n-by-n matrix, Cn, where n is the value specified in the SpreadingFactor property.

You can define the matrix Cn recursively as follows:

First, define C1 = [1].
Next, assume that Cn is defined and let Cn(k) denote the k-th row of Cn.
Then, C2n = [Cn(0) Cn(0); Cn(0) -Cn(0); ... ; Cn(n-1) Cn(n–1); Cn(n–1)–Cn(n–1)].
Cn is only defined for values of n that are a power of 2. Set this property to a value of k to choose the k-th row of the C matrix as the code of interest.


Number of output samples per frame

Specify the number of OVSF code samples that the step method outputs as a numeric, positive, integer scalar value. The default is 1. If you set this property to a value of M, then the step method outputs M samples of an OVSF code of length N. N is the length of the OVSF code that you specify in the SpreadingFactor property.


Data type of output

Specify output data type as one of double | int8. The default is double.


stepGenerate OVSF code
Common to All System Objects

Allow System object property value changes


Reset internal states of System object


Generate 10 samples of an OVSF code with a spreading factor of 64.

    hOVSF = comm.OVSFCode('SamplesPerFrame', 10,'SpreadingFactor',64);
    seq = step(hOVSF)


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

  • The object does not have a property to select frame based outputs.

  • The object does not have a property that corresponds to the Sample time parameter.

Version History

Introduced in R2012a