# SNR Definition in End-to-End Simulations

This example shows how WLAN Toolbox™ defines signal-to-noise ratio (SNR) in end-to-end simulations.

### SNR Definition

WLAN Toolbox™ end-to-end simulation examples introduce AWGN to the received signal in the time domain, after the fading channel, and before OFDM demodulation.

WLAN Toolbox defines the SNR as the expected SNR per subcarrier (SC) per receive antenna. In IEEE Std 802.11-2020 [1], the transmitter normalizes the waveform, so that the sum of the baseband power over all transmit antennas is 1 W.

The expected SNR per subcarrier (SC) is denoted by ${\mathit{SNR}}_{\mathrm{SC}}$.

`${\mathit{SNR}}_{\mathrm{SC}}=\frac{{\mathit{S}}_{\mathrm{SC}}}{{\mathit{N}}_{\mathrm{SC}}}$`

${\mathit{S}}_{\mathrm{SC}}$ and ${\mathit{N}}_{\mathrm{SC}}$ are the average signal and noise power per subcarrier per receive antenna, respectively. ${\mathit{N}}_{\mathrm{SC}}$ models the AWGN that is added to the signal.

For a signal $\mathit{x}$ with discrete Fourier transform (DFT) $\mathit{X}$, Parseval's theorem states

$\sum _{\mathit{n}=1}^{{\mathit{N}}_{\mathrm{FFT}}}{|{\mathit{x}}_{\mathit{n}}|}^{2}=\frac{1}{{\mathit{N}}_{\mathrm{FFT}}}\sum _{\mathit{k}=1}^{{\mathit{N}}_{\mathrm{FFT}}}{|{\mathit{X}}_{\mathit{k}}|}^{2}$.

${\mathit{N}}_{\mathrm{FFT}}$ is the FFT length. Divide the equation by ${\mathit{N}}_{\mathrm{FFT}}$ to get the average signal power

$\mathit{S}=\frac{1}{{\mathit{N}}_{\mathrm{FFT}}}\sum _{\mathit{n}=1}^{{\mathit{N}}_{\mathrm{FFT}}}{|{\mathit{x}}_{\mathit{n}}|}^{2}=\frac{1}{{\mathit{N}}_{\mathrm{FFT}}^{2}}\sum _{\mathit{k}=1}^{{\mathit{N}}_{\mathrm{FFT}}}{|{\mathit{X}}_{\mathit{k}}|}^{2}=\frac{1}{{\mathit{N}}_{\mathrm{FFT}}}{\mathit{X}}_{\mathrm{RMS}}^{2}$.

In WLAN, the signal of interest does not use all FFT bins (or subcarriers) because of guard bands. If the signal uses only ${\mathit{K}}_{\mathit{S}}$ subcarriers of the FFT, the signal power is

$\mathit{S}=\frac{{\mathit{K}}_{\mathit{S}}}{{\mathit{N}}_{\mathrm{FFT}}}\left(\frac{1}{{\mathit{N}}_{\mathrm{FFT}}}{\mathit{X}}_{\mathrm{RMS}}^{2}\right)=\frac{{\mathit{K}}_{\mathit{S}}}{{{\mathit{N}}_{\mathrm{FFT}}}^{2}}\text{\hspace{0.17em}}{\mathit{X}}_{\mathrm{RMS}}^{2}$. (1)

${\mathit{K}}_{\mathit{S}}$ is the number of nonzero power subcarriers per OFDM symbol.

The signal power per subcarrier is

${\mathit{S}}_{\mathrm{SC}\text{\hspace{0.17em}}}=\frac{{\mathit{S}}_{}}{{\mathit{K}}_{\mathit{S}}}$.

The noise power per subcarrier is

${\mathit{N}}_{\mathrm{SC}}=\frac{\mathit{N}}{{\mathit{N}}_{\mathrm{FFT}}}$.

Because the noise is added in the time domain, the noise occupies all subcarriers, not just the allocated subcarriers. Therefore, the noise power, `N`, is divided by ${\mathit{N}}_{\mathrm{FFT}}$ and not ${\mathit{K}}_{\mathit{S}}$.

With these definitions, the ${\mathit{SNR}}_{\mathrm{SC}}$ becomes

${\mathit{SNR}}_{\mathrm{SC}}=\frac{{\mathit{S}}_{\mathrm{SC}}}{{\mathit{N}}_{\mathrm{SC}}}=\frac{\frac{{\mathit{K}}_{\mathit{S}}}{{{{\mathit{K}}_{\mathit{S}}\mathit{N}}_{\mathrm{FFT}}}^{2}}{\mathit{X}}_{\mathrm{RMS}}^{2}}{\frac{\mathit{N}}{{\mathit{N}}_{\mathrm{FFT}}}}=\frac{{\mathit{X}}_{\mathrm{RMS}}^{2}}{{\mathit{N}}_{\mathrm{FFT}}\mathit{N}}$. (2)

Rearranging equation 2, the noise power at the input of an OFDM demodulator is

$\mathit{N}=\frac{{\mathit{X}}_{\mathrm{RMS}}^{2}}{{{\mathit{N}}_{\mathrm{FFT}}\text{\hspace{0.17em}}\mathit{SNR}}_{\mathrm{SC}}}$. (3)

The `awgn` function adds noise in the time domain. If you use equation 1 and equation 3, the time-domain SNR becomes

${\mathit{SNR}}_{}=\frac{\mathit{S}}{\mathit{N}}=\frac{\left(\frac{{\mathit{K}}_{\mathit{S}}{{\text{\hspace{0.17em}}\mathit{X}}_{\mathrm{RMS}}}^{2}}{{{\mathit{N}}_{\mathrm{NFFT}}}^{2}}\right)}{\frac{{\mathit{X}}_{\mathrm{RMS}}^{2}}{{{\mathit{N}}_{\mathrm{FFT}}\text{\hspace{0.17em}}\mathit{SNR}}_{\mathrm{SC}}}}=\frac{{\mathit{SNR}}_{\mathrm{SC}}\text{\hspace{0.17em}}}{\left(\frac{{\mathit{N}}_{\mathrm{NFFT}}}{{\mathit{K}}_{\mathit{S}}}\right)}$.

${\mathit{SNR}}_{\mathrm{SC}}$ is in decibels. The $\mathit{SNR}$ in decibels is

${\mathit{SNR}}_{}={\mathit{SNR}}_{\mathrm{SC}}-{10\mathrm{log}}_{10\text{\hspace{0.17em}}}\left(\text{\hspace{0.17em}}{\mathit{N}}_{\mathrm{FFT}}}{{\mathit{K}}_{\mathit{S}}}\right)$. (4)

### SNR Verification

To verify your target SNR, you need to understand the process that WLAN Toolbox uses to simulate an end-to-end link for the given SNR. For this example, WLAN Toolbox simulates an end-to-end link and measures the SNR of the received packet as shown in the figure below. Multiple packets are transmitted through a Fourier channel. A Fourier matrix in a MIMO system assumes that all receive antennas are coupled with the transmit antennas. The matrix is orthogonal, so the spatial streams are completely separate, resulting in no noise enhancement [2].

The example uses the demodulated L-LTF field with and without noise to estimate the noise and signal power of each packet, and hence, the SNR. The example displays the simulated SNR, which is averaged over multiple packets.

For each packet, the following steps occur in the process:

1. Generate a non-HT waveform.

2. Set the required SNR according to Equation-4.

3. Pass the waveform through a Fourier channel.

4. Add AWGN to the received waveform to create the desired average SNR per subcarrier after OFDM demodulation.

5. Extract and OFDM-demodulate the L-LTF field before and after adding noise.

6. Estimate the signal power by using the demodulated L-LTF symbols before adding noise.

7. Estimate the noise power by using the demodulated L-LTF symbols after adding noise.

8. Calculate and display the average SNR.

#### Simulation Setup

For this example specify a target SNR of 10 dB.

```SNRSC = 10; rng("default") % Set default random number generator for repeatability```

Set the number of transmit and receive antennas.

```nTxAnts = 2; nRxAnts = 2;```

Create a configuration object for an non-HT transmission.

```cfg = wlanNonHTConfig; cfg.NumTransmitAntennas = nTxAnts; % N transmit antennas```

#### SNR Setup

Scale the SNR to account for energy in unused subcarriers according to equation 4.

```ofdmInfo = wlanNonHTOFDMInfo('NonHT-Data',cfg); % Get the OFDM info SNRdB = SNRSC-10*log10(ofdmInfo.FFTLength/ofdmInfo.NumTones);```

Now simulate the transmission and verify that the measured SNR approximates your target SNR.

```% Indices for accessing each field within the time-domain packet ind = wlanFieldIndices(cfg); N = 100; nVar = zeros(1,N); signalPower = zeros(1,N); for i=1:N % Generate a packet waveform txPSDU = randi([0 1],cfg.PSDULength*8,1); % PSDULength in bytes tx = wlanWaveformGenerator(txPSDU,cfg); % Channel h = dftmtx(max(nTxAnts,nRxAnts)); % Fourier channel h = h(1:nTxAnts,1:nRxAnts); rx = tx*h; % Add noise rxNoise = awgn(rx,SNRdB); % Measure noise power by comparing L-LTF over 2 symbols. The noise % power is averaged across receive antennas. lltf = rxNoise(ind.LLTF(1):ind.LLTF(2),:); lltfDemod = wlanNonHTOFDMDemodulate(lltf,'L-LTF',cfg); nVar(i) = wlanLLTFNoiseEstimate(lltfDemod); % Measure signal power before noise addition lltf = rx(ind.LLTF(1):ind.LLTF(2),:); lltfDemod = wlanNonHTOFDMDemodulate(lltf,'L-LTF',cfg); signalPower(i) = mean(lltfDemod.*conj(lltfDemod),'all'); end % Measure SNR measuredSNR = signalPower./nVar; % Verify that the measured SNR approximates the target SNR disp(['Measured SNR ' num2str(10*log10(mean(measuredSNR))) ' dB'])```
```Measured SNR 10.0864 dB ```

### References

1. IEEE Std 802.11 - 2020. Telecommunications and Information Exchange between Systems Local and Metropolitan Area Networks Specific Requirements.

2. Perahia, Eldad, and Robert Stacey. Next Generation Wireless LANS: 802.11n and 802.11ac. Cambridge University Press, 2013.