From e2d2414c3984f6627c3398e0b08147ceae7eac0f Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 3 Mar 2010 08:41:04 +0100 Subject: [PATCH] =?UTF-8?q?Aggiunte=20alcune=20FilterBanks=20di=20base=20(?= =?UTF-8?q?che=20per=C3=B2=20ancora=20mi=20danno=20problemi)=20e=20un=20te?= =?UTF-8?q?ntativo=20di=20indovinare=20la=20lunghezza=20della=20filter=20b?= =?UTF-8?q?ank=20dalla=20lunghezza=20del=20filtro=20lowpass=20che=20le=20v?= =?UTF-8?q?iene=20assegnato.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Filtering/Filtering.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++---- Filtering/Splitting.py | 5 +++- 2 files changed, 63 insertions(+), 6 deletions(-) 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) -- 2.1.4