(*This document contains a number of Mathematica examples for Tuesday, Feb. 19's lecture.*)
(*This first example illustrates part of the relation between sine waves in sound.  It should correspond to a B-flat-4, i.e. the B-flat that's about in the middle of the treble clef, if I'm not mistaken.*)
Play[Evaluate[Sin[(466)*2*Pi*t]], {t,.5,2.5}]

Plot[Sin[(466)*2*Pi*t], {t, 0, 2/233}, ImageSize->600]

(*Something you might have noticed about the above sound is that it doesn't sound a lot like a musical instrument!  This is because musical instruments have things called overtones: i.e. when they play a note, they also create sounds that correspond to a number of octaves above that note.  For example, if you record a clarinet playing B-flat-3, you can see that it (in addition to producing the sine wave corresponding to B-flat-3) produces sine waves corresponding to B-flat-4, B-flat-5, B-flat-6, and so on/so forth, all scaled by appropriate constants.  Mathematically, this means that a clarinet playing B-flat-3 isn't just playing Sin((233)*2*pi*t), but instead a series of the form
Sum[coefficients * Sin[233 * 2 * Pi * n * t], {n, 1, infinity}].  In practice, the eight-term series below is a decent approximation to the sounds most clarinets make: listen to it and see if you're persuaded!*)
Play[Evaluate[Sin[(233)*2*Pi*t] +  
.08*Sin[(233)*2*2*Pi*t] +
.82*Sin[(233)*3*2*Pi*t] +
.07*Sin[(233)*4*2*Pi*t] +
.29*Sin[(233)*5*2*Pi*t] +
.35*Sin[(233)*6*2*Pi*t] +
.06*Sin[(233)*7*2*Pi*t] +
.10*Sin[(233)*8*2*Pi*t] ], {t,.5,2.5}]

Plot[Sin[(233)*2*Pi*t] +  
.08*Sin[(233)*2*2*Pi*t] +
.82*Sin[(233)*3*2*Pi*t] +
.07*Sin[(233)*4*2*Pi*t] +
.29*Sin[(233)*5*2*Pi*t] +
.35*Sin[(233)*6*2*Pi*t] +
.06*Sin[(233)*7*2*Pi*t] +
.10*Sin[(233)*8*2*Pi*t], {t, 0, 2/233}, ImageSize->600]

(*In class, we discussed how to turn a function f(x) into a Fourier series, using the example of a sawtooth wave.  We illustrate both the sawtooth wave and its approximations by a Fourier series here, providing both sound files (so you can hear our approximation) and an animation that illustrates what increasing approximations of the sawtooth wave look like.*)
Play[Evaluate[SawtoothWave[{-1,1},400*t]],{t,.5,2.5}]

Plot[SawtoothWave[{-1,1},x], {x, 0, 5}, ImageSize->600]

Play[Evaluate[Sum[((2*(-1)^(n+1))/n)*Sin[400*2*Pi*n*t],{n,1,500}]],{t,.5,2.5}]

Animate[Plot[Sum[((2*(-1)^(n+1))/(Pi*n))*Sin[2*Pi*n*t],{n,1,k}], {t, 0, 5}, ImageSize->1200, PerformanceGoal->"Quality",PlotRange->{-1.5,1.5}],{k,0,100,1}, AnimationRate->20, AnimationRepetitions->1,AnimationRunning->False]