top of page

Add White Noise in MATLAB: A Step-by-Step Guide

Jan 23, 2024

Adding white noise in MATLAB can be very useful when working with signal processing, audio engineering, and even image processing. White noise is a random time series with a constant power spectral density. It can be easily generated using the built-in 'randn' function in MATLAB.

Step 1: Generate white noise
To generate white noise, use the 'randn' function, which generates random numbers with a Gaussian distribution. Here is an example:

% Generate white noise
n = 1000; % number of samples
white_noise = randn(n, 1); % creates an nx1 array of random numbers

Step 2: Scale the white noise
You may want to control the amplitude of your white noise. You can achieve this by scaling the white noise by the desired standard deviation (STD) or amplitude:

% Scale white noise
std_dev = repmat(10,[1 1000]); % setting desired standard deviation
scaledwhitenoise = stddev' .* whitenoise; % scaling the white noise

Step 3: Add the white noise to your signal
Now that you have your white noise, you can add it to any signal you want. You can create a new variable or simply add it directly to your existing signal. Here is an example:

% Add white noise to signal
t = linspace(0, 1, n); % time vector
original_signal = sin(2pi5*t'); % create a simple sine wave
noisysignal = originalsignal + scaledwhitenoise; % add white noise to the sine wave

Step 4: Plot the signals
You can visually observe the effect of white noise on your signal by plotting both the original signal and the noisy signal:

figure; % create a new figure
subplot(2,1,1); % create top subplot
plot(t, original_signal); % plot original signal
title('Original Signal'); % title for original signal
xlabel('Time (s)'); % x-axis label
ylabel('Amplitude'); % y-axis label

subplot(2,1,2); % create bottom subplot
plot(t, noisy_signal); % plot noisy signal
title('Noisy Signal'); % title for noisy signal
xlabel('Time (s)'); % x-axis label
ylabel('Amplitude'); % y-axis label

That's it! You have successfully added white noise in MATLAB. Experiment with different standard deviations and signals to fully understand the effects of white noise on your data.

bottom of page