Aggiunte alcune FilterBanks di base (che però ancora mi danno

Leonardo Robol [2010-03-03 07:41]
Aggiunte alcune FilterBanks di base (che però ancora mi danno
problemi) e un tentativo di indovinare la lunghezza della filter
bank dalla lunghezza del filtro lowpass che le viene assegnato.
Filename
Filtering/Filtering.py
Filtering/Splitting.py
diff --git a/Filtering/Filtering.py b/Filtering/Filtering.py
index bf939be..705de28 100644
--- a/Filtering/Filtering.py
+++ b/Filtering/Filtering.py
@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 #

-from numpy import array, zeros, convolve, dot, roll
+from numpy import array, zeros, convolve, dot, roll, sqrt

 class AbstractFilter():

@@ -29,14 +29,14 @@ class FIR(AbstractFilter):
                          samples, 'same')


-    def GetResponseFunction(self):
+    def GetResponse(self):
         """
         Obtain the vector of coefficients.
         """
         return self.coefficients

     def __mul__(self, other):
-        return FIR(convolve(self.coefficients, other.GetResponseFunction()))
+        return FIR(convolve(self.coefficients, other.GetResponse()))



@@ -108,6 +108,10 @@ class FilterBank():
         """
         self.lowPassFilter = lowpass

+        # Sembra che la lunghezza del filtro debba essere
+        # la metà del filtro lowpass, arrotondata per eccesso
+        self.SetLength ( (len(lowpass) + 1)/2 )
+
     def SetHighPassFilter(self, highpass):
         """
         Set the High pass filter. It is usually
@@ -184,5 +188,55 @@ class FilterBank():



-
-
+DaubechiesFilterBank = FilterBank ()
+DaubechiesFilterBank.SetFilterMatrix ( [
+        0.125 * array([ 1 + sqrt(3), 3 + sqrt(3), 3 - sqrt(3), 1 - sqrt(3)]),
+        0.125 * array([ 1 - sqrt(3),-3 + sqrt(3), 3 + sqrt(3),-1 - sqrt(3)]),
+        0.25  * array([ 1 - sqrt(3), 3 - sqrt(3), 3 - sqrt(3), 1 - sqrt(3)]),
+        0.25  * array([-1 - sqrt(3), 3 + sqrt(3),-3 + sqrt(3), 1 - sqrt(3)])
+        ])
+DaubechiesFilterBank.SetLength (3)
+
+HaarFilterBank = FilterBank ()
+HaarFilterBank.SetFilterMatrix ( [
+        [0.5, 0.5],
+        [0.5 ,-0.5],
+        [1 , 1 ],
+        [-1 , 1]
+        ])
+HaarFilterBank.SetLength(1)
+
+LeoFilterBank = FilterBank()
+LeoFilterBank.SetFilterMatrix ( [
+        [0.25 , 0.5 , 0.25 ],
+        [0.25 , -0.5, 0.25] ,
+        [0.5 , 1, 0.5],
+        [0.5, -1, 0.5]
+        ])
+LeoFilterBank.SetLength(3)
+
+StrangFilterBank = FilterBank ()
+StrangFilterBank.SetFilterMatrix ( [
+        0.125 * array([-1,2,6,2,-1]),
+        0.25 * array([1,-2,1]),
+        0.5 * array([1,2,1]),
+        0.25 * array([1,2,-6,2,1])
+        ])
+StrangFilterBank.SetLength(3)
+
+def PRCheck(f):
+
+    a = (f.lowPassFilter * f.lowPassInverseFilter).GetResponse ()
+    b = (f.highPassFilter*f.highPassInverseFilter).GetResponse ()
+    c = (f.highPassFilter*f.lowPassFilter).GetResponse ()
+    return a, b, c
+
+
+h0 = StrangFilterBank.lowPassFilter
+h1 = StrangFilterBank.highPassFilter
+f0 = StrangFilterBank.lowPassInverseFilter
+f1 = StrangFilterBank.highPassInverseFilter
+
+
+
+
diff --git a/Filtering/Splitting.py b/Filtering/Splitting.py
index 4d10bf5..e55f28d 100644
--- a/Filtering/Splitting.py
+++ b/Filtering/Splitting.py
@@ -21,7 +21,10 @@ class SplittingExample():

         filterBank = Filtering.FilterBank ()
         filterBank.SetFilterMatrix ([h0,h1,f0,f1])
-        filterBank.SetDepth (4)
+        filterBank.SetDepth (3)
+
+        # filterBank = Filtering.StrangFilterBank
+        # filterBank.SetDepth(2)

         samples = self.LoadSamples ("sunny.pcm")
         wavelets = filterBank.Split (samples)
ViewGit