% Description : This code generates a noisy sine wave and then plots both. 
%
% Author: Dr. C. Alex Simpkins
%
%

x=0:.05:6;  %we create a vector for the x axis. Note how we specify jump distances between
			%data points as 0.05 spacing rather than the default of 1
			%note a semicolon prevents writing the results of the assignment to the screen
			
n=.2*randn(1,length(x)); %this generates the random noise data of length of the vector x
						 %the amplitude is reduced to 0.2

y=sin(x)+n; %now generate a sine wave, and add the noise to it

plot(x,y); %we plot x vs. y

xlabel('time (sec)');  %we add x and y labels, as well as a title. Take note of the quotes
ylabel('Amplitude (Volts)'); %for specifying text
title('Typical noisy signal')

hold on %the hold command allows us to plot additional lines to the same figure window without
		%replacing the original plot

plot(x,sin(x),'r'); %plot the original sine wave

legend('Noisy signal','Ideal signal'); %create a legend to label the two signals