clear all
close all

tplot = linspace(0,.01,4000);
n = length(tplot);
tsound = (0:n-1)/8192;      % Time for entire signal
f = 220.0;

figure
puresine = @(f,t) sin(2*pi*f*t);
plot(tplot,puresine(f,tplot),'r','LineWidth',2)
ylim([-1.5,1.5])
title('Pure sine wave')
sound(puresine(f,tsound))
pause

figure
f1 = 2*f;
plot(tplot,puresine(f1,tplot),'r','LineWidth',2)
ylim([-1.5,1.5])
title('Pure sine wave one octave higher')
sound(puresine(f1,tsound))
pause

figure
f1 = 2*f;
f2 = 3*f;
f3 = 4*f;
foursine = @(f1,f2,f3,f4,t) sin(2*pi*f1*t)/2 + sin(2*pi*f2*t)/4 + sin(2*pi*f3*t)/6 + sin(2*pi*f4*t)/4;
plot(tplot,foursine(f,f1,f2,f3,tplot),'r','LineWidth',2)
ylim([-1.5,1.5])
title('Sine wave with next 3 harmonics')
sound(foursine(f,f1,f2,f3,tsound))
pause

figure
f1 = 3*f;
f2 = 5*f;
f3 = 7*f;
foursine = @(f1,f2,f3,f4,t) sin(2*pi*f1*t)/2 + sin(2*pi*f2*t)/4 + sin(2*pi*f3*t)/4 + sin(2*pi*f4*t)/8;
plot(tplot,foursine(f,f1,f2,f3,tplot),'r','LineWidth',2)
ylim([-1.5,1.5])
title('Sine wave with next 3 odd harmonics')
sound(foursine(f,f1,f2,f3,tsound))
pause

