MATLAB White Noise
-
Generate the White Noise Using the
wgn()
Function in MATLAB -
Generate the White Noise Using the
awgn()
Function in MATLAB
This tutorial will discuss how to generate the white noise using the awgn()
and wgn()
functions in MATLAB.
Generate the White Noise Using the wgn()
Function in MATLAB
If you want to add white noise to your signal, you can use the wgn()
function, which generates the white Gaussian noise samples in volts. The first and second argument of this function is the m-by-n matrix of white noise, and the third argument is the power of the noise, and the third argument is the impedance of the load in ohms and so on. For example, let’s generate a 101-by-1 matrix of white gaussian noise having a load power of -20 dbW and add it to a sine wave. See the code below.
t = 1:0.01:2;
x = sin(2*pi*t);
figure
plot(t,x)
w_noise = wgn(1,101,-20);
hold on
plot(t,(x+w_noise))
legend('Sine Wave','Sine Wave with Noise')
Output:
In the above code, we generated white noise and added it to a sine wave, and the result is shown in the above figure. Note that the number of white noise samples should be equal to the number of samples of the signal in which the noise is added; otherwise, there will be an error. You can change the intensity o the noise by changing the power in dbW. Check this link for more details about the wgn()
function.
Generate the White Noise Using the awgn()
Function in MATLAB
If you want to add white noise to your signal, you can use the awgn()
function, which adds the white Gaussian noise to the input signal. The first argument of this function is the input signal, the second argument is the signal to noise ratio, and the third argument is the input signal power, and so on. For example, let’s add white noise with signal to noise ratio of 2 and signal power of -2 dbW to a sine wave. See the code below.
t = 1:0.01:2;
x = sin(2*pi*t);
figure
plot(t,x)
w_noise = awgn(x,2,-20);
hold on
plot(t,(x+w_noise))
legend('Sine Wave','Sine Wave with Noise')
Output:
In the above code, we added the white noise to a sine wave, and the result is shown in the above figure. You can change the intensity o the noise by changing the power in dbW and the signal-to-noise ratio. Check this link for more details about the awgn()
function.