(* 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[ 14389, 479] NotebookOptionsPosition[ 12419, 411] NotebookOutlinePosition[ 12837, 427] CellTagsIndexPosition[ 12794, 424] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Daubechies Filters", "Title", CellChangeTimes->{{3.4217479401079364`*^9, 3.4217479429048653`*^9}}], Cell["\<\ Wavelet Workshop June 4-7, 2008 University of St. Thomas\ \>", "Subtitle", CellChangeTimes->{{3.421426484890625*^9, 3.42142648821875*^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 Daubechies filters and \ see how they can be used in applications.\ \>", "Text"] }, 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}}, 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["Solving for the D4 Filter", "Section", CellChangeTimes->{{3.4217480856584387`*^9, 3.421748091408586*^9}}], Cell["We first set up the orthogonality conditions", "Text", CellChangeTimes->{{3.421748098877527*^9, 3.4217481194249277`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", RowBox[{"h", ",", "h0", ",", "h1", ",", "h2", ",", "h3"}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"h", "=", RowBox[{"{", RowBox[{"h0", ",", "h1", ",", "h2", ",", "h3"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"orth", "=", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"Total", "[", RowBox[{"h", "^", "2"}], "]"}], "\[Equal]", "1"}], ",", RowBox[{ RowBox[{ RowBox[{"h0", "*", "h2"}], "+", RowBox[{"h1", "*", "h3"}]}], "\[Equal]", "0"}]}], "}"}]}]}], "Input", CellChangeTimes->{{3.421748125471958*^9, 3.42174818355157*^9}, { 3.4217489035856276`*^9, 3.4217489036950045`*^9}, {3.4217490726680803`*^9, 3.4217490727930837`*^9}}], Cell["\<\ Next the lowpass conditions - we do this with a Fourier series! The last \ argument of FiniteFourier is the starting index for the series.\ \>", "Text", CellChangeTimes->{{3.42174818494223*^9, 3.421748239146743*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"H", "[", "w_", "]"}], ":=", RowBox[{ StyleBox["FiniteFourier", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"w", ",", "h", ",", "0"}], "]"}]}], ";"}], " "}], "\[IndentingNewLine]", RowBox[{"lowpass", "=", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"H", "[", "0", "]"}], "\[Equal]", RowBox[{"Sqrt", "[", "2", "]"}]}], ",", RowBox[{ RowBox[{"H", "[", "Pi", "]"}], "\[Equal]", "0"}], ",", RowBox[{ RowBox[{ RowBox[{"H", "'"}], "[", "Pi", "]"}], "\[Equal]", "0"}]}], "}"}]}]}], "Input", CellChangeTimes->{{3.4217482055365076`*^9, 3.421748258475363*^9}, { 3.421748904804408*^9, 3.421748904945037*^9}, {3.4217490716211786`*^9, 3.421749071746182*^9}}], Cell["Now we solve the system", "Text", CellChangeTimes->{{3.421748276100814*^9, 3.421748281772834*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"eqs", "=", RowBox[{"Join", "[", RowBox[{"orth", ",", "lowpass"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"s", "=", RowBox[{"Solve", "[", RowBox[{"eqs", ",", "h"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"Length", "[", "s", "]"}], ",", "\"\< solutions.\>\""}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"sln1", "=", RowBox[{"h", "/.", RowBox[{"s", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"sln2", "=", RowBox[{"h", "/.", RowBox[{"s", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"TableForm", "[", "sln1", "]"}], ",", "\"\<.\\n\>\""}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"TableForm", "[", "sln2", "]"}], ",", "\"\<.\>\""}], "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", "\"\\"", "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"TableForm", "[", RowBox[{"N", "[", "sln1", "]"}], "]"}], ",", "\"\<.\\n\>\""}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"TableForm", "[", RowBox[{"N", "[", "sln2", "]"}], "]"}], ",", "\"\<.\>\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.421748291179325*^9, 3.4217484861530657`*^9}, { 3.4217489021637154`*^9, 3.421748902304344*^9}, {3.4217490693398705`*^9, 3.421749069480499*^9}}], Cell["Note that the second solution is a reflection of the first.", "Text", CellChangeTimes->{{3.421748489090641*^9, 3.42174849782524*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["The Fourier Series Associated with the Daub4 Filter.", "Section", CellChangeTimes->{{3.4217485035910125`*^9, 3.42174851521631*^9}}], Cell["Here is the Fourier series for the D4 filter.", "Text", CellChangeTimes->{{3.4217485239040327`*^9, 3.4217485290135384`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"H4", "[", "w_", "]"}], ":=", RowBox[{ StyleBox["FiniteFourier", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"w", ",", "sln2", ",", "0"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"H2", "[", "w_", "]"}], ":=", RowBox[{ StyleBox["FiniteFourier", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"w", ",", RowBox[{"Haar", "[", "]"}], ",", "0"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Abs", "[", RowBox[{"H4", "[", "w", "]"}], "]"}], ",", RowBox[{"Abs", "[", RowBox[{"H2", "[", "w", "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Red", ",", "Blue"}], "}"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.4217485360293427`*^9, 3.4217485967965236`*^9}, 3.421748634422487*^9, {3.421748900069912*^9, 3.4217489001636643`*^9}, { 3.421749067324194*^9, 3.421749067449197*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["The Highpass Filter", "Section", CellChangeTimes->{{3.42174876719151*^9, 3.4217487693634415`*^9}}], Cell["\<\ We obtain the highpass filter by reversing the solution and multiplying each \ coefficient alternately by 1 and - 1.\ \>", "Text", CellChangeTimes->{{3.421748777098014*^9, 3.421748813177063*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"hp", "=", RowBox[{"sln2", "*", RowBox[{"{", RowBox[{"1", ",", RowBox[{"-", "1"}], ",", "1", ",", RowBox[{"-", "1"}]}], "}"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"G", "[", "w_", "]"}], ":=", RowBox[{ StyleBox["FiniteFourier", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"w", ",", "hp", ",", "0"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Abs", "[", RowBox[{"G", "[", "w", "]"}], "]"}], ",", RowBox[{"{", RowBox[{"w", ",", "0", ",", "Pi"}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.421748818786581*^9, 3.4217488986948767`*^9}, { 3.421749065777279*^9, 3.4217490659491587`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["The Wavelet Matrix", "Section", CellChangeTimes->{{3.421748660438778*^9, 3.4217486630169687`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"n", "=", "8"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"g", "=", RowBox[{"{", RowBox[{"g0", ",", "g1", ",", "g2", ",", "g3"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r1", "=", RowBox[{"Join", "[", RowBox[{"h", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "-", "4"}], "}"}]}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"top", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"r1", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", RowBox[{ RowBox[{"n", "/", "2"}], "-", "1"}]}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r2", "=", RowBox[{"Join", "[", RowBox[{"g", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "-", "4"}], "}"}]}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"bot", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"r2", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", RowBox[{ RowBox[{"n", "/", "2"}], "-", "1"}]}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"W", "=", RowBox[{"Join", "[", RowBox[{"top", ",", "bot"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", "W", "]"}]}], "Input", CellChangeTimes->{{3.4217486744235106`*^9, 3.421748763066405*^9}, { 3.421748896147937*^9, 3.4217488965229464`*^9}, {3.4217490393547277`*^9, 3.421749064011609*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Daubechies Filters in DiscreteWavelets", "Section", CellChangeTimes->{{3.4217489075076027`*^9, 3.4217489150859213`*^9}}], Cell[TextData[{ "We can generate Daubechies filters in DiscreteWavelets using the ", StyleBox["Daub", FontColor->RGBColor[1, 0, 0]], " command." }], "Text", CellChangeTimes->{{3.421748919429783*^9, 3.421748933633271*^9}}], Cell[BoxData[ RowBox[{"Daub", "[", "2", "]"}]], "Input", CellChangeTimes->{{3.4217489493367987`*^9, 3.4217489510712175`*^9}}], Cell[BoxData[ RowBox[{"Daub", "[", "4", "]"}]], "Input", CellChangeTimes->{{3.421748953165021*^9, 3.4217489539150405`*^9}}], Cell[BoxData[ RowBox[{"Daub", "[", "6", "]"}]], "Input", CellChangeTimes->{{3.4217489573526287`*^9, 3.4217489590245466`*^9}}], Cell[BoxData[ RowBox[{"Daub", "[", "12", "]"}]], "Input", CellChangeTimes->{{3.4217489615089846`*^9, 3.4217489635715375`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Exercise", "Section", CellChangeTimes->{{3.421748966024726*^9, 3.421748967524764*^9}}], Cell["Can you write code to find the D6 filter?", "Text", CellChangeTimes->{{3.4217489728530254`*^9, 3.4217489812282395`*^9}}], Cell[BoxData[ RowBox[{"(*", " ", RowBox[{"Put", " ", "code", " ", "here"}], " ", "*)"}]], "Input", CellChangeTimes->{{3.42174898672838*^9, 3.421748990009714*^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, 105, 1, 73, "Title"], Cell[698, 26, 149, 5, 96, "Subtitle"], Cell[850, 33, 158, 6, 89, "Subsubtitle"], Cell[CellGroupData[{ Cell[1033, 43, 96, 1, 75, "Section"], Cell[1132, 46, 142, 3, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[1311, 54, 35, 0, 75, "Section"], Cell[1349, 56, 312, 10, 29, "Text"], Cell[1664, 68, 177, 3, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[1878, 76, 43, 0, 75, "Section"], Cell[1924, 78, 461, 15, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2422, 98, 112, 1, 75, "Section"], Cell[2537, 101, 128, 1, 29, "Text"], Cell[2668, 104, 764, 22, 82, "Input"], Cell[3435, 128, 228, 4, 29, "Text"], Cell[3666, 134, 785, 24, 62, "Input"], Cell[4454, 160, 105, 1, 29, "Text"], Cell[4562, 163, 1890, 51, 242, "Input"], Cell[6455, 216, 140, 1, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[6632, 222, 138, 1, 75, "Section"], Cell[6773, 225, 131, 1, 29, "Text"], Cell[6907, 228, 1111, 33, 82, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8055, 266, 105, 1, 75, "Section"], Cell[8163, 269, 207, 4, 29, "Text"], Cell[8373, 275, 762, 23, 82, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[9172, 303, 105, 1, 75, "Section"], Cell[9280, 306, 1768, 57, 182, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11085, 368, 127, 1, 75, "Section"], Cell[11215, 371, 227, 6, 29, "Text"], Cell[11445, 379, 127, 2, 41, "Input"], Cell[11575, 383, 125, 2, 41, "Input"], Cell[11703, 387, 127, 2, 41, "Input"], Cell[11833, 391, 128, 2, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11998, 398, 93, 1, 75, "Section"], Cell[12094, 401, 127, 1, 29, "Text"], Cell[12224, 404, 167, 3, 41, "Input"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)