def wiener_filter_eigen(spec1,spec2,win_size=None,r_step=1): spec1_temp=spec1 spec2_temp=spec2 nframe=spec1.shape[1] if spec1.shape[1]!=spec2.shape[1]: nframe1=spec1.shape[1] nframe2=spec2.shape[1] nframe=min(nframe1,nframe2) spec1_temp=spec1[:,0:nframe,:] spec2_temp=spec2[:,0:nframe,:] if win_size==None: win_size=nframe r1=estimate_correlation(spec1_temp,spec1_temp,win_size,r_step) r2=estimate_correlation(spec2_temp,spec2_temp,win_size,r_step) #r1=estimate_self_correlation(spec1_temp) #r2=estimate_self_correlation(spec2_temp) out_w=np.zeros(r1.shape,dtype=complex) for frame in xrange(r1.shape[0]): for freq_bin in xrange(r1.shape[1]): #a vr[:,i] = w[i] b vr[:,i] rz=r1[frame,freq_bin,:,:] k=r2[frame,freq_bin,:,:] w,vr=scipy.linalg.eig(a=rz,b=k) eigen_id = np.argsort(w)[::-1] eigen_values=w[eigen_id] eigen_vecs=vr[:,eigen_id] v1_inv= np.linalg.inv(eigen_vecs.conj().T) v1= eigen_vecs.conj().T v2= eigen_vecs #i=0 #print k #print "=====" #print rz.dot(eigen_vecs[:,i]) #print w[i]*k.dot(eigen_vecs[:,i]) #print "=====" #print eigen_values #print (v1.dot(rz).dot(v2)) #print (v1.dot(k).dot(v2)) l=np.diagonal(v1.dot(rz).dot(v2)) s=np.diagonal(v1.dot(k).dot(v2)) one=np.ones_like(l) g=one-s/l G=np.diag(g) out_w[frame,freq_bin,:,:]=v1_inv.dot(G.dot(v1)) return out_w
def wiener_filter_eigen(spec1, spec2, win_size=None, r_step=1): spec1_temp = spec1 spec2_temp = spec2 nframe = spec1.shape[1] if spec1.shape[1] != spec2.shape[1]: nframe1 = spec1.shape[1] nframe2 = spec2.shape[1] nframe = min(nframe1, nframe2) spec1_temp = spec1[:, 0:nframe, :] spec2_temp = spec2[:, 0:nframe, :] if win_size == None: win_size = nframe r1 = estimate_correlation(spec1_temp, spec1_temp, win_size, r_step) r2 = estimate_correlation(spec2_temp, spec2_temp, win_size, r_step) #r1=estimate_self_correlation(spec1_temp) #r2=estimate_self_correlation(spec2_temp) out_w = np.zeros(r1.shape, dtype=complex) for frame in xrange(r1.shape[0]): for freq_bin in xrange(r1.shape[1]): #a vr[:,i] = w[i] b vr[:,i] rz = r1[frame, freq_bin, :, :] k = r2[frame, freq_bin, :, :] w, vr = scipy.linalg.eig(a=rz, b=k) eigen_id = np.argsort(w)[::-1] eigen_values = w[eigen_id] eigen_vecs = vr[:, eigen_id] v1_inv = np.linalg.inv(eigen_vecs.conj().T) v1 = eigen_vecs.conj().T v2 = eigen_vecs #i=0 #print k #print "=====" #print rz.dot(eigen_vecs[:,i]) #print w[i]*k.dot(eigen_vecs[:,i]) #print "=====" #print eigen_values #print (v1.dot(rz).dot(v2)) #print (v1.dot(k).dot(v2)) l = np.diagonal(v1.dot(rz).dot(v2)) s = np.diagonal(v1.dot(k).dot(v2)) one = np.ones_like(l) g = one - s / l G = np.diag(g) out_w[frame, freq_bin, :, :] = v1_inv.dot(G.dot(v1)) return out_w
def wiener_filter_freq(spec1,spec2,win_size=None,r_step=1): spec1_temp=spec1 spec2_temp=spec2 nframe=spec1.shape[1] if spec1.shape[1]!=spec2.shape[1]: nframe1=spec1.shape[1] nframe2=spec2.shape[1] nframe=min(nframe1,nframe2) spec1_temp=spec1[:,0:nframe,:] spec2_temp=spec2[:,0:nframe,:] if win_size==None: win_size=nframe rz=estimate_correlation(spec1_temp,spec1_temp,win_size,r_step) rzd=estimate_correlation(spec1_temp,spec2_temp,win_size,r_step) rz=np.squeeze(rz) rzd=np.squeeze(rzd) w=np.zeros(rzd.shape,dtype=complex) for i in xrange(rzd.shape[0]): #print np.linalg.inv(rz)#+np.identity(rz.shape[1])) # Ax=b w[i,:]=np.linalg.solve(rz[i,:,:], rzd[i,:]) return w,rz,rzd
def wiener_filter_freq(spec1, spec2, win_size=None, r_step=1): spec1_temp = spec1 spec2_temp = spec2 nframe = spec1.shape[1] if spec1.shape[1] != spec2.shape[1]: nframe1 = spec1.shape[1] nframe2 = spec2.shape[1] nframe = min(nframe1, nframe2) spec1_temp = spec1[:, 0:nframe, :] spec2_temp = spec2[:, 0:nframe, :] if win_size == None: win_size = nframe rz = estimate_correlation(spec1_temp, spec1_temp, win_size, r_step) rzd = estimate_correlation(spec1_temp, spec2_temp, win_size, r_step) rz = np.squeeze(rz) rzd = np.squeeze(rzd) w = np.zeros(rzd.shape, dtype=complex) for i in xrange(rzd.shape[0]): #print np.linalg.inv(rz)#+np.identity(rz.shape[1])) # Ax=b w[i, :] = np.linalg.solve(rz[i, :, :], rzd[i, :]) return w, rz, rzd