% son (presque) periodique (approx trompette)
%--------------------------------------------

clear all; close all;

Fe = 22050; h = 1/Fe;
f0 = 440; T =  3;
th = 0:h:T;

am = [450 820 650 250 100 40 30 20 10];
N = length(am); harm = 1:N;
fr = harm*f0;

% ajout des harmoniques
y = zeros(1,length(th));
for k = harm
    % avec enveloppe harmonique variable
    tr = T*[0 .05*k^2/7 1-.05*k/4 1];
    yr = [0 1 .8 0];
    env = envelop(tr,yr,Fe);
    z = cos(2*pi*fr(k)*th).*env;
    y = y + am(k)*z;
end

% scaling, graphique et son
y = .98*y/(max(abs(y)));
tfen = Fe/2+1:Fe/2+6*round(Fe/f0);
plot(th(tfen),y(tfen));
sound(y,Fe);
%wavwrite(y,Fe,'../SONS/102sonperiod.wav');
