1 Introduction

Currently, most wireless applications are operating in a specific spectrum band (2.4 GHz, ISMFootnote 1 band), which leads to overload in this spectrum band and a reduction in the quality of communications. In this situation, the use of this spectrum for the wireless sensor network results in poor quality. Cognitive radio technology, with the possibility of opportunistic use of the licensed spectrum, improves the optimum efficiency of the spectrum and improves wireless sensor network communication quality.

Wireless sensor networks that consist of sensor nodes equipped with cognitive radio technology have many advantages, including opportunistic use of the channel for bursty traffic, dynamic access to the spectrum, and the use of adaptability to reduce power consumption [1]. Despite the many advantages of cognitive radio wireless sensor networks, the design of such networks faces many challenges due to their unique characteristics. The rules of the Federal Communications Commission are based on the notion that cognitive radio networks should not create harmful interference to primary users (PU) when using spectral white spaces. In this way, if the PU wants to use this spectrum, the secondary user (SU) should change its channel. One of the main constraints in wireless sensor networks is energy consumption, which should be minimized as much as possible to prolong the network life span. Among the sources of energy consumption in cognitive radio wireless sensor networks, is switching between the appropriate channels for transmitting information. Consequently, frequent switching between channels consumes energy, which should be avoided.

In order to reduce energy consumption in cognitive radio wireless sensor networks, it is better to use a PU activity model, resulting in increasing the appropriate spectrum selection and reducing the number of channel switching. This paper proposes a method in which the problem of channel selection and power allocation is formulated as a potential function. This function uses parameters derived from the behavioral analysis of the PU’s activity. The following cases are obtained by using this function: reducing the number of channel reallocation, decreasing the interference on PUs and SUs and increasing the efficiency of spectrum resources. Using the defined potential function, it is possible to find a solution to place the network in the optimal state by using a recursive algorithm for selecting a channel and allocating transmission power.

The rest of the paper is organized as follows. Section. 2 reviews the previous studies conducted in this regard. The assumptions of the proposed method are discussed in Sect. 3. Further, Sect. 4 describes the proposed method and the details of the frequency spectrum selection algorithm, as well as the elements used in the algorithm. Section 5 is related to the simulation process of this method and its results, in addition to the corresponding diagrams and their analysis. Finally, the conclusions will be conducted in Sect. 6.

2 Related Works

Channel selection is one of the essential issues in cognitive radio networks. Cognitive radio users are intrinsically autonomous and, by changing its sending parameters, can learn from the environment and optimize their performance. As a result, the spectrum allocation problem becomes a multi-criteria optimization problem, which makes it challenging to analyze and solve. In order to coordinate different variables, their performance can be modeled as game theory. A lot of researches are done on the application of Game Theory in cognitive radio networks [2, 3]. Some of them use the Game theory to choose suitable spectrum to reduce energy consumption. In [4], using the Game Theory, a player’s strategy is to select a channel between several channels to reduce interference on rest of SUs. Zeng and Zhang dealt with the design of a two-stage model using the Betrand game model and the Nash equilibrium to solve the allocation of bandwidth problem in the Cognitive Radio Sensor Networks (CRSNs) [5, 6] Presented a game theory-based approach in order to dynamic spectrum allocation and effective resource sharing. In addition, to deal with the complexity, the authors apply a greedy based backtracking search optimization algorithm. This technique leads towards performance enhancement of power consumption and reducing queuing delay. Salim and Moh, state that energy optimization is the most critical issue in the design of CRSNs because this will determine the network lifetime. In this paper, the EGSD model has been used to select a spectrum, which includes two functional modes, random selection and selection based on game theory. Ultimately, this model has increased the network lifetime [7]. Chiwewe and Hancke presented an algorithm based on Game Theory. This algorithm deals with the dynamic allocation of the frequency band, which results in faster convergence by using simultaneous multi-channel sensing [8, 9] discussed that based on application type, a certain level of reliability in the cognitive radio wireless sensor network is needed. This level affected due to several other aspects such as energy consumption in the data delivery mechanism. The authors developed a game theory-based framework that aspects mentioned above are considered [10]. A game theory framework for dynamic spectrum allocation is designed based on auction theory. This method tries to improve the primary user's revenue along with enhancing the secondary user's spectral efficiency. Moreover, using pricing based auction theory has an important effect on decreasing the secondary user's collision.

Some researchers have used other variables, such as power transmission to apply the game theory in increasing the efficiency of the network. In [11], the authors have dealt with power allocation in addition to channel allocation to improve their strategy. By providing a potential function and an iterative algorithm, they have come up with a solution that achieves a Nash equilibrium. In the Nash equilibrium, no player can unilaterally deviate the equilibrium to increase his gain. In a similar method, other writers have presented a model for channel selection and transmit power allocation. A potential function is defined which, by creating a Nash equilibrium, attempts to control the total interference generated on licensed users [12]. Gallego and Canales [13] did the channel allocation and power control using the potential game. In this method, the goal is to increase the overall network utilization defined by maximizing the transmission capacity in bps. In [14] proposed a power transmission plan and frequency band selection based on reinforcement learning that sensors are learning from their previous choices or their neighbors’ choices. Gmira proposed a model based on the channel access process when the PU is active. It takes into account the level of interference and presents a system based on the collaboration of PUs and SUs, which attempts to increase the overall system performance. This model is based on the coalition game. The purpose of the utility function is to optimize the two parameters of transmitted, power and noise channel level [15]. In all of the proposed solutions, the behavior and activity of the licensed user in the spectrum and its effect on selecting the appropriate spectrum are not considered.

Routing algorithms in the networks with energy constraints is critical. According to the researches on routing algorithms in cognitive radio networks, there are so many algorithms which none of them apply energy consumption and energy constraints in their calculations [16]. However, some energy-efficient algorithms for these networks are presented. These algorithms address the energy constraint challenge [17, 18]. In [18], the reduction of the number of reallocations has been applied in calculations as a factor in reducing network energy consumption. Although this algorithm takes into account the energy constraints and the effect of the number of reallocations in its calculations, it does not mention the PUs activity model of the licensed user as a factor in reducing the number of switching channels.

Diagnosis of channel occupation is effective in reducing energy consumption and increasing network lifetime. Some articles have suggested ways to reduce the misdiagnosis of channel occupation. Li and Chang provided a new method to improve the probability of detection for spectrum sensing. It has been shown in this paper that only channel whose occupancy status is changed in consecutive time slots needs to consider. This method greatly reduces the misdiagnosis of channel occupation [19]. Qiao, provided a model to reduce the overhead of misdiagnosis of the occupied channel, which increases the power consumption and the energy loss of the nodes. The plan addresses energy optimization by using the D-S Theory, minimizing the misdiagnosis of occupation on the channel [20]. None of them has been used the prediction of PUs’ activity based on their previous behaviors for detecting the channel occupation.

3 Proposed Method Assumptions

In our modeling, it is assumed that the wireless sensor network is clustered. In the network initialization phase, each sensor node knows its cluster head via a control message, and each cluster head knows its neighbors. The neighbors’ information includes cluster head identification, the frequency spectrum that the nodes of the cluster currently work with, and the number of neighbors working in each frequency spectrum and their transmission power.

In this model, exist k frequency spectrum bands \({ }R_{1} { , }R_{2} , \ldots ,{ }R_{{\text{k}}}\) in which the PUs are operating, and each PU only operates on one frequency spectrum band. These k channels are not always available and cannot be used in the presence of the PU. The 2.4 GHz unlicensed frequency spectrum band named \(R_{0}\), is always available. The network uses \(R_{0}\) to send control messages. Also, in this algorithm, as long as one of the \({ }R_{1} { , }R_{2} , \ldots ,{ }R_{{\text{k}}}\) spectra is selectable due to the absence of a PU, \(R_{0}\) will not be selected and returned as the output of the algorithms [17].

We assumed that the location of the nodes is fixed. Besides, these nodes are equipped with a transmitter/receiver that can adjust and operate on different frequency spectra. Cluster heads whose primary capability considered are sensing the frequency spectrum and collecting information from it. Additionally, similar to sensors, they should be equipped with a transmitter/receiver that can operate on different frequency spectra. These nodes also have limited energy, which, given the tasks assigned to it, requires higher initial energy of the sensors. The cluster head node for communicating with other nodes has a determined communication range limited to its neighboring cluster head. The main function of routing and transmitting messages from the sensor node to the sink is the responsibility of this node.

In the process of this algorithm for routing and selecting the next step by cluster heads, the distributed routing algorithm is used to reduce energy consumption across the entire network. In this algorithm, instead of choosing the whole path from source to target, each node involved in the routing process determines only the best next step in the path locally [17].

Due to the fact that the frequency spectrum status will change over time due to the variability of the PU’s activity, it is necessary to perform the appropriate band selection to be sent periodically and dynamically. In the proposed algorithm, cluster heads are responsible for this task. Each cluster head periodically senses the existing radio spectra \({ }R_{1} { , }R_{2} , \ldots ,{ }R_{{\text{k}}}\) and obtains information about the presence or absence of a PU. In the stage of decision-making about the spectrum, according to the values obtained from the spectral checking stage, the n spectra in which the PU is employed is excluded from choices. Given that the cluster holds information about its neighbors, from among the remaining k-n spectra, it selects a spectrum with the lowest number of neighbors active in it. This spectrum is used for the activity of all nodes in this cluster. The reason for this choice is to reduce the probability of collision in packets sent in neighboring clusters. To reduce the delay caused by the movement of radio bands, it is preferable that if after the re-sensation of the spectrum, the current band used was still available and we did not need to move to a new band, the cluster head would not replace the band. After communicating this selected spectrum to sensors, all sensors in that cluster regulate their transmitter/receiver in order to send all of their data packets to the cluster head on this spectrum.

In a cluster head, after choosing the node that is the next step in sending route of the packet to the sink, you need to select the appropriate frequency range. To select this spectrum with the mentioned components, the Nash equilibrium and the potential function are used. Nash equilibrium is one of the concepts of the Game Theory in which each player chooses the best possible strategy, concerning the performance of others, seeking to achieve its maximum utility function, and the best strategy is provided in which all players are in the Nash equilibrium. When a game is modeled as a potential game, it can be guaranteed that the game will end on a Nash equilibrium [21].

If N represents the number of players, Ai is a set of operations of Player i and Ui is a utility function represented as Ui: Ai → R which indicates the gain of the Player i when the player has performed the Ai operation; the game \(\langle N,(A_{i} ),(U_{i} )\rangle\) is a potential game if it can be defined for a potential function \(P:A \to R\) that meets Eq. 1 conditions for all \(i \in N\) and \(a \in N\) and \(a_{i}^{\prime } \in A_{i}\):

$$P(a_{i} ,a_{ - i} ) - P(a_{i}^{\prime } ,a_{ - i} ) = u_{i} (a_{i} ,a_{ - i} ) - u_{i} (a_{i}^{\prime } ,a_{ - i} )$$
(1)

By defining this function, it is clear that the individual operations of each player, and choose the best strategy regarding the performance of other players, improve the status of others and thus improves overall performance. In a potential game where all players choose the best strategy based on the maximum value of the potential function, we will reach a Nash equilibrium after limited stages. As a result, all players will be at the best status in relation to the performance of the rest of the players.

In the potential function presented, parameters are considered to reduce the interference on other SUs and reduce the interference of other SUs on the SU. Also, other benefits of using these parameters include reducing Signal-to-Interference Ratio (SIR), reducing interference with PUs, and improving network performance by choosing the most appropriate spectrum in terms of bandwidth and increasing the occupation time of the spectrum.

Each cluster head is modeled as a cognitive radio user and has the ability to select its channel and power to maximize the potential function. The cluster head will not select a channel for sending unless the total value of the potential function is maximized. The transmission power of cognitive radio users using a shared frequency channel to send data affects the link quality. The purpose of choosing the most suitable transmission power is to set the appropriate transmission power to all SUs in order to improve the link quality and reach the minimum Bit error rate required by them.

Cognitive radio users are aware of the bandwidth and frequency range of the PU. The most critical issue raised in opportunistic access to the spectrum in cognitive radio networks is that the SU is permitted to work on the spectrum band of a PU only when the band is free. Therefore, our main priority is in deciding the non-interference spectrum with the PU. If, after sensing the frequency spectrum, it was determined that a band is occupied due to the presence of a PU, the band will be removed from the choices at that time.

Energy constraints are the most fundamental challenge in wireless sensor networks. Repeatedly reallocating the channel increases the energy consumption of the sensor nodes. By choosing the right spectrum in terms of the low probability of presence a PU, and the more use of the spectrum by a SU, the power consumption can be significantly reduced.

Periodically, in intervals of τ seconds, each cluster head senses radio spectra and concludes about working band. After that, it broadcast its decision result. Because this message is transmitted as broadcast, all nodes in the communication domain of the sender cluster head will receive it. The receiver cluster head compares the identification in the message with that of its neighbors’ cluster heads. If this message were sent from one of the neighbors, the new information would replace the previously stored information. From now on, decisions will be made based on new information.

4 Proposed Method

Given those mentioned above, we present a potential function for selecting the frequency spectrum to cover constraints with the following elements:

4.1 Bit Error Rate

The quality of the transmission channel can be described based on the Bit error rate required for the desired application. To satisfy the Bit error rate required for a particular application, one can consider the SIR [12]. SIR in receiver j with transmitter i is calculated by Eq. 2:

$${ }SIR_{ij} = \frac{{P_{i} G_{ij} }}{{P_{N} + \mathop \sum \nolimits_{{\begin{array}{*{20}c} {k = 1} \\ {k \ne i} \\ \end{array} }}^{N} P_{k} G_{kj} I\left( {k,j} \right)}}$$
(2)

In which, for N radio transmitter, \(P_{i}\) is the transmission power of the transmitter i and \(G_{ij}\), are the link gain between the transmitter i and the receiver j. \(P_{N}\) is the received noise power that is assumed to be the same for all receivers. I (k, j) is the interference function by node k to node j, which is equal to 1 if the transmit channel is the same. Otherwise, its value is zero. The channel gain is defined between sender i to receiver j, which is defined as \(G_{i,j} = d_{i,j}^{ - \gamma }\) where \(\gamma\) is the path loss index, and d is the distance between the transmitter and the receiver.

By setting the transmission power level and selecting the appropriate channel to reduce the interference, it is possible to improve the quality of the link and ensure the minimum SIR required by all receivers in a shared transmission channel.

It is assumed that there are k frequency channels, and each channel can be used by several SUs to transmit. All SUs should determine the proper transmission power according to the level of interference in channels shared with other SUs. Hence, one of the most effective factors in the potential function is this:

$$[P_{i} G_{ij} ] {-}\left[ {\left( {\sum\nolimits_{\begin{subarray}{l} c = 1 \\ c \ne i \end{subarray} }^{N} {P_{i} G_{ci} X} } \right) + \left( { \sum\nolimits_{\begin{subarray}{l} k = 1 \\ k \ne j \end{subarray} }^{N} {P_{k} G_{jk} X} } \right)} \right]$$
(3)

If the channel is shared by the selected channel of the neighbors, X takes the value of 1 and otherwise 0. For N radio transmitters, \(P_{i}\) is the transmission power of transmitter i and \(G_{ij}\), channel gain between the transmitter i and the receiver j. This term tries to select the maximum transmission power in order to meet the minimum SIR for the given interference constraints. At the same time, this term takes into account the SU interference on other SUs as well as the interference by other SUs in the shared channel on SU as a cost. Choosing the right transmission power is important in order to increase the quality of transmission and also reduce the level of interference with other neighbors.

4.2 Channel Capacity

According to Nyquist, even the best transmission channel has limited capacity. There is noise in the transmission channel. Shannon defined the Nyquist equation for noised channels as the maximum rate that can be transmitted on a channel, while being able to detect information at the destination, with a low probability of error. The channel capacity is fixed and dependent on the channel characteristics. Transmitting at a rate higher than the capacity of a channel leads to error. Therefore, in addition to SIR, the bandwidth of a channel which determines the maximum channel capacity is effective in increasing the network utility. Thus, another element added to our potential function, \(W_{c}\) as the selected channel bandwidth.

4.3 Activity model of Primary User

The use of the elements as mentioned above in the potential function is some instantaneous and memoryless decision making and reveals the effect of a particular channel selection merely at that moment. But, the impact of the probable presence of a PU and learning from it also has a significant effect on network performance. Therefore, there is a need for the components that can compensate for this deficiency. These components are \(M_{c}\) conditional probability of PU’s absence and \(P_{c}\) probability of PU’s presence on the frequency spectrum c.

4.3.1 Probability of Primary User’s Presence

Awareness of the activity history of the PUs and the presence probability of them will significantly help in the use of spectra with better conditions in terms of access to more spectral free opportunities. The choice of frequency spectra with the lower presence probability of a PU, in addition to the possibility of using the spectrum over a longer period, will reduce the number of switching channels and reduce the probability of interference with the PU.

Cognitive radio networks must intelligently sense the licensed bands and carefully monitor them to find the right opportunities and also prevent interfering with the licensed users [22,23,24,25]. By specifying the activity of PUs, contrary to consider them as a Poisson model [22], the PU’s behavior can be carefully determined. Consequently, at any moment, a precise activity model of 0 and 1 could be obtained from the activity of a PU. Using this algorithm, SU can detect the occupation and non-occupation of the spectrum and then use Eq. 4, to calculate the probability of each licensed user presence in the frequency spectrum:

$$P_{c} = \frac{{{ }Count_{On} }}{{Count_{On} + Count_{Off} }}$$
(4)

Counton is the number of times a PU is present on the spectrum, checked at intervals of τ seconds, and Countoff is the number of times it is absent. Each cluster head, in the entire lifetime of the network and as long as it has the energy required to operate, periodically in intervals of τ seconds, senses the frequency spectra and calculates \(P_{c}\). This value becomes more realistic over time.

4.3.2 Conditional Probability of Primary User’s Absence

Using the probability parameter of the PU’s presence and applying it to the potential function, somewhat helps to improve the potential function and its results are effective in improving the overall optimization of the network. But it’s not efficient alone. With careful consideration of the PU’s behavior, we find that although the use of PU’s presence probability is essential in reducing channel switching, it is not enough in some cases. For example, in the sample given, although the duration of the presence and absence of two PUs varies, their presence probability is the same. Therefore, the use of probability is not enough:

PU1′s activity model:

1111111000000011111110000000111111

PU2′s activity model:

1100110011001100110011001100110011

“0” indicates the absence of PU on the frequency spectrum and “1” indicates its presence. The two PUs with different activity models have the same probability of absence as 50%. However, in terms of the duration of absence time of PU, the spectrum in which PU1 is active, gives us more suitable free space. The duration of the PU’s absence, is important to recognize its behavior, and its long-term checking gives us a model of PU’s activity.

Collect and Map Data With each spectrum checking, we map the data obtained from the absence time of PU to a function. The domain of this function represents the duration of the absence of a licensed user in the spectrum, and its range is the number of repeated times of that duration. In fact, with this mapping, in the long run, we'll get a distribution from the duration of PU’s presence.

The process of recording values is such that each cluster head checks a spectrum using a timer, whose time is the smallest unit that allows PUs to change activity status within that interval. With each checking, in the absence of a licensed user, until the licensed user is inactive, the duration of its absence in the spectrum is recorded. By starting the PU’s activity, the cluster head calculates the total duration of its absence and record it in its database. Each time this inactivity time is added to the number of times of PU absence with this particular period. In this way, each cluster head will be aware of the approximate time of inactivity of PUs and the number of such times, which in turn results in produce a distribution function of them.

Hence, according to the timer’s periodical function, the inactivity information of each PU is stored in cluster head. An example of this data information is given in Fig. 1; 1 indicates presence, and 0 indicates the absence of PU in the spectrum:

Fig. 1
figure 1

A sample of the stored information from the PU in the cluster head

Based on this activity cycle, its distribution function will be completed as in Fig. 2. As you can see, the number of times the PU is absent for 2 s is three times. Also, in the checked interval, this PU was not present once for 3 s. It can be concluded that at this interval, the PU's frequency spectrum has not been free for more than 3 s.

Fig. 2
figure 2

A sample of distribution function of PU in the cluster head

The Primary User’s Absence Probability for a Certain Period of Time To calculate the PU’s absence probability in the next few seconds, according to its activity history in the spectrum, we will explain the concepts that this method is based on. A conditional probability is used to calculate the probability of occurrences, when some partial information concerning the result is available [26].

If the event F occurs, then for E to happen we need the actual occurrence be a point both in E and F, that is, it should be in EF. Now, as we know, F has occurred, as a result our sample space decreases to F, and so the probability of (E|F) occurring is equal to the probability of EF occurring relative to the probability of F occurring:

$$P\left( {E{|}F} \right) = \frac{{P\left( {EF} \right)}}{P\left( F \right)}$$
(5)

With the distribution function, at any moment by sensing the spectrum, in addition to determining whether a PU is present in the spectrum, the duration of its absence can also be estimated. ‌Based on the use of the conditional probability Eq. 5 in the distribution function and according to the period of the PU’s absence until that time, it is possible to estimate the duration of its absence in the future. Also, by knowing the time required to transmit the specific data, the best spectrum in terms of the most reliable spectrum that will be free during the desired time, will be selected.

As noted in the previous section, each cluster head senses spectrum periodically at intervals of τ seconds and obtains the necessary information. The amount of each time interval of a timer is a small unit that the cluster head senses the spectrum and then calculates the following values:

  • T0-count: This variable displays the PU’s absence time. Each time, sensing the absence of a PU (0), one is added to its value. By sensing the first presence of the PU (1), its value is changed to zero, and the calculations for the absence period are made.

  • T1-count: This variable displays the duration of the PU’s presence in the spectrum. Sensing every presence of a PU, one is added to its value. By detecting the first absence, its value is changed to zero and calculations are made for the PU’s presence in the spectrum.

The result of the cluster head observations in certain intervals will be as Fig. 3:

Fig. 3
figure 3

Diagnosis of user activity model by cluster head

The values of the function are calculated in two states, change the PU’s activity state from zero to one (the rising edge) and change its state from one to zero (the falling edge).

The function diagram is based on sensing spectrum data, in such a way that the values of the duration, the values of the T0-count are placed on the horizontal axis, and the values of repeated times of these periods, are placed on the vertical axis Fig. 2 After constructing this function, whose data become gradually more complete and closer to the PU’s activity model, to select the frequency spectrum for the transmission, the cluster head calculates the parameter of the PU’s activity model shown by Mc, using this function:

$$M_{c} = P \left( { \left( { T \ge t_{prv} + t_{ftr} } \right) {|} T \ge t_{prv} } \right) = \frac{{P\left( {T \ge t_{prv} + t_{ftr} } \right)}}{{P\left( { T \ge t_{prv} } \right)}}$$
(6)

Mc is the conditional probability of the absence of a PU in the frequency spectrum c, for the \(t_{ftr}\) seconds later, provided that it has not been present in the \(t_{prv}\) previous seconds in the spectrum. Schematic view of Eq. 6 on a PU activity model is as Fig. 4:

Fig. 4
figure 4

Schematic view of PU’s activity to calculate the conditional probability

Now, in the potential equation, we use the factor Mc, which makes it possible to choose the most appropriate spectrum in terms of being free in a longer time in the future.

With respect to the elements explained, the final potential function \(V_{ij}\) for the transmitter node i and the receiver node j is defined as:

$$V_{ij} = \mathop \sum \limits_{i = 0}^{N} \left( {\alpha [\left( {M_{c} \times \left( {1 - P_{c} } \right) \times W_{c} } \right) + P_{i} G_{ij} ] - \beta \left[ { \left( {\sum\nolimits_{\begin{subarray}{l} d = 1 \\ d \ne i \end{subarray} }^{N} {P_{i} G_{di} X} + \sum\nolimits_{\begin{subarray}{l} k = 1 \\ k \ne j \end{subarray} }^{N} {P_{k} G_{jk} X} } \right)} \right]} \right)$$
(7)

In this function, for N radio transmitters in a neighborhood,\({ }P_{i}\) is the transmission power of the transmitter i, and \(G_{ij}\) is the gain link between the transmitter i and the receiver j. Mc represents the conditional probability of the absence of a PU that is calculated based on the current state of the PU and its previous conditions, using the conditional probability equation, and Pc is the present probability of the PU in channel c. \(W_{c}\) is the bandwidth of the selected spectrum c which is a spectral feature. X is equal to 1 if the channel selected is the same as the channel selected by neighbors, and 0 otherwise. \(\propto\) and \({\upbeta }\) are coefficients by which the sensitivity of the system to the degree of optimization or cost can be determined. The first part of this equation is a beneficial part. The greater the amount of this part, the greater the amount of potential function and profit. At the same time, the negative value of the equation is considered costly. Thus, increase in interference reduces the usefulness.

By expressing the problem as a potential function, one can be sure that a Nash equilibrium point will always exist for the channel allocation. On this basis, each cluster head, at the time of selecting the spectrum and transmission power, chooses a spectrum that, will have the most gain for the whole network according to the potential function.

figure c

5 Simulation and Evaluation

In this section, simulation of the proposed model and analysis of its results are presented. In the first section, the simulation environment and the assumptions are introduced. Then, the results of using the potential function in the choice of the spectrum by the SUs are examined. In addition, applying a PU’s activity model and the effect of alternative and non-alternative behavioral models of the PUs in the proposed model have been investigated. In the final section, the proposed method results are compared to the CR-CEA method [17].

5.1 Simulation Environment

The simulator area is a square 500 × 500 m, which is divided into 100 × 100 m grids and has a sink. Each grid represents a cluster. Each cluster head is located in the middle of a grid and the sensors of each cluster are dispersed in their environment. Each cluster head selects its transmission power dynamically from the specified powers \(P_{i}\), based on the calculation of the potential function. The bandwidth of each licensed frequency spectrum is considered constant and normalized in order to observe the effect of other factors. The simulation parameters are defined in Table 1.

Table 1 Simulation parameters

In order to simulate, k frequency spectra that a PU is operating in each, and one free spectrum are considered. The seven different PU’s activity models, based on their presence and absence, are considered according to Table 2.

Table 2 Primary Users Activity mode

The schematic representation of the PU’s activity model in Table 2 is shown in Fig. 5. The value of 1 represents the PU’s presence in the frequency spectrum, and the value of zero represents the absence. The values are related to intervals of 0.5 sec:

Fig. 5
figure 5

Schematic view of PUs’ activity

As it is clear from the PU’s activity model and their presence probability, in addition to showing the presence probability, the activity model also offers more useful information, such as time periods for presence and absence. By comparing the behavior model of PUs, it can be deduced that although the PU2 has less presence probability than PU4, but with care in the activity model of these two users in the frequency spectrum, it’s apparent that the use of the frequency spectrum in which the PU4 is operating is far more appropriate in terms of providing more spectral opportunities.

5.2 Simulation Results and Analysis

Each SU senses the frequency spectra in 0.2 sec intervals by its timer and calculates the presence probability of that PU on the frequency spectrum. Each PU, based on the pattern of activity designed for it, operates in the spectrum over specified periods. As noted in Sect. 5.1, the PU’s activity state changes within 0.5 sec intervals. In order to sense all PU’s activity, the time interval for sensing spectrum is assumed by the SU to less than this interval and equal to 0.2 sec. Figure 6 displays the result of calculating the presence probability of a PU on its frequency spectrum, by a SU. The result shows that the SU, after a short time, obtains the correct value of these probabilities.

Fig. 6
figure 6

Probability calculation of PU's presence in the frequency spectrum

As stated, applying the presence probability of a PU alone, prevents optimal use of the spectrum because of the existence of identical probability for different activity models. Each SU, using its timer, at intervals of 0.2 sec, to calculate the presence probability of a PU and the Conditional probability of spectrum being free in the next 2 sec. Figure 7 shows the value of the total potential function in the network. In the process of this simulation, which lasts for 100 sec, ten events per second occur throughout the network. At a time interval of 0 to 10 sec, gradually with increasing packets in the network, the value of the total potential function increases, and because the probability values and conditional probability do not yet reach their constant value, the maximum value reaches 2.4. After 10 sec, with the stabilization of probability values, the trend chart has slow and slightly downtrend changes. The downward slope is due to interference that occurs in the transmission with the same channel and interference with neighbors. It's seen that from the second 70 forth, the trend of changes is much slower and progressed to stability, but it is not fully linear, since sometimes with the presence of a PU on the spectrum, SUs are forced to leave the better spectrum and choose a lower efficiency spectrum.

Fig. 7
figure 7

Total potential function across the entire network in 100 s

Figure 8 shows selecting the spectrum by SU in 100 sec in two states. In the process of this simulation, the PUs’ activity model is alternative. Ten events occur every second in the whole network. The results for the two states of non-applying the PU’s activity model and applying the PU’s activity model in the potential function are shown.

Fig. 8
figure 8

Selected spectra using potential function in alternative activity mode of PU in 100 s

In the non-applying of the PU’s activity model in the frequency spectrum, the SU calculates the value of the potential function, regardless of the PU’s activity model, and selects its transmission channel accordingly. However, in the case of applying a PU’s activity model, the SU uses the PU’s activity model based on the conditional probability in calculating the potential function.

In the case of non-applying the PU’s activity model, the use of spectra with a lower probability of PU’s presence is the priority of being chosen. Accordingly, most use belongs to channel 2, then 5, 4, 1, and channel 3 with a presence probability of 0.2, 0.3, 0.4, 0.5 and, 0.8, respectively. In the case of applying a PU’s activity model, investigating the results clearly shows that the SU’s selection has been driven towards the 4th and 5th spectrum, which both have a low presence probability and a more free space. Also, the spectra that provide a more appropriate chance of utilizing to SUs, due to having more free consecutive space, such as spectrums 4 and 5, are more likely to be selected, and vice versa, the spectrum 3 is less used with very little free space and being occupied most of the time.

Figure 9 shows the selection of the spectrum throughout the network in 100 sec in two states of PU’s non-alternative activity model and the PU’s alternative activity model. This simulation has been conducted to check the effect of the alternation of PU’s activity model on the performance of the potential function. Ten events occur each second in the whole network. In the process of this simulation, the activity models of two PU1 and PU4, which give us a spectrum with few and many free opportunities, respectively, are converted to non-alternative activity models. The converted activity models of these two PUs are PU6 and PU7, respectively.

Fig. 9
figure 9

Selected spectra using potential function in 100 s

As the results show, the non-alternation in the activity model of the PU7 eliminates freed spectral opportunities and reduces the use of the PU7 spectrum and, and vice versa, the non-alternation in the activity model of the PU7 increases freed spectral opportunities in the PU6 spectrum. But the amount of changes is not enough to change the order of the use of the spectra. The system adapts well to the changes, and PUs activity models are correctly identified. Spectra 7 and 5 still have more chances to be selected.

In Fig. 10, the number of switching channels by SUs in the entire network is shown in 100 sec with two T1, T2 traffic according to Table 3. In traffic T1, ten events occur per second, and in traffic T2, 100 events per second occur on the entire network. Three modes of channel selection are checked with this two traffic. In CR-CEA method [17], where a random probability is allocated to each spectrum, and each SU decides regarding this probability at the time of his choice. In the mode of using the potential function by using PU's presence probability, each SU, when deciding, uses the potential function proposed by Eq. 7, without the coefficient of the PU’s activity model Mc. In the potential function mode, applying the PU’s presence probability and activity model, the potential function proposed by Eq. 7 is used. The results of the simulation show that the proposed function, by considering the interference with other SUs and the PUs, has significantly reduced the number of switches compared to the CR-CEA method. In addition, the use of a PU’s activity model has improved the process of this decline. The low number of switching on the network is the benefits of this proposed method, which reduces energy consumption and increases network lifetime.

Fig. 10
figure 10

The number of switching channels by SUs with two T1, T2 traffics in 100 s

Table 3 Traffic models

Figure 11 checks the efficiency of the potential function in three modes of channel selection: using the CR-CEA method [17], the mode of using the potential function by using PU’s non-alternative activity model and the mode of using the potential function by using PU’s alternative activity model. The number of switching channels by SUs throughout the network is shown with the two T1 and T2 traffic in 100 sec. As the results show, in the case of applying a non-alternative PU activity mode, we are faced with a reduction in the functionality of the potential function relative to the mode of the alternative PU activity model. However, due to the system being adapted to the changes of the non-alternative activity of PU after a while, the functionality of using the potential function by non-alternative activity model is better than the CR-CEA method, which lacks the use of a PU activity model. In the case of applying a non-alternative activity model, by detecting the model after a while, the number of switches is reduced and consequently, the number of switching becomes lower than the CR-CEA method. The time required to detect an activity model depends on the degree of irregularity of the PU's behavior.

Fig. 11
figure 11

The number of switching channels by SUs with two T1, T2 traffics in 100 s

6 Conclusion

As mentioned above, none of the proposed methods have considered the effect of the PUs’ activity model and the cost of channel reallocation reduction on energy consumption in wireless sensor networks. This proposed method, by formulating the spectral allocation problem as a potential function, covers the constraints mentioned in the wireless sensor networks, such as energy limitation and network lifetime. This method covers the goals of reducing channel reallocation, reducing interference to other SUs and increasing the application of available spectral opportunities.

In the proposed model, the spectral capacity feature, as well as the selection of the most suitable transmission power, is used in the potential function. In addition, for selecting spectrum, the presence probability of PUs in the spectrum and, conditional probability of PU’s absence are applied. The simulation results show that the application of the presences probability and conditional probability of PUs in the potential function reduce the number of channel reallocations compare to the CR-CEA method [17]. In this method, by selecting the most suitable spectrum, the network converges to Nash equilibrium and optimization.

In the proposed method, a parameter is presented, which is the result of an activity analysis of PUs in the spectrum. In future works, we intend to apply learning algorithms on the results of this parameter, and with the knowledge of the time needed to have the spectrum available for transmitting in specific applications, a spectrum which is free during a suitable time is further considered. In addition, in the proposed algorithm, spectrum sensing time by the SUs is supposed to be fixed and periodical. Due to the energy-consuming process of spectrum sensing, as a future plan, the results of the learning algorithm on the proposed parameters can be effective in increasing the intervals between senses, and thus by reducing the frequency of spectral senses reduce the energy consumption of nodes.