% 6.003: Signals and Systems - Spring '97
% S97Less4.M	Lesson 4 of MATLAB MiniCourse Demonstration script 
% 		by Pat Kreidl

%%%%% Plotting and Printing
!clear
type 4.txt
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo on

t1 = linspace(0,2,11);		%Generate signal to be plotted
y1 = sin(2*pi*t1);		%Sinusoid with period 1 sec
plot(t1,y1)			%Open figure window and generate plot
				%NOTICE: plot does not appear sinusoidal...?
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t2 = linspace(0,2,51);		%Regenerate signal using more data points
y2 = sin(2*pi*t2 + pi/2);	%Sinusoid with period 1 sec shifted by 90 deg
figure(1),plot(t2,y2)		%Make figure window #1 active (rather than open
				%a second figure window) and plot
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
				%Annotate plot in current figure window
title('Sinusoid y2(t) shifted by 90 deg')	%Add title
xlabel('t     (sec)')				%Label x-axis
ylabel('Amplitude')				%label y-axis
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)			%Make figure window #1 active
				%Can put many plots in same figure window
subplot(2,1,1)			%Generate 2x1 figure window, activate plot 1
plot(t1,y1)			%Generate plot 1
title('Sinusoid y1(t) with too few datapoints')	%Add title
xlabel('t     (sec)')				%Label x-axis
ylabel('Amplitude')				%label y-axis
subplot(2,1,2)			%Activate plot 2
plot(t2,y2)			%Generate plot 2
title('Sinusoid y2(t) shifted by 90 deg')	%Add title
xlabel('t     (sec)')				%Label x-axis
ylabel('Amplitude')				%label y-axis
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)			%Make figure window #1 active
plot(t1,y1,'y-',t2,y2,'r--')	%Generate plots using different line styles
title('Sinusoid y1(t) and y2(t)')		%Add title
xlabel('t     (sec)')				%Label x-axis
ylabel('Amplitude')				%label y-axis
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
				%Can customize figure further
text(0.4,0.8,'y1(t)')		%Label curve for y1(t)
text(0.15,-0.5,'y2(t)')		%Label curve for y2(t)
axis([0,2,-1.2,1.2])		%Can change range of figure axes
grid on				%Can add a grid...
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grid off			%...and remove it if clutters the plot
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y3 = exp(-4*t2);		%Generate a third signal--decaying exponential
				%Plot new curve without erasing previous plots
hold on, plot(t2,y3,'g:'), hold off
title('Sinusoid y1(t) and y2(t), and Exponential y3(t)')
text(0.6,0.3,'y3(t)')
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
				%To send active figure to printer, simply type
				%  print
print -deps plot1.ps		%Prints active figure to postscript file, can
				%then check it before printing on paper 8-)
keyboard                %To continue, type:    return

pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close(1)			%Close figure window #1
pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
				%Several other useful types of plots
subplot(2,2,1),stem(t2,y3)	%Plots discrete "stems"
title('Discrete Stem Plot: y = exp(-4t)')
subplot(2,2,2),loglog(t2,y3)	%Log scale on both axes
title('Log Scale on Both Axes: y = exp(-4t)')
grid on
subplot(2,2,3),semilogx(t2,y3)	%Log scale on x-axis only
title('Log Scale on x-axis Only: y = exp(-4t)')
grid on
subplot(2,2,4),semilogy(t2,y3)	%Log scale on y-axis only
title('Log Scale on y-axis Only: y = exp(-4t)')
grid on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% NOTE: MAXIMIZE THE FIGURE WINDOW TO IMPROVE VIEW %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pause	  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo off
close(1)
clear



