# Optical Code Construction of 2D Spectral/Spatial BIBD Codes for SAC-OCDMA Systems
## 2 2D-BIBD Code for SAC-OCDMA Systems
### 2D-BIBD Code Properties  
Four characteristic matrices were introduced to design the transmitter and receiver module through \(C^{(d)}\), where \(d\in[0,\ldots,3]\). They will be used to evaluate the cross-correlation characteristics of the 2D-BIBD code.  
\[\begin{array}{l}C_{g,h}{}^{(0)}={Y_{g}}^{T}\ X_{h}\\ C_{g,h}{}^{(1)}=\overline{Y_{g}}^{T}X_{h}\\ C_{g,h}{}^{(2)}={Y_{g}}^{T}\overline{X_{h}}\\ C_{g,h}{}^{(3)}=\overline{Y_{g}}^{T}\overline{X_{h}}\end{array} \tag{7}\]  
where \(\overline{X_{h}}\) and \(\overline{Y_{g}}\) are the complementary of \(X_{h}\) and \(Y_{g}\). The 2D-BIBD code \(C_{g,h}\) is represented by set of elements \(C_{i,j}\) where \(i\) varies from \((0,\ldots,L_{2}-1)\) and j varies from \((0,\ldots,L_{1}-1)\).  
The cross-correlation for 2D-BIBD coding technique between \(C_{g,h}\) and \(C^{(m)}\) is represented as:  
\[R_{g,h}^{(d)}=\sum_{i=0}^{L_{2}-1}\sum_{j=0}^{L_{1}-1}c_{i,j}^{(d)}\times c_{ i,j}(g,h) \tag{8}\]  
where \(c_{i,j}^{(d)}\) and \(c_{i,j}(g,h)\) are the \((i,j)^{\text{th}}\) elements of \(C^{(d)}\) and \(C_{g,h}\), respectively.  
Based on Equations (7) and (8), 2D-BIBD codes cross-correlation values are listed in Table 3.  
```
Input: \(N_{max}\), \(N^{\prime}_{max}\) // number of served users Input: \(w_{i}=\{w_{1},w_{2}\}\) // \(w_{i}\) represents weight of spectral and special generated codes Output: \(C_{g,h}=Y_{g}^{T}X_{h}//\ C_{g,h}\) is \(2D\ BIBD\) matrix CODE
1. Define \(L_{1}=w_{1}\times(w_{1}-1)N_{\max}+1\ //L_{1}\) represents spectral code sequence length
2. Define \(L_{2}=w_{2}\times(w_{2}-1)N^{\prime}_{max}+1\ //L_{2}\) represents spatial code sequence length
3. Define \(\alpha_{1}//\) primitive element of \(GF(L_{1})\)
4. Define \(\alpha_{2}//\) primitive element of \(GF(L_{2})\)
5. Define \(X//\) X is a \(N^{\prime}_{max}L_{1}\) matrix spectral codes
6. Define \(Y//\) Y is a \(N_{max}L_{2}\) matrix spatial codes
7. BIBD blocks generation
8. \(X_{0}(L_{1}-1\ downtron\ 0) = (others =>^{\prime}\ 0^{\prime})\);
9. \(Y_{0}(L_{2}-1\ downtron\ 0) = (others =>^{\prime}\ 0^{\prime})\);
10. For i = 0 to \(w_{1}-1\) loop
10.1. \(X_{0}\big{(}(a_{1}^{2N_{max}+1}\ mod\ L_{1})-1)=1\);
11. End for
12. For i = 0 to \(w_{2}-1\) loop
12.1. \(Y_{0}\big{(}(a_{2}^{2N_{max}+1}\ mod\ L_{2})-1\big{)}\)=1;
13. End for
14. BIBD spectral codes generation
15. For h = 1 to \(N^{\prime}_{max}-1\) loop
16. \(X_{h}(L_{1}-1\ downtron\ 0) = (others =>^{\prime}\ 0^{\prime})\);
17. \(X_{h}=ROR(X_{h-1},1)\);
18. End for
19. BIBD spatial codes generation
20. For g = 1 to \(N_{max}-1\) loop
21. \(Y_{g}(L_{2}-1\ downtron\ 0) = (others =>^{\prime}\ 0^{\prime})\);
22. \(Y_{g}=ROR\big{(}Y_{g-1},1)\);
23. End for
24. 2D-BIBD codes generation
25. For g = 0 to \(N_{max}-1\) loop
25. For h = 0 to \(N^{\prime}_{max}-1\) loop
25.1. \(C_{g,h}=Y_{g}^{T}X_{h}\)
25. End for
26. End for
27. Return \(C_{g,h}\)
```  
**Algorithm 1** Proposed 2D-BIBD Spectral/Spatial code for OCDMA systems.  
We identified that R(1)(g,_h_), and R(3)(g,_h_) values showed no role in constructing the new correlation function, which resulted in an easier MUI cancellation process. Therefore, a new cross-correlation function can be represented as follows (Table 3):  
\[R^{(0)}_{g,h}-\frac{R^{(2)}_{g,h}}{(w_{1}-1)}=\left\{\begin{array}{cc}w_{1} w_{2}&,\ for\ g=h=0\\ 0&\ otherwise\end{array}\right. \tag{9}\]