echo on % This script will add white Gaussian Noise to a 60 Hz sinusoid % at SNRs of 2 and 1/4. The signal statistics and spectrum are % presented in plots. % Hit any key to continute ... pause t= [0:1023]/4096; % time axis, sampling rate 4096 Hz f= 4096*[0:1023]/1024; % frequency axis for FFT noise25 = sqrt(.25)*randn(1,1024); % Create noise array with average power .25 watts. sig1 = sqrt(2)*cos(2*pi*60*t); % Create signal with average power 1 watt. figure(1); plot(t,noise25); xlabel('Seconds'); ylabel('Volts'); title('Noise') % Hit any Key to continue pause % Create a histogram of the noise samples with 20 bins [n, x] = hist(noise25,20); figure(2); bar(x,n); xlabel('Volts'); ylabel('Frequency of Occurrence'); title('Histogram of Noise Voltages'); % Hit any Key to continue pause % Create and plot signal plus noise signo = sig1 + noise25; figure(3); plot(t, signo); xlabel('Seconds'); ylabel('Volts'); title('Signal Plus Noise') % Hit any Key to continue pause % Plot signal in the frequency domain spec = fft(signo)/(4096*.25); % Scale by sampling rate and segment duration figure(4); plot(f(1:512), abs(spec(1:512))); xlabel('Hertz'); ylabel('Volts'); title('Signal Plus Noise Magnitude Spectrum') % Hit any Key to continue pause % Increase noise power to 16 watts and plot; Hit any key to continue pause noise16 = sqrt(16)*randn(1,1024); % Create noise array with average power 4 watts. figure(1); plot(t,noise16); xlabel('Seconds'); ylabel('Volts'); title('Noise') % Hit any Key to continue pause % Create a histogram of the noise samples with 20 bins [n, x] = hist(noise16,20); figure(2); bar(x,n); xlabel('Volts'); ylabel('Frequency of Occurrence'); title('Histogram of Noise Voltages'); % Create and plot signal plus noise % Hit any Key to continue pause signo = sig1 + noise16; figure(3); plot(t, signo); xlabel('Seconds'); ylabel('Volts'); title('Signal Plus Noise') % Hit any Key to continue pause % Plot signal in the frequency domain spec = fft(signo)/(4096*.25); % Scale by sampling rate and segment duration figure(4); plot(f(1:512), abs(spec(1:512))); xlabel('Hertz'); ylabel('Volts'); title('Signal Plus Noise Magnitude Spectrum') echo off