# Optical Code Construction of 2D Spectral/Spatial BIBD Codes for SAC-OCDMA Systems
## 2 2D-BIBD Code for SAC-OCDMA Systems
### Construction of BIBD Code Families
#### 2.1.2 Proposed 2D Spectral/Spatial BIBD Code  
In order for the users to cause minimal interference to other codes, the auto and cross-correlation values must be small so that there will be fewer overlapping chips in the SAC OCDMA system. Optimal OOC codes based on the BIBD construction should have minimum cross-correlation and maximum off-peak auto-correlation. A cyclic shifting approach can obtain 1D-BIBD code sequences. Further, 2D-BIBD codes are extended or converted from the 1D-BIBD, constructed by using two different code-sets of a 1D-BIBD code family based on previously developed 2D spectral/spatial coding approaches [25]. In addition, 2D-BIBD code sets are entitled by unitary matrices. To convert 1D-BIBD into 2D-BIBD, we consider following two 1D code sequences: \(X=[x_{0},x_{1},\ldots x_{L1}]\) with \([N_{max}=3,\ w_{1}=3]\) and \(Y=[y_{0},y_{1},\ldots y_{L2}]\) with \([N^{\prime}_{max}=2,\ w_{2}=3]\), respectively, where \(L_{1}\) and \(L_{2}\) are the code lengths which are 19 and 13 for the \(X\) and \(Y\) code sequences, respectively, and \(w\) is the code weight (\(w=w_{1}=w_{2}=3\)). The resulting 2D-BIBD code can be expressed as:  
\[C_{g,h}=Y_{g}^{T}X_{h} \tag{6}\]where, \(X_{h}\) and \(Y_{g}^{T}\) are the \(h^{th}\) and \(g^{th}\) code sequences of the spectral (\(X\)) and spatial (\(Y\)) code sequence, respectively, whereas \(\,\mathrm{g}\,=\,0,\,1,\,\ldots,\,N_{max}-1\) and \(\,\mathrm{h}\,=\,0,\,1,\,\ldots,\,N_{max}^{\prime}-1\). The resulting code size of the 2D-BIBD code is \(N_{max}N_{max}\), where \(N_{max}\) and \(N_{max}\) are the code sizes (number of code matrices/users per code sequence). An example of a 2D-BIBD code development using two 1D-BIBD code sequences, belonging to two different code families is illustrated in Table 2. \(X_{1}\,=\,(1,\,7,\,11),\,X_{2}\,=\,(2,\,3,\,14),\) and \(X_{3}\,=\,(4,\,6,\,9)\) will be the resulting three blocks of the 2D-BIBD code matrix and \(Y_{1}\,=\,(1,3,9  
The construction process of the proposed code is shown as Algorithm 1. The BIBD coding algorithm is derived using two BIBD blocks. The BIBD algorithm has four specified inputs: \(N_{max}\), \(N^{\prime}_{max}\) and the set numbers of \(W_{i}\), while the output of the algorithm is the \(C_{g,h}\) generated codes for \(N_{max}\)\(N^{\prime}_{max}\) users. The proposed design of the 2D-BIBD coding technique includes six steps to determine the \(N_{max}\)\(N^{\prime}_{max}\) codes:  
* Determining the total code length (line 1-line 2). The proposed 2D-BIBD codes can support a total of \(N_{max}\times N^{\prime}_{max}\) users with code length of \(L_{1}\times L_{2}\). For example, when \((\text{w}_{1},\text{N}_{\text{max}})=(3,3)\), \(L_{1}=3\times(3-1)3+1\) resulting in 19 as the code length for the spectral dimension, likewise for \(L_{2}\). * Selecting two prime numbers over \(\text{GF}(L_{i})\) (line 3-line 4). \(\alpha_{1}\) and \(\alpha_{2}\) denote the primitive elements of \(\text{GF}(L_{1})\) and \(\text{GF}(L_{2})\), respectively. _For \(\text{GF}(L_{1}=19)\)_, \(\alpha_{1}=2\) is selected as a prime number for the spectral dimension. * Generating the first spectral and spatial BIBD blocks (C1 and C2) by using Equation (5) (line 5-line 13). For \((\alpha_{1},L_{1})=(2,19)\), the first selected 1D-BIBD block \(C1=((\alpha_{1}{}^{1}\ mod\ L_{1})-1\), \(\left((\alpha_{1}{}^{2\times 3+1}\ mod\ L_{1})\right)-1\), \((\alpha_{1}{}^{4\times 3+1}\ mod\ L_{1})-1\), ) resulting in \((1,\,14,\,3)\) which represents the positions of 1s. Likewise for the spatial dimension. * Generating the \(X_{h}\) matrix for the BIBD spectral codes (line 15-line 18). The 1D-BIBD spectral codes are represented by a set of sequence designed by rotating right \(C1\)_by 1_. When C1 is represented by \((1,\,3,\,14)\), the generated code for the second user becomes \((2,\,4,\,15)\). * Generating the \(Y_{g}\) matrix for the BIBD spatial codes (line 20-line 23). The 1D-BIBD spatial codes are represented by a set of sequences designed by rotating right C2 by 1.