# -*- coding: utf-8 -*- """ Created on Fri Nov 19 15:13:47 2010 @author: daryl Presents an "efficient" implementation of a simple QMF filter bank for simulation purposes. If you find my code useful, I'd appreciate it if you'd email me my email address is wasden eng utah edu. """ import numpy as np from numpy.fft import fft,ifft def qmfSynthesis(xp): ''' Performs the synthesis portion of a simple Quadrature Mirror Filterbank. The filter coefficients are [1.0,1.0] for the low-pass and [1.0,-1.0] for the highpass. The input should be a 2-D array with the first column representing the low pass component and the second column representing the high pass component. Returns the signal in a 1-D array. ''' # Calculate polyphase outputs sp = np.vstack((xp[:,0]+xp[:,1], xp[:,0]-xp[:,1])).T s = sp.flatten() # Calculate outut return s def qmfAnalysis(s): ''' Performs the analysis portion of a simple Quadrature Mirror Filterbank. The filter coefficients are [0.5,0.5] for the low-pass and [0.5,-0.5] for the highpass. Returns the two components in a 2-D array with each column representing one of the signals (first column is the lowpass signal, second is the high pass). ''' # Force a 1-D array s = s.flatten() # Make sure the array length is even if(float(s.size)/2.0 != s.size/2): s = np.hstack((s.flatten,np.array([0.0]))) # Separate polyphase components sp = s/2.0 sp.shape = (-1,2) # Calculate outputs xp = np.vstack((sp[:,0]+sp[:,1], sp[:,0]-sp[:,1])) return xp.T # Begin Script if __name__ == '__main__': import matplotlib.pyplot as pyplot import numpy.random as npr s = npr.standard_normal(1000) xp = qmfAnalysis(s) s2 = qmfSynthesis(xp) pyplot.figure() pyplot.plot(s,'b',linewidth=2.0) pyplot.plot(s2,'r-.',linewidth=2.0)