1 Introduction

The optical code division multiple access (OCDMA) technique has caught much attention as a great solution for optical networks whether wired or wireless. Many OCDMA schemes have been proposed and enhanced to support service needs and to overcome the complications found in the electronic networks and the other optical communication techniques (Sahbudin et al. 2009; Aljunid et al. 2004; Dimitrov and Haas 2013; Aldhaibani et al. 2013). Several encoding techniques have been implemented for OCDMA. Spectral amplitude coding (SAC) would be the technique chosen regarding other OCDMA techniques because it offers security to the clients during their access time on the same transmission medium (Palais 2005). SAC-OCDMA acquires a respectable reputation due to its irreplaceable advantages of high speed, large bandwidth, huge capacity, fully asynchronous access as well as its simple network structure.

On the other hand, some shortcomings in OCDMA systems make it challenging for a flawless performance like phase induced intensity noise (PIIN) and multiple access interference (MAI) that leads to performance degradation. Using a unique code with the SAC-OCDMA system for encoding the data with appropriate detection approaches (single photodiode (SPD), AND-subtraction, and modified-AND subtraction) at the receiver helps with eliminating the effect of MAI (Abd El-Mottaleb et al. 2018, 2019; Al-Khafaji et al. 2012) (Abd El-Mottaleb et al. 2018, 2019; Al-Khafaji et al. 2012). Many codes that have either zero cross correlation as multi diagonal (MD) (Abd et al. 2011), zero cross correlation (ZCC) (Abd et al. 2012) and random diagonal (RD) (Fadhil et al. 2009) or unity cross correlation as enhanced double weight (EDW) [12], and modified double weight (MDW) (Abd El-Mottaleb et al. 2020) are proposed by researchers for SAC-OCDMA with appropriate detection techniques to reduce MAI. Unfortunately, the use of the above mentioned detection techniques still contains PIIN in the system. The use of direct detection (DD) technique reduces MAI as well as PIIN (Sarangal et al. 2017; Sarangal et al. 2021a, b).

Free space optics (FSO) is a telecommunication technology that is overrunning fiber optics technology because of its remarkable advantages such as: installation time and maintenance costs (Chaudhary et al. 2014; Karpagarajesh et al. 2022). It also offers many advantages like low implementation costs, license-free and immunity to electromagnetic interference (Khalighi and Uysal 2014).

Recently, SAC-OCDMA is used in FSO communication systems to allow secure transmission for areas where implementing optical fiber cables is difficult. In (Mostafa et al. 2017), the performance of SAC-OCDMA using ZCC code and MD code in FSO communication systems is studied under various weather conditions. In (Abd El-Mottaleb et al. 2021), enhanced double weight (EDW) code is used in SAC-OCDMA with modified-AND and SPD detection techniques in FSO systems. The majority of SAC-OCDMA systems transmitting over optical fiber employ LED sources. However, they are not suitable for FSO transmission due to the low peak power and wide beam divergence. Hence, utilization of the multi-wavelength laser source offers better system performance for outdoor wireless optical networks, where there is high attenuation due to weather fluctuations (Wei et al. 2001, Moghaddsi et al. 2016). The FSO link performance is affected by atmospheric conditions (Robinson and Jasmine 2016).

Nowadays, a vast amount of data is readily available. As a result, analyzing this data in order to extract some relevant information and developing an algorithm based on this analysis is critical. Data mining and machine learning (ML) can be used to do this.

ML is a subset of artificial intelligence (AI) that is used to create algorithms based on data trends and past data correlations. ML is utilized in a variety of industries, including bioinformatics, wireless communication networking and picture deconvolution (Angra and Ahuja 2017). The ML algorithms extract information from data. These data are accustomed to learning (Abdualgalil and Abraham 2020).

In wireless communications, the key promises of 6G are to expand ML benefits in wireless networks and to consumers. Using ML approaches, 6G will also deliver gains in technical metrics like high throughput, support for new high-demand applications and enhanced radio frequency band use (Kaur et al. 2021).

In this paper, we use a laser source, instead of LED, in three different SAC-OCDMA systems that use three different codes EDW, MDW, and MD, with direct detection (DD) in FSO communication systems. This is used at 10 Gbps with a continuous wave (CW) laser that can support higher bit rates and has stable output power over any averaged of time periods which is suitable to be used in free space optical communication system than LED source has low peak power. A performance comparison of the SAC-OCDMA based FSO system using different codes is performed under different weather conditions, in terms of propagation range, received power, SNR, BER and Q-factor.

Additionally, the simulation data that obtained for SNR, BER and Q-factor by simulating these different systems with software Optisystem version 18 are applied as input and training to the ML classifiers.

ML algorithms are employed in order to classify the receiving code whether it is EDW, MDW or MD at different weather conditions, including clear air (CA), light mist (LM), very light fog (VLF), and light fog (LF).

The remainder of the paper is organized as follows. Section 2 describes the SAC-OCDMA codes constructions. Section 3 explains the proposed model and analysis. The obtained results are displayed and discussed in Sect. 4, followed by Sect. 5 that is devoted to the main conclusions.

2 SAC-OCDMA code construction

The configurable SAC-OCDMA transceiver is based on the type of assigned codes. Three different codes (EDW, MDW and MD) are used and assigned to three different users in the proposed ML model. These codes are characterized by N, W and \({R}_{c}\), referring to code length, code weight and cross correlation, respectively (Moghaddasi et al. 2017). The cross correlation between any two code sequences is (Mirza et al. 2021)

$$ R_{c} = \sum\nolimits_{i = 1}^{N} {A_{i} B_{i} } $$
(1)

where \({A}_{i}\) and \({B}_{i}\) are non-identical sequences, and A = \({a}_{1}, {a}_{2},\dots {a}_{N}\) and B = \({b}_{1}, {b}_{2},\dots {b}_{N}\). So, \(i\) in \({A}_{i}\) and \({B}_{i}\) refers to the bit value of the respective code word. Knowing the value of cross correlation between any two-code sequences is important to find the suitable structure of encoder and decoder.

Mathematically, the EDW code can be represented using a K × N matrix, where K represents the number of users. A basic 3 × 6 matrix with W = 3 and Rc = 1 can be expressed as (Abd El-Mottaleb et al. 2020)

$$ {\text{EDW }} = \left| {\begin{array}{*{20}c} 1 & {\quad 1} & {\quad 0} \\ 0 & {\quad 1} & {\quad 0} \\ 0 & {\quad 0} & {\quad 1} \\ \end{array} \begin{array}{*{20}c} {\quad 1} & {\quad 0} & {\quad 0} \\ {\quad 0} & {\quad 1} & {\quad 1} \\ {\quad 1} & {\quad 0} & {\quad 1} \\ \end{array} } \right| $$
(2)

While the relation between the code length and the number of users is (Abd El-Mottaleb et al. 2021)

$$ N = 2k + \frac{4}{3}\left[ {\sin \left( {\frac{k\pi }{3}} \right)} \right]^{2} \frac{8}{3}\left[ {\sin \left( {\frac{{\left( {k + 1} \right)\pi }}{3}} \right)} \right]^{2} + \frac{4}{3}\left[ {\sin \left( {\frac{{\left( {k + 2} \right)\pi }}{3}} \right)} \right]^{2} $$
(3)

For the MDW code, the given 3 × 9 matrix with W = 4 and unity cross correlation is (Abd El-Mottaleb et al. 2020)

$$ {\text{MDW}} = \left| {\begin{array}{*{20}c} 1 & {\quad 1} & {\quad 0} \\ 0 & {\quad 1} & {\quad 1} \\ 0 & {\quad 0} & {\quad 0} \\ \end{array} \begin{array}{*{20}c} {\quad 1} & {\quad 1} & {\quad 0} \\ {\quad 0} & {\quad 0} & {\quad 0} \\ {\quad 0} & {\quad 1} & {\quad 1} \\ \end{array} \begin{array}{*{20}c} {\quad 0} & {\quad 0} & {\quad 0} \\ {\quad 1} & {\quad 1} & {\quad 0} \\ {\quad 0} & {\quad 1} & {\quad 1} \\ \end{array} } \right| $$
(4)

The relation between N and K is (Abd El-Mottaleb et al. 2021)

$$ N = 3K + \frac{8}{3}\left[ {\sin \left( {\frac{k\pi }{3}} \right)} \right]^{2} $$
(5)

The MD code has an easy construction depending on identity matrix, zero cross correlation, flexibility on choosing number of users as well as the code weight (Abd et al. 2012). In this code, the relation of code length depends on the number of users and code weight and is illustrated as (Abd et al. 2012)

$$ N \, = \, K \times W $$
(6)

So, for three users and W = 3, one can write the 3 × 9 MD matrix as

$$ {\text{MD }} = \left| {\begin{array}{*{20}c} 1 & {\quad 0} & {\quad 0} \\ 0 & {\quad 1} & {\quad 0} \\ 0 & {\quad 0} & {\quad 1} \\ \end{array} \begin{array}{*{20}c} {\quad 0} & {\quad 0} & {\quad 1} \\ {\quad 0} & {\quad 1} & {\quad 0} \\ {\quad 1} & {\quad 0} & {\quad 0} \\ \end{array} \begin{array}{*{20}c} {\quad 1} & {\quad 0} & {\quad 0} \\ {\quad 0} & {\quad 1} & {\quad 0} \\ {\quad 0} & {\quad 0} & {\quad 1} \\ \end{array} } \right| $$
(7)

Table 1 shows the existing wavelengths assigned for the EDW code that has a code weight, code length and cross correlation of 3, 6 and 1, respectively, for three users. Wavelengths are assigned only when bit ‘1’ exists.

Table 1 Wavelengths assigned to users using EDW codes

Table 2 gives the wavelengths corresponding to three users for MDW codes having N = 9,W = 4 and \({R}_{c}\)= 1 as well as for MD codes having 9 code length, 3 code weight and zero cross correlation.

Table 2 Wavelengths assigned to users using MDW codes and MD codes

3 System model and analysis

Figure 1 is the schematic diagram of the proposed model. The transmitter section contains three parts. The first part contains a pseudo random bit generator (PRBG) and non-return to zero (NRZ) responsible for information data generation in the electrical domain while the second part has the laser source to obtain wavelengths corresponding to the presence of ‘1’ bit in the code for the SAC-OCDMA encoder. The third part has a Mach–Zehnder modulator (MZM) to modulate the electrical data signals into optical signals. An FSO channel is investigated under CA, LM, VLF and LF weather conditions. At the receiver section, fiber Bragg gratings (FBGs) are used having the same spectral wavelengths of the encoder to decode the desired user using a DD technique. A photodiode (PD) is used for optical/electrical conversion and then a low pass Bessel filter (LPF) is used for rejecting noise and interference components.

Fig. 1
figure 1

Proposed OCDMA model using DD based FSO communication

Now, performance analysis is discussed and evaluated through BER, SNR and received power.

Using the DD technique and a Gaussian approximation for simplicity, the code property for SAC-OCDMA codes with regards to correlation at the photodetector is expressed as (Moghaddasi et al. 2015)

$$ \mathop \sum \limits_{n = 1}^{N} Z_{a} \left( n \right) \cdot Z_{b} \left( n \right) = \left\{ {\begin{array}{*{20}c} {W_{h} , } & {for\, a = b} \\ {0,} & {for\, a \ne b} \\ \end{array} } \right. $$
(8)

where \({Z}_{a}\left(n\right)\) and \({Z}_{b}\left(n\right)\) represent the nth element of the element of A and B code sequence for the SAC-OCDMA codes, respectively, and \({W}_{h}\) represents the number of chips that reach the PD and is equal to W − 2, (W/2) and W, respectively, for EDW (Sarangal et al. 2017), MDW (Moghaddasi et al. 2017) and MD (Mostafa et al. 2017), respectively.

The signal to noise ratio (SNR) is expressed as (Mostafa et al. 2017)

$$ SNR = \frac{{P_{User}^{2} }}{{\sigma_{Shot - noise}^{2} + \sigma_{Thermal - noise}^{2} + \alpha_{FSO - attenuation} }} $$
(9)

where \(P_{User}^{2}\) is the average power of the desired user that is received at the PD and is equal to \(\mathcal{R}\) b \({w}_{h}{S}_{r}\) (Moghaddasi et al. 2015), where \(\mathcal{R}\) is the PD responsivity, b is the bit value that is either ‘1’ or ‘0’ for the transmission of desired user and \({S}_{r}\) is the received power, expressed as (Kolev et al. 2012)

$$ S_{r} = S_{t} \left( {\frac{{d_{r} }}{{d_{t} + \theta L}}} \right)^{2} 10^{{\frac{ - \alpha L}{{10}}}} $$
(10)

where \({S}_{t}\) is the transmitted power, \({d}_{t}\) and \({d}_{r}\) are the transmitter and receiver aperture diameters, respectively, \(\theta \) is the beam angle, L is the propagation length in free space. The values of parameters \({S}_{t}\), \({d}_{r}\), \({d}_{t}\), \(\theta \), and \(\alpha \) are given in Table 3 while L that is propagation range. In simulation we took different values for it under different weather conditions. \(\alpha \) is the attenuation according to the certain weather condition, given by (Fadhil et al. 2013)

$$ \propto = \frac{3.912}{V}\left( {\frac{\lambda }{{550{ }nm}}} \right)^{ - x} $$
(11)

where V is the visibility, \(\lambda \) is the operating wavelength and x is the size distribution of the scattering particle. According to Kim model, x is expressed as (Singh and Malhotra et al. 2019)

$$ x = \left\{ {\begin{array}{*{20}l} {1.6 } \hfill & {V > 50} \hfill \\ {1.3 } \hfill & {6 < V < 50} \hfill \\ {0.16 V + 0.34} \hfill & {1 < V < 6} \hfill \\ {V - 0.5} \hfill & {0.5 < V < 1} \hfill \\ 0 \hfill & {V < 0.5} \hfill \\ \end{array} } \right. $$
(12)
Table 3 Simulation Parameters (Sarangal et al. 2021a, b; Abd El-Mottaleb et al. 2021)

The shot noise variance is defined as (Moghaddasi et al. 2017)

$$ \sigma_{Shot - noise}^{2} = {\text{ 2e }}\left( {{\text{b}}w_{h} S_{r} + {\text{X }}P_{o} } \right)B_{e} $$
(13)

where e is the electron charge, \({P}_{o}\) is the optical power of crosstalk pulses, and X refers to the event of all interfering pulses from the possible interfering users out of (K-1) and its value is expressed as (Moghaddasi et al. 2017)

$$ {\text{X }} = \frac{{W_{h}^{2} \left( {K - 1} \right)}}{2N} $$
(14)

The values of e and \({P}_{o}\), are given in Table 3. As we use the DD technique, so, the value of X is equal to zero.

As we use the DD technique, so, the value of X is equal to zero.

The thermal noise variance can be obtained by (Anuar et al. 2013)

$$ \sigma_{Thermal - noise}^{2} = \frac{{4k_{B} TB_{e} }}{{R_{L} }} $$
(15)

where \({k}_{B}\) is Boltzmann constant, \(T\) is the receiver noise absolute temperature and \({R}_{L}\) is the receiver load resistance. The values of \({k}_{B}\), \(T\), and \({R}_{L}\) are given in Table 3.

The bit error rate (BER) of the optical signal transmitted in terms of SNR using the Gaussian approximation is defined by (Wei et al. 2001)

$$ BER = \frac{1}{2}erfc\left( {\sqrt{\frac{SNR}{8}} } \right) $$
(16)

Figure 2 illustrates the flow chart that describes the model, showing the codes that could be used in the model of ML to distinguish between them according to the Q-factor, BER and SNR.

Fig. 2
figure 2

Flow chart of the model

3.1 ML algorithms

The ML is discussed through its classification scheme and results. First, the extracted ML input parameters (Q-factor, BER and SNR) require some data preprocessing before employing the ML algorithms. The labelled outcome (target column), which is to be predicted by ML, contains three labels: EDW, MDW and MD for each weather condition. Finally, the ML algorithms are applied and then evaluated using confusion matrices in order to retrieve the accuracy information for each code prediction under the four different weather conditions.

  1. 1.

    Data preprocessing

    Data preprocessing flow is essential since the data should be normalized before applying any ML algorithm. The data normalization solves the problem of high variance and outliers (Aggarwal et al. 2019). Here, these 3 parameters (Q-factor, BER and SNR) are extracted and normalized using the Z-score method. Normalization solves these issues by generating new values that preserve the source data general distribution and ratios while maintaining values within a scale that is applied to all numeric columns in the model. Each data point \({Z}_{i}^{j}\) should be normalized using the Z-score and can be expressed as

    $$ Z_{i}^{j} = \frac{{Z_{i}^{j} - \overline{{Z^{j} }} }}{{\sigma_{{Z^{j} }} }} $$
    (17)

    where \(\overline{{\mathrm{Z}}^{j}}\) and \({\sigma }_{{Z}^{j}}\) are the mean and standard deviation of each feature j.

    Since the number of input variables is three, data dimension reduction is not required and the ML algorithms can be applied instantly in order to reduce preprocessing complexity.

  2. 2.

    Data classification

    Data classification using ML is less complex than deep learning. Moreover, in ML, there are two main techniques: supervised learning and unsupervised learning. The supervised learning is a labeled technique which requires a label as target or output column unlike the unsupervised learning which only takes input variables and creates clusters based on statistics. Both learning techniques are important and are required in different applications. But, in this paper, since the three codes are known in the dataset, so, supervised learning approaches are employed. Both KNN algorithm and SVM proved their high accuracy achievement in wireless communication scenario classification (Zhang et al. 2020). Both classifiers are chosen among other ML classifiers because of their simplicity and efficiency. Moreover, the software implementation of KNN and SVM is easy, reachable, and can be performed using many tools and libraries. One of the most popular libraries is Scikit-Learn Library in Python, which facilitates the use of ML techniques (Hwang et al. 2018).

    Figure 3 illustrates the two algorithms under the classification process. When there is a little or no prior knowledge about the data distribution, the KNN is one of the most fundamental and easy classification algorithms. It should be one of the initial options for a classification problem. It is a non-parametric classification and regression approach. The core principle behind KNN is to categorize an item based on a majority vote from its immediate surroundings, with the object being allocated to the most prevalent class as shown in Fig. 3 (a). The SVM has been shown to be a reliable regression and classification model, even when dealing with nonlinear connections, noisy and complicated data, and training data sets with outliers. SVM, like any other ML algorithm, cannot avoid overfitting; nonetheless, it is resistant to overfitting to training data. Moreover, to segregate data, the SVM constructs a hyperplane or group of hyperplanes in a high- or infinite-dimensional space with the greatest distance to the nearest training-data point of any class as shown in Fig. 3b. The challenge of finding the best hyperplanes may be expressed as an optimization problem that can be addressed using a quadratic program.

    Fig. 3
    figure 3

    Machine learning classifiers (a) KNN, (b) SVM

    The shape of the data is 900 row and 4 columns. The rows represent the number of samples while the 4 columns represent the 4 features. The 900 samples contain 300 data points for each class of EDW, MD and MDW codes. The 300 data points for each class are split into training and test data. The training set is 200 samples for each class while the test set is 100 data points for each class. The 4 columns consist of the predictors and the output label. The predictors are Q-factor, BER and SNR while the fourth column is the label (output). The label is categorized as EDW, MD, and MDW. The training set is used for both KNN and SVM classifiers for model training. Then, the test set is used for model evaluation.

4 Results and discussion

In this section, we present the obtained simulation results and ML classification results.

4.1 Simulation results

Here, we present the obtained simulation results that are conducted through Optisystem ver. 18, using the parameters given in Table 3 (Sarangal et al. 2021a, b; Abd El-Mottaleb et al. 2021).

The obtained number of chips that reach the PHD, Wh, for each case, is as follows.

Wh = 3 for MD code as there is no interference between users so at the receiver, decoder has the same spectral of the encoder and that is equal to W = 3.

Wh = 1 for EDW code as the decoder has only the non-interference bits that are equal to W − 2 = 3 −  2 = 1.

Wh = 2 for MDW code as the decoder has only the non-interference bits that are equal to (W/2) = (4/2) = 2.

Figure 4 illustrates the impact of different CA, LM, VLF, and LF conditions, respectively, on the proposed FSO system performance in terms of BER. Clearly, a longer propagation range can be achieved when EDW code is used with log(BER) less than − 3 under various weather scenarios. Ranges of 7, 3.5, 1.8, and 0.98 km, respectively, with log (BER) values − 5, − 7.2, − 7.9 and − 6.7, respectively, are achieved under CA, LM, VLF and LF, respectively. While, when MD code is used, minimum propagation distances can be achieved; 6.3, 3.2, 1.7, and 0.92 km with log(BER) less than − 3. As expected, when the range between transmitter and receiver increases, the BER decreases and the VLF condition gives the worst performance for all the codes while LM gives moderate performance and the best performance is CA.

Fig. 4
figure 4

Log(BER) versus propagation range under: (a) CA, (b) LM, (c) VLF, (d) LF

Figure 5 shows the relation between the Q-factor and propagation distance for different codes under different weather scenarios. As expected, as the distance between transmitter and receiver increases, the Q-factor decreases and the FSO communication system that uses EDW code gives the best value of Q-factor for higher propagation range which is 9.1, 7.1, 5.5 and 5, respectively for ranges 5.5, 3.2, 1.8 and 0.98 km, under CA, LM, VLF and LF, respectively. The system that uses MD code gives the worst performance at a longer propagation range. Also, the three systems can propagate longer distances under CA while a shorter range is obtained under VLF due to the attenuation that occurs under this weather condition and causes signal degradation.

Fig. 5
figure 5

Q-factor versus propagation range under: (a) CA, (b) LM, (c) VLF, (d) LF

Figure 6 displays the received power for different FSO systems that use EDW code with a code weight of 3, MDW code with a code weight of 4 and MD code with a code weight of 3 for three users versus the propagation range. For a shorter range between transmitter and receiver, higher received power is obtained and it degrades with increasing the range. Both EDW and MDW codes achieve a received power higher than MD code. The obtained received power at 5.5 km under CA for EDW, MDW and MD codes is, respectively, − 21.58, − 22.04 and − 23.8 dBm. While under the LM condition, the received power is − 22.7, − 23.18 and − 24.9 dBm for EDW, MDW and MD codes, respectively, at a propagation distance of 3.2 km. The received powers for EDW code as well as MDW code under VLF are − 23.8 and − 24.3 dBm, respectively, at 1.9 km and a BER less than \({10}^{-9}\) while for MD code, its received power at the same distance is − 26.08 with BER greater than 10–9. So, this system cannot be used for longer propagation distances. Under the LF condition, to make the three systems that use three different codes propagate with achievable received power that corresponds to log (BER) less than -2.5, it is preferred to take the propagation link 0.92 km.

Fig. 6
figure 6

Received power versus propagation range under: (a) CA, (b) LM, (c) VLF, (d) LF

Table 4 summarizes the received power for the different codes under CA, LM, VLF, and LF, at 5.5, 3.2, 1.9, and 0.92 km propagation range, respectively.

Table 4 Received power for three codes under different weather conditions

Figure 7 reports the SNR with the propagation range under various weather scenarios and different codes. As the propagation distance between transmitter and receiver increases, the SNR increases and the three systems give the best value for SNR under CA weather, while the worst value occurs under VLF, as expected. The system that uses EDW code gives the best value of SNR as declared from Fig. 7, which is 7.62, 5.3, 3, and 2.2 dB, at 5.5, 3.2, 1.9, and 0.98 km, respectively, under CA, LM, VLF and LF, respectively.

Fig. 7
figure 7

SNR versus propagation range under: (a) CA, (b) LM, (c) VLF, (d) LF

4.2 ML results

In this part, we will display and discuss the obtained ML results. The KNN and SVM results are displayed in Figs. 8 and 9, respectively, for each weather condition. When the color of the diagonal cells is biased toward yellow, this indicates high classification accuracy.

Fig. 8
figure 8

Confusion matrices of KNN classifier in code prediction under: (a) CA, (b) LM, (c) VLF, (d) LF

Fig. 9
figure 9

Confusion matrices of SVM classifier in code prediction under: (a) CA, (b) LM, (c) VLF, (d) LF

Since the software used in the classification task takes a random state of the data groups: EDW, MDW and MD, so, the number of test or training data may vary within 1%, for example, instead of using 100 data points for test. It takes 99 or 101 data points such as the case of EDW and MDW in confusion matrices in Figs. 8 and 9, respectively. Figure 8 displays the classification results of the KNN classifier, where the classification results of CA, LM and LF are reliable. The VLF case has the worst classification accuracy among the other cases. This is because of the distribution of the complex data in the VLF case. On the other hand, Fig. 9 is the visualization of SVM confusion matrices for each weather condition. The figure shows promising SVM classification results in CA, LM and LF but slightly less accurate than KNN. So, the KNN has better results than SVM. This is because, in this case, the distribution of the input dataset which is more adequate for KNN. Also, the worst classification accuracy case for the SVM is the same like the KNN classifier which is the VLF case. Table 5 shows the average and standard deviation of each parameter for the three codes under different weather conditions and the highest ML classification performance is achieved under the LM weather condition.

Table 5 Average and standard deviation of each parameter for each code under different weather conditions (Q-factor, log(BER) and SNR)

The two supervised learning algorithms are simple and efficient in terms of the computational time. As the number of neighbors, K, in the KNN algorithm increases, the complexity of computing decreases, but, in a trade-off with noise consideration. So, the K neighbors in the KNN is taken equal to 10 in order to reduce the computational complexity, showing good results. The Euclidian distance is the metric used in calculations. Moreover, the SVM with radial basis function (RBF) Kernel adopted shows also satisfying results. In CA, LM and LF, both classifiers show more than 97% of classification accuracy and in most cases. The KNN provides better results such as 99% accuracy since SVM requires less complexity than KNN. Also, in case of LF, both classifiers achieve 100% accuracy, i.e. highest precision and recall. However, many misclassifications may occur in some cases such as the VLF case since the accuracies are 82% and 81% for KNN and SVM, respectively. These misclassifications are due to the structure of the dataset in VLF and at certain cases, the SNR of MD code is 0. This is because of the distance range at which the measurements are taken according to the corresponding weather condition.

Since the accuracy is not enough to evaluate the model performance, so, other important performance evaluation parameters such as precision, recall and F1-score are adopted (Bansal and Singhrova 2021). These parameters are extracted from the statistical properties of the confusion matrix. The precision indicates the quality of a positive prediction provided by the algorithm. The recall is the number of true positives divided by the number of true positives plus the number of false negatives. The F1-score is a combination of recall and precision. Table 6 shows more of the ML evaluation parameters. In case of CA, both SVM and KNN show promising results in classifying the EDW, MD and MDW codes. The F1-score of SVM is 0.98, 0.98 and 1 for EDW, MD and MDW, respectively. The KNN shows exactly similar values like SVM. This indicates that the classification accuracy and performance for both algorithms in CA are reliable. The KNN outperforms the SVM in the case of LM, where the KNN shows a F1-score of 0.99, 0.99 and 1, while the SVM has a F1-score of 0.97, 0.95 and 0.98. In case of VLF, both algorithms show the worst classification performance since the F1-score 0.73 and 0.75 in MD for KNN and SVM, respectively. The LF case is ideal as both KNN and SVM achieve 100% precision, recall and F1-score. This indicates that the LF case has the best reliability of using KNN or SVM.

Table 6 Evaluation parameters: precision, recall and F1-score

5 Conclusion

This paper proposes different SAC-OCDMA systems assigned three different codes; EDW, MDW, and MD codes based FSO communication. A coherent continuous wave laser source is used at the transmitter. A direct detection (DD) technique is used at the receiver for detecting the required user. The performance of the proposed systems is evaluated under different weather conditions: CA, LM, VLF, and LF in terms of Q-factor, bit error rate (BER), received power, and signal to noise ratio (SNR). Moreover, two machine learning (ML) algorithms, K-Nearest Neighbor (KNN) and Support Vector Machine (SVM), are used to classify the receiving code, whether it is EDW code, MDW code, or MD code. The conducted results reveal that the FSO communication system with the EDW code achieves the longest propagation distance with higher received power compared with the other codes; MDW and MD. It can transmit up to 7 km under CA, 3.5 km under LM, 1.8 km under VLF, and 0.8 km under LF with BER less than \({10}^{-6}\). The received power when the EDW code is used at a 5 km FSO link is − 21.58 dBm under CA, which is decreased to − 22.04 dBm and − 23 dBm when MDW and MD codes are used, respectively. Furthermore, the transmitting code (EDW, MDW, or MD) is translated into a classification issue from the perspective of ML by normalizing and employing the evaluation parameters (Q-factor, BER, and SNR) that are used as ML input features. Both ML algorithms, KNN and SVM, showed good classification between the three codes in most weather conditions in terms of accuracy, precision, and recall. They achieved 100% accuracy under LF while under VLF, the accuracy is 82% when the KNN algorithm is used and 81% when the SVM algorithm is used.

The enhancement of the classification of the VLF case should be considered as a future work. The VLF case must be studied from the perspective of the ML classifier. So, some preprocessing methods can be carried out, including cross-validation techniques. This step will most likely lead to better classification results during ML processes.