def signal_by_db(x1, x2, snr, handle_method):
x1 = x1.astype(np.int32)
x2 = x2.astype(np.int32)
l1 = x1.shape[0]
l2 = x2.shape[0]
if l1 != l2:
if handle_method == 'cut':
ll = min(l1, l2)
x1 = x1[:ll]
x2 = x2[:ll]
elif handle_method == 'append':
ll = max(l1, l2)
if l1 < ll:
x1 = np.append(x1, x1[:ll-l1])
if l2 < ll:
x2 = np.append(x2, x2[:ll-l1])
from numpy.linalg import norm
x2 = x2 / norm(x2) * norm(x1) / (10.0 ** (0.05 * snr))
mix = x1 + x2
return mix
评论列表
文章目录