Applicable VersionsNetSim StandardNetSim Pro


In NetSim ZigBee protocol which is part of WSN/IoT networks, the fading model is not 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.


The steps explained below vary across versions. Please refer to the respective section of this article based on the version of NetSim you are using.


Note: From NetSim v13.2 onwards, fading loss is factored in for received power calculations. 


Applicable Releasesv13.1



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 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()

{

    FILE* fp;

    char filename[BUFSIZ];

    sprintf(filename, "%s\\%s", pszIOLogPath, "ZIGBEE_LOG.csv");

    fp = fopen(filename, "w+");

    if (fp)

    {

        fprintf(fp, "Simulation Time(micro second),\tTx ID,\tRx ID,\tFading power(dBm),\tSNR(dB),\tRx_power(dBm)");

        fclose(fp);

    }

    return fn_NetSim_Zigbee_Init_F();

}

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


NetSim_PACKET *pstruPacket;

PACKET_STATUS nPacketStatus;

NETSIM_ID ifid;

double dFadingPower = 0;

double SNR;

double dBER;


pstruPacket = pstruEventDetails->pPacket;

//Getting interface id of transmitter

ifid = fn_NetSim_Stack_GetConnectedInterface(pstruEventDetails->nDeviceId,

        pstruEventDetails->nInterfaceId,

        pstruPacket->nTransmitterId);

if(pstruPacket->nReceiverId && pstruPacket->nReceiverId != pstruEventDetails->nDeviceId)

{

        fnNetSimError("Different device packet received..");

        assert(false);

        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(find_propagation_info(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;

char filename[BUFSIZ];

sprintf(filename, "%s\\%s", pszIOLogPath, "ZIGBEE_LOG.csv");

fp = fopen(filename, "a+");

if (fp)

{

        fprintf(fp, "\n%lf,%d,%d,%lf,%lf,%lf", pstruEventDetails->dEventTime, pstruPacket->nTransmitterId,                              pstruPacket->nReceiverId, dFadingPower, SNR, pdbm);

        fclose(fp);

}

if(fn_NetSim_Packet_DecideError(dBER,pstruEventDetails->dPacketSize))

{

        pstruPacket->nPacketStatus = PacketStatus_Error;

        nPacketStatus = PacketStatus_Error;

}

4. Right-click on the Zigbee project and rebuild.
5. Upon a successful build of the 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 %temp%\NetSim\<ver>_13.1\log 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(WSN_Pathloss_and_Fading_v13_1) 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 the 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.
  • In the Results Dashboard in the log files section, Open the ZIGBEE_LOG.csv file filter for Transmitter ID  as 4 and Reciever ID as 10 and observe the changes in Fading power, SNR, and Rx power values.


Result and analysis:


In NetSim v13.1:


Shape(m)and Scale(w) ParametersRX Power(dBm)SNR(dB)Fading Power(dBm)
m=1 w=1
-83.1824.65-0.82
m=2 w=2-83.6523.71-0.35
m=3 w=3-83.7523.53-0.26
m=4 w=4-83.8023.41-0.20
m=5 w=5-83.8423.33-0.17


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


Applicable Releasesv12v13.0


In NetSim ZigBee protocol which is part of WSN/IoT networks, the fading model is not 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)");
        fclose(fp);
    }

    pstruEventDetails=pstruEventDetails_Formal;
    NETWORK=NETWORK_Formal;
    pszAppPath =pszAppPath_Formal;
    pszIOPath = pszWritePath_Formal;
    fn_NetSim_Zigbee_Init_F(NETWORK_Formal,pstruEventDetails_Formal,pszAppPath_Formal,\
        pszWritePath_Formal,nVersion_Type,fnPointer);
    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;
NETSIM_ID ifid;
double dFadingPower = 0;
double SNR;
double dBER;

pstruPacket = pstruEventDetails->pPacket;
//Getting interface id of transmitter
ifid = fn_NetSim_Stack_GetConnectedInterface(pstruEventDetails->nDeviceId,
                pstruEventDetails->nInterfaceId,
                pstruPacket->nTransmitterId);
if(pstruPacket->nReceiverId && pstruPacket->nReceiverId != pstruEventDetails->nDeviceId)
            {
                fnNetSimError("Different device packet received..");
                assert(false);
                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);
fclose(fp);
}
 
if(fn_NetSim_Packet_DecideError(dBER,pstruEventDetails->dPacketSize))
            {
                pstruPacket->nPacketStatus = PacketStatus_Error;
                nPacketStatus = PacketStatus_Error;
            }


4. Right-click on Zigbee project and rebuild.
5. Upon a successful build of the 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 the 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.
  • In Results Dashboard, Open the ZIGBEE_LOG.csv file filter for Transmitter ID  as 4 and Reciever ID as 10 and observe the changes in Fading power, SNR, and Rx power values.


Result and analysis:


In NetSim v12:


Shape(m)and Scale(w) ParametersRX Power(dBm)SNR(dB)Fading Power(dBm)
m=1 w=1
-77.6028.70-0.02
m=2 w=2-77.6128.69-0.01
m=3 w=3-77.6128.68-0.01
m=4 w=4-77.6128.68-0.01
m=5 w=5-77.6128.67-0.01


In NetSim v13.0:


Shape(m)and Scale(w) ParametersRX Power(dBm)SNR(dB)Fading Power(dBm)
m=1 w=1
-77.6028.98-0.00
m=2 w=2-77.3329.29-0.00
m=3 w=3-77.1229.54-0.01
m=4 w=4-76.8429.72-0.00
m=5 w=5-76.3630.12
-0.00


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