def testEncodeDecodeShift(self):
x = np.linspace(-1, 1, 1000).astype(np.float32)
with self.test_session() as sess:
encoded = mu_law_encode(x, QUANT_LEVELS)
decoded = mu_law_decode(encoded, QUANT_LEVELS)
roundtripped = sess.run(decoded)
# Detect non-unity scaling and non-zero shift in the roundtripped
# signal by asserting that slope = 1 and y-intercept = 0 of line fit to
# roundtripped vs x values.
coeffs = np.polyfit(x, roundtripped, 1)
slope = coeffs[0]
y_intercept = coeffs[1]
EPSILON = 1e-4
self.assertNear(slope, 1.0, EPSILON)
self.assertNear(y_intercept, 0.0, EPSILON)
评论列表
文章目录