def bessel_rotate(image_org, theta, mask = False, smooth = False, mode = 1): image = image_org.copy() if(mask): image = circle_mask(image, smooth, mode) Ib = np.zeros(image.shape) theta = to_radian(theta) s = (image.shape[0]-1)/2. x = np.linspace(-s, s, image.shape[1]) y = np.linspace(-s, s, image.shape[0]) xx, yy = np.meshgrid(x,y) rM = np.array([[np.cos(theta), -np.sin(theta)],[np.sin(theta), np.cos(theta)]]) for i in np.arange(-s,s+1): for j in np.arange(-s,s+1): new_x = np.dot(rM, np.array([i,j])) if(np.sum(abs(np.round(new_x,5))>s)): Ib[i+s,j+s] = 0 else: R = np.sqrt((xx-new_x[1])**2 + (yy-new_x[0])**2) mask_R = (R == 0) Bess = np.zeros(R.shape) Bess[~mask_R] = scipy.special.j1(np.pi*R[~mask_R])*hann(R[~mask_R],image.shape[0]*mode)/(np.pi*R[~mask_R]) Bess[mask_R] = 0.5 Bess = Bess/np.sum(Bess) tmp = image*Bess Ib[i+s,j+s] = np.sum(tmp) #np.round(np.sum(tmp),10) return Ib
def bessel_rotate_halton(image, theta, x1, y1): Ib = [] theta = to_radian(theta) s = (image.shape[0]-1)/2. rM = np.array([[np.cos(theta), -np.sin(theta)],[np.sin(theta), np.cos(theta)]]) x = [] for i in np.arange(-s,s+1): for j in np.arange(-s,s+1): x.append(np.dot(rM, np.array([i,j]))) x = np.array(x) for idx in xrange(len(x1)): R = np.sqrt((x[:,1]-x1[idx])**2 + (x[:,0]-y1[idx])**2) mask_R = (R == 0) Bess = np.zeros(R.shape) Bess[~mask_R] = scipy.special.j1(np.pi*R[~mask_R])*hann(R[~mask_R],image.shape[0])/(np.pi*R[~mask_R]) #Bess[~mask_R] = scipy.special.j1(np.pi*R[~mask_R])/(np.pi*R[~mask_R]) Bess[mask_R] = 0.5 Bess = Bess/np.sum(Bess) tmp = image.ravel()*Bess Ib.append(np.sum(tmp)) return np.array(Ib)
import numpy as np from utils import hann, linear_2D_array fft_size = 512 # fft size fft_hop = 8 # hop size in stft fft_zp = 512 # zero padding in stft analysis_window = np.concatenate((hann(fft_size), np.zeros(fft_zp))) t_cut = 0.83 # length in [s] 用于消除无信号的片段 # 仿真参数 Fs = 8000 t0 = 1./(Fs*np.pi*1e-2) # 开始时间 absorption = 0.1 # 墙面的吸收程度 0-1, 越小表述多径效应越明显 max_order_sim = 2 sigma2_n = 5e-7 # 环境噪声 # 麦克风阵列的几何结构 mic1 = np.array([2, 1.5]) # 坐标 M = 8 # 麦克风数量 d = 0.08 # 麦克风间隔 8cm phi = 0. # 摆放角度为水平 max_order_design = 1 # 仿真相关的参数 Lg_t = 0.100 # 滤波器的窗口长度 时域上为0.1s Lg = np.ceil(Lg_t*Fs) # 滤波器的窗口长度 具体的阶数 delay = 0.050 # 仿真beamforming的延迟 N = 1024