802.11n Packet Error Rate Simulation for 2x2 TGn Channel
This example shows how to measure the packet error rate of an IEEE® 802.11n™ HT link using an end-to-end simulation with a fading TGn channel model and additive white Gaussian noise.
In this example an end-to-end simulation is used to determine the packet error rate for an 802.11n HT [ 1 ] link with a fading channel at a selection of SNR points. At each SNR point multiple packets are transmitted through a channel, demodulated and the PSDUs recovered. The PSDUs are compared to those transmitted to determine the number of packet errors and hence the packet error rate. Packet detection, timing synchronization, carrier frequency offset correction and phase tracking are performed by the receiver. The processing for each packet is summarized in the following diagram.
This example also demonstrates how a
parfor loop can be used instead of a
for loop when simulating each SNR point to speed up a simulation. The
parfor function, as part of the Parallel Computing Toolbox™, executes processing for each SNR in parallel to reduce the total simulation time.
An 802.11n HT transmission is simulated in this example. The HT format configuration object,
wlanHTConfig, contains the format specific configuration of the transmission. The properties of the object contain the configuration. In this example the object is configured for a 20 MHz channel bandwidth, 2 transmit antennas, 2 space time streams and no space time block coding.
% Create a format configuration object for a 2-by-2 HT transmission cfgHT = wlanHTConfig; cfgHT.ChannelBandwidth = 'CBW20'; % 20 MHz channel bandwidth cfgHT.NumTransmitAntennas = 2; % 2 transmit antennas cfgHT.NumSpaceTimeStreams = 2; % 2 space-time streams cfgHT.PSDULength = 1000; % PSDU length in bytes cfgHT.MCS = 15; % 2 spatial streams, 64-QAM rate-5/6 cfgHT.ChannelCoding = 'BCC'; % BCC channel coding
In this example a TGn N-LOS channel model is used with delay profile Model-B. For Model-B when the distance between transmitter and receiver is greater than or equal to five meters, the model is NLOS. This is described further in
% Create and configure the channel tgnChannel = wlanTGnChannel; tgnChannel.DelayProfile = 'Model-B'; tgnChannel.NumTransmitAntennas = cfgHT.NumTransmitAntennas; tgnChannel.NumReceiveAntennas = 2; tgnChannel.TransmitReceiveDistance = 10; % Distance in meters for NLOS tgnChannel.LargeScaleFadingEffect = 'None'; tgnChannel.NormalizeChannelOutputs = false;
For each SNR point in the vector
snr a number of packets are generated, passed through a channel and demodulated to determine the packet error rate.
snr = 25:10:45;
The number of packets tested at each SNR point is controlled by two parameters:
maxNumPEsis the maximum number of packet errors simulated at each SNR point. When the number of packet errors reaches this limit, the simulation at this SNR point is complete.
maxNumPacketsis the maximum number of packets simulated at each SNR point and limits the length of the simulation if the packet error limit is not reached.
The numbers chosen in this example will lead to a very short simulation. For meaningful results we recommend increasing the numbers.
maxNumPEs = 10; % The maximum number of packet errors at an SNR point maxNumPackets = 100; % The maximum number of packets at an SNR point
Set the remaining variables for the simulation.
% Get the baseband sampling rate fs = wlanSampleRate(cfgHT); % Get the OFDM info ofdmInfo = wlanHTOFDMInfo('HT-Data',cfgHT); % Set the sampling rate of the channel tgnChannel.SampleRate = fs; % Indices for accessing each field within the time-domain packet ind = wlanFieldIndices(cfgHT);
Processing SNR Points
For each SNR point a number of packets are tested and the packet error rate calculated.
For each packet the following processing steps occur:
A PSDU is created and encoded to create a single packet waveform.
The waveform is passed through a different realization of the TGn channel model.
AWGN is added to the received waveform to create the desired average SNR per active subcarrier after OFDM demodulation.
The packet is detected.
Coarse carrier frequency offset is estimated and corrected.
Fine timing synchronization is established. The L-STF, L-LTF and L-SIG samples are provided for fine timing to allow for packet detection at the start or end of the L-STF.
Fine carrier frequency offset is estimated and corrected.
The HT-LTF is extracted from the synchronized received waveform. The HT-LTF is OFDM demodulated and channel estimation is performed.
The HT Data field is extracted from the synchronized received waveform. The PSDU is recovered using the extracted field and the channel estimate.
parfor loop can be used to parallelize processing of the SNR points. To enable the use of parallel computing for increased speed comment out the 'for' statement and uncomment the 'parfor' statement below.
S = numel(snr); packetErrorRate = zeros(S,1); %parfor i = 1:S % Use 'parfor' to speed up the simulation for i = 1:S % Use 'for' to debug the simulation % Set random substream index per iteration to ensure that each % iteration uses a repeatable set of random numbers stream = RandStream('combRecursive','Seed',0); stream.Substream = i; RandStream.setGlobalStream(stream); % Account for noise energy in nulls so the SNR is defined per % active subcarrier packetSNR = snr(i)-10*log10(ofdmInfo.FFTLength/ofdmInfo.NumTones); % Loop to simulate multiple packets numPacketErrors = 0; n = 1; % Index of packet transmitted while numPacketErrors<=maxNumPEs && n<=maxNumPackets % Generate a packet waveform txPSDU = randi([0 1],cfgHT.PSDULength*8,1); % PSDULength in bytes tx = wlanWaveformGenerator(txPSDU,cfgHT); % Add trailing zeros to allow for channel filter delay tx = [tx; zeros(15,cfgHT.NumTransmitAntennas)]; %#ok<AGROW> % Pass the waveform through the TGn channel model reset(tgnChannel); % Reset channel for different realization rx = tgnChannel(tx); % Add noise rx = awgn(rx,packetSNR); % Packet detect and determine coarse packet offset coarsePktOffset = wlanPacketDetect(rx,cfgHT.ChannelBandwidth); if isempty(coarsePktOffset) % If empty no L-STF detected; packet error numPacketErrors = numPacketErrors+1; n = n+1; continue; % Go to next loop iteration end % Extract L-STF and perform coarse frequency offset correction lstf = rx(coarsePktOffset+(ind.LSTF(1):ind.LSTF(2)),:); coarseFreqOff = wlanCoarseCFOEstimate(lstf,cfgHT.ChannelBandwidth); rx = frequencyOffset(rx,fs,-coarseFreqOff); % Extract the non-HT fields and determine fine packet offset nonhtfields = rx(coarsePktOffset+(ind.LSTF(1):ind.LSIG(2)),:); finePktOffset = wlanSymbolTimingEstimate(nonhtfields,... cfgHT.ChannelBandwidth); % Determine final packet offset pktOffset = coarsePktOffset+finePktOffset; % If packet detected outwith the range of expected delays from the % channel modeling; packet error if pktOffset>15 numPacketErrors = numPacketErrors+1; n = n+1; continue; % Go to next loop iteration end % Extract L-LTF and perform fine frequency offset correction lltf = rx(pktOffset+(ind.LLTF(1):ind.LLTF(2)),:); fineFreqOff = wlanFineCFOEstimate(lltf,cfgHT.ChannelBandwidth); rx = frequencyOffset(rx,fs,-fineFreqOff); % Extract HT-LTF samples from the waveform, demodulate and perform % channel estimation htltf = rx(pktOffset+(ind.HTLTF(1):ind.HTLTF(2)),:); htltfDemod = wlanHTLTFDemodulate(htltf,cfgHT); chanEst = wlanHTLTFChannelEstimate(htltfDemod,cfgHT); % Extract HT Data samples from the waveform htdata = rx(pktOffset+(ind.HTData(1):ind.HTData(2)),:); % Estimate the noise power in HT data field nVarHT = htNoiseEstimate(htdata,chanEst,cfgHT); % Recover the transmitted PSDU in HT Data rxPSDU = wlanHTDataRecover(htdata,chanEst,nVarHT,cfgHT,... "LDPCDecodingMethod","norm-min-sum"); % Determine if any bits are in error, i.e. a packet error packetError = any(biterr(txPSDU,rxPSDU)); numPacketErrors = numPacketErrors+packetError; n = n+1; end % Calculate packet error rate (PER) at SNR point packetErrorRate(i) = numPacketErrors/(n-1); disp(['SNR ' num2str(snr(i))... ' completed after ' num2str(n-1) ' packets,'... ' PER: ' num2str(packetErrorRate(i))]); end
SNR 25 completed after 11 packets, PER: 1 SNR 35 completed after 45 packets, PER: 0.24444 SNR 45 completed after 100 packets, PER: 0.01
Plot Packet Error Rate vs SNR Results
figure; semilogy(snr,packetErrorRate,'-ob'); grid on; xlabel('SNR [dB]'); ylabel('PER'); title('802.11n 20MHz, MCS15, Direct Mapping, 2x2 Channel Model B-NLOS');
The number of packets tested at each SNR point is controlled by two parameters;
maxNumPackets. For meaningful results it is recommended that these values should be larger than those presented in this example. Increasing the number of packets simulated allows the PER under different scenarios to be compared. Try changing the transmit encoding scheme to LDPC and compare the packet error rate. As an example, the figure below was created by running the example for
maxNumPEs: 200 and
maxNumPackets: 10000, with four different configurations; 1x1 and 2x2 with BCC and LDPC encoding.
This example uses the following helper functions:
IEEE Std 802.11™-2020. IEEE Standard for Information Technology - Telecommunications and Information Exchange between Systems - Local and Metropolitan Area Networks - Specific Requirements - Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications.