關於matlab
轉python
代碼的基礎規則, 參見: NumPy for MATLAB users
這裡列出我在matlab
轉python
代碼過程中, 涉及到的其他matlab
函數, 這些函數在"NumPy for MATLAB users"中可能不存在.
如果你覺得這篇博客,對你有幫助, 歡迎收藏訂閱!
d = bi2de(b,p,flg)
d = bi2de(b,p,left_msb)
flg='left-msb'
時, left_msb=True
; flg='right-msb'
時, left_msb=False
.CC = bwconncomp(BW,conn)
CC = bwconncomp(BW,conn)
參見: matlab函數(bwconncomp)的python實現Y = circshift(A, K)
Y = circshift(A, K)
參見: circshiftw = conv(u,v,shape)
w = numpy.convolve(u,v, shape)
[f,x] = ecdf(y)
f, x = ecdf(y)
參見: ecdfb = fir1(n, Wn)
b = scipy.signal.firwin(n+1, Wn)
y = pskmod(x,M,ini_phase)
y = pskmod(x,M,ini_phase)
參見: pskmodimport numpy as np
def bi2de(b: np.ndarray, p: int = 2, left_msb = False):
if left_msb == True:
b = b[::-1]
if b.ndim == 1:
d = 0
for i, bi in enumerate(b):
d += bi * (p**i)
else:
d = np.zeros(b.shape[-1])
for i, bi in enumerate(b):
d += bi * (p**i)
return d
import numpy as np
def circshift(A, K):
return np.hstack((A[-K:], A[:-K]))
與
matlab
中的ecdf
功能不同,matlab
中deecdf
返回的f
(累計概率)為線性遞增, 這裡的ecdf
返回的x
為線性遞增.
import numpy as np
from statsmodels.distributions.empirical_distribution import ECDF
def ecdf(y):
ecdf0 = ECDF(y)
x = np.linspace(np.min(y), np.max(y), len(y)+1)
f = ecdf0(x)
return f, x
import numpy as np
def pskmod(x: np.ndarray, M: int, ini_phase: float = 0):
theta = 2*np.pi*x/M
y = np.exp(1j*(theta + ini_phase))
return y