Main Content


Generate Hadamard code


The HadamardCode object generates a Hadamard code from a Hadamard matrix, whose rows form an orthogonal set of codes. You can use orthogonal codes for spreading in communication systems in which the receiver is perfectly synchronized with the transmitter. In these systems, the despreading operation is ideal, because the codes decorrelate completely.

To generate a Hadamard code:

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

  2. Call step to generate a Hadamard according to the properties of comm.HadamardCode. 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) and y = obj() perform equivalent operations.


H = comm.HadamardCode creates a Hadamard code generator System object, H. This object generates Hadamard codes from a set of orthogonal codes.

H = comm.HadamardCode(Name,Value) creates a Hadamard 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 a numeric, integer scalar value with a power of two. The default is 64.


Row index of Hadamard matrix

Specify the row index of the Hadamard matrix as a numeric, integer scalar value in the range [0, 1, ... , N-1]. N is the value of the Length property. The default is 60. An N×N Hadamard matrix, denoted as P(N), is defined recursively as follows: P(1) = [1] P(2N) = [P(N) P(N); P(N) –P(N)] The NxN Hadamard matrix has the property that P(N)×P(N)' = N×eye(N). The step method outputs code samples from the row of the Hadamard matrix that you specify in this property.

When you set this property to an integer k, the output code has exactly k zero crossings, for k = 0, 1, ... , N1.


Number of output samples per frame

Specify the number of Hadamard code samples that the step method outputs as a numeric, positive, integer scalar value. The default is 1.

When you set this property to a value of M, the step method outputs M samples of a Hadamard code of length N. N equals the length of the code that you specify in the Length property.


Data type of output

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


stepGenerate Hadamard code
Common to All System Objects

Allow System object property value changes


Reset internal states of System object


collapse all

Generate 10 samples of a Hadamard code sequence having a length of 128.

hadamard = comm.HadamardCode('Length',128,'SamplesPerFrame',10)
hadamard = 
  comm.HadamardCode with properties:

             Length: 128
              Index: 60
    SamplesPerFrame: 10
     OutputDataType: 'double'

seq = hadamard()
seq = 10×1



This object implements the algorithm, inputs, and outputs described on the Hadamard 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.

Extended Capabilities

Version History

Introduced in R2012a