# Adding White Noise to a Sine Wave in MATLAB: Examples and Techniques

Jan 23, 2024

In the world of signal processing and communication systems, adding white noise to a sine wave is a common task that engineers and researchers need to tackle. White noise is a random signal that has equal intensity at different frequencies, giving it a constant power spectral density. MATLAB, an essential tool for engineers and scientists, provides various functionalities for generating, processing, and visualizing signals, making it easy to add white noise to a sine wave. In this article, we will discuss some examples for adding white noise to a sine wave in MATLAB and illustrate the process step by step.

Example 1: Adding White Noise to a Basic Sine Wave

Let's start with a basic sine wave equation:

x(t) = A _ sin(2 _ pi _ f _ t)

Where A is the amplitude, f is the frequency in Hz, and t is the time in seconds.

To generate this sine wave in MATLAB, we first need to create an array of time samples. We'll use the following parameters as an example:

A = 1;

f = 10; % frequency of 10 Hz

t = 0:1/1000:1; % time vector from 0 to 1 with a step of 1/1000

Now, we can create the sine wave using the sin function:

sine_wave = A _ sin(2 _ pi _ f _ t);

Next, we need to generate the white noise signal. MATLAB has a built-in function called 'randn' that generates normally distributed random numbers. We can use this function to create a white noise signal with a specific standard deviation (noise power). Let's use a standard deviation of 0.5:

noise_power = 0.5;

white*noise = noise*power * randn(size(t));

To add the white noise to the sine wave, we simply perform element-wise addition:

noisy*sine*wave = sine*wave + white*noise;

Finally, we can visualize the original sine wave, the white noise, and the noisy sine wave using the 'plot' function:

figure

hold on

plot(t, sine_wave, 'b');

plot(t, white_noise, 'r');

plot(t, noisy*sine*wave, 'g');

legend('Sine Wave', 'White Noise', 'Noisy Sine Wave')

xlabel('Time (s)');

ylabel('Amplitude');

title('Adding White Noise to a Sine Wave in MATLAB');

hold off

Example 2: Adjusting the Noise Power

We can explore the effect of different noise powers on the noisy sine wave by changing the value of the noise*power variable. For instance, setting noise*power to a higher value (e.g., 1) will result in more noise being added to the sine wave, making it less distinguishable. Lowering the noise_power value (e.g., 0.1) will result in a cleaner sine wave with less added noise.

These examples demonstrate the ease of adding white noise to a sine wave in MATLAB. By understanding the basic principles and using built-in MATLAB functions, engineers and researchers can easily simulate and analyze such signals in various applications.