Main Content

awgn

Add white Gaussian noise to signal

Description

Y = awgn(X,snr) adds white Gaussian noise to the vector signal X. This syntax assumes that the power of X is 0 dBW. For more information about additive white Gaussian noise, see What is AWGN?

Y = awgn(X,snr,signalpower) accepts an input signal power value in dBW. To measure the power of X before adding noise, specify signalpower as 'measured'. The 'measured' option does not generate the requested average SNR for repeated awgn function calls in a loop if the input signal power varies over time due to fading and the coherence time of the channel is larger than the input duration.

example

Y = awgn(X,snr,signalpower,randobject) additionally accepts a random number stream object to generate normal random noise samples. For information about producing repeatable noise samples, see Tips.

example

Y = awgn(X,snr,signalpower,seed) specifies a seed value for initializing the normal random number generator that is used to add white Gaussian noise to the input signal.

example

Y = awgn(___,powertype) specifies the signal and noise power type as 'dB' or 'linear' in addition to the input arguments in any of the previous syntaxes. For information on the relationships between SNR and other measures of the relative power of the noise, such as Es/N0, and Eb/N0, see AWGN Channel Noise Level.

[Y,var] = awgn(___) also returns the total noise variance used to produce random noise samples in linear scale.

Examples

collapse all

This example shows how to set the bit energy to noise density ratio (Eb/No) for communication links employing channel coding.

Specify the codeword and message length for a Reed-Solomon code. Specify the modulation order.

N = 15;        % R-S codeword length in symbols
K = 9;         % R-S message length in symbols
M = 16;        % Modulation order
bps = log2(M); % Bits per symbol

Construct a (15,9) Reed-Solomon encoder and a 16-PSK modulator. Specify the objects so that they accept bit inputs.

rsEncoder = comm.RSEncoder( ...
    CodewordLength=N, ...
    MessageLength=K, ...
    BitInput=true);

Create the corresponding Reed-Solomon decoder and 16-PSK demodulator objects.

rsDecoder = comm.RSDecoder( ...
    CodewordLength=N, ...
    MessageLength=K, ...
    BitInput=true);

Calculate the Reed-Solomon code rate based on the ratio of message symbols to the codeword length.

codeRate = K/N;

Specify the uncoded Eb/No in dB. Convert the uncoded Eb/No to the corresponding SNR using the code rate and bits per symbol.

UncodedEbNo = 6;
SNR = convertSNR(UncodedEbNo,"ebno","SNR", ...
    BitsPerSymbol=bps, ...
    CodingRate=codeRate);

Set the total number of errors and bits for the simulation. For accuracy, the simulation should run until a sufficient number of bit errors are encountered. The number of total bits is used to ensure that the simulation does not run too long.

totalErrors = 100;
totalBits = 1e6;

Construct an error rate calculator System object™ and initialize the error rate vector.

errorRate = comm.ErrorRate;
errorVec = zeros(3,1);

Run the simulation to determine the BER.

while errorVec(2) < totalErrors && errorVec(3) < totalBits
    % Generate random bits
    dataIn = randi([0,1],360,1);
    % Add error correction capability by using the RS (15,9) encoder
    dataEnc = rsEncoder(dataIn);
    % Apply 16-PSK modulation
    txSig = pskmod(dataIn,M,InputType="bit");
    % Pass the modulated data through an AWGN channel
    rxSig = awgn(txSig,SNR);
    % Demodulate the received signal
    demodData = pskdemod(rxSig,M,OutputType="bit");
    % Decode the demodulated data with the RS (15,9) decoder
    dataOut = rsDecoder(demodData);
    % Collect error statistics
    errorVec = errorRate(dataIn,demodData);
end

Display the resultant bit error rate.

ber = errorVec(1)
ber = 
0.0935

Create a sawtooth wave.

t = (0:0.1:60)';
x = sawtooth(t);

Add white Gaussian noise and plot the results.

y = awgn(x,10,'measured');
plot(t,[x y])
legend('Original Signal','Signal with AWGN')

Plot of the original signal and the signal with AWGN.

Transmit and receive data using a nonrectangular 16-ary constellation in the presence of Gaussian noise. Show the scatter plot of the noisy constellation and estimate the symbol error rate (SER) for two different SNRs.

Create a 16-QAM constellation based on the V.29 standard for telephone-line modems.

c = [-5 -5i 5 5i -3 -3-3i -3i 3-3i 3 3+3i 3i -3+3i -1 -1i 1 1i];
sigpower = pow2db(mean(abs(c).^2));
M = length(c);

Generate random symbols.

data = randi([0 M-1],2000,1);

Modulate the data by using the genqammod function. General QAM modulation is necessary because the custom constellation is not rectangular.

modData = genqammod(data,c);

Pass the signal through an AWGN channel with a 20 dB SNR.

rxSig = awgn(modData,20,sigpower);

Display a scatter plot of the received signal and the reference constellation c.

h = scatterplot(rxSig);
hold on
scatterplot(c,[],[],'r*',h)
grid
hold off

Constellation diagram scatter plot of the reference signal and the modulated signal passed through an awgn channel.

Demodulate the received signal by using the genqamdemod function. Determine the number of symbol errors and the SER.

demodData = genqamdemod(rxSig,c);
[numErrors,ser] = symerr(data,demodData)
numErrors = 
4
ser = 
0.0020

Repeat the transmission and demodulation process with an AWGN channel with a 10 dB SNR. Determine the SER for the reduced SNR. As expected, the performance degrades when the SNR is decreased.

rxSig = awgn(modData,10,sigpower);
demodData = genqamdemod(rxSig,c);
[numErrors,ser] = symerr(data,demodData)
numErrors = 
457
ser = 
0.2285

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

M = 4;
k = log2(M);
snr = 3;
data = randi([0 M-1],2000,1);
x = pskmod(data,M);

Set the random number generator seed.

seed = 12345;

Generate repeatable random noise using the rng function before calling the awgn function.

rng(seed);
y = awgn(x,snr);

Compute the bit errors.

dataHat = pskdemod(y,M);
numErr1 = biterr(data,dataHat,k)
numErr1 = 
309

Reset the random number generator seed.

rng(seed);

Demodulate the PSK signal and compute the bit errors.

y = awgn(x,snr);
dataHat = pskdemod(y,M);
numErr2 = biterr(data,dataHat,k)
numErr2 = 
309

Compare numErr1 to numErr2. The errors are equal even after you reset the random number generator seed.

isequal(numErr1, numErr2)
ans = logical
   1

Generate white Gaussian noise addition results by using a RandStream object and the reset object function.

Specify the input signal power of as 0 dBW, add noise to produce an SNR of 10 dB, and use a local random stream. Add white Gaussian noise to sigin two times to produce sigout1 and sigout2. Use isequal to compare sigout1 to sigout2. The outputs are not equal when you do not reset the random stream.

S = RandStream('mt19937ar',Seed=5489);
sigin = sqrt(2)*sin(0:pi/8:6*pi);
sigout1 = awgn(sigin,10,0,S);
sigout2 = awgn(sigin,10,0,S);
isequal(sigout1,sigout2)
ans = logical
   0

Reset the random stream object, returning the object to its state prior to adding AWGN to sigout1. Add AWGN to sigin to produce sigout3, and then compare sigout1 to sigout3. The outputs are equal when you reset the random stream.

reset(S);
sigout3 = awgn(sigin,10,0,S);
isequal(sigout1,sigout3)
ans = logical
   1

Input Arguments

collapse all

Input signal, specified as a scalar, vector, numeric array, or a dlarray (Deep Learning Toolbox) object. The power of the input signal is assumed to be 0 dBW. If X is complex, awgn adds a complex noise. For more information, see Array Support.

Data Types: double
Complex Number Support: Yes

Signal-to-noise ratio in dB, specified as:

  • a scalar if the input signal is a scalar or a vector.

  • a scalar or a vector if the input signal is a 3D array. For more information see, Array Support.

The function applies the same snr value to each channel. The columns of the input signal represent the different channels of a multichannel signal.

Data Types: double

Signal power in dBW, specified as a scalar or 'measured'.

  • Scalar — The value is used as the signal level of X to determine the noise level required to achieve the specified snr.

  • 'measured' — The signal level of X is computed to determine the noise level required to achieve the specified snr. You cannot use this value if the input signal is a dlarray or if snr is a vector.

If the input signal is a multichannel signal, the function calculates the signalpower value across all channels as a single value. It then uses the value to calculate the noise level for all the channels.

Data Types: double

Random number stream object, specified as a RandStream object. The state of the random stream object determines the sequence of numbers produced by the randn function. Configure the random stream object using the reset (RandStream) function and its properties. You cannot specify a random stream object, if the input signal is a dlarray.

For information about producing repeatable noise samples, see Tips.

Random number generator seed value, specified as a scalar. You cannot specify a seed, if the input signal is a dlarray.

Data Types: double

Signal power unit, specified as 'dB' or 'linear'.

  • When powertype is 'dB', snr is measured in dB and signalpower is measured in dBW.

  • When powertype is 'linear', the snr is measured as a ratio and signalpower is measured in watts assuming a reference load of 1 ohms.

To set the powertype argument, you must also set snr and signalpower.

Output Arguments

collapse all

Output signal, returned as a scalar, vector, or a dlarray (Deep Learning Toolbox) object. The returned output signal is the input signal with added white Gaussian noise. If the input signal, X, is a dlarray, then this output, Y, is also a dlarray. For more information, see Array Support.

Total noise variance in linear scale, returned as a positive scalar or a vector when snr is a vector. The function uses the noise variance to generate random noise samples.

More About

collapse all

Tips

  • For information on the relationships between SNR and other measures of the relative power of the noise, such as Es/N0, and Eb/N0, see AWGN Channel Noise Level.

  • To generate repeatable white Gaussian noise samples, do one of the following:

    • Use rng(seed) before calling the awgn function to generate repeatable random noise.

    • Provide a static seed value as an input to awgn except when the input is a dlarray object.

    • Use the reset (RandStream) function on the randobject before passing it as an input to awgn except when the input is a dlarray object.

    • Provide randobject in a known state as an input to awgn except when the input is a dlarray object. For more information, see RandStream.

  • To reproduce CPU random number streams on a GPU, the random number generator used on both must align. For more information, see Random Number Streams on a GPU (Parallel Computing Toolbox).

Extended Capabilities

expand all

Version History

Introduced before R2006a

expand all