BPSK modulation and demodulation — constellation, decision rule, and BER intuition

Digital Modulations 101 — 5 lessons (same on every page in this path)

1. BPSK (you are here) → 2. QPSK → 3. M-PSK sim → 4. QAM sim → 5. EVM

Tools: BER vs Eb/N0 · EVM → SNR · Eb/N0 ↔ SNR

Lesson 1 of 5. Start here: one bit on one carrier is the cleanest digital modem. Next: QPSK (two bits, same energy-efficiency story).

In one sentence: BPSK sends one bit as $latex \pm$ phase on a carrier; coherent detection in AWGN yields $latex P_b=Q(\sqrt{2E_b/N_0})$.

Key focus: BPSK, Binary Phase Shift Keying, bpsk modulation, bpsk demodulation, BPSK matlab, BPSK python implementation, BPSK constellation

BPSK – introduction

BPSK stands for Binary Phase Shift Keying. It is a type of modulation used in digital communication systems to transmit binary data over a communication channel.

In BPSK, the carrier signal is modulated by changing its phase by 180 degrees for each binary symbol. Specifically, a binary 0 is represented by a phase shift of 180 degrees, while a binary 1 is represented by no phase shift.

BPSK is a straightforward and effective modulation method and is frequently utilized in applications where the communication channel is susceptible to noise and interference. It is the modulation you reach for when the link is power-limited: deep-space probes, some satellite beacons, and the most robust rate of the older direct-sequence Wi-Fi modes. Bluetooth and current Wi-Fi use other constellations.

Implementation details

Binary Phase Shift Keying (BPSK) is a two phase modulation scheme, where the 0’s and 1’s in a binary message are represented by two different phase states in the carrier signal:$latex \theta=0^{\circ}$ for binary 1 and$latex \theta=180^{\circ}$ for binary 0.

In digital modulation techniques, a set of basis functions are chosen for a particular modulation scheme. Generally, the basis functions are orthogonal to each other. Basis functions can be derived using Gram Schmidt orthogonalization procedure [1]. Once the basis functions are chosen, any vector in the signal space can be represented as a linear combination of them. In BPSK, only one sinusoid is taken as the basis function. Modulation is achieved by varying the phase of the sinusoid depending on the message bits. Therefore, within a bit duration$latex T_b$, the two different phase states of the carrier signal are represented as,

\begin{align*} s_1(t) &= A_c\; cos\left(2 \pi f_c t \right), & 0 \leq t \leq T_b \quad \text{for binary 1}\\ s_0(t) &= A_c\; cos\left(2 \pi f_c t + \pi \right), & 0 \leq t \leq T_b \quad \text{for binary 0} \end{align*}

where,$latex A_c$ is the amplitude of the sinusoidal signal,$latex f_c$ is the carrier frequency$latex Hz$,$latex t$ being the instantaneous time in seconds,$latex T_b$ is the bit period in seconds. The signal$latex s_0(t)$ stands for the carrier signal when information bit$latex a_k=0$ was transmitted and the signal$latex s_1(t)$ denotes the carrier signal when information bit$latex a_k=1$ was transmitted.

The constellation diagram for BPSK (Figure 3 below) will show two constellation points, lying entirely on the x axis (inphase). It has no projection on the y axis (quadrature). This means that the BPSK modulated signal will have an in-phase component but no quadrature component. This is because it has only one basis function. It can be noted that the carrier phases are$latex 180^{\circ}$ apart and it has constant envelope. The carrier’s phase contains all the information that is being transmitted.

BPSK transmitter

A BPSK transmitter, shown in Figure 1, is implemented by coding the message bits using NRZ coding ($latex 1$ represented by positive voltage and$latex 0$ represented by negative voltage) and multiplying the output by a reference oscillator running at carrier frequency$latex f_c$.

BPSK transmitter (binary phase shift keying modulation)
Figure 1: BPSK transmitter

The following function (bpsk_mod) implements a baseband BPSK transmitter according to Figure 1. The output of the function is in baseband and it can optionally be multiplied with the carrier frequency outside the function. In order to get nice continuous curves, the oversampling factor ($latex L$) in the simulation should be appropriately chosen. If a carrier signal is used, it is convenient to choose the oversampling factor as the ratio of sampling frequency ($latex f_s$) and the carrier frequency ($latex f_c$). If a carrier is present, the sampling rate has to clear the Nyquist rate of that carrier,$latex f_s > 2 f_c$. Taking the oversampling factor as$latex f_s/f_c$ only helps once that inequality is already true. For baseband waveform simulation, the oversampling factor can simply be chosen as the ratio of bit period ($latex T_b$) to the chosen sampling period ($latex T_s$), where the sampling period is sufficiently smaller than the bit period.

Refer Digital Modulations using Matlab : Build Simulation Models from Scratch for full Matlab code.
Refer Digital Modulations using Python for full Python code

File 1: bpsk_mod.m: Baseband BPSK modulator

function [s_bb,t] = bpsk_mod(ak,L)
%Function to modulate an incoming binary stream using BPSK(baseband)
%ak - input binary data stream (0's and 1's) to modulate
%L - oversampling factor (Tb/Ts)
%s_bb - BPSK modulated signal(baseband)
%t - generated time base for the modulated signal
N = length(ak); %number of symbols
a = 2*ak-1; %BPSK modulation
ai=repmat(a,1,L).'; %bit stream at Tb baud with rect pulse shape
ai = ai(:).';%serialize
t=0:N*L-1; %time base
s_bb = ai;%BPSK modulated baseband signal

BPSK receiver

A correlation type coherent detector, shown in Figure 2, is used for receiver implementation. In coherent detection technique, the knowledge of the carrier frequency and phase must be known to the receiver. This can be achieved by using a Costas loop or a Phase Lock Loop (PLL) at the receiver. For simulation purposes, we simply assume that the carrier phase recovery was done and therefore we directly use the generated reference frequency at the receiver -$latex cos( 2 \pi f_c t)$.

Coherent detection of BPSK (correlation type) - (binary phase shift keying demodulation)
Figure 2: Coherent detection of BPSK (correlation type)

In the coherent receiver, the received signal is multiplied by a reference frequency signal from the carrier recovery blocks like PLL or Costas loop. Here, it is assumed that the PLL/Costas loop is present and the output is completely synchronized. The multiplied output is integrated over one bit period using an integrator. A threshold detector makes a decision on each integrated bit based on a threshold. Since, NRZ signaling format was used in the transmitter, the threshold for the detector would be set to$latex 0$. The function bpsk_demod, implements a baseband BPSK receiver according to Figure 2. To use this function in waveform simulation, first, the received waveform has to be downconverted to baseband, and then the function may be called.

Refer Digital Modulations using Matlab : Build Simulation Models from Scratch for full Matlab code.
Refer Digital Modulations using Python for full Python code

File 2: bpsk_demod.m: Baseband BPSK detection (correlation receiver)

function [ak_cap] = bpsk_demod(r_bb,L)
%Function to demodulate an BPSK(baseband) signal
%r_bb - received signal at the receiver front end (baseband)
%N - number of symbols transmitted
%L - oversampling factor (Tsym/Ts)
%ak_cap - detected binary stream
x=real(r_bb); %I arm
x = conv(x,ones(1,L));%integrate for L (Tb) duration
x = x(L:L:end);%I arm - sample at every L
ak_cap = (x > 0).'; %threshold detector

End-to-end simulation

The complete waveform simulation for the end-to-end transmission of information using BPSK modulation is given next. The simulation involves: generating random message bits, modulating them using BPSK modulation, addition of AWGN noise according to the chosen signal-to-noise ratio and demodulating the noisy signal using a coherent receiver. The topic of adding AWGN noise according to the chosen signal-to-noise ratio is discussed in section 4.1 in chapter 4. The resulting waveform plots are the four panels of Figure 3. The performance simulation for the BPSK transmitter/receiver combination is also coded in the program shown next (see chapter 4 for more details on theoretical error rates).

The bit error rate of coherent BPSK in AWGN is exactly$latex P_b = Q\left(\sqrt{2 E_b/N_0}\right)$. The baseband model below is that receiver: symbols at$latex \pm 1$, noise of variance$latex N_0/2$ on the real line, and a threshold at zero.

Refer Digital Modulations using Matlab : Build Simulation Models from Scratch for full Matlab code.
Refer Digital Modulations using Python for full Python code

File 3: bpsk_wfm_sim.m: Waveform simulation for BPSK modulation and demodulation

Baseband BPSK , BPSK transmitted signal, constellation of BPSK and received signal in AWGN
Figure 3: (a) Baseband BPSK signal,(b) transmitted BPSK signal – with carrier, (c) constellation at transmitter and (d) received signal with AWGN noise
import numpy as np
from scipy.special import erfc

def q_function(x):
    return 0.5 * erfc(np.asarray(x, dtype=float) / np.sqrt(2.0))

def bpsk_ber_sim(ebn0_db, n_bits=200000, seed=1):
    """Baseband coherent BPSK. Symbol energy is 1, so N0 = 1/(Eb/N0)."""
    rng = np.random.default_rng(seed)
    ebn0 = 10 ** (ebn0_db / 10.0)
    n0 = 1.0 / ebn0
    bits = rng.integers(0, 2, size=n_bits)
    symbols = 2 * bits - 1
    noise = np.sqrt(n0 / 2.0) * rng.normal(size=n_bits)
    detected = (symbols + noise) > 0
    return np.mean(detected != bits)

for db in (0, 2, 4, 6, 8):
    simulated = bpsk_ber_sim(db)
    theory = q_function(np.sqrt(2 * 10 ** (db / 10.0)))
    print("Eb/N0=%4.1f dB   simulated %.3e   theory %.3e" % (db, simulated, theory))
Start of path Next: QPSK →

FAQ

What is the recommended reading order? Follow the five lessons at the top: BPSK → QPSK → M-PSK → QAM → EVM. Use the BER and EVM calculators to check numbers as you go.

Why learn BPSK before QPSK? Every later constellation reuses the same matched-filter / correlator idea. If BPSK BER vs $latex E_b/N_0$ is clear, QPSK and M-PSK are mostly bookkeeping.

Similar articles

References:

[1] Lloyd N. Trefethen, David Bau III , Numerical linear algebra, Philadelphia: Society for Industrial and Applied Mathematics, ISBN 978-0-89871-361-9, pp.56

Leave a Comment

29 thoughts on “BPSK modulation and demodulation — constellation, decision rule, and BER intuition”

  1. Thanks Bassel for pointing it out.

    psd will work till Matlab version 9 (although with a warning). Users can employ following syntax for plotting PSD.

    Hs=spectrum.welch;
    psd(Hs,bpskModulated,’Fs’,Fs)

    Reply
  2. was just wondering, would it be possible to implement BPSK using manchester coding instead of the NRZ shown in the example mentioned? if it is, how could it be implemented and what would the tradeoffs be?

    any input would be greatly appreciated..

    thanks 🙂

    Reply
  3. Hi Tan
    You can simulate BPSK with manchester code by simple changing the argument ‘Polar’ to ‘Manchester’ in line 20. The file is written for three line codes namely ‘Manchester’,’Polar’ and ‘Unipolar’.
    [time,nrzData,Fs]=NRZ_Encoder(data,Rb,amplitude,’Manchester’);

    You will see the difference between Manchester coded BPSK and polar coded BPSK by looking at their PSDs

    Reply
  4. The bpsk modulator is basically implemented by having a binary data stream (which is just a string of 1’s and 0’s) going into a NRZ coder. NRZ coder is used to assign some meaningful voltage to the incoming binary data stream. The NRZ coder converts 1’s to (say for example) 1V and 0’s to -1V. Then the output of NRZ is multiplied by a sinusoid to get modulated signal.

    Binary data stream is the input to NRZ coder.

    Reply
  5. i still have question about demodulator

    about function of component respectively :
    it uses PLL, to keep the carrier frequency to be same with carrier frequency at modulator, isn’t it ?

    detector, to convert signal to be digital form

    and for integrator, i still don’t know the purpose of it. why the signal must be integrated first before detector?

    thank you

    best regards

    Reply
  6. PLL is used to track any frequency changes in the incoming signal to lock it with the carrier frequency.

    Here,the integrator functions as a Low pass filter that removes the harmonics created by the multiplier that precedes the integrator.

    Once the harmonics are removed, the threshold detector is used to detect ones and zeros.

    If we insert a sampler after the integrator, it becomes a correlator demodulator. The sampler samples the output of the integrator where the maximum occurs (it occurs at time instant T).

    To maximize the SNR performance of the receiver, a matched filter is usually used.

    Reply
  7. Please add the directory (in which you have downloaded the files given here) to the Matlab path.

    Open matlab, go to File-> Set Path and add the directory there.

    Now you should not get the “Function Not defined” error.

    Reply
  8. Hi Zein,
    In the matlab code the carrier frequency (Fc) is set as twice the bit rate (Rb).

    You can modify the line (search for this line in the code)
    Fc=2*Rb

    or you can modify the bit rate Rb

    If you want to set your carrier frequency to 125KHz, the bit rate must be atleast half of this value.

    Fc=125*1000; %Fc =125KHz
    Then Rb has to be atmost
    Rb=62.5*1000; bit rate

    Reply
  9. Hi mathuranathan

    please can you give me Theory BER equation in Rayleigh channel for QPSK Modulation?

    because i need to compare my simulated program with it

    Reply
  10. I don’t get the demodulation.

    Say you got r(t) is Acos(wt), so you multiply it with another cos(wt) and it becomes A[cos(wt)]^2, and then you integrate A[cos(wt)]^2? Where does this all lead?

    Reply
  11. thanks mathuranathan for this interresting post,

    I want to know why the BPSK is sometimes a NRZ signal multiplied by a carrier(sin’2piftime)) and sometimes its represented by a sequence of 1 and -1.

    then is it Fc=2*Rc a condition we does respect usually ???? and why ?

    Reply
  12. Hello Mr. Mathuranathan,

    Why the Fc carrier frequency is 2*Rb(2/Tb). Can it be set to 1/Tb or 10/Tb…Aren’t we wasting the symbols if we set Fc other than 1/Tb

    Reply
    • Hi,
      There is no specific relationship between carrier frequency Fc and the bit rate Rb. Usually Fc >> Rb. If Fc is integral multiple of Rb, we will have full cycles of carrier waveform contained in a given bit period (Tb). For example, Fc = 2*Rb, you will have two whole cycles of carrier signal contained inside the bit period Tb.

      You can choose Fc = 10*Rb, then the simulation code has to process 10 cycles of signal for one bit of information transmitted, this consumes more memory and takes more time for executing the simulation (Typically in BER simulation, we will be processing minimum 10^5 to 10^6 bits for obtaining smooth BER curves).

      Reply
  13. Hi, i just ordered your three books. Do you happen to show how to run any of your examples on low cost SDRs, like RTL-SDRs, bladeRFs, HackRFs, or LimeSDRs? Thx! Don

    Reply