def mu_law_bins(num_bins):
"""
this functions returns the mu-law bin (right) edges and bin centers, with num_bins number of bins
"""
#all edges
bins_edge = np.linspace(-1, 1, num_bins + 1)
#center of all edges
bins_center = np.linspace(-1 + 1.0 / num_bins, 1 - 1.0 / num_bins, num_bins)
#get the right edges
bins_trunc = bins_edge[1:]
#if sample >= right edges, it might be assigned to the next bin, add 0.1 to avoid this
bins_trunc[-1] += 0.1
#convert edges and centers to mu-law scale
bins_edge_mu = np.multiply(np.sign(bins_trunc), (num_bins ** np.absolute(bins_trunc) - 1) / (num_bins - 1))
bins_center_mu = np.multiply(np.sign(bins_center), (num_bins ** np.absolute(bins_center) - 1) / (num_bins - 1))
return (bins_edge_mu, bins_center_mu)
评论列表
文章目录