-
sdr.hadamard_code(length: int, index: int, output: 'binary' =
'binary'
) ndarray[Any, dtype[int64]] - sdr.hadamard_code(length: int, index: int, output: 'field') FieldArray
- sdr.hadamard_code(length: int, index: int, output: 'bipolar') ndarray[Any, dtype[float64]]
Returns the Hadamard code/sequence of length \(N\).
- Parameters:¶
- length: int¶
The length \(N\) of the Hadamard code/sequence. Must be a power of 2.
- index: int¶
The index \(i\) in \([0, N)\) of the Hadamard code.
- output: 'binary' =
'binary'
¶ - output: 'field'
- output: 'bipolar'
The output format of the Hadamard code/sequence.
"binary"
(default): The Hadamard code with binary values of 0 and 1."field"
: The Hadamard code as a Galois field array over \(\mathrm{GF}(2)\)."bipolar"
: The Hadamard sequence with bipolar values of 1 and -1.
- Returns:¶
The Hadamard code/sequence of length \(N\) and index \(i\).
References¶
Examples¶
Create a Hadamard code and sequence of length 16.
In [1]: sdr.hadamard_code(16, 4) Out[1]: array([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) In [2]: sdr.hadamard_code(16, 4, output="bipolar") Out[2]: array([ 1., 1., 1., 1., -1., -1., -1., -1., 1., 1., 1., 1., -1., -1., -1., -1.]) In [3]: sdr.hadamard_code(16, 4, output="field") Out[3]: GF([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1], order=2)
The Hadamard and Walsh code sets are equivalent, however they are indexed differently.
In [4]: np.array_equal(sdr.hadamard_code(16, 3), sdr.walsh_code(16, 8)) Out[4]: True In [5]: np.array_equal(sdr.hadamard_code(16, 11), sdr.walsh_code(16, 9)) Out[5]: True
Hadamard sequences have zero cross correlation when time aligned.
In [6]: seq1 = sdr.hadamard_code(32, 4, output="bipolar"); \ ...: seq2 = sdr.hadamard_code(32, 10, output="bipolar"); \ ...: seq3 = sdr.hadamard_code(32, 15, output="bipolar"); ...: In [7]: plt.figure(); \ ...: sdr.plot.time_domain(seq1 + 3, label="Index 4"); \ ...: sdr.plot.time_domain(seq2 + 0, label="Index 10"); \ ...: sdr.plot.time_domain(seq3 - 3, label="Index 15") ...:
Hadamard sequences have zero cross correlation when time aligned. However, the sidelobes can be quite large when time misaligned. Because of this, Hadamard sequences for spreading codes are useful only when precise time information is known.
In [8]: lag = np.arange(-seq1.size + 1, seq1.size); \ ...: xcorr12 = np.correlate(seq1, seq2, mode="full"); \ ...: xcorr13 = np.correlate(seq1, seq3, mode="full"); \ ...: xcorr23 = np.correlate(seq2, seq3, mode="full"); ...: In [9]: plt.figure(); \ ...: sdr.plot.time_domain(lag, np.abs(xcorr12), label="4 and 10"); \ ...: sdr.plot.time_domain(lag, np.abs(xcorr13), label="4 and 15"); \ ...: sdr.plot.time_domain(lag, np.abs(xcorr23), label="10 and 15"); \ ...: plt.xlabel("Lag"); \ ...: plt.title("Cross correlation of length-32 Hadamard sequences"); ...:
Hadamard sequence autocorrelation sidelobes are not uniform as a function of sequence index. In fact, the sidelobes can be quite high.
In [10]: lag = np.arange(-seq1.size + 1, seq1.size); \ ....: acorr1 = np.correlate(seq1, seq1, mode="full"); \ ....: acorr2 = np.correlate(seq2, seq2, mode="full"); \ ....: acorr3 = np.correlate(seq3, seq3, mode="full"); ....: In [11]: plt.figure(); \ ....: sdr.plot.time_domain(lag, np.abs(acorr1), label="Index 4"); \ ....: sdr.plot.time_domain(lag, np.abs(acorr2), label="Index 10"); \ ....: sdr.plot.time_domain(lag, np.abs(acorr3), label="Index 15"); \ ....: plt.xlabel("Lag"); \ ....: plt.title("Autocorrelation of length-32 Hadamard sequences"); ....: