Matlab 转换到 Python
一、
[B,A]=besself(od,coh);
→
import scipy
import scipy.signal
B, A = scipy.signal.bessel(od, coh, analog=True, output='ba')
二、
abpsig=smooth(abpsig);
→
def smooth(y):
n = len(y)
yy = np.zeros_like(y)
for i in range(n):
if i == 0:
yy[i] = y[i]
elif i == 1:
yy[i] = np.mean(y[i-1:i+2])
elif 2 <= i <= n - 3:
yy[i] = np.mean(y[i-2:i+3])
elif i == n - 2:
yy[i] = np.mean(y[i-1:i+2])
else:
yy[i] = y[i]
return yy
abpsig = smooth(abpsig)
三、
abpsig=filter(B,A,abpsig);
→
import numpy as np
import scipy
import scipy.signal
mid = np.zeros(4)
mid[-1] = B
B = mid
abpsig = np.transpose(abpsig)
abpsig = scipy.signal.lfilter(B, A, abpsig)
abpsig = np.transpose(abpsig)
四、
rad = resample(rad,100,1000);
→
from scipy.signal import resample_poly
rad = resample_poly(rad, 100, 1000)
五、
for x = A : -1 : B
→
for x in range(A, B-1, -1):