(* 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[ 34345, 1073] NotebookOptionsPosition[ 31509, 981] NotebookOutlinePosition[ 31927, 997] CellTagsIndexPosition[ 31884, 994] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Haar Transform 1D", "Title"], Cell["\<\ Wavelet Workshop June 2-5, 2009 University of South Florida\ \>", "Subtitle", CellChangeTimes->{{3.421426484890625*^9, 3.42142648821875*^9}, { 3.4528156820625*^9, 3.45281569046875*^9}}], Cell["\<\ Catherine Beneteau Caroline Haddad David Ruch Patrick Van Fleet\ \>", "Subsubtitle", CellChangeTimes->{{3.42144927371875*^9, 3.42144928703125*^9}}], Cell[CellGroupData[{ Cell["Objective", "Section"], Cell["\<\ In this notebook, we will explore the one-dimensional discrete Haar wavelet \ transform.\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Conventions", "Section"], Cell[TextData[{ "This notebook uses the package ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " (written by Patrick Van Fleet). All commands from the ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " library will be denoted in ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], ". Help is available for every command in ", StyleBox["the package", FontColor->GrayLevel[0]], ". Click on Help and then Documentation Center. At the bottom-right of the \ page is a link for Installed AddOns. Click this link and one of the options \ is DiscreteWavelets. Click this link to go to the Help Browser. Like all ", StyleBox["Mathematica", FontSlant->"Italic"], " help screens, the help is \"live\" - you can either execute the commands \ in the help to see the effects of the command or cut and paste them into your \ own notebook.\n\nComments are useful within cells of code. Any code enclosed \ by (* *) is a comment and ignored by the ", StyleBox["Mathematica", FontSlant->"Italic"], " kernel." }], "Text", CellChangeTimes->{{3.4085631561875*^9, 3.408563201375*^9}, { 3.4085632433125*^9, 3.408563315796875*^9}, {3.40856339940625*^9, 3.4085634034375*^9}, {3.408565167890625*^9, 3.40856516825*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Load DiscreteWavelets", "Section", CellChangeTimes->{3.408563584328125*^9}], Cell[BoxData[ RowBox[{"<<", "DiscreteWavelets`DiscreteWavelets`"}]], "Input", CellChangeTimes->{{3.408563455078125*^9, 3.408563467234375*^9}, { 3.408565207546875*^9, 3.40856520834375*^9}, {3.40856604671875*^9, 3.408566047*^9}, {3.4216017085341864`*^9, 3.421601708877948*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["One-Dimensional Discrete Haar Transform Module", "Section"], Cell["\<\ In the cell below, write a module that creates one iteration of the discrete \ Haar wavelet transformation. \ \>", "Text", CellChangeTimes->{{3.4216012112995253`*^9, 3.4216012380816326`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"MyHWT1D1", "[", "x_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"(*", " ", RowBox[{"Put", " ", "local", " ", "variables", " ", "here"}], " ", "*)"}], "}"}], ","}], "\[IndentingNewLine]", "\t", RowBox[{"(*", " ", RowBox[{"Put", " ", "commands", " ", "here"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.40856368753125*^9, 3.408563689078125*^9}, { 3.408563744203125*^9, 3.40856374434375*^9}, {3.40856521884375*^9, 3.408565238609375*^9}, {3.408566059609375*^9, 3.40856614703125*^9}, { 3.408566390734375*^9, 3.40856639828125*^9}, {3.40865894084375*^9, 3.40865898509375*^9}, {3.4216012438318167`*^9, 3.4216012775047693`*^9}, { 3.4216016064059186`*^9, 3.421601624797132*^9}, {3.4216017115030317`*^9, 3.4216017138781075`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Using MyHWT1D1", "Section", CellChangeTimes->{{3.40856374971875*^9, 3.408563751765625*^9}, 3.421601291723974*^9}], Cell["\<\ The cells below contain commands that illustrate the use of MyHWT1D1. Feel \ free to change the input list x.\ \>", "Text", CellChangeTimes->{{3.408563756390625*^9, 3.408563758609375*^9}, 3.421601296317871*^9}], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"x", "=", RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8"}], "}"}]}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "=", RowBox[{"MyHWT1D1", "[", "x", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "x", ",", "\"\< is \>\"", ",", "y", ",", "\"\<.\>\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.40856376153125*^9, 3.40856376334375*^9}, { 3.408565244421875*^9, 3.40856524525*^9}, {3.408566383765625*^9, 3.408566384140625*^9}, 3.4216012987710743`*^9, {3.4216017156750402`*^9, 3.4216017158469205`*^9}}], Cell["What should MyHWT1D1 do to a constant vector?", "Text", CellChangeTimes->{{3.40856376840625*^9, 3.408563770390625*^9}, 3.4216013007711387`*^9}], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{"1", ",", RowBox[{"{", "10", "}"}]}], "]"}]}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "=", RowBox[{"MyHWT1D1", "[", "x", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "x", ",", "\"\< is \>\"", ",", "y", ",", "\"\<.\>\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.4085637744375*^9, 3.408563777578125*^9}, { 3.408565248625*^9, 3.40856524975*^9}, {3.408566380609375*^9, 3.40856638096875*^9}, 3.421601302958709*^9, {3.421601717050084*^9, 3.421601717190714*^9}}], Cell["\<\ Here is an example that introduces a command we can use to plot the wavelet \ transform.\ \>", "Text"], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"k", "^", "2"}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", "100"}], "}"}]}], "]"}]}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "=", RowBox[{"MyHWT1D1", "[", "x", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"ListPlot", "[", RowBox[{"x", ",", RowBox[{"PlotStyle", "\[Rule]", "Blue"}]}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "1"}], ",", RowBox[{"Frame", "\[Rule]", "True"}], ",", RowBox[{"UseColors", "\[Rule]", "True"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Plot", " ", "the", " ", "differences", " ", "only"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "1"}], ",", RowBox[{"Frame", "\[Rule]", "True"}], ",", RowBox[{"UseColors", "\[Rule]", "True"}], ",", RowBox[{"Region", "\[Rule]", "HighPass"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.408562861484375*^9, 3.40856287496875*^9}, { 3.408563781140625*^9, 3.408563788421875*^9}, {3.408563819578125*^9, 3.408563832875*^9}, {3.408565252390625*^9, 3.4085652533125*^9}, { 3.408566378234375*^9, 3.40856637846875*^9}, 3.4216013045681353`*^9, { 3.421601718643885*^9, 3.4216017187845144`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Partition, Flatten, Transpose", "Section"], Cell[TextData[{ "If you want to better understand the commands ", StyleBox["Partition,", FontWeight->"Bold"], " ", StyleBox["Flatten", FontWeight->"Bold"], ", and ", StyleBox["Transpose", FontWeight->"Bold"], ", have a look at the cells below.\n\nHere are two lists" }], "Text"], Cell[BoxData[{ RowBox[{"a", "=", RowBox[{"{", RowBox[{"a1", ",", "a2", ",", "a3", ",", "a4"}], "}"}]}], "\[IndentingNewLine]", RowBox[{"b", "=", RowBox[{"{", RowBox[{"b1", ",", "b2", ",", "b3", ",", "b4"}], "}"}]}]}], "Input", CellChangeTimes->{{3.40856404525*^9, 3.4085640554375*^9}, { 3.408565257890625*^9, 3.4085652586875*^9}, {3.408566374890625*^9, 3.408566375125*^9}, {3.4216017201595583`*^9, 3.421601720331439*^9}}], Cell["\<\ We can build a 2 x 4 matrix from the lists. The second command prints the \ output in a more conventional way.\ \>", "Text"], Cell[BoxData[{ RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "]"}]}], "Input", CellChangeTimes->{{3.40856526309375*^9, 3.408565263859375*^9}, { 3.40856637284375*^9, 3.40856637309375*^9}, {3.4216017213470964`*^9, 3.421601721487726*^9}}], Cell[TextData[{ "We can perform operations like ", StyleBox["Transpose", FontWeight->"Bold"], "." }], "Text"], Cell[BoxData[{ RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "]"}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "]"}], "]"}]}], "Input", CellChangeTimes->{{3.40856526621875*^9, 3.4085652668125*^9}, { 3.408566368796875*^9, 3.4085663690625*^9}, {3.421601723659671*^9, 3.4216017238159256`*^9}}], Cell["\<\ In the cell below, we use Flatten and Transpose to intertwine the elements of \ a and b. Flatten simply removes all inner sets of { } leaving only a single \ list of numbers.\ \>", "Text"], Cell[BoxData[{ RowBox[{"c", "=", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}]}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", "c", "]"}], "\[IndentingNewLine]", RowBox[{"d", "=", RowBox[{"Transpose", "[", "c", "]"}]}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", "d", "]"}], "\[IndentingNewLine]", RowBox[{"Flatten", "[", "d", "]"}]}], "Input", CellChangeTimes->{{3.40856526925*^9, 3.408565270015625*^9}, { 3.408566364328125*^9, 3.408566364640625*^9}, {3.421601724987838*^9, 3.4216017251284676`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["One-Dimensional Inverse Discrete Haar Transform Module", "Section"], Cell["\<\ The cell below contains a module for computing the one-dimensional inverse \ discrete Haar wavelet transform. It takes as input a list of n elements. \ The number of elements must be even or the module returns an error message. The routine starts with an error check on the length of the input. Then the \ input is partitioned into an 2 x n/2 matrix. The matrix is multiplied by (1, \ -1) to obtain the odd elements of the transform and (1,1) to form the even \ elements of the transform. The two parts are then intertwined and returned \ by the module. \ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"MyIHWT1D1", "[", "y_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"(*", " ", RowBox[{"Put", " ", "local", " ", "variables", " ", "here"}], " ", "*)"}], "}"}], ","}], "\[IndentingNewLine]", "\t", RowBox[{"(*", " ", RowBox[{"Put", " ", "commands", " ", "here"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.4085641175*^9, 3.408564119796875*^9}, { 3.4085652745625*^9, 3.40856527540625*^9}, {3.40856636078125*^9, 3.408566361640625*^9}, 3.421601307661984*^9, 3.421601348069527*^9, { 3.4216014447913723`*^9, 3.4216014588855734`*^9}, {3.4216016514073586`*^9, 3.421601659235734*^9}, {3.421601727019153*^9, 3.4216017272535353`*^9}, 3.4216017585826635`*^9}] }, Open ]], Cell[CellGroupData[{ Cell["Using MyIHWT1D1", "Section", CellChangeTimes->{{3.408565847375*^9, 3.408565853234375*^9}, 3.4216013093807893`*^9, 3.4216013495383244`*^9}], Cell["\<\ Feel free to change the input vector x. For something different, I've formed \ x as a list of 20 random integers whose values range from 0 to 100.\ \>", "Text", CellChangeTimes->{3.421601491386613*^9}], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"x", "=", RowBox[{"RandomInteger", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "100"}], "}"}], ",", RowBox[{"{", "20", "}"}]}], "]"}]}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "=", RowBox[{"MyHWT1D1", "[", "x", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["newx", FontColor->GrayLevel[0]], " ", "=", " ", RowBox[{"MyIHWT1D1", "[", "y", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "x", ",", "\"\<.\>\""}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "y", ",", "\"\<.\>\""}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", StyleBox["newx", FontColor->GrayLevel[0]], ",", "\"\<.\>\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.40856299865625*^9, 3.40856301365625*^9}, { 3.4085641421875*^9, 3.408564149359375*^9}, {3.4085652793125*^9, 3.408565280078125*^9}, {3.408566357578125*^9, 3.408566358015625*^9}, { 3.408635478484375*^9, 3.40863553746875*^9}, {3.4216013138809333`*^9, 3.42160135160089*^9}, {3.4216014980899525`*^9, 3.4216015251845694`*^9}, { 3.4216017296911135`*^9, 3.4216017297848663`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["An Illuminating Exercise for Students", "Section"], Cell["\<\ I use this example every time I introduce the Haar wavelet transform. The \ student can create a basic function from Calculus I (some examples are \ provided). The function is then sampled 100 times from a to b. This creates \ a list x that we plot. Note the x-axis on the plot is in terms of the list \ elements while the y-axis is in terms of the list values. Feel free to uncomment other functions, define your own, or change n, a, b.\ \>", "Text"], Cell[BoxData[{ RowBox[{ StyleBox[ RowBox[{ RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", RowBox[{"Sin", "[", RowBox[{"2", "*", "Pi", "*", "t"}], "]"}]}], ";"}], FontColor->GrayLevel[0]], StyleBox["\[IndentingNewLine]", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", RowBox[{"Cos", "[", RowBox[{"2", "*", "Pi", "*", "t"}], "]"}]}], ";"}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], StyleBox["\[IndentingNewLine]", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"(*", " ", RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", RowBox[{"t", "^", "2"}]}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], StyleBox["\[IndentingNewLine]", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"(*", " ", RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", "t"}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", StyleBox[ RowBox[{"(*", " ", RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", "1"}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", StyleBox[ RowBox[{"(*", " ", RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", RowBox[{"E", "^", "t"}]}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], StyleBox["\[IndentingNewLine]", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"f", "[", "t_", "]"}], ":=", RowBox[{"Log", "[", RowBox[{"1", "+", "t"}], "]"}]}], ";"}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], StyleBox["\[IndentingNewLine]", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ StyleBox[ RowBox[{"n", "=", "100"}], FontColor->GrayLevel[0]], StyleBox[";", FontColor->GrayLevel[0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"(*", " ", RowBox[{"This", " ", "must", " ", "be", " ", RowBox[{"even", "!"}]}], " ", "*)"}], FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", StyleBox[ RowBox[{"a", "=", "0"}], FontColor->GrayLevel[0]], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox[ RowBox[{ RowBox[{"b", "=", "1"}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"a", "+", RowBox[{"k", "/", "n"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"ListPlot", "[", RowBox[{"x", ",", RowBox[{"PlotStyle", "\[Rule]", "Red"}]}], "]"}]}], "Input", CellChangeTimes->{ 3.40856304378125*^9, {3.408565284421875*^9, 3.408565285*^9}, { 3.408566352703125*^9, 3.408566353015625*^9}, {3.4216017340506277`*^9, 3.4216017341912575`*^9}}], Cell["\<\ Next compute the HWT of x. The first plot is the entire transform. The \ second plot shows only the approximation portion of the transform while the \ third plot shows only the differences portion of the transform. How are the second and third plots related? Try a couple of other functions.\ \ \>", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"y", "=", RowBox[{"MyHWT1D1", "[", "x", "]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "1"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "1"}], ",", RowBox[{"Region", "\[Rule]", "LowPass"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "1"}], ",", RowBox[{"Region", "\[Rule]", "HighPass"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.408563051953125*^9, 3.408563057359375*^9}, { 3.408564213234375*^9, 3.408564215265625*^9}, {3.408565293328125*^9, 3.4085653156875*^9}, {3.40856634915625*^9, 3.4085663494375*^9}, 3.4216013229749737`*^9, {3.4216017362850747`*^9, 3.421601736363202*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Iterating the Process", "Section"], Cell[TextData[{ "In many applications, scientists will ", StyleBox["iterate", FontWeight->"Bold"], " the wavelet transform. Suppose you are given n-vector x and you compute \ the HWT y. The next iteration of transform is applied to the approximation \ portion of the y. Here is some code (bulky) to do the job. Note that to \ iterate a second time requires n to be divisible by 4. " }], "Text"], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"x", " ", "=", " ", RowBox[{"{", RowBox[{ "2", ",", "4", ",", "6", ",", "8", ",", "10", ",", "12", ",", "14", ",", "16"}], "}"}]}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Length", "[", "x", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"MyHWT1D1", "[", "x", "]"}]}], "\[IndentingNewLine]", StyleBox[ RowBox[{"approx", " ", "=", " ", RowBox[{"Take", "[", RowBox[{"y", ",", RowBox[{"n", "/", "2"}]}], "]"}]}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ StyleBox[ RowBox[{"diff", " ", "=", " ", RowBox[{"Drop", "[", RowBox[{"y", ",", RowBox[{"n", "/", "2"}]}], "]"}]}], FontColor->GrayLevel[0]], StyleBox["\[IndentingNewLine]", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", StyleBox[ RowBox[{"z", "=", RowBox[{"MyHWT1D1", "[", "approx", "]"}]}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", StyleBox[ RowBox[{"iterated", " ", "=", " ", RowBox[{"Join", "[", RowBox[{"z", ",", "diff"}], "]"}]}], FontColor->GrayLevel[0]]}], "Input", CellChangeTimes->{{3.40856427290625*^9, 3.408564274578125*^9}, { 3.408564316625*^9, 3.40856431925*^9}, {3.40856532078125*^9, 3.408565321453125*^9}, {3.408566345421875*^9, 3.408566345734375*^9}, { 3.4216013240531335`*^9, 3.4216013275844965`*^9}, {3.421601738472645*^9, 3.4216017385663977`*^9}}], Cell[TextData[{ "In general, if the length of x contains the factor ", Cell[BoxData[ SuperscriptBox["2", "i"]]], ", we can iterate i times. There is a routine in ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " for computing the iterated Haar Wavelet Transform. It is called ", StyleBox["HWT1D", FontColor->RGBColor[1, 0, 0]], ". It needs two arguments. The first is the input vector. The second \ input is the number of iterations. \n\nHere is an example. Note that the \ length of the input vector is divisible by 32 so we can perform as many as 5 \ iterations." }], "Text", CellChangeTimes->{ 3.40856358584375*^9, {3.408565892015625*^9, 3.4085658975625*^9}, { 3.408565930359375*^9, 3.408565944328125*^9}}], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"n", "=", "96"}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", StyleBox[ RowBox[{ RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"k", "/", "n"}], ")"}], "^", "2"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}]}], ";"}], FontColor->GrayLevel[0]], "\n", RowBox[{ RowBox[{ RowBox[{"y", "=", RowBox[{ StyleBox["HWT1D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"x", ",", RowBox[{"NumIterations", "\[Rule]", "2"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "2"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.408564362609375*^9, 3.408564400296875*^9}, { 3.408565325796875*^9, 3.408565326140625*^9}, {3.4085659496875*^9, 3.408565951296875*^9}, {3.408566189203125*^9, 3.408566190546875*^9}, { 3.408566341515625*^9, 3.408566341828125*^9}, {3.4216017401133223`*^9, 3.421601740316454*^9}}], Cell[TextData[{ "Here is three iterations of the transform. Note the approximation portion \ contains 96/", Cell[BoxData[ SuperscriptBox["2", "3"]]], " = 12 elements." }], "Text"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"y", "=", RowBox[{ StyleBox["HWT1D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"x", ",", RowBox[{"NumIterations", "\[Rule]", "3"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "3"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.4085645700625*^9, 3.4085645799375*^9}, { 3.408565330140625*^9, 3.408565330578125*^9}, {3.408565955328125*^9, 3.40856595825*^9}, {3.4085661959375*^9, 3.408566198375*^9}, { 3.408566338515625*^9, 3.408566338875*^9}, {3.4216017419727564`*^9, 3.4216017421290116`*^9}}], Cell["You can look at particular portions of the transform.", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "3"}], ",", RowBox[{"Iteration", "\[Rule]", "2"}], ",", RowBox[{"Region", "\[Rule]", "HighPass"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletVectorPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "3"}], ",", RowBox[{"Region", "\[Rule]", "LowPass"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.408564661171875*^9, 3.408564711765625*^9}, { 3.40856533309375*^9, 3.4085653334375*^9}, {3.40856633596875*^9, 3.408566336328125*^9}, {3.421601743597809*^9, 3.4216017437540636`*^9}}], Cell[TextData[{ "The process is invertible using the ", StyleBox["IHWT1D", FontColor->RGBColor[1, 0, 0]], " routine from ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], ". Like ", StyleBox["HWT1D", FontColor->RGBColor[1, 0, 0]], ", the routine requires two arguments. The first is the input vector and \ the second is the number of iterations." }], "Text", CellChangeTimes->{ 3.40856358703125*^9, {3.408566224890625*^9, 3.40856625925*^9}, { 3.4216015746549025`*^9, 3.421601581639501*^9}}], Cell[BoxData[{ RowBox[{ StyleBox[ RowBox[{ RowBox[{"x", "=", RowBox[{"RandomInteger", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "100"}], "}"}], ",", RowBox[{"{", "32", "}"}]}], "]"}]}], ";"}], FontColor->GrayLevel[0]], StyleBox[" ", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "=", RowBox[{ StyleBox["HWT1D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"x", ",", RowBox[{"NumIterations", "\[Rule]", "5"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"orig", " ", "=", " ", RowBox[{ StyleBox["IHWT1D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"y", ",", RowBox[{"NumIterations", "\[Rule]", "5"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "x", ",", "\"\<.\>\""}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"N", "[", "y", "]"}], ",", "\"\<.\>\""}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"N", "[", "orig", "]"}], ",", "\"\<.\>\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.408563074234375*^9, 3.408563084328125*^9}, { 3.40856533653125*^9, 3.408565337*^9}, {3.408565994328125*^9, 3.408566002140625*^9}, {3.4085662081875*^9, 3.40856621496875*^9}, { 3.40856629296875*^9, 3.40856633075*^9}, {3.4086355556875*^9, 3.408635571546875*^9}, {3.4216015487009473`*^9, 3.4216015561230593`*^9}, { 3.4216017448791*^9, 3.4216017450041037`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Orthogonalizing the Transform", "Section"], Cell["\<\ In the early development of wavelets, the transforms were designed to be \ orthogonal matrices. Consider the Haar Wavelet transform matrix of size 8 x \ 8 and its inverse:\ \>", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{"h", "=", RowBox[{"Join", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "/", "2"}], ",", RowBox[{"1", "/", "2"}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", "6", "}"}]}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tp", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"h", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "3"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"g", "=", RowBox[{"Join", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"-", "1"}], "/", "2"}], ",", RowBox[{"1", "/", "2"}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", "6", "}"}]}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"bt", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"g", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "3"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"W8", " ", "=", " ", RowBox[{"Join", "[", RowBox[{"tp", ",", "bt"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", "W8", "]"}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", RowBox[{"Inverse", "[", "W8", "]"}], "]"}], "\[IndentingNewLine]"}], "Input",\ CellChangeTimes->{{3.408565340640625*^9, 3.408565340953125*^9}, { 3.4085663270625*^9, 3.408566327421875*^9}, {3.4216017469260397`*^9, 3.4216017470197935`*^9}}], Cell[TextData[{ "How could we modify the matrix so that it is orthgonal?\n\n\nWhen we use \ orthogonal transformations, we can use the same list as the second arguments \ for ", StyleBox["WT1D", FontColor->RGBColor[0.501961, 0, 0]], " and ", StyleBox["IWT1D", FontColor->RGBColor[0.501961, 0, 0]], ". There is a command in ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " for generating this list:" }], "Text", CellChangeTimes->{3.408563589203125*^9}], Cell[BoxData[ RowBox[{ StyleBox["Haar", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]], "Input", CellChangeTimes->{{3.408565346015625*^9, 3.408565346359375*^9}, { 3.421601749801132*^9, 3.421601749973013*^9}}] }, Open ]] }, Open ]] }, WindowSize->{1272, 902}, 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, 34, 0, 73, "Title"], Cell[627, 25, 198, 6, 96, "Subtitle"], Cell[828, 33, 158, 6, 89, "Subsubtitle"], Cell[CellGroupData[{ Cell[1011, 43, 28, 0, 75, "Section"], Cell[1042, 45, 112, 3, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[1191, 53, 30, 0, 75, "Section"], Cell[1224, 55, 1259, 28, 101, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2520, 88, 82, 1, 75, "Section"], Cell[2605, 91, 282, 4, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2924, 100, 65, 0, 75, "Section"], Cell[2992, 102, 202, 5, 47, "Text"], Cell[3197, 109, 899, 19, 82, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4133, 133, 124, 2, 75, "Section"], Cell[4260, 137, 226, 5, 29, "Text"], Cell[4489, 144, 753, 20, 82, "Input"], Cell[5245, 166, 154, 2, 29, "Text"], Cell[5402, 170, 707, 19, 82, "Input"], Cell[6112, 191, 112, 3, 29, "Text"], Cell[6227, 196, 1872, 52, 162, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8136, 253, 48, 0, 75, "Section"], Cell[8187, 255, 291, 11, 65, "Text"], Cell[8481, 268, 448, 10, 62, "Input"], Cell[8932, 280, 135, 3, 29, "Text"], Cell[9070, 285, 348, 8, 62, "Input"], Cell[9421, 295, 114, 5, 29, "Text"], Cell[9538, 302, 421, 10, 62, "Input"], Cell[9962, 314, 200, 4, 29, "Text"], Cell[10165, 320, 535, 11, 122, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10737, 336, 73, 0, 75, "Section"], Cell[10813, 338, 584, 11, 119, "Text"], Cell[11400, 351, 828, 18, 82, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[12265, 374, 149, 2, 75, "Section"], Cell[12417, 378, 213, 4, 29, "Text"], Cell[12633, 384, 1448, 38, 142, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[14118, 427, 56, 0, 75, "Section"], Cell[14177, 429, 466, 8, 83, "Text"], Cell[14646, 439, 2995, 97, 302, "Input"], Cell[17644, 538, 325, 7, 65, "Text"], Cell[17972, 547, 1455, 44, 122, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[19464, 596, 40, 0, 75, "Section"], Cell[19507, 598, 406, 8, 47, "Text"], Cell[19916, 608, 1494, 42, 182, "Input"], Cell[21413, 652, 750, 17, 83, "Text"], Cell[22166, 671, 1507, 49, 122, "Input"], Cell[23676, 722, 185, 6, 29, "Text"], Cell[23864, 730, 1055, 33, 82, "Input"], Cell[24922, 765, 69, 0, 29, "Text"], Cell[24994, 767, 1028, 30, 82, "Input"], Cell[26025, 799, 524, 15, 29, "Text"], Cell[26552, 816, 2109, 65, 162, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[28698, 886, 48, 0, 75, "Section"], Cell[28749, 888, 196, 4, 29, "Text"], Cell[28948, 894, 1750, 56, 182, "Input"], Cell[30701, 952, 482, 14, 83, "Text"], Cell[31186, 968, 295, 9, 41, "Input"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)