def MDCTsynfb(y, fb): #MDCT synthesis filter bank. #Arguments: y: 2-d array of blocks of subbands, of shape (N, # of blokcs) #returns xr, the reconstructed signal, a 1-d array. N = y.shape[0] Fa = symFmatrix(fb) #invert Fa matrix for synthesis after removing last dim: Fs = np.linalg.inv(Fa[:, :, 0]) #add again last dimension for function polmatmult: Fs = np.expand_dims(Fs, axis=-1) Dinv = Dinvmatrix(N) #add first dimension to y for polmatmult: y = np.expand_dims(y, axis=0) xp = DCT4(y) xp = polmatmult(xp, Dinv) xp = polmatmult(xp, Fs) xr = polyphase2x(xp) return xr
def LDFBsyn(y, fb): #Low Delay synthesis filter bank. #Arguments: y: 2-d array of blocks of subbands, of shape (N, # of blokcs) #returns xr, the reconstructed signal, a 1-d array. Fa = symFmatrix(fb[0:int(1.5 * N)]) #invert Fa matrix for synthesis after removing last dim: Fs = np.linalg.inv(Fa[:, :, 0]) #add again last dimension for function polmatmult: Fs = np.expand_dims(Fs, axis=-1) Ginv = Ginvmatrix(fb[int(1.5 * N):(2 * N)]) Dinv = Dinvmatrix(N) #Display the synthesis folding matrix Fs(z): Fsz = polmatmult(polmatmult(Ginv, Dinv), Fs) #add first dimension to y for polmatmult: y = np.expand_dims(y, axis=0) xp = DCT4(y) xp = polmatmult(xp, Ginv) xp = polmatmult(xp, Dinv) xp = polmatmult(xp, Fs) xr = polyphase2x(xp) return xr
xp = DCT4(y) xp = polmatmult(xp, Dinv) xp = polmatmult(xp, Fs) xr = polyphase2x(xp) return xr #Testing: if __name__ == '__main__': import numpy as np import matplotlib.pyplot as plt #Number of subbands: N = 4 D = Dmatrix(N) Dinv = Dinvmatrix(N) #Filter bank coefficients for sine window: #fb=np.sin(np.pi/(2*N)*(np.arange(int(1.5*N))+0.5)) fb = np.loadtxt("MDCTcoeff.txt") #Coeff. from optimization print("fb=", fb) #input test signal, ramp: x = np.arange(64) plt.plot(x) plt.title('Input Signal') plt.xlabel('Sample') plt.show() y = MDCTanafb(x, N, fb) print("y=\n", y) plt.imshow(np.abs(y)) plt.title('MDCT Subbands') plt.xlabel('Block No.')