<s> """<STR_LIT>""" <EOL> from numpy import complex , sum , pi , arange , array , size , shape , real , sqrt <EOL> from numpy import matrix , sqrt , sum , zeros , concatenate , sinc <EOL> from numpy . random import randn , seed , random <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def bec ( input_bits , p_e ) : <EOL> """<STR_LIT>""" <EOL> output_bits = input_bits . copy ( ) <EOL> output_bits [ random ( len ( output_bits ) ) <= p_e ] = - <NUM_LIT:1> <EOL> return output_bits <EOL> def bsc ( input_bits , p_t ) : <EOL> """<STR_LIT>""" <EOL> output_bits = input_bits . copy ( ) <EOL> flip_locs = ( random ( len ( output_bits ) ) <= p_t ) <EOL> output_bits [ flip_locs ] = <NUM_LIT:1> ^ output_bits [ flip_locs ] <EOL> return output_bits <EOL> def awgn ( input_signal , snr_dB , rate = <NUM_LIT:1.0> ) : <EOL> """<STR_LIT>""" <EOL> avg_energy = sum ( input_signal * input_signal ) / len ( input_signal ) <EOL> snr_linear = <NUM_LIT:10> ** ( snr_dB / <NUM_LIT> ) <EOL> noise_variance = avg_energy / ( <NUM_LIT:2> * rate * snr_linear ) <EOL> if input_signal . dtype is complex : <EOL> noise = ( sqrt ( noise_variance ) * randn ( len ( input_signal ) ) ) + ( sqrt ( noise_variance ) * randn ( len ( input_signal ) ) * <NUM_LIT> ) <EOL> else : <EOL> noise = sqrt ( <NUM_LIT:2> * noise_variance ) * randn ( len ( input_signal ) ) <EOL> output_signal = input_signal + noise <EOL> return output_signal </s>
