Applicable Versions | NetSim Standard | NetSim Pro |
In NetSim ZigBee protocol which is part of WSN/IoT networks, the fading model is not factored in for received power calculation.
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 Releases | v13.1 |
Code changes to include fading loss in received power calculations:
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;
}
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:
- 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.
Shape(m)and Scale(w) Parameters | RX Power(dBm) | SNR(dB) | Fading Power(dBm) |
m=1 w=1 | -83.18 | 24.65 | -0.82 |
m=2 w=2 | -83.65 | 23.71 | -0.35 |
m=3 w=3 | -83.75 | 23.53 | -0.26 |
m=4 w=4 | -83.80 | 23.41 | -0.20 |
m=5 w=5 | -83.84 | 23.33 | -0.17 |
Applicable Releases | v12 | v13.0 |
Code changes to include fading loss in received power calculations:
2. In the function fn_NetSim_Zigbee_Init() and add the lines of code highlighted in red:
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:
PACKET_STATUS nPacketStatus;
NETSIM_ID ifid;
double SNR;
double dBER;
pstruEventDetails->nInterfaceId,
pstruPacket->nTransmitterId);
{
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;
pdbm -= dFadingPower;
ZIGBEE_SINR(&SNR, WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower, DBM_TO_MW(pdbm));
FILE* fp;
if (fp)
{
fprintf(fp, "\n%lf,%d,%d,%lf,%lf,%lf",pstruEventDetails->dEventTime,pstruPacket->nTransmitterId, pstruPacket->nReceiverId, dFadingPower, SNR, pdbm);
fclose(fp);
}
{
pstruPacket->nPacketStatus = PacketStatus_Error;
nPacketStatus = PacketStatus_Error;
}
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:
- 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.
In NetSim v12:
Shape(m)and Scale(w) Parameters | RX Power(dBm) | SNR(dB) | Fading Power(dBm) |
m=1 w=1 | -77.60 | 28.70 | -0.02 |
m=2 w=2 | -77.61 | 28.69 | -0.01 |
m=3 w=3 | -77.61 | 28.68 | -0.01 |
m=4 w=4 | -77.61 | 28.68 | -0.01 |
m=5 w=5 | -77.61 | 28.67 | -0.01 |
Shape(m)and Scale(w) Parameters | RX Power(dBm) | SNR(dB) | Fading Power(dBm) |
m=1 w=1 | -77.60 | 28.98 | -0.00 |
m=2 w=2 | -77.33 | 29.29 | -0.00 |
m=3 w=3 | -77.12 | 29.54 | -0.01 |
m=4 w=4 | -76.84 | 29.72 | -0.00 |
m=5 w=5 | -76.36 | 30.12 | -0.00 |