format compact

Fs = 8000;		% Sample everything at 8000 Hz
Fo = 660;		% Use 660 Hz as the fundamental freq of each waveform
T_total = 1.2;		% Compute a total of 1.2 seconds so the sound can be played
tt = 0:(1/Fs):T_total;	% Set up the time axis

% =====  First the cosine  =====
y1 = cos(2*pi*Fo*tt);
range = 801:880;	% Only plot a part of the signal

subplot('Position',[0.1 0.8 0.8 0.15])
plot(tt(range),y1(range))
	xlabel('TIME (sec)')
 	title(['SINE WAVE at ',num2str(Fo),' Hz'])
sound(y1, Fs)

% =====  Square wave  =====
y2 = 0.9*square(2*pi*Fo*tt);

subplot('Position',[0.1 0.55 0.8 0.15])
plot(tt(range),y2(range))
	xlabel('TIME (sec)')
	title(['SQUARE WAVE at ',num2str(Fo),' Hz'])
sound(y2, Fs)

% =====  Sawtooth  =====
y3 = 0.9*sawtooth(2*pi*Fo*tt);

subplot('Position',[0.1 0.30 0.8 0.15])
plot(tt(range),y3(range))
	xlabel('TIME (sec)')
	title(['SAWTOOTH WAVE at ',num2str(Fo),' Hz'])
sound(y3,Fs)

% ======  Beats  =====
Fm = 12;
y4 = sin(2*pi*Fm*tt).*cos(2*pi*Fo*tt);

beatRange = 801:1600;

subplot('Position',[0.1 0.05 0.8 0.15])
plot(tt(beatRange),y4(beatRange))
	xlabel('TIME (sec)')
	title(['BEATS: Fo = ',num2str(Fo),' Hz,  Fm = ', num2str(Fm),' Hz'])
sound(y4,Fs)