def PCM_encode(x,N_bits):
xq = np.int16(np.rint(x*<NUM_LIT:2>**(N_bits-<NUM_LIT:1>)))<EOL>x_bits = np.zeros((N_bits,len(xq)))<EOL>for k, xk in enumerate(xq):<EOL><INDENT>x_bits[:,k] = to_bin(xk,N_bits)<EOL><DEDENT>x_bits = np.reshape(x_bits,(<NUM_LIT:1>,len(x)*N_bits),'<STR_LIT:F>')<EOL>return np.int16(x_bits.flatten())<EOL>
Parameters
----------
x : signal samples to be PCM encoded
N_bits ; bit precision of PCM samples

Returns
-------
x_bits = encoded serial bit stream of 0/1 values. MSB first.

Mark Wickert, Mark 2015