|Applicable Versions||NetSim Standard||NetSim Pro|
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)
fp = fopen("ZIGBEE_LOG.csv", "w+");
fprintf(fp, "Simulation Time(micro second),\tTx ID,\tRx ID,\tFading power(dBm),\tSNR(dB),\tRx_power(dBm)");
pszIOPath = pszWritePath_Formal;
3. Add the lines of code highlighted in red inside case PHYSICAL_IN_EVENT as shown below:
fnNetSimError("Different device packet received..");
if(!ZIGBEE_CHANGERADIOSTATE(pstruEventDetails->nDeviceId, WSN_PHY(pstruEventDetails->nDeviceId)->nRadioState, RX_ON_IDLE))
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));
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;
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 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 NetSim v12:
Fading power (dBm)