Spectrum sensing in cognitive radio networks: threshold optimization and analysis

Cognitive radio is a technology developed for the effective use of radio spectrum sources. The spectrum sensing function plays a key role in the performance of cognitive radio networks. In this study, a new threshold determination method based on online learning algorithm is proposed to increase the spectrum sensing performance of spectrum sensing methods and to minimize the total error probability. The online learning algorithm looks for the optimum decision threshold, which is the most important parameter to decide the presence or absence of the primary user, using historical detection data. Energy detection- and matched filter-based spectrum sensing methods are discussed in detail. The performance of the proposed algorithm was tested over non-fading and different fading channels for low signal-to-noise ratio regime with noise uncertainty. In the conclusion of the simulation studies, improvement in spectrum sensing performance according to optimal threshold selection was observed.

approach. Communication performance and continuity in cognitive radio networks are highly dependent on whether the spectrum sensing function is performed correctly.
Spectrum sensing is a critical issue of cognitive radio technology because of the shadowing, fading, and time-varying natures of wireless channels. To sense limited or unused frequency bands, different methods for spectrum sensing have been proposed in the literature like matched filtering [4,5], cyclostationary-based sensing [6][7][8], waveformbased sensing [9], wavelet-based sensing [10], eigenvalue-based sensing [11,12], and energy detection sensing [13][14][15]. Matched filtering detection methods with shorter detection periods are preferred if certain signal information is known, such as bandwidth, operating frequency, modulation type and grade, pulse shape, and frame structure of the primary user [16,17]. The detection performance of this method largely depends on the channel response. To overcome this, it requires perfect timing and synchronization in both physical and medium access control layers. This situation increases the complexity of calculation. Cyclostationary detection is a method for detecting primary user transmissions by exploiting the cyclostationarity features of the received signals [18][19][20]. It exploits the periodicity in the received primary signal to identify the presence of primary users. In this way, the detector can distinguish primary user signals, secondary user signals or interference. However, the performance of this detection method depends on a sufficient number of samples, which increases the computational complexity. Waveform-based sensing is only applicable to systems with known signal patterns. Such patterns include preambles, midambles, regularly transmitted pilot patterns, and spreading sequences [21]. A preamble is a known sequence transmitted before each burst and a midamble is transmitted in the middle of a burst or slot. In the case of a known model, the spectrum detection function is performed by associating the received signal with a copy of itself. Wavelet transform is a powerful method for analyzing singularities and edges. In the wavelet-based spectrum sensing method, the frequency bands of interest are usually decomposed as a train of consecutive frequency subbands [22]. By using wavelet transform, irregularities in these bands are detected and the spectrum is decided whether it is full or empty. Eigenvalue-based spectrum sensing does not require much prior knowledge about the primary user signals and noise power [23][24][25]. The concept of this detection technique is presented in 2007 [26]. In the eigenvalue-based spectrum sensing methods, the decision threshold has been obtained based on random matrix theory to make a hypothesis testing. In order to determine the presence or absence of the primary user signal, the decision threshold is compared with the test statistic formed using the ratio of the maximum or average eigenvalue to the minimum eigenvalue. Nevertheless, having a high operational complexity is a disadvantage of this method. Similarly, if the information of the primary users is not known precisely, energy detection-based methods with low mathematical and hardware complexities are preferred [27,28].
Energy detection is a spectrum sensing technique based on measuring the received signal energy and deciding on the presence or absence of the primary user by comparing the received energy level with a threshold. The threshold function calculation depends on noise power. Numerous studies have been carried out in the literature to obtain the optimal threshold expression and to improve spectrum sensing performance [29][30][31][32][33][34]. In [29], the authors proposed a new method for adaptive threshold selection in multiband detection. Estimating the threshold is performed by using the functions of the first and second statistics of the received signal. In [30], the Wigner-Ville distribution is used to improve detection performance at a low SNR. In this case, a better decision threshold is defined by reducing the effects of the cross-correlation terms. In [31], using Gauss-Hettite integration, analytical expressions of detection, and mean-field probabilities on compound Nakagami-m and log-normal fading channels were obtained, and detection performance was investigated. Also, an optimized threshold expression was obtained to increase spectrum sensing performance. In [32], an energy detector, using an adaptive dual threshold, is proposed for solving the detection problem. In [33], the authors proposed an adaptive threshold detection algorithm based on an image binarization technique. Here, the dynamic threshold is estimated based on previous repetition decision statistics, parameters such as SNR, number of instances, and detection probabilities. In [34], a dynamic threshold detection scheme was proposed depending on the noise level present in the received signal. For the measurement of the noise level, a blind technique based was used on the sample covariance matrix values of the received signal.
The energy detection method is widely used for its simplicity in calculation and ease of application. However, the spectrum sensing performance of the energy detector is severely affected by destructive channel effects such as shadowing and fading, and noise. To minimize the negative effects caused by noise uncertainty and communication channel, the cooperative spectrum sensing model is defined in the literature [35,36]. In [35], the researchers proposed a fuzzy logic-based perception format for collaborative energy detection, based on the new reliability factors for local spectrum sensing. The fuzzy logic process consists of three stages. These are the ordering of blurring, the run-in motor, and the clearing phase. The performance of the nodes is compared with the performance of the other nodes to try to make the most accurate predictions. When these processes are performed, the reliability factor is defined by using the SNR, detection differences, and threshold, and the detection performance is measured. In [36], energy detector parameters are optimized for the best detection performance. Simulation studies have been carried out on fading channels about the optimal threshold, several cognitive radio users, and the number of antennas.
In recent years, hybrid models in which two or more detection schemes are used together have been developed to improve spectrum sensing performance in a cognitive radio network. Artificial intelligence and machine learning algorithms (MLA) are widely used in hybrid models [37][38][39][40]. In [37], a learning algorithm based on artificial neural networks (ANN) is used to detect the presence/absence of primary users in a cognitive radio environment. In [38], the authors proposed a collaborative spectrum sensing (CSS) scheme based on machine learning techniques. Supervised [e.g., support vector machine (SVM) and weighted K-nearest neighbor (KNN)], and unsupervised [e.g., K-means clustering and Gaussian mixture model (GMM)] classification techniques are used for CSS. In [39], the authors proposed a sensing method based on machine learning for solving the spectrum sensing problem. This method is dependent on signal characteristics and the clustering algorithm that is used for classification. The received signals are classified by using the k-means clustering algorithm. Class parameters, eigenvalues, and covariance were determined, and the performance of the proposed algorithm was investigated.
Using the MLA, it is stated that the error probability decreased and the detection performance increased. In [40], the researchers proposed a new decision threshold model based on an online learning algorithm to increase the probability of detection and decrease the probability of total detection.
In this paper, we proposed a new threshold expression based on online learning algorithm to overcome the spectrum sensing problem and improve detection accuracy. Statistical error analysis was performed by using data on detection, miss detection, and false alarm parameters used in spectrum sensing performance measurement. The proposed new method consists of two stages. In the first stage, a hypothesis test is created and analyzed depending on the noise threshold. In the second stage, the threshold expression that minimizes the total error probability with the help of an online learning algorithm is redefined. The detection performance of the proposed method was investigated on AWGN, Rayleigh, Rician, Nakagami-m, and Weibull fading channels and presented comparatively with the traditional method suggested in the literature.
The rest of this paper is organized as follows: Sect. 2 considers the theoretical aspects of energy-based spectrum sensing. Optimal thresholds are presented with a sufficient optimality condition in Sect. 2.2. In Sect. 3, the optimal threshold expression is redefined and formulated by using the proposed online learning algorithm. Simulation results are discussed in Sect. 4, and finally, the paper is concluded in Sect. 5.

System model
Spectrum sensing is one of the most important components of cognitive radio networks. Spectrum sensing enables a cognitive radio to have information about its environment and spectrum availability. The most widely used spectrum sensing methods are energy detection and matched filter detection.

Energy detection
Energy detection is the most widely used method since it has low complexity and it does not require prior information about of the primary signals. In the energy detection process, the spectrum occupancy decision is based only on the threshold obtained depending on the noise. The threshold is compared with the perceived energy, and it is decided whether the primary user is present or not. It aims essentially to decide between two states: primary user signal is absent, denoted by H 0 , or primary user signal is present, denoted by H 1 . The decision of energy detector is the test of the following hypothesis: where Y (n) is the signal received by the secondary user, S(n) is the primary user's transmitted signal, and W (n) is the additive white Gaussian noise (AWGN) with zero mean. Figure 1 shows the basic block diagram of the energy detection.
In an energy detector, the received signal is first pre-filtered by an ideal band pass filter which has bandwidth "W. " The filtered signal is then passed through A/D converter. Output of the A/D converter is then squared and integrated over a predefined time :Primary user absent H 1 : Y (n) = S(n) + W (n), :Primary user present interval. The resultant signal is used to formulate a test statistic. The test statistic can be formulated as shown in Eq. 2.
If N sample numbers are sufficient, the T statistic distribution, according to the central limit theorem, is Gaussian distribution [41]. The binary hypothesis test is redefined as follows: where σ 2 n and σ 2 s are the noise variance and signal variance, respectively. The test statistic ( T ) is compared with the threshold ( ) to make the final decision on whether the primary signal is present or not. The performance of the energy detector is characterized by using three parameters presented based on test statistics under the binary hypothesis. According to [42], the probabilities of detection P d , false alarm P fa , and miss detection ( P m = 1 − P d ) are given by, where Q(.) is the complementary distribution function of standard Gaussian. Q-function Q(x) is expressed as follows:

Matched filter detection
Matching filter technique is widely used in spectrum sensing as it is a good filtering technique that maximizes the SNR. When an unknown signal matched the known signal, it is assumed that PU is present in the spectrum. The whole process of the matched filter is shown in Fig. 2 [43].
The operation of matched filter detection is expressed as: where y(n) is the received signal, s(l) is the unknown signal, and h(n − l) is the impulse response of the matched filter which matches with the known signal for maximizing the output SNR. P d and P fa can be given in Eqs. (8) and (9) which depend upon threshold [44].
where E is the PU signal energy. The detection threshold is given in Eq. 10 as a function of PU signal energy and noise variance.

Threshold detection model
The performance of energy sensing-based methods is largely dependent on the previously defined threshold expression [45,46]. A threshold is required to decide whether the target signal is absent or present. This threshold determines all spectrum sensing performance metrics. The sensing performance of the energy detector is measured according to two metrics. The performance metrics P d and P fa over AWGN channels can be defined as [47,48]: where erfc is the complementary error function. It then follows that the mean and the variance of the test statistic could be represented as shown in Eqs. 13 to 16.

Fig. 2 Block diagram of matched filter detection
The probability of miss detection would be given as, The balance between P fa and P m should be considered when determining the threshold for the energy detector. P d should be maximized, while P fa should be minimized. This is called the constant false alarm rate (CFAR) detection scheme. P m can be set to a minimum value, or P fa can be reduced to a minimum by fixing P d to a maximum value. In practice, the threshold is normally chosen to meet a certain P fa , in situations where only the noise power needs to be known. Depending on the balance between P d and P fa , for a certain P fa value is derived as: where Q −1 (.) is the inverse function of Q(.).
Due to this threshold at low SNR, the detection performance is greatly reduced. What is important here is to improve the low SNR perception performance. For this reason, the optimal threshold expression is defined by using the total error probability,P e , which is dependent on P fa and P m . The total error probability is the sum of P fa and P m weights. P e can be given as where PH 1 and PH 0 represent the probabilities of primary user presence and absence, respectively. The minimization problem can be represented as The threshold can be obtained by satisfying the following conditions [46]: From Eqs. (12, 17) on differentiating P fa and P m are given as follows: (15)

Proposed adaptive threshold optimization model
In cognitive radio systems, the detection performance of the energy detector depends on the high accuracy selection of the threshold expression. When developing spectrum sensing models, it is aimed that the noise and primary user signals are fully distinguished. Developed models are generally evaluated based on parameters such as accuracy and correct positive rate. However, the actual performance can be analyzed by using backwardly artificially generated estimates in the measurements. In this section, a new threshold expression model based on online learning algorithm is presented to improve spectrum sensing performance in cognitive radio networks. The fundamental nature of spectrum sensing is a defined binary hypothesis testing problem that depends on the threshold expression. This relationship is illustrated in Fig. 3. This shows the expected distribution of a difference between two groups under H 0 [true negative (TN)] and H 1 [true positive (TP)]. It is clear that if we increase the type I error rate [false positive (FP) or false alarm], we reduce the type II error rate [false negative (FN) or missed detection], and vice versa. Changes in the accuracy of H 0 and H 1 hypotheses cause changes in the total error probability. Therefore, there is a very delicate balance between the possibility of miss detection and the possibility of false detection. To maintain and analyze the balance between these two, two classes are created by classifying the negative and positive data as shown in Fig. 3. Critical thresholds are Fig. 3 Statistical distribution curves related to classes determined for these classes, creating a gray area. Then, with the help of an online learning algorithm, the steps to be applied to obtain the most appropriate threshold in the gray area are given as follows:

Stage 1: data collection and pre-processing
The Gauss distribution curves of H 1 (signal present) and H 0 (signal absent) are obtained by using the threshold expression in Eq. 25. Two classes are constructed by classifying the negative and positive data, as shown in Fig. 3. Type I and II error parameters and correct perception parameters are analyzed. Critical thresholds are determined for these classes, creating a gray area.
1 Each (N i , P i ) value is determined, and classes are created.
2 Critical thresholds expressions of the two classes are defined ( N , P ).
The data in the gray area, defined as R in Fig. 3, were subclassified using the k-mean algorithm (k = 4). The classes created are graded according to their performance levels, considering type I and II errors.

Stage 2: computation on the dataset
Error analysis is performed to further increase the success level of successful classes with the help of the data obtained during data collection and pre-processing. As a result of the analysis, weight, error, and improvement coefficients are defined as follows: 1 Weights are defined for each subclass. (w t ).
2 Averages of weights are found. It is expressed as shown in Eq. 29; 3 The data are classified and the total error rate is obtained. It can be represented as shown in Eqs. 30 and 31.
4 Incorrect positive error (H 1 /incorrect detection) is expressed in Eq. 32 as follows:

Incorrect negative error (H 0 /incorrect detection) is expressed in 33.
6 Classification probabilities and ratios can be formulated as follows, respectively: 7 Mathews correlation coefficient can be represented as shown in Eq. 38.
8 Improvement coefficient ( p i ) can be formulated by Eq. 39 as follows:

Stage 3: training phase
We are provided with a training dataset (X i , Y i ), i = 1, 2, 3, . . . , N where X i represents an n-dimensional continuous-valued vector and Y i {0,1} represents the corresponding class label with "0" for normal and "1" for an anomaly. The proposed method has two steps: (1) training and (2) testing. During training, the k-means-based anomaly detection method is first applied to partition the training space into k disjoint clusters C 1 , C 2 , C 3 , . . . , C N . Then, the decision tree is trained with the instances in each k-means cluster. The k-means method ensures that each training instance is associated with only one cluster. However, if there are any subgroups or overlaps within a cluster, the decision tree trained on that cluster refines the decision boundaries by partitioning the instances with a set of if-then rules over the feature space. In the testing phase, we have two subdivided phases: (1) the selection phase and (2) the classification phase. In the selection phase, the Euclidean distance is calculated for each test sample and the closest cluster is found. The decision tree for the closest cluster is calculated. In the classification phase, the data are separated according to the detection successes. Finally, in this phase, the threshold will learn from the best learner in class. Learner modification is expressed as, (33)

Stage 4: learner phase
In this phase, by comparing the advantages and disadvantages between the other two learners, the learners new i will learn from their advantages which draw on the idea of the differential evolution algorithm. Randomly select two learners i and j , where i = j . Learner modification is expressed as where rand(a) is a uniformly distributed random number between "0" and "1. " Accept new i if it gives an optimum threshold.

Simulation results
In this section, numerical results are presented to verify the effectiveness of our proposed algorithm. Spectrum sensing performance can be characterized by using the receiver operating characteristic (ROC) curve in cognitive radio networks. ROC curves are generated by plotting either detection probability versus false alarm probability or missed detection probability versus false alarm probability. Detection probability and false alarm probability depend on the threshold, number of samples, fading parameters, number of diversity branches, and average SNR. The sensing performance of the proposed algorithm has been analyzed on different fading channels using energy-based detection and matched filter detection techniques. In Figs. 4, 5, 6, 7, 8, 9, 10, 11, 12, (40) new i = + p i min energy i + max energy i 2 .
(41) Because the performance of energy-based technique mainly depends on SNR, two different SNR values (-5 and -10 dB) are considered. Figure 4 shows the ROC curve for the AWGN channel. As can be seen, the performance of the proposed algorithm for different SNR scenarios is higher than those of conventional algorithm: dynamic threshold (-5 dB): P d = 0.6371; online learning threshold (-5 dB): P d = 0.6509; dynamic threshold   Figures 5, 6, 7, and 8 illustrate the ROC curves for Rayleigh, Nakagami-m, Rician, and Weibull channels, respectively. When the graphs are examined, it is seen that the detection performance of cognitive radio increases with the proposed method. Besides, detection probability is less in Rayleigh fading channel when compared to the AWGN channel and other fading channels. This situation is shown in Fig. 5. In Fig. 7, we can see that the performance of the energy detector in the Rician fading channel is better than in the other channels (Rician factor K = 5).   Figure 8 shows that, for energy detection in the Weibull fading channels, ROC curves move to the upper left corner with the proposed method, confirming better overall detection performance.
In Figs. 9, 10, 11, 12, and 13, the evaluation of the performance of the matched filter detection technique is carried out by plotting P d versus P fa and ROC curves for the AWGN, Rayleigh, Nakagami-m, Rician, and Weibull channels conditions. Figure 9 shows the comparison of the performance of the proposed scheme and the dynamic threshold selection method and verifies the accuracy of the theoretical expressions for the matched filter technique over a non-fading AWGN channel.   Figure 10 shows the ROC curve in the Rayleigh fading channel. It is observed that when compared to AWGN, Rayleigh fading has less detection probability due to fading. Spectrum sensing performance is dependent on SNR. As the SNR increases, the probability of detection is improved. Figures 11, 12, and 13 show the ROC curves over Nakagami-m, Rician, and Weibull fading channels, respectively.
When comparing the detection probability of all these fading channels (AWGN, Rayleigh, Nakagami-m, Rician and Weibull), it is clear that the Rician fading channel has the best detection performance. It is also seen that the performance of the matched filter detector is affected by the average SNR values.  It is clearly seen that the detection performance of the online learning algorithmbased decision threshold method and the detection performance of the dynamic decision threshold determination method are better for different SNR values on different fading channels. This is because conventional methods offer a strict threshold model. The proposed method in this study has made the threshold expression flexible. Furthermore, with the proposed online learning algorithm-based threshold expression model, the spectrum sensing performance of cognitive radio networks has been made more sensitive to changes in communication channels.

Conclusions
In this study, a new threshold expression model based on online learning algorithm is presented to increase spectrum sensing accuracy in cognitive radio networks. Detection, false detection, and false alarm probabilities have been comprehensively analyzed statistically, and the optimum decision threshold expression has been redefined to minimize the possibility of decision error. Numerical results obtained from simulations on AWGN and different fading channels (Rayleigh, Nakagami-m, Rician, and Weibull) are presented to show the performance of the proposed algorithm and compare it with the dynamic decision threshold determination method. The proposed sensing scheme has significantly improved the detection performance of the energy detection-and matched filter-based spectrum sensing under low SNR conditions.
In future studies, we aim to apply and verify the performance of the proposed algorithm on different spectrum sensing methods. Also, we will focus on the optimization of some expressions used in the algorithm to reduce mathematical complexity and improve detection time.