(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 7480, 239]*) (*NotebookOutlinePosition[ 8384, 270]*) (* CellTagsIndexPosition[ 8340, 266]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Fourier Series and Music", "Title", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ H. Edward Donley April 30, 1994\ \>", "Subtitle", ImageRegion->{{0, 1}, {0, 1}}] }, Closed]], Cell[CellGroupData[{ Cell["Fourier Series", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[BoxData[{ \(Clear[f, x]\), "\[IndentingNewLine]", \(f[x_] = 2. \ \[Pi]\ \((\(x - \[Pi]\)\/\(2. \ \[Pi]\) - Floor[\(x - \[Pi]\)\/\(2. \ \[Pi]\)])\)\)}], "Input"], Cell["Plot[f[x], {x,-4\[Pi],4\[Pi]}];", "Input", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Notice that there are many barriers to convergence if we were to approximate \ this function with a Taylor series. But f[x] is periodic with period 2\[Pi]. \ So let's approximate it with a series of sine and cosine functions.\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["Needs[\"Calculus`FourierTransform`\"]", "Input", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Here is an expansion with respect to a constant term, Cos[x], Sin[x], \ Cos[2x], Sin[2x], Cos[3x], and Sin[3x].\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell[BoxData[ \(fourierApprox[x_] = NFourierTrigSeries[f[x], x, 3, FourierParameters \[Rule] {1, 1\/\(2 \[Pi]\)}]\)], "Input"], Cell["\<\ and here is a graph of the original function and its Fourier series \ approximation.\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell[BoxData[ \(\(Plot[{f[x], fourierApprox[x]}, {x, \(-2\) \[Pi], 2 \[Pi]}, PlotStyle \[Rule] {{Thickness[0.01]}, {RGBColor[1, 0, 0]}}];\)\)], "Input"], Cell["\<\ The approximation was not blocked by the jumps in the function. It rode the \ jump and went right on approximating the next piece of f[x] !\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ We can add more terms to get a better approximation. Let's go out to Cos[8x] \ and Sin[8x].\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell[BoxData[ \(fourierApprox[x_] = NFourierTrigSeries[f[x], x, 8, FourierParameters \[Rule] {1, 1\/\(2 \[Pi]\)}]\)], "Input"], Cell[BoxData[ \(\(Plot[{f[x], fourierApprox[x]}, {x, \(-2\) \[Pi], 2 \[Pi]}, PlotStyle \[Rule] {{Thickness[0.01]}, {RGBColor[1, 0, 0]}}];\)\)], "Input"], Cell["\<\ The approximation gets better. Reminds you a bit of power series, doesn't \ it?\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Closed]], Cell[CellGroupData[{ Cell["Synthesizing Music", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ The terms in the Fourier series can be thought of as tones in a sound. The \ value of n in Sin[n x] determines the frequency of the tone and the \ coefficient of Sin[n x] is the amplitude of the tone. All of the component \ tones are added together to make a sound. The following function is composed \ of two tones, one at 440 Hertz and the other at 660 Hertz. The first tone is \ three times as loud as the second.\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Clear[f,t] f[t_] = 3 Sin[440 \[Pi] t] + Sin[660 2\[Pi] t];\ \>", "Input", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ You may be able to hear both tones if you listen to the sound. Double-click \ on the sound graph below. You can stop the playing the sound by clicking \ anywhere outside the graph.\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["Play[f[t], {t,0,1}];", "Input", ImageRegion->{{0, 1}, {0, 1}}] }, Closed]], Cell[CellGroupData[{ Cell["Analyzing Musical Notes", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Fourier analysis means to take a wave and determine its component frequencies \ and amplitudes. Fourier synthesis is just the opposite--take a set of \ frequencies and amplitudes and add them together to get a composite wave. If \ you are into electronic music, then you have already heard of synthesizers.\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ The Fourier transform does the Fourier analysis very nicely. It picks out \ the frequencies and amplitudes from a sound wave. \ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Clear[f,t] f[t_] = 3 Sin[440 2\[Pi] t] + Sin[660 2\[Pi] t]; data = Table[N[f[n/1024]], {n,1,1024}];\ \>", "Input", ImageRegion->{{0, 1}, {0, 1}}], Cell["fourierData = Abs[Fourier[data]];", "Input", ImageRegion->{{0, 1}, {0, 1}}], Cell[BoxData[ \(\(ListPlot[fourierData, PlotJoined \[Rule] True, PlotRange \[Rule] All];\)\)], "Input"], Cell["\<\ Notice that there are peaks at 440 and at 660 and that the peak at 660 is \ three times as tall as the peak at 440. (There are also peaks at 1024 - 440 \ and at 1024 - 660, but ignore these--they are an artifact of the Fourier \ algorithm.)\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ We will do the Fourier analysis as a group, since we have only one analyzer \ on the computer at the front of the room. If you reach this point before the \ rest of the class, then try adding some sine waves together. Find \ combinations that sound good and combinations that sound terrible. You are \ being a synthesizer. Your mission is to irritate the person sitting next to \ you!\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "If you want to use ", StyleBox["Mathematica", FontSlant->"Italic"], " to further explore music synthesis, you ought to look at the package, \ Miscellaneous", StyleBox["`", FontFamily->"New York"], "Audio", StyleBox["`", FontFamily->"New York"], ". The Guide to Standard ", StyleBox["Mathematica", FontSlant->"Italic"], " Packages briefly describes each of the functions in this package and \ gives some examples." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Closed]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1920}, {0, 1127}}, WindowToolbars->{}, CellGrouping->Manual, WindowSize->{1084, 1099}, WindowMargins->{{73, Automatic}, {Automatic, 0}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, StyleDefinitions -> "Default.nb" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 74, 1, 115, "Title"], Cell[1816, 54, 92, 4, 93, "Subtitle"] }, Closed]], Cell[CellGroupData[{ Cell[1945, 63, 66, 1, 39, "Section"], Cell[2014, 66, 194, 4, 61, "Input"], Cell[2211, 72, 81, 1, 30, "Input"], Cell[2295, 75, 284, 5, 33, "Text"], Cell[2582, 82, 87, 1, 30, "Input"], Cell[2672, 85, 168, 4, 33, "Text"], Cell[2843, 91, 147, 3, 42, "Input"], Cell[2993, 96, 141, 4, 33, "Text"], Cell[3137, 102, 183, 3, 30, "Input"], Cell[3323, 107, 197, 4, 33, "Text"], Cell[3523, 113, 149, 4, 33, "Text"], Cell[3675, 119, 147, 3, 42, "Input"], Cell[3825, 124, 183, 3, 30, "Input"], Cell[4011, 129, 137, 4, 33, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[4185, 138, 70, 1, 39, "Section"], Cell[4258, 141, 477, 8, 52, "Text"], Cell[4738, 151, 116, 4, 48, "Input"], Cell[4857, 157, 239, 5, 33, "Text"], Cell[5099, 164, 70, 1, 30, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[5206, 170, 75, 1, 39, "Section"], Cell[5284, 173, 365, 6, 52, "Text"], Cell[5652, 181, 185, 4, 33, "Text"], Cell[5840, 187, 157, 5, 66, "Input"], Cell[6000, 194, 83, 1, 30, "Input"], Cell[6086, 197, 116, 2, 30, "Input"], Cell[6205, 201, 298, 6, 52, "Text"], Cell[6506, 209, 445, 8, 52, "Text"], Cell[6954, 219, 510, 17, 52, "Text"] }, Closed]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)