Pulizia del codice.
Leonardo Robol [2010-03-13 16:08]
diff --git a/Filtering/Filtering.py b/Filtering/Filtering.py
index ecf2dd3..6a280fa 100644
--- a/Filtering/Filtering.py
+++ b/Filtering/Filtering.py
@@ -241,6 +241,12 @@ class FilterBank():
will be the delay when recovering
"""
self.length = length
+
+ def EndEffectLength(self):
+ """Cerchiamo di dare una valutazione di quanto gli effetti
+ di bordo potrebbero rovinare la traccia per preseravare le
+ informazioni finali"""
+ return (-2) * pow(2,self.depth) * len(self.lowPassFilter.GetResponse())
def Split(self, samples):
"""
@@ -257,8 +263,7 @@ class FilterBank():
samplesStack.PushEndSamples (end)
# Non sono proprio sicuro che questo sia il modo migliore per farlo.
- end_effect_number = (-2) * self.depth * len(self.lowPassFilter.GetResponse())
- samplesStack.PushEndEffectSamples (low[end_effect_number:])
+ samplesStack.PushEndEffectSamples (low[self.EndEffectLength():])
# Do the real filtering and downsampling. Store the downsampled
# details in the array.
@@ -299,7 +304,7 @@ class FilterBank():
low = roll(low, -1 * self.length)
# Riparo gli eventuali end effect
- low[-2*self.depth*len(self.lowPassFilter.GetResponse()):] = samplesStack.PopEndEffectSamples ()
+ low[self.EndEffectLength():] = samplesStack.PopEndEffectSamples ()
# Riattacchiamo la coda
return concatenate ((low, end))
@@ -328,9 +333,9 @@ LeoFilterBank.SetFilterMatrix ( [
[0.25 , 0.5 , 0.25 ],
[0.25 , -0.5, 0.25] ,
[0.5 , 1, 0.5],
- [0.5, -1, 0.5]
+ [-0.5, 1, -0.5]
])
-LeoFilterBank.SetLength(3)
+LeoFilterBank.SetLength(2)
StrangFilterBank = FilterBank ()
StrangFilterBank.SetFilterMatrix ( [
diff --git a/Filtering/dwt.py b/Filtering/dwt.py
index c515b08..3cf2eb0 100755
--- a/Filtering/dwt.py
+++ b/Filtering/dwt.py
@@ -61,7 +61,7 @@ LoadingLibrariesStarted()
# Importing libraries
import Filtering
from pylab import show, plot, title, xlabel, ylabel, rcParams
-from numpy import array, sqrt, memmap, roll
+from numpy import array, sqrt, memmap, roll, inf
from numpy.linalg import norm
import time
@@ -100,6 +100,7 @@ class DWT():
filterBank = Filtering.StrangFilterBank
self.filterBankName = "Strang"
elif filterbank == 'leo':
+ # Ci sono ancora dei problemi con questa.
filterBank = Filtering.LeoFilterBank
self.filterBankName = "Leo"
else:
@@ -128,11 +129,14 @@ class DWT():
a = norm(rebuilt - samples)
if (a > 1E-2):
Output ("Error while reconstructing. Rebuilt samples differs from original ones")
- Output ("||rebuilt - samples|| = %f" % a)
+ Output ("|rebuilt - samples| = %f" % a)
+ Output ("|rebuilt - samples|_inf = %f" % norm(rebuilt-samples,inf))
Output ("There is likely an error in the code")
+
elif (a > 1E-6):
Output ("Error while reconstructing. Rebuilt samples differs from original ones")
Output ("This is likely an approximation error (the error is quite small)")
+ Output ("|rebuilt - samples|_inf = %f" % norm(rebuilt-samples,inf))
else:
Output ("Perfect reconstruction succeeded")
self.WriteSamples(rebuilt, filewrite)