% memes harmoniques, variation de la phase
%-----------------------------------------

clear all; close all;

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

nh = 10;
N = 1:nh;
f = f0*(2*N-1);
am = 1./f;

% somme de sinus
%---------------
y = zeros(1,length(th));
for k = 1:nh
    z = sin(f(k)*2*pi*th);
    y = y + am(k)*z;   
end

tr = [0 .001 T*.99 T];
yr = [0  1  1 0];
env = envelop(tr,yr,Fe);
y = y.*env;
y1 = .3*y/(max(abs(y)));
sound(y1,Fe)
pause(T+2)
%wavwrite(y1,Fe,'../SONS/213sommesin.wav');

% somme de cosinus
%-----------------
y = zeros(1,length(th));
for k = 1:nh
    z = cos(f(k)*2*pi*th);
    y = y + am(k)*z;   
end

y = y.*env;
% normalisation differente pour avoir a peu
% pres meme norme 2
y2 = .8*y/(max(abs(y)));
sound(y2,Fe)
%wavwrite(y2,Fe,'../SONS/214sommecos.wav');

figure(1);
nech = round(3*Fe/f0);
subplot(2,1,1); plot(y1(Fe:Fe+nech));
subplot(2,1,2); plot(y2(Fe:Fe+nech));
