def sccs_bit_sync(y,Ns):
<EOL>rx_symb_d = np.zeros(int(np.fix(len(y)/Ns)))<EOL>track = np.zeros(int(np.fix(len(y)/Ns)))<EOL>bit_count = -<NUM_LIT:1><EOL>y_abs = np.zeros(len(y))<EOL>clk = np.zeros(len(y))<EOL>k = Ns+<NUM_LIT:1> <EOL>for i in range(len(y)):<EOL><INDENT>if i >= Ns: <EOL><INDENT>y_abs[i] = np.abs(np.sum(y[i-Ns+<NUM_LIT:1>:i+<NUM_LIT:1>]))<EOL>if (k == <NUM_LIT:0>):<EOL><INDENT>w_hat = y_abs[i-<NUM_LIT:2>:i+<NUM_LIT:1>]<EOL>bit_count += <NUM_LIT:1><EOL>if w_hat[<NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>if w_hat[<NUM_LIT:0>] < w_hat[<NUM_LIT:2>]:<EOL><INDENT>k = Ns-<NUM_LIT:1><EOL>clk[i-<NUM_LIT:2>] = <NUM_LIT:1><EOL>rx_symb_d[bit_count] = y[i-<NUM_LIT:2>-int(np.round(Ns/<NUM_LIT:2>))-<NUM_LIT:1>]<EOL><DEDENT>elif w_hat[<NUM_LIT:0>] > w_hat[<NUM_LIT:2>]:<EOL><INDENT>k = Ns+<NUM_LIT:1><EOL>clk[i] = <NUM_LIT:1><EOL>rx_symb_d[bit_count] = y[i-int(np.round(Ns/<NUM_LIT:2>))-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>k = Ns<EOL>clk[i-<NUM_LIT:1>] = <NUM_LIT:1><EOL>rx_symb_d[bit_count] = y[i-<NUM_LIT:1>-int(np.round(Ns/<NUM_LIT:2>))-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>k = Ns<EOL>clk[i-<NUM_LIT:1>] = <NUM_LIT:1><EOL>rx_symb_d[bit_count] = y[i-<NUM_LIT:1>-int(np.round(Ns/<NUM_LIT:2>))]<EOL><DEDENT>track[bit_count] = np.mod(i,Ns)<EOL><DEDENT><DEDENT>k -= <NUM_LIT:1><EOL><DEDENT>rx_symb_d = rx_symb_d[:bit_count]<EOL>return rx_symb_d, clk, track<EOL>
rx_symb_d,clk,track = sccs_bit_sync(y,Ns)

//////////////////////////////////////////////////////
 Symbol synchronization algorithm using SCCS
//////////////////////////////////////////////////////
     y = baseband NRZ data waveform
    Ns = nominal number of samples per symbol

Reworked from ECE 5675 Project
Translated from m-code version
Mark Wickert April 2014