def hard_Pk(k,R,SNR,M=<NUM_LIT:2>):
k = int(k)<EOL>if M == <NUM_LIT:2>:<EOL><INDENT>p = Q_fctn(np.sqrt(<NUM_LIT>*R*SNR))<EOL><DEDENT>else:<EOL><INDENT>p = <NUM_LIT>/np.log2(M)*(<NUM_LIT:1> - <NUM_LIT:1.>/np.sqrt(M))*Q_fctn(np.sqrt(<NUM_LIT:3>*R*np.log2(M)/float(M-<NUM_LIT:1>)*SNR))<EOL><DEDENT>Pk = <NUM_LIT:0><EOL>if np.mod(k,<NUM_LIT:2>) == <NUM_LIT:0>:<EOL><INDENT>for e in range(int(k/<NUM_LIT:2>+<NUM_LIT:1>),int(k+<NUM_LIT:1>)):<EOL><INDENT>Pk += float(factorial(k))/(factorial(e)*factorial(k-e))*p**e*(<NUM_LIT:1>-p)**(k-e);<EOL><DEDENT>Pk += <NUM_LIT:1.>/<NUM_LIT:2>*float(factorial(k))/(factorial(int(k/<NUM_LIT:2>))*factorial(int(k-k/<NUM_LIT:2>)))*p**(k/<NUM_LIT:2>)*(<NUM_LIT:1>-p)**(k/<NUM_LIT:2>);<EOL><DEDENT>elif np.mod(k,<NUM_LIT:2>) == <NUM_LIT:1>:<EOL><INDENT>for e in range(int((k+<NUM_LIT:1>)//<NUM_LIT:2>),int(k+<NUM_LIT:1>)):<EOL><INDENT>Pk += factorial(k)/(factorial(e)*factorial(k-e))*p**e*(<NUM_LIT:1>-p)**(k-e);<EOL><DEDENT><DEDENT>return Pk<EOL>
Pk = hard_Pk(k,R,SNR)

Calculates Pk as found in Ziemer & Peterson eq. 7-12, p.505

Mark Wickert and Andrew Smit 2018