% ajout des harmoniques 1,2,3,4 ou 1,3,5,7
%-------------------------------------------

clear all; close all;

Fe = 22050; h = 1/Fe;
f0 = 330; T =  1.6;
th = 0:h:T;

silence = 0*(0:h:.3);

% creation d'une enveloppe 
tr = T*[0 .02 .98 1];
yr = [0 1 1 0];
env = envelop(tr,yr,Fe);

% ajout des harmoniques 1,2,3,...,N
%----------------------------------
% x est le signal a ecouter, s est pour le visualiser
N = 8;
x = sin(2*pi*f0*th).*env; 
s = x;
figure(1);
nech = round(3*(Fe/f0));
subplot(N,1,1); plot(s(Fe/2+1:Fe/2+nech));
for k = 2:N
    z = sin(2*pi*k*f0*th).*env/k;
    s = s + z; 
    subplot(N,1,k); plot(s(Fe/2+1:Fe/2+nech));
    x = [x silence s]; 
end
x = .98*x/(max(abs(x)));
sound(x,Fe);
%wavwrite(x,Fe,'../SONS/103ajoutharm.wav');
pause(2*k)

% ajout des harmoniques 1,3,5,...,N
%----------------------------------
N = 11;
x = sin(2*pi*f0*th).*env; 
s = x;
figure(2);
j = 1;
subplot(4,1,1); plot(s(Fe/2+1:Fe/2+nech));
for k = 3:2:N
    z = sin(2*pi*k*f0*th).*env/k;
    s = s + z; 
    j = j+1;
    subplot((N+1)/2,1,j); plot(s(Fe/2+1:Fe/2+nech));
    x = [x silence s]; 
end
x = .98*x/(max(abs(x)));
sound(x,Fe);
%wavwrite(x,Fe,'../SONS/104ajoutharm.wav');
