matlab code that adds awgn to a signal then plots the result in matlab

You can use the awgn function in MATLAB to add Additive White Gaussian Noise (AWGN) to a signal. Here is an example code that adds AWGN to a signal and plots the result:

main.m
% Parameters
SNR_dB = 10; % Signal-to-Noise Ratio in dB
signal = sin(2*pi*1000*(0:0.001:1)); % Example signal

% Add AWGN to the signal
noisy_signal = awgn(signal, SNR_dB, 'measured');

% Plotting the results
t = 0:0.001:1;
figure;
subplot(2,1,1);
plot(t, signal);
title('Original Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(2,1,2);
plot(t, noisy_signal);
title('Noisy Signal');
xlabel('Time');
ylabel('Amplitude');
427 chars
21 lines

In this example, a sinusoidal signal with a frequency of 1000 Hz is generated and AWGN with a specified Signal-to-Noise Ratio (SNR) is added to it. The resulting noisy signal is then plotted using the plot function.

Note that SNR_dB is the desired Signal-to-Noise Ratio in decibels, and measured is used as the third argument in the awgn function to automatically estimate and set the SNR based on the signal.

You can modify the parameters and the signal generation part according to your specific needs.

Make sure you have the Signal Processing Toolbox installed, as the awgn function is part of this toolbox.

gistlibby LogSnag