f=220;
w=2Pi*f;
p[t_]:=Sin[w t];
Plot[p[t],{t,0,0.01}]
Export["~/Documents/teaching/Fis-2-FCM0102/220Hz.wav",Play[p[t],{t,0,2}]]

f=220;
w=2Pi*f;
p[t_]:=Sin[w t] - 0.3*Sin[2*w t];
Plot[p[t],{t,0,0.01}]
Export["~/Documents/teaching/Fis-2-FCM0102/220-440Hz.wav",Play[p[t],{t,0,2}]]

f=220;
w=2Pi*f;
p[t_]:=Sin[w t] - 0.1*Sin[2*w t] + 0.6*Sin[3*w t];
Plot[p[t],{t,0,0.01}]
Export["~/Documents/teaching/Fis-2-FCM0102/220-440-660Hz.wav",Play[p[t],{t,0,2}]]

w=2Pi*440;
dw=2Pi*20;
p[t_]:=Cos[w t] + Cos[(w-dw) t];
Plot[p[t],{t,0,0.01}]
Plot[p[t],{t,0,0.1}]
Export["~/Documents/teaching/Fis-2-FCM0102/440-420.wav",Play[p[t],{t,0,2}]]

f=220;
w=2Pi*f;
p[t_]:=Sin[3*w t];
Plot[p[t],{t,0,0.01}]
Export["~/Documents/teaching/Fis-2-FCM0102/660Hz.wav",Play[p[t],{t,0,2}]]

f=220;
w=2Pi*f;
p[t_]:=Sin[w/2 t];
Plot[2*p[t],{t,0,0.01}]
Export["~/Documents/teaching/Fis-2-FCM0102/110Hz.wav",Play[p[t],{t,0,2}]]

f=40;
w=2Pi*f;
p[t_]:=Sin[w t^2.5];
Plot[p[t],{t,0,2}]
Export["~/Documents/teaching/Fis-2-FCM0102/crazyHz.wav",Play[p[t],{t,0,4}]]

f=80;
w=2Pi*f;
p[t_]:=Sin[w t/Sin[3t]];
Plot[p[t],{t,0,2}]
Export["~/Documents/teaching/Fis-2-FCM0102/crazy2Hz.wav",Play[p[t],{t,0,4}]]

(*Corda*)

H=0.01;
L=0.5;
Nr=100;
an=Table[16H*Sin[n Pi/2](Sin[n Pi/4]/(n Pi))^2,{n,1,Nr}];

v=200;
y[x_,t_,nh_]:=Sum[an[[n]]*Sin[n Pi x/L]*Cos[n Pi v t/L],{n,1,nh}]

Plot[{y[x,0,1],y[x,0,3]-y[x,0,1],y[x,0,5]-y[x,0,3]},{x,0,L},AspectRatio->0.3]

Plot[{y[x,0,1],y[x,0,3],y[x,0,5],y[x,0,91]},{x,0,L},AspectRatio->0.3]

T=2*L/v;
1/T
Animate[Plot[{y[x,t,1],y[x,t,3]-y[x,t,1],y[x,t,5]-y[x,t,3]},{x,0,L},PlotRange->{-H,H},AspectRatio->0.4],{t,0,5T,0.01T},AnimationRunning->False]
Animate[Plot[y[x,t,5],{x,0,L},PlotRange->{-H,H},AspectRatio->0.4],{t,0,5T,0.01T},AnimationRunning->False]

Plot[y[L/2,t,5],{t,0,2T}]

Export["~/Documents/teaching/Fis-2-FCM0102/corda-5harmonic.wav",Play[y[L/2,t,5],{t,0,2}]]

Plot[y[L/2,t,90],{t,0,2T}]

Export["~/Documents/teaching/Fis-2-FCM0102/corda-90harmonic.wav",Play[y[L/2,t,90],{t,0,2}]]

(*Atenuacao*)

t0=1;
Plot[y[L/2,t,10]*Exp[-t/t0],{t,0,800T},PlotRange->{-H,H}]

Export["~/Documents/teaching/Fis-2-FCM0102/corda-10harmonic-atenuado.wav",Play[y[L/2,t,10]*Exp[-t/t0],{t,0,4},PlayRange-> All]]

(*Notas musicais*)

fdo=261.6;
fre=293.7;
fmi=329.6;
ffa=349.2;
fso=392;
fla=440;
fsi=493.9;

freq={261.6,293.7,329.6,349.2,392,440,493.9}

f[t_,tau_,t0_]:=If[t<t0,0,(t-t0)^2*Exp[-((t-t0)/tau)^2]]
nota[t_,tau_,t0_,n_]:=Sin[2*Pi*freq[[n]]*t]*f[t,tau,t0]

Plot[{f[t,1,2],nota[t,1,1,1]},{t,0,10}]

tau=0.25;
t1=0.5;
t2=0.1;
music[t_]:=nota[t,tau,0,1]+nota[t,tau,t1,2]+nota[t,tau,2t1,3]+nota[t,tau,3t1,4]+nota[t,tau,4t1+t2,4]+nota[t,tau,5t1,4]+nota[t,tau,6t1,1]+nota[t,tau,7t1,2]+nota[t,tau,8t1,1]+nota[t,tau,9t1,2]+nota[t,tau,10t1+t2,2]+nota[t,tau,11t1,2]+nota[t,tau,12t1,1]+nota[t,tau,13t1,5]+nota[t,tau,14t1,4]+nota[t,tau,15t1,3]+nota[t,tau,16t1+t2,3]+nota[t,tau,17t1,3]+nota[t,tau,18t1,1]+nota[t,tau,19t1,2]+nota[t,tau,20t1,3]+nota[t,tau,21t1,4]+nota[t,tau,22t1+t2,4]+nota[t,tau,23t1,4]

Plot[music[t],{t,0,24t1+tau}]

Export["~/Documents/teaching/Fis-2-FCM0102/music.wav",Play[music[t],{t,0,24t1+tau},PlayRange-> All]]

w=2Pi*400;
dw=2Pi*10;
p[t_]:=Cos[w t] + Cos[(w+dw) t];
Plot[p[t],{t,0,0.01}]
Plot[p[t],{t,0,0.1}]
Export["~/Documents/teaching/Fis-2-FCM0102/400-410.wav",Play[p[t],{t,0,5}]]

w=2Pi*440;
p[t_]:=Cos[w t] + Cos[w(1+0.1t) t];
Plot[p[t],{t,0,0.01}]
Plot[p[t],{t,0,0.1}]
Export["~/Documents/teaching/Fis-2-FCM0102/400-up-600.wav",Play[p[t],{t,0,5},PlayRange->All]]

w=2Pi*500000;
p[t_]:=Cos[w t] ;
Plot[p[t],{t,0,0.01}]
Plot[p[t],{t,0,0.1}]
Export["~/Documents/teaching/Fis-2-FCM0102/50000.wav",Play[p[t],{t,0,2},PlayRange->All]]