(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 15881, 505] NotebookOptionsPosition[ 14468, 456] NotebookOutlinePosition[ 14886, 472] CellTagsIndexPosition[ 14843, 469] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Fourier Series and Filter Design", "Title", CellChangeTimes->{{3.4217479401079364`*^9, 3.4217479429048653`*^9}, { 3.453067144234375*^9, 3.453067148609375*^9}}], Cell["\<\ Wavelet Workshop June 2-5, 2009 University of St. Thomas\ \>", "Subtitle", CellChangeTimes->{{3.421426484890625*^9, 3.42142648821875*^9}, { 3.453030366875*^9, 3.4530303721875*^9}}], Cell["\<\ Catherine Beneteau Caroline Haddad David Ruch Patrick Van Fleet\ \>", "Subsubtitle", CellChangeTimes->{{3.42144927371875*^9, 3.42144928703125*^9}}], Cell[CellGroupData[{ Cell["Objective", "Section", CellChangeTimes->{{3.4217479766243973`*^9, 3.421747978296315*^9}}], Cell["\<\ The purpose of this notebook is to introduce you to Fourier series and how to \ use them to design filters for discrete wavelet transforms.\ \>", "Text", CellChangeTimes->{{3.4530671613125*^9, 3.45306717890625*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["DiscreteWavelets", "Section"], Cell[TextData[{ StyleBox["You should run this cell each time you open this notebook!!", FontColor->RGBColor[1, 0, 0]], " It loads the ", StyleBox["Mathematica", FontSlant->"Italic"], " package ", StyleBox["DiscreteWavelets", FontFamily->"Courier"], " for use in subsequent computations." }], "Text"], Cell[BoxData[ RowBox[{"<<", "DiscreteWavelets`DiscreteWavelets`"}]], "Input", CellChangeTimes->{{3.421749074496252*^9, 3.421749074590005*^9}, { 3.453030844328125*^9, 3.453030845421875*^9}, {3.453068001671875*^9, 3.453068002140625*^9}}, FontColor->GrayLevel[0.500008]] }, Open ]], Cell[CellGroupData[{ Cell["Help on DiscreteWavelets", "Section"], Cell[TextData[{ "If you ever need help with ", StyleBox["DiscreteWavelets", FontFamily->"Courier"], ", go to the ", StyleBox["Documentation Center", FontSlant->"Italic"], ", then look at the lower right for a link called ", StyleBox["Installed Add-Ons", FontSlant->"Italic"], ". Click this and then click ", StyleBox["DiscreteWavelets", FontSlant->"Italic"], ". " }], "Text", CellChangeTimes->{{3.421748017312939*^9, 3.4217480658454313`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[" A Partial Fourier Series for the Sawtooth Function", "Section", CellChangeTimes->{{3.4217480856584387`*^9, 3.421748091408586*^9}, { 3.453067187515625*^9, 3.453067230484375*^9}}], Cell["\<\ Here is some code for generating partial Fourier series for the periodically \ extended function f(w) = w.\ \>", "Text", CellChangeTimes->{{3.421748098877527*^9, 3.4217481194249277`*^9}, { 3.45306723459375*^9, 3.453067252015625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Sawtooth", "[", RowBox[{"w_", ",", "n_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"c", ",", "k"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"c", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"-", "2"}], "*", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"-", "1"}], ")"}], "^", "k"}], "/", "k"}]}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"d", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Sin", "[", RowBox[{"k", "*", "w"}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"c", ".", "d"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"\t"}]}], "Input", CellChangeTimes->{{3.421748125471958*^9, 3.42174818355157*^9}, { 3.4217489035856276`*^9, 3.4217489036950045`*^9}, {3.4217490726680803`*^9, 3.4217490727930837`*^9}, {3.453030848203125*^9, 3.45303084896875*^9}, { 3.453067261453125*^9, 3.453067280140625*^9}, {3.453067320484375*^9, 3.453067402921875*^9}, {3.453068004390625*^9, 3.45306800453125*^9}}], Cell["Plot the series for various values of n", "Text", CellChangeTimes->{{3.4530674115*^9, 3.4530674194375*^9}}], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Sawtooth", "[", RowBox[{"w", ",", "10"}], "]"}], ",", RowBox[{"{", RowBox[{"w", ",", RowBox[{"-", "Pi"}], ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Brown"}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.453067357015625*^9, 3.45306736890625*^9}, { 3.453067451671875*^9, 3.45306745928125*^9}, {3.453068006203125*^9, 3.4530680063125*^9}}], Cell[TextData[{ "Use the ", StyleBox["Manipulate", FontWeight->"Bold"], " command to animate the series." }], "Text", CellChangeTimes->{{3.42174818494223*^9, 3.421748239146743*^9}, { 3.45303038496875*^9, 3.453030385125*^9}, {3.453067430296875*^9, 3.453067440984375*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Sawtooth", "[", RowBox[{"w", ",", "n"}], "]"}], ",", "w", ","}], "}"}], ",", RowBox[{"{", RowBox[{"w", ",", RowBox[{"-", "Pi"}], ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Thick", ",", "Orange"}], "}"}], ",", RowBox[{"{", "Black", "}"}]}], "}"}]}], ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"-", "3.5"}], ",", "3.5"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "Pi"}], ",", RowBox[{ RowBox[{"-", "Pi"}], "/", "2"}], ",", RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3"}], ",", RowBox[{"-", "2"}], ",", RowBox[{"-", "1"}], ",", "1", ",", "2", ",", "3"}], "}"}]}], "}"}]}]}], "]"}], ",", RowBox[{"{", RowBox[{"n", ",", "1", ",", "100"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.4217482055365076`*^9, 3.421748258475363*^9}, { 3.421748904804408*^9, 3.421748904945037*^9}, {3.4217490716211786`*^9, 3.421749071746182*^9}, {3.453030391296875*^9, 3.45303043871875*^9}, { 3.4530308516875*^9, 3.45303085234375*^9}, {3.45306744609375*^9, 3.45306767728125*^9}, {3.453068007359375*^9, 3.453068007484375*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Verifying the Theorem from the Lecture", "Section", CellChangeTimes->{{3.421748276100814*^9, 3.421748281772834*^9}, { 3.453067698171875*^9, 3.4530677245*^9}}], Cell[TextData[{ "We use the DiscreteWavelets commands ", StyleBox["Haar[ ]", FontWeight->"Bold"], " and ", StyleBox["FiniteFourier", FontWeight->"Bold"], " to create the Fourier series H (w)." }], "Text", CellChangeTimes->{{3.45306772659375*^9, 3.453067757421875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"H", "[", "w_", "]"}], ":=", RowBox[{"FiniteFourier", "[", RowBox[{"w", ",", RowBox[{"Haar", "[", "]"}], ",", "0"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"H", "[", "w", "]"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Abs", "[", RowBox[{"H", "[", "w", "]"}], "]"}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Gray"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], RowBox[{"{", RowBox[{"1", ",", RowBox[{"Sqrt", "[", "2", "]"}]}], "}"}]}], "}"}]}]}], "]"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"H", "[", "w", "]"}], "*", RowBox[{"H", "[", RowBox[{"-", "w"}], "]"}]}], "+", RowBox[{ RowBox[{"H", "[", RowBox[{"w", "+", "Pi"}], "]"}], "*", RowBox[{"H", "[", RowBox[{ RowBox[{"-", "w"}], "+", "Pi"}], "]"}]}]}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Brown"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "}"}]}], ",", RowBox[{"AxesOrigin", "\[Rule]", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.421748291179325*^9, 3.4217484861530657`*^9}, { 3.4217489021637154`*^9, 3.421748902304344*^9}, {3.4217490693398705`*^9, 3.421749069480499*^9}, {3.453030465203125*^9, 3.453030476078125*^9}, { 3.453030855234375*^9, 3.453030856234375*^9}, {3.453067773515625*^9, 3.453067867859375*^9}, {3.453068008875*^9, 3.45306800896875*^9}, { 3.453071430546875*^9, 3.4530714638125*^9}, {3.453071499546875*^9, 3.453071499671875*^9}}], Cell["\<\ We can repeat the above computations with any orthogonal Daubechies filter.\ \>", "Text", CellChangeTimes->{{3.453030483078125*^9, 3.453030508015625*^9}, { 3.45306788146875*^9, 3.453067893609375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"H", "[", "w_", "]"}], ":=", RowBox[{"FiniteFourier", "[", RowBox[{"w", ",", RowBox[{"Daub", "[", "4", "]"}], ",", "0"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"H", "[", "w", "]"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Abs", "[", RowBox[{"H", "[", "w", "]"}], "]"}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Gray"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], RowBox[{"{", RowBox[{"1", ",", RowBox[{"Sqrt", "[", "2", "]"}]}], "}"}]}], "}"}]}]}], "]"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"H", "[", "w", "]"}], "*", RowBox[{"H", "[", RowBox[{"-", "w"}], "]"}]}], "+", RowBox[{ RowBox[{"H", "[", RowBox[{"w", "+", "Pi"}], "]"}], "*", RowBox[{"H", "[", RowBox[{ RowBox[{"-", "w"}], "+", "Pi"}], "]"}]}]}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Brown"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "}"}]}], ",", RowBox[{"AxesOrigin", "\[Rule]", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.421748291179325*^9, 3.4217484861530657`*^9}, { 3.4217489021637154`*^9, 3.421748902304344*^9}, {3.4217490693398705`*^9, 3.421749069480499*^9}, 3.453030465203125*^9, {3.453030858453125*^9, 3.45303085909375*^9}, {3.453067904328125*^9, 3.453067909046875*^9}, { 3.4530680099375*^9, 3.453068010015625*^9}, {3.453071479484375*^9, 3.45307149865625*^9}}], Cell["We can also verify the Theorem for the highpass filter.", "Text", CellChangeTimes->{{3.421748489090641*^9, 3.42174849782524*^9}, { 3.453067915796875*^9, 3.45306792490625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"G", "[", "w_", "]"}], ":=", RowBox[{"FiniteFourier", "[", RowBox[{"w", ",", RowBox[{ RowBox[{"Reverse", "[", RowBox[{"Daub", "[", "4", "]"}], "]"}], "*", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"-", "1"}], ")"}], "^", "k"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "3"}], "}"}]}], "]"}]}], ",", "0"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"G", "[", "w", "]"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Abs", "[", RowBox[{"G", "[", "w", "]"}], "]"}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Gray"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], RowBox[{"{", RowBox[{"1", ",", RowBox[{"Sqrt", "[", "2", "]"}]}], "}"}]}], "}"}]}]}], "]"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"G", "[", "w", "]"}], "*", RowBox[{"G", "[", RowBox[{"-", "w"}], "]"}]}], "+", RowBox[{ RowBox[{"G", "[", RowBox[{"w", "+", "Pi"}], "]"}], "*", RowBox[{"G", "[", RowBox[{ RowBox[{"-", "w"}], "+", "Pi"}], "]"}]}]}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", "Brown"}], "}"}]}], ",", RowBox[{"Ticks", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "}"}]}], ",", RowBox[{"AxesOrigin", "\[Rule]", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.453067930984375*^9, 3.453067964484375*^9}, { 3.45306801125*^9, 3.453068011375*^9}, {3.45307148425*^9, 3.453071497015625*^9}}] }, Open ]] }, Open ]] }, WindowSize->{1272, 683}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (April 20, 2007)", StyleDefinitions->FrontEnd`FileName[{"Creative"}, "NaturalColor.nb", CharacterEncoding -> "WindowsANSI"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 168, 2, 73, "Title"], Cell[761, 27, 193, 6, 96, "Subtitle"], Cell[957, 35, 158, 6, 89, "Subsubtitle"], Cell[CellGroupData[{ Cell[1140, 45, 96, 1, 75, "Section"], Cell[1239, 48, 226, 4, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[1502, 57, 35, 0, 75, "Section"], Cell[1540, 59, 312, 10, 29, "Text"], Cell[1855, 71, 275, 5, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2167, 81, 43, 0, 75, "Section"], Cell[2213, 83, 461, 15, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2711, 103, 187, 2, 75, "Section"], Cell[2901, 107, 246, 5, 29, "Text"], Cell[3150, 114, 1439, 38, 142, "Input"], Cell[4592, 154, 114, 1, 29, "Text"], Cell[4709, 157, 491, 13, 41, "Input"], Cell[5203, 172, 281, 8, 29, "Text"], Cell[5487, 182, 1594, 43, 62, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7118, 230, 167, 2, 75, "Section"], Cell[7288, 234, 278, 9, 29, "Text"], Cell[7569, 245, 2177, 63, 102, "Input"], Cell[9749, 310, 213, 4, 29, "Text"], Cell[9965, 316, 2116, 62, 102, "Input"], Cell[12084, 380, 184, 2, 29, "Text"], Cell[12271, 384, 2169, 68, 102, "Input"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)