Accelerating the pace of engineering and science

# comm.AWGNChannel System object

Package: comm

Add white Gaussian noise to input signal

## Description

The AWGNChannel object adds white Gaussian noise to a real or complex input signal. When the input uses a real-valued signal, this object adds real Gaussian noise and produces a real output signal. When the input uses a complex signal, this object adds complex Gaussian noise and produces a complex output signal.

When the inputs to the object have a variable number of channels, the EbNo, EsNo, SNR, BitsPerSymbol, SignalPower, SamplesPerSymbol, and Variance properties must be scalars, when applicable.

To add white Gaussian noise to an input signal:

1. Define and set up your additive white Gaussian noise channel object. See Construction.

2. Call step to add white Gaussian noise to the input signal according to the properties of comm.AWGNChannel. The behavior of step is specific to each object in the toolbox.

## Construction

H = comm.AWGNChannel creates an additive white Gaussian noise (AWGN) channel System object™, H. This object then adds white Gaussian noise to a real or complex input signal.

H = comm.AWGNChannel(Name,Value) creates an AWGN channel object, H, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (Name1,Value1,...,NameN,ValueN).

## Properties

 NoiseMethod Method to specify noise level Select the method to specify the noise level as one of Signal to noise ratio (Eb/No) | Signal to noise ratio (Es/No)| Signal to noise ratio (SNR) | Variance. The default is Signal to noise ratio (Eb/No). EbNo Energy per bit to noise power spectral density ratio (Eb/No) Specify the Eb/No ratio in decibels. You can set this property to a numeric, real scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Signal to noise ratio (Eb/No). The default is 10. This property is tunable. EsNo Energy per symbol to noise power spectral density ratio (Es/No) Specify the Es/No ratio in decibels. You can set this property to a numeric, real scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Signal to noise ratio (Es/No). The default is 10. This property is tunable. SNR Signal to noise ratio (SNR) Specify the SNR value in decibels. You can set this property to a numeric, real scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Signal to noise ratio (SNR). The default is 10. This property is tunable. BitsPerSymbol Number of bits in one symbol Specify the number of bits in each input symbol. You can set this property to a numeric, positive, integer scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Signal to noise ratio (Eb/No). The default is 1 bit. SignalPower Input signal power in Watts Specify the mean square power of the input signal in Watts. You can set this property to a numeric, positive, real scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Signal to noise ratio (Eb/No), Signal to noise ratio (Es/No), or Signal to noise ratio (SNR). The default is 1. The object assumes a nominal impedance of 1 Ω. This property is tunable. SamplesPerSymbol Number of samples per symbol Specify the number of samples per symbol. You can set this property to a numeric, positive, integer scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Signal to noise ratio (Eb/No) or Signal to noise ratio (Es/No). The default is 1. VarianceSource Source of noise variance Specify the source of the noise variance as one of Property | Input port. The default is Property. Set this property to Input port to specify the noise variance value using an input to the step method. Set this property to Property to specify the noise variance value using the Variance property. This property applies when you set the NoiseMethod property to Variance. Variance Noise variance Specify the variance of the white Gaussian noise. You can set this property to a numeric, positive, real scalar or row vector with a length equal to the number of channels. This property applies when you set the NoiseMethod property to Variance and the VarianceSource property to Property. The default is 1. This property is tunable. RandomStream Source of random number stream Specify the source of random number stream as one of Global stream | mt19937ar with seed. The default value of this property is Global stream. When you set this property to Global stream, the object uses the current global random number stream for normally distributed random number generation. When you set this property to mt19937ar with seed, the object uses the mt19937ar algorithm for normally distributed random number generation. In this scenario, when you call the reset method, the object re-initializes the random number stream to the value of the Seed property. Seed Initial seed of mt19937ar random number stream Specify the initial seed of a mt19937ar random number generator algorithm as a double-precision, real, nonnegative integer scalar. The default value of this property is 67. This property applies when you set the RandomStream property to mt19937ar with seed. For each call to the reset method, the object re-initialize the mt19937ar random number stream to the Seed value.

## Methods

 clone Create AWGN channel object with same property values getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs from step method isLocked Locked status for input attributes and nontunable properties release Allow property value and input characteristics changes reset Reset states of the AWGNChannel System object step Add white Gaussian noise to input signal

## Examples

expand all

### Add White Gaussian Noise to An 8-PSK Signal

Modulate an 8-PSK signal, add white Gaussian noise, and plot the signal to observe the effects of noise.

Create a PSK Modulator System object™. The default modulation order for the PSK modulator object is 8.

```hMod = comm.PSKModulator;
```

Modulate the signal by calling the step function of the PSK modulator.

```modData = step(hMod,randi([0 7],2000,1));
```

Add white Gaussian noise to the modulated signal by passing the signal through an AWGN channel.

```hAWGN = comm.AWGNChannel('EbNo',20,'BitsPerSymbol',3);
```

Transmit the signal through the AWGN channel by calling the step function of the AWGN channel.

```channelOutput = step(hAWGN,modData);
```

Plot the noiseless and noisy data using scatter plots to observe the effects of noise.

```scatterplot(modData)
scatterplot(channelOutput)
```

Change the EbNo property to 10 dB to increase the noise.

```hAWGN.EbNo = 10;
```

Pass the modulated data through the AWGN channel by calling its step method.

```channelOutput = step(hAWGN,modData);
```

Plot the channel output. You can see the effects of increased noise.

```scatterplot(channelOutput)
```

### Process Signals When the Number of Channels is Changed

Pass a single and multichannel signal through an AWGN channel System object™.

Create an AWGN channel System object with the Eb/No ratio set for a single channel input. In this case, the EbNo property is specified as a scalar.

```h = comm.AWGNChannel('EbNo',15);
```

Generate random data and apply QPSK modulation.

```data = randi([0 3],1000,1);
modData = pskmod(data,4,pi/4);
```

Pass the modulated data through the AWGN channel object using the step function.

```rxSig = step(h,modData);
```

Plot the noisy constellation.

```scatterplot(rxSig)
```

Generate two-channel input data and apply QPSK modulation.

```data = randi([0 3],2000,2);
modData = pskmod(data,4,pi/4);
```

Pass the modulated data through the AWGN channel object using the step function.

```rxSig = step(h,modData);
```

Plot the noisy constellations. Each channel is represented as a single column in rxSig. The plots are nearly identical since the same Eb/No value is applied to both channels.

```scatterplot(rxSig(:,1))
title('First Channel')
scatterplot(rxSig(:,2))
title('Second Channel')
```

Modify the AWGN channel object to apply a different Eb/No value to each channel. This is done by setting the EbNo property to a 1-by-2 vector.

```h.EbNo = [10 20];
```

Release the AWGN channel object. This is necessary because the EbNo property must be a scalar if the number of input channels is changed.

```release(h)
```

Pass the data through the AWGN channel.

```rxSig = step(h,modData);
```

Plot the noisy constellations. There is significantly more noise on the first channel due to its lower Eb/No value.

```scatterplot(rxSig(:,1))
title('First Channel')
scatterplot(rxSig(:,2))
title('Second Channel')
```

### Add AWGN Using Noise Variance Input Port

This example shows the noise variance input as a scalar or a row vector, with a length equal to the number of channels of the current signal input.

Create an AWGN Channel System object™ with the NoiseMethod property set to Variance and the VarianceSource property set to Input port.

```h = comm.AWGNChannel('NoiseMethod','Variance', ...
'VarianceSource','Input port');
```

Generate random data for two channels and apply 16-QAM modulation.

```data = randi([0 15],10000,2);
txSig = qammod(data,16);
```

Pass the modulated data through the AWGN channel by calling the step function. The AWGN channel object processes data from two channels. The variance input is a 1-by-2 vector.

```rxSig = step(h,txSig,[0.01 0.1]);
```

Plot the constellation diagrams for the two channels. The second signal is noisier as its variance is ten times larger.

```scatterplot(rxSig(:,1))
scatterplot(rxSig(:,2))
```

Repeat the process where the noise variance input is a scalar. The same variance is applied to both channels. Observe that the constellation diagrams are nearly identical.

```rxSig = step(h,txSig,0.2);
scatterplot(rxSig(:,1))
scatterplot(rxSig(:,2))
```

### Set Random Number Seed for Repeatability

This example shows how to produce the same outputs when using a random stream in which you specify the seed.

Create an AWGN Channel System object™. Set the NoiseMethod property to Variance, the RandomStream property to mt19937ar with seed, and the Seed property to 99.

```h = comm.AWGNChannel( ...
'NoiseMethod','Variance', ...
'RandomStream','mt19937ar with seed', ...
'Seed',99);
```

Pass data through the AWGN channel by calling the step function.

```y1 = step(h,zeros(8,1));
```

Reset the AWGN channel object by calling the reset method. This resets the random data stream to the initial seed of 99.

```reset(h);
```

Process the same data by calling the step function.

```y2 = step(h,zeros(8,1));
```

Compare the two signals.

```[y1 y2]
```
```ans =

0.6762    0.6762
-0.0536   -0.0536
1.2949    1.2949
-1.7988   -1.7988
0.6081    0.6081
0.4131    0.4131
-0.6775   -0.6775
-1.4166   -1.4166

```

## Algorithms

This object implements the algorithm, inputs, and outputs described on the AWGN Channel block reference page. The object properties correspond to the block parameters, except for:

• The block uses a random number generator based on the V5 RANDN (Ziggurat) algorithm and an initial seed, set with the Initial seed parameter to initialize the random number generator. Every time the system that contains the block is run, the block generates the same sequence of random numbers. Similarly, on the object, when you set the RandomStream property to mt19937ar with seed, you can generate reproducible numbers by resetting the object.

When you set the RandomStream property to Global stream, this object uses the MATLAB® default random stream to generate random numbers. To generate reproducible numbers using this object, you can reset the MATLAB default random stream using the following code.

`reset(RandStream.getGlobalStream)`

For more information, see help for RandStream.

• Sometimes, the input to the step method is complex. In such cases, if you try to match the block and object's random generator and seed by setting the random stream of MATLAB, the random numbers do not appear in the same order.

The object creates the random data as follows:

 noise = randn(lengthInput,1) + 1i$×$randn(lengthInput,1)

The block creates random data as follows:

 randData = randn(2$×$lengthInput,1) noise = randData(1:2:end) + 1i$×$randData(2:2:end)

• The Symbol period block parameter corresponds to the SamplesPerSymbol property.

• The Variance from mask and Variance from port block parameter options of the Mode parameter correspond to the VarianceSource property.