0
MATLAB代碼:無法MATLAB轉換爲Python代碼爲repmat和對稱性
n = 2048;
d = 1;
order = 2048;
nn = [-(n/2):(n/2-1)]';
h = zeros(size(nn),'single');
h(n/2+1) = 1/4;
odd = mod(nn,2) == 1;
h(odd) = -1 ./ (pi * nn(odd)).^2;
f_kernel = abs(fft(h))*2;
filt = f_kernel(1:order/2+1)';
w = 2*pi*(0:size(filt,2)-1)/order;
filt(w>pi*d) = 0;
filt = [filt , filt(end-1:-1:2)];
filt = repmat(filt',[1 1024]);
Python代碼:
import numpy as np
import numpy.matlib
from numpy.matlib import repmat
d = 1
filt_length = 2048
nn = np.linspace(-1024,1023,2048)
nn = np.transpose(nn)
h = np.zeros((2048))
h[1024] = 0.25
odd = (nn%2)
for i in range(0,2048) :
if odd[i] == 1 :
h[i] = -1/((np.pi*nn[i])**2)
f_kernel = abs(fft(h))*2
filt = np.transpose(f_kernel[0:1024])
w = (np.pi)*np.linspace(0,1,1025)
不過,我一直無法最後3行MATLAB代碼轉換爲蟒蛇。有什麼建議麼? MATLAB代碼的第二步創建了一個尺寸爲2048的斜坡濾波器(以1024爲單位從0到1,在另外1024個步驟中從1到0)。最後一個repmat將filter的大小設爲(2048,1024)。