OVSF Code Generator
Generate OVSF code
Libraries:
Communications Toolbox /
Comm Sources /
Sequence Generators
Description
The OVSF Code Generator block generates a code from an orthogonal variable spreading factor (OVSF) matrix. Use OVSF codes to preserve orthogonality between different channels in a spread spectrum communications system. For more information, see Algorithms.
Examples
Generate OVSF Code in Simulink
Generate 10 samples of an OVSF code with a spreading factor of 32.
The cm_generate_ovsf_code
model sets Code length to 32, Code index to 12, and Samples per frame to 10. Other parameters use the default settings.
Run the model and display the generated OVSF code.
ans = 1 1 1 1 1 1 1 1 1 1
Ports
Output
Out — Output data
column vector
Output data, returned as a binaryvalued column vector containing the OVSF code generated from a set of orthogonal codes.
Data Types: double
 int8
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink^{®} Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Code length — Code length
64
(default)  positive integer
Length of the generated code, specified as a positive integer power of 2. The code length value is the spreading factor of the code. For more information, see Spread Spectrum.
The spreading factor is the length of the code selected from the OVSF code matrix. OVSF codes are defined as the rows of an NbyN matrix, C_{N}. The Code index parameter specifies the row of the C_{N} matrix as the code of interest. For more information, see Orthogonal Variable Spreading Factor Codes.
Code index — Row index of OVSF code matrix
60
(default)  integer
Row index of the OVSF code matrix, specified as an integer in the range [0, (N – 1)], where N is the spreading factor as specified by the value of the Code length parameter. OVSF codes are defined as the rows of an NbyN matrix, C_{N}. The value of this property specifies the row of the C_{N} matrix as the code of interest. For more information, see Recovering and Reconstructing OVSF Codes.
Sample time — Sample time, in seconds
1
(default)  positive scalar
Positive scalars specify the time in seconds between each
sample of the output signal. If you set the sample time to 1
, the output
signal inherits the sample time from downstream. For information on the relationship between the
Sample time and Samples per frame parameters,
see
Sample Timing.
Samples per frame — Number of OVSF chips output
1
(default)  positive integer
Number of OVSF code chips output, specified as a positive integer. Each time the block runs, it outputs the first Samples per frame chips of the OVSF code specified by the Code length and Code index property values. For more information, see Spread Spectrum.
For information on the relationship between Sample time and Samples per frame, see Sample Timing.
Output data type — Output type
double
(default)  int8
Output data type, specified as double
or
int8
.
Simulate using — Type of simulation to run
Code generation
(default)  Interpreted execution
Type of simulation to run, specified as Code generation
or
Interpreted execution
.
Code generation
— Simulate the model by using generated C code. The first time you run a simulation, Simulink generates C code for the block. The model reuses the C code for subsequent simulations unless the model changes. This option requires additional startup time, but the speed of the subsequent simulations is faster than with theInterpreted execution
option.Interpreted execution
— Simulate the model by using the MATLAB^{®} interpreter. This option shortens startup time, but the speed of subsequent simulations is slower than with theCode generation
option. In this mode, you can debug the source code of the block.
For more information, see Simulation Modes (Simulink).
Block Characteristics
Data Types 

Multidimensional Signals 

VariableSize Signals 

More About
Sample Timing
The time between output updates is equal to the product of the
Samples per frame and Sample time parameter
values. For example, if Sample time and Samples per
frame each equal 1
, the block outputs one sample every
second. If you increase Samples per frame to 10, then the block outputs
a 10by1 vector every 10 seconds. This timing ensures that the equivalent output rate is
not dependent on the Samples per frame parameter.
Algorithms
As discussed in [1], OVSF codes were first introduced for 3G communication systems and are primarily used to preserve orthogonality between different channels in a spread spectrum communications system.
Orthogonal Variable Spreading Factor Codes
OVSF codes with spreading factor N of an NbyN OVSF code matrix, C_{N}, are the individual rows of an NbyN matrix, C_{N}, which is defined recursively. 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}(N1)& {C}_{N}(N1)\\ {C}_{N}(N1)& {C}_{N}(N1)\end{array}\right]$$
C_{N} is defined for N only as a nonnegative 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.
If [C] has 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}.
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 requirement 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.
Recovering and Reconstructing OVSF Codes
To select the OVSF code to output, you specify the spreading factor and the code index. The code index specifies how far down the column of the tree at depth r the code appears. For C_{N, k} in the tree structure diagram, N is the spreading factor and k is the code index. The code index must be an integer in the range [0, N – 1]. If the code appears at depth r in the tree structure, the spreading factor is 2^{r}.
To recover the code, based on the spreading factor and the code index:
Convert the code index to the corresponding binary number.
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 binary 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}:
Let C_{0} be the root [1].
Assuming that C_{i} has been defined, for i < r, define C_{i+1} by
$${C}_{\text{i}+1}=\{\begin{array}{ll}{C}_{\text{i}}{C}_{\text{i}}\hfill & \text{if}{x}_{\text{i}}=0\hfill \\ {C}_{\text{i}}({C}_{\text{i}})\hfill & \text{if}{x}_{\text{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
.
Spread Spectrum
In general, spread spectrum multiplies each data message sample by a coded set of chips. To avoid confusion with samples of the data message, the term chips refers to samples or bits of a code used to spread data over a wide spectrum in digital communications. The length of the code is the spreading factor.
The spreading factor, SF = R_{chip}/R_{data},
R_{chip} is the chip rate. The chip rate of a code is the number of chips per second transmitted or received. Multiple chips represent each data sample because the spreading factor must be a positive power of 2 that is greater than 1.
R_{data} is the sample rate of the message data.
References
[1] S. Kasapović and N. Sarajlić, "OVSF code assignment in UMTS networks," 2010 20th International Crimean Conference "Microwave & Telecommunication Technology", Sevastopol, Ukraine, 2010, pp. 429–432, doi: 10.1109/CRMICO.2010.5632706.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Does not support integer only code generation.
Version History
Introduced before R2006aR2020a: Existing models automatically update this block to current version
Starting in R2020a, Simulink no longer allows you to use the OVSF Code Generator block version available before R2015b.
Existing models automatically update to load the OVSF Code Generator block version announced in Source blocks output frames of contiguous time samples but do not use frame attribute. For more information on block forwarding, see Maintain Compatibility of Library Blocks Using Forwarding Tables (Simulink).
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)