Applicable Versions
NetSim StandardNetSim Pro

Applicable Releases

In NetSim ZigBee protocol which is part of WSN/IoT networks, fading model is not being factored in for received power calculation. 
However, underlying source codes can be modified, if you want to see the impact of fading on received power.

Code changes to include fading loss in received power calculations:

Follow the steps given below to include fading in received power calculations:

1. Open NetSim source codes and go to the 802_15_4.c file that is part of the ZigBee project. 

2. In the function fn_NetSim_Zigbee_Init() and add the lines of code highlighted in red:

 _declspec (dllexport) int fn_NetSim_Zigbee_Init(struct stru_NetSim_Network *NETWORK_Formal,\
NetSim_EVENTDETAILS *pstruEventDetails_Formal,char *pszAppPath_Formal,\
    char *pszWritePath_Formal,int nVersion_Type,void **fnPointer)
    FILE* fp;
    fp = fopen("ZIGBEE_LOG.csv", "w+");
    if (fp)
        fprintf(fp, "Simulation Time(micro second),\tTx ID,\tRx ID,\tFading power(dBm),\tSNR(dB),\tRx_power(dBm)");

    pszAppPath =pszAppPath_Formal;
    pszIOPath = pszWritePath_Formal;
    return 0;

3. Add the lines of code highlighted in red inside case PHYSICAL_IN_EVENT as shown below:

NetSim_PACKET *pstruPacket;
PACKET_STATUS nPacketStatus;
double dFadingPower = 0;
double SNR;
double dBER;

pstruPacket = pstruEventDetails->pPacket;
//Getting interface id of transmitter
ifid = fn_NetSim_Stack_GetConnectedInterface(pstruEventDetails->nDeviceId,
if(pstruPacket->nReceiverId && pstruPacket->nReceiverId != pstruEventDetails->nDeviceId)
                fnNetSimError("Different device packet received..");
                return 0;

if(!ZIGBEE_CHANGERADIOSTATE(pstruEventDetails->nDeviceId, WSN_PHY(pstruEventDetails->nDeviceId)->nRadioState, RX_ON_IDLE))
return 0;
if(WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower - GET_RX_POWER_mw(pstruPacket->nTransmitterId,pstruPacket->nReceiverId,pstruEventDetails->dEventTime) >= WSN_PHY(pstruEventDetails->nDeviceId)->dReceiverSensivity)
pstruPacket->nPacketStatus = PacketStatus_Collided;
//start pathloss fading calculation

double pdbm = GET_RX_POWER_dbm(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime); //Received power without fading loss
nPacketStatus = pstruPacket->nPacketStatus;
//calculating fading loss
dFadingPower = propagation_calculate_fadingloss(propagationHandle, pstruPacket->nTransmitterId, ifid, pstruEventDetails->nDeviceId, pstruEventDetails->nInterfaceId);
pdbm -= dFadingPower;
//Using received power with fading considered for SINR calculations
ZIGBEE_SINR(&SNR, WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower, DBM_TO_MW(pdbm));
//end pathloss fading calculation

dBER = fn_NetSim_Zigbee_CalculateBER(SNR);
FILE* fp;
fp = fopen("ZIGBEE_LOG.csv", "a+");
if (fp)
fprintf(fp, "\n%lf,%d,%d,%lf,%lf,%lf",pstruEventDetails->dEventTime,pstruPacket->nTransmitterId, pstruPacket->nReceiverId, dFadingPower, SNR, pdbm);
                pstruPacket->nPacketStatus = PacketStatus_Error;
                nPacketStatus = PacketStatus_Error;
4. Right-click on Zigbee project and rebuild.
5. Upon a successful build of ZigBee project, fading models will be considered for received power calculations while simulating any WSN/IoT network scenario.

6. NetSim will create a log file ZIGBEE_LOG.csv in <NetSim_Install_Directory>/bin path which contains the fading power, received power and SNR for each packet along with the event time, transmitter id and receiver id information.

Designing a network scenario in WSN to see the impact of fading:

The results that you get will depend on several factors based on how the network has been created, the device configuration, the channel characteristics, etc

  • We have considered a WSN network modeled in a 500x500 grid. The devices are randomly placed in different locations of the grid as shown below:
  • Attached herewith is the netsim experiment file associated with the network scenario shown above. You can download and import the network configuration and run simulations.
  • Mobility in the sensor nodes can be configured optionally if you want the device coordinates of the sensor to vary with time. We have set the mobility to Random walk and velocity to 10 m/s.
  • We have created 2 applications with the source node as Sensor 9,4 and destination as WSN_Sink_10.
  • Open the NetSim design window change the Channel Characteristics to PATHLOSS_AND_FADING_AND_SHADOWING and set fading model to NAKAGAMI.
  • Change shape parameter(m) and scale parameter(w) as 1,2,3,4, and 5 and observe the Fading power, SNR, and Rx power values.

Result and analysis:

In NetSim v12:

Rx_Power (dBm)
SNR (dB)
Fading power (dBm)
m=1 w=1
m=2 w=2
m=3 w=3
m=4 w=4
m=5 w=5

In NetSim v13.0:

Rx_Power (dBm)
SNR (dB)
Fading power (dBm)
m=1 w=1
m=2 w=2
m=3 w=3
m=4 w=4
m=5 w=5

For more information about path loss and fading power please go through sections 2 and 4 from the propagation model technology library.