less than 1 minute read

BPSK (Binary Phase Shift Keying) Modulation 🚀

BitPerNoiseDB_iter = range(0,11)     # Set the Eb/N0 range we wanna see

Num_Bit = 1           # BPSK = 1bit
BER = []

for BitPerNoiseDB in BitPerNoiseDB_iter:
  SymbolPerNoiseRATIO = 10**(BitPerNoiseDB/10)
  AWGN_sigma = math.sqrt(1/(2*SymbolPerNoiseRATIO))
  
  Error_Count = 0
  Bit_Count = 0

  while Error_Count < 100:
    Information_Generator = randrange(2)
    Detected_Signal = 0
    Bit = Information_Generator
    Detected_Array = 0

    if Bit == 1:
      symbol = 1+0j

    else:
      symbol = -1+0j

    AWGN = np.random.normal(size = (1,2))
    AWGN = complex(AWGN[0][0], AWGN[0][1]) * AWGN_sigma

    Received_Signal = symbol + AWGN
    Received_Signal_Phase = math.atan2(Received_Signal.imag, Received_Signal.real)

    if (Received_Signal_Phase >= -1 * PI / 2) and (Received_Signal_Phase <  PI / 2):
      Detected_Array = 1

    else:
      Detected_Array = 0

    
    if Bit is not Detected_Array:
      Error_Count += 1
    
    Bit_Count += Num_Bit
    
  BER.append(Error_Count/Bit_Count)

  print("Bit_Count :", Bit_Count)
  print("Eb/N0 :{} [dB]".format(BitPerNoiseDB))
  print("The number of bits with error :", Error_Count)
  print("BER :", BER[BitPerNoiseDB] )
  print("---------------------------------")
%matplotlib inline 
import matplotlib.pyplot as plt

plt.figure(figsize=(8,7))
plt.plot(BitPerNoiseDB_iter, BER, '-*', label = 'BPSK', color="green")
plt.title('BPSK BER', fontsize = 20) 
plt.xlabel("Eb/N0 [dB]", fontsize=15) 
plt.ylabel("BER", fontsize=15)
plt.grid(True, color='blue', alpha=0.3, linestyle='--')
plt.yscale('log')
plt.legend(fontsize=15)

BPSK

Categories:

Updated: