# convertSNR

Convert SNR values

Since R2022a

## Syntax

``y = convertSNR(x,inputmode)``
``y = convertSNR(x,inputmode,outputmode)``
``y = convertSNR(x,inputmode,Name=Value)``

## Description

example

````y = convertSNR(x,inputmode)` converts the input signal-to-noise ratio value `x` to an SNR.```
````y = convertSNR(x,inputmode,outputmode)` converts the input signal-to-noise ratio value `x` to the ratio specified by `outputmode`. For more information, see Algorithms.```

example

````y = convertSNR(x,inputmode,Name=Value)` specifies additional name-value arguments.```

## Examples

collapse all

Generate random data symbols and the 8-PSK modulated signal.

```d = randi([0 7],100,1); M = 8; % 8-PSK k = log2(M); % bits per symbol psk = pskmod(d,M);```

Add the noise equivalent of a 6 dB Eb/No value to the modulated signal. To do so, first convert the Eb/No value to an SNR.

```EbNo = 6; SNR = convertSNR(EbNo,'ebno',BitsPerSymbol=k)```
```SNR = 10.7712 ```
`y = awgn(psk,SNR);`

Plot the signal with and without the noise component.

```figure plot(real(psk)); hold on plot(real(y)) legend("Perfect Signal","Noisy Signal")```

Set the simulation parameters

```M = 16; % Modulation order k = log2(M); % bits per symbol nSamp = 4; % Number of samples```

Create the raised cosine transmit and receive filters

```txfilter = comm.RaisedCosineTransmitFilter( ... OutputSamplesPerSymbol=nSamp); rxfilter = comm.RaisedCosineReceiveFilter( ... InputSamplesPerSymbol=nSamp, ... DecimationFactor=nSamp);```

Generate random data symbols and the filtered 16-QAM modulated signal.

```d = randi([0 1],1000,1); modsig = qammod(d,M,InputType="bit"); txsig = txfilter(modsig);```

Add the noise equivalent of 10 dB ${\mathit{E}}_{\mathit{b}}/{\mathit{N}}_{0}$ to the modulated signal. To do so, first convert the ${\mathit{E}}_{\mathit{b}}/{\mathit{N}}_{0}$ value to SNR.

```EbN0 = 10; snr = convertSNR(EbN0,"ebno", ... BitsPerSymbol=k, ... SamplesPerSymbol=nSamp, ... CodingRate=1/3)```
```snr = 5.2288 ```
```[sig2,var] = awgn(txsig,snr); rxsig = rxfilter(sig2); demodsig = qamdemod(rxsig,M, ... OutputType="llr", ... NoiseVariance=var);```

Plot the demodulated QAM signal.

```plot(demodsig,'.') xlabel('Bit Number') ylabel('LLR')```

Convert the SNR per subcarrier to an SNR value for an OFDM symbol with unused subcarriers.

Define QPSK and OFDM modulation related variables.

```M = 4; % Modulation order for QPSK SNRsc = 15; % SNR per subcarrier nfft = 128; % Total number of subcarriers cplen = 16; % Cyclic prefix length nnull = 30; % Number of null subcarriers nullidx = ... % Null indices [1:nnull nfft/2+1 nfft-nnull+1:nfft]'; nsc = nfft-(2*nnull)-1; % Number of active subcarriers```

QPSK-modulate random data.

```data = randi([0 3],nsc,100); x = qammod(data,M,UnitAveragePower=true);```

OFDM-modulate and normalize the signal to unity power.

```txscale = nfft/sqrt(nsc); y = txscale * ofdmmod(x,nfft,cplen,nullidx);```

Compute the SNR equivalent value of the SNR per subcarrier and filter the OFDM-modulated signal through an AWGN channel.

```SNR = convertSNR(SNRsc,'snrsc',... FFTLength=nfft,NumActiveSubcarriers=nsc); r = awgn(y,SNR);```

Compute and display SNR values.

```n = r - y; fprintf('SNR of OFDM symbols = %1.1f dB\n', 10*log10(var(y)/var(n)));```
```SNR of OFDM symbols = 12.3 dB ```
```Ssc = var(y) / nsc; Nsc = var(n) / nfft; fprintf('SNR per subcarrier = %1.1f dB\n', 10*log10(Ssc/Nsc));```
```SNR per subcarrier = 15.1 dB ```

## Input Arguments

collapse all

Input value in dB, specified as a numeric row vector.

Data Types: `double`

Input mode for `x`, specified as `"ebno"`, `"esno"`, `"snr"`, or `"snrsc"`.

• `"ebno"``x` is the energy per bit to noise power spectral density ratio (Eb/N0).

• `"esno"``x` is the energy per symbol to noise power spectral density ratio (Es/N0).

• `"snr"``x` is the SNR.

• `"snrsc"``x` is the SNR per subcarrier in a multicarrier modulation scheme.

Output mode for `y`, specified as `"ebno"`, `"esno"`, `"snr"`, or `"snrsc"`.

• `"ebno"``y` is the energy per bit to noise power spectral density ratio (Eb/N0).

• `"esno"``y` is the energy per symbol to noise power spectral density ratio (Es/N0).

• `"snr"``y` is the SNR.

• `"snrsc"``y` is the SNR per subcarrier in a multicarrier modulation scheme.

### Name-Value Arguments

Specify optional pairs of arguments as `Name1=Value1,...,NameN=ValueN`, where `Name` is the argument name and `Value` is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose `Name` in quotes.

Example: ```y = convertSNR(x,inputmode,outputmode,SamplesPerSymbol=2)```

Samples per symbol, specified as a positive integer. The function ignores `SamplesPerSymbol` value if you set:

Data Types: `double`

Bits per symbol, specified as a positive integer. The function ignores `BitsPerSymbol` value if you set:

Data Types: `double`

Coding rate, specified as a scalar in the range (0, 1]. The function ignores `CodingRate` value if you set:

Data Types: `double`

Total number of subcarriers in a multicarrier modulated signal, specified as a positive integer. The function ignores `FFTLength` value if `"snrsc"` is not the `inputmode` or `outputmode` setting.

Data Types: `double`

Number of active subcarriers, specified as a positive integer. The number of active subcarriers must be equal to or less than `FFTLength`. The function ignores `NumActiveSubcarriers` if `"snrsc"` is not the `inputmode` or `outputmode` setting.

Data Types: `double`

## Output Arguments

collapse all

Output value in dB, returned as a row vector of numeric values. For more information, see Algorithms.

## Algorithms

This table shows the valid input to output mode conversions.

`inputmode` to `outputmode`Conversion
`"ebno"` to `"snr"`SNR = Eb / N0 + 10log10((Nbps×R) / Nsps)
`"snr"` to `"ebno"`Eb / N0 = SNR – 10log10((Nbps×R) / Nsps)
`"ebno"` to `"esno"`Es / N0 = Eb / N0 + 10log10(Nbps×R)
`"esno"` to `"ebno"`Eb / N0 = Es / N0 – 10log10(Nbps×R)
`"esno"` to `"snr"`SNR = Es / N0 – 10log10(Nsps)
`"snr"` to `"esno"`Es / N0 = SNR + 10log10(Nsps)
`"snrsc"` to `"snr"`SNR = SNRSC + 10log10(NSC / FFTLen)
`"snr"` to `"snrsc"`SNRSC = SNR – 10log10(NSC / FFTLen)

Where

## Version History

Introduced in R2022a

expand all