/// <summary> /// NOTE: THIS METHOD IS RECURSIVE. /// It performs a depth first calculation of the wavelet coefficients. /// Depth first search terminates when the bin vector contains only one element. /// </summary> /// <param name="list"></param> /// <param name="bv"></param> /// <returns></returns> public static List <BinVector> GetTreeOfBinVectors(List <BinVector> list, BinVector bv) { int level = bv.levelNumber; int bin = bv.binNumber; // display info about nodes // Console.WriteLine("nodeCount={0} level={1} bin={2} seqNum={3} sigLength={4}", list.Count, level, bin, bv.sequenceNumber, bv.signal.Length); double[] approxVector = LowPassAndDecimate(bv.signal); double[] detailVector = HiPassAndDecimate(bv.signal); if (approxVector == null || approxVector == null) { //list.Add(null); return(list); } BinVector approxBin = new BinVector(level + 1, (2 * bin) - 1, approxVector); approxBin.parent = bv; bv.childApprox = approxBin; BinVector detailBin = new BinVector(level + 1, 2 * bin, detailVector); detailBin.parent = bv; bv.childDetail = detailBin; list.Add(approxBin); GetTreeOfBinVectors(list, approxBin); list.Add(detailBin); GetTreeOfBinVectors(list, detailBin); return(list); }
} // END of class BinVector each of which is a node in the WPD tree. // ############################### NEXT TWO METHODS CREATE THE TREE. SECOND METHOD IS RECURSIVE ########################### /// <summary> /// /// </summary> /// <param name="signal"></param> /// <returns></returns> public static List <BinVector> GetTreeOfBinVectors(double[] signal) { var list = new List <BinVector>(); BinVector sigBin = new BinVector(1, 1, signal); sigBin.childApprox = null; sigBin.childDetail = null; list.Add(sigBin); // call recursive method to construct tree GetTreeOfBinVectors(list, sigBin); return(list); }