# WON-OCDMA System Based on MW-ZCC Codes for Applications in Optical Wireless Sensor Networks
## 2 Code Construction  
The novel MW-ZCC code for SAC-OCDMA system is matrix-based, and its construction follows a series of simple steps described below. **Step 1:** The code is based on an \(X\times N\) matrix where a number of lines \(N\) represents a number of codes (i.e., users or sensors \(\cdots\)) and a number of columns \(N\) represents a number of chips, respectively. Thus the base matrix produces \(X\) code sequences with code length \(N\). The cornerstone of each matrix is a matrix, \(H_{0}\) where:  
\[H_{0}= \begin{bmatrix}0&1&1\\ 1&0&0\end{bmatrix}  \tag{1}\]  
This matrix is utilised for increasing the number of users and weights using a simple replacement technique. **Step 2:** A new matrix \(H_{j}\) can be generated from the existing \(H_{(j-1)}\) matrix using a replacement technique as follows:  
\[H_{j}= \begin{bmatrix}0&H_{(j-1)}&H_{(j-1)}\\ H_{(j-1)}&0&0\end{bmatrix}  \tag{2}\]  
**Step 3:** When the replacement (\(H_{(j-1)}\)) is done, there will be blank spaces in the newly generated matrix \(H_{j}\) which are filled in by a series of '0's according to the matrix size; therefore, all the created matrices are symmetrical. For example, in the earlier substitution, \(R=1\), we have:  
\[ \begin{split} H_{j}&=\begin{bmatrix}0&H_{0}&H_{0}\\ H_{0}&0&0\end{bmatrix}\\ &=\begin{bmatrix}0&0&0&0&1&1&0&1&1\\ 0&0&0&1&0&0&1&0&0\\ 0&1&1&0&0&0&0&0&0\\ 1&0&0&0&0&0&0&0\end{bmatrix}\end{split}  \tag{3}\]  
**Step 4:** To generate higher code weights and users, another replacement is required. Now we use \(R=2\):  
\[ \begin{split} H_{j}&=\begin{bmatrix}0&H_{1}&H_{1}\\ H_{1}&0&0\end{bmatrix}\\ &=\begin{bmatrix}0&0&0&0&H_{0}&H_{0}&0&H_{0}\\ 0&0&0&H_{0}&0&0&H_{0}&0&0\\ 0&H_{0}&H_{0}&0&0&0&0&0&0\\ H_{0}&0&0&0&0&0&0&0&0\end{bmatrix}\end{split}  \tag{4}\]  
If \(W\) is the code weight, \(X\) is the number of codewords (i.e., the number of users), and \(N\) will be the length of the constructed code. The described code generation procedure produces multiple weight codes all with code-weights of power of 2:  
\[W_{i}=2^{i}\qquad 0\leq i\leq R+1 \tag{5}\]  
The highest achievable code-weight, \(W_{max}\) for the proposed code is, therefore, \(2^{R}+1\). From this, the number of the required replacement, \(R\) can be calculated:  
\[R=Log_{2}W_{max}-1 \tag{6}\]  
Similarly, a number of the generated codes (signature), \(X\) (i.e., users) is obtained by \(2^{R}+1\), and the code length can be calculated as \(N=3^{R+1}\). **Step 5:** To achieve code-weights increments without increasing the number of users, the matrix can simply be multiplied horizontally. For example, a double code weight and double code length can be achieved as  
\[W_{i}^{\prime}=2W_{i} \tag{7}\]  
and  
\[N_{i}^{\prime}=2N \tag{8}\]  
**Step 6:** If it is only desired to increase the number of users without the code-weight increase, the mapping technique is applied to double the number of users. In Equation (9) matrix \(H^{\prime}\) illustrates the increment of the code-weight while in Equation (10), matrix \(\hat{H}\) denotes the increase in the number of users, as was explained in steps 5 and 6 respectively. Here, the the code-weight which were initially 4, 2 and 1 had been increased to 8, 4 and 2 while the number of users has been maintained as 4:\[ \begin{split}& H^{\prime}=\\ &\begin{bmatrix}0&0&0&0&1&1&0&1&1&0&0&0&0&1&1&0&1&1\\ 0&0&0&1&0&0&1&0&0&0&0&0&1&0&0&0\\ 0&1&1&0&0&0&0&0&0&0&0&1&1&0&0&0&0&0&0\\ 1&0&0&0&0&0&0&0&0&1&0&0&0&0&0&0&0&0\end{bmatrix}\\ \\ &\hat{H}=\\ &\begin{bmatrix}0&0&0&0&1&1&0&1&1\\ 0&0&0&1&0&0&1&0&0&0\\ 0&1&1&0&0&0&0&0&0&0\\ 1&0&0&0&0&0&0&0&0&0&0\end{bmatrix}\\ \\ &\hat{H}=\\ &\begin{bmatrix}0&0&0&0&1&1&0&1&1\\ 0&0&0&1&0&0&1&0&0&0\\ 0&1&1&0&0&0&0&0&0&0&0\end{bmatrix}\\ \\ &\begin{bmatrix}0&0&0&0&0&0&1&1&0&1&1\\ 0&0&0&1&0&0&1&0&0\\ 0&1&1&0&0&0&0&0&0&0\end{bmatrix}\\ \\ &\begin{bmatrix}0&0&0&0&0&0&0&0&0&0&0&0&0\end{bmatrix}\\ \end{split} \end{split}\end{split} \tag{10}\]  
All empty spaces are filled by \"0\"s. Thus, the number of users has increased from four to eight while the number of code-weight is maintained as four.