Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views10 pages

Exp 4

The experiment aims to reconstruct a transmitted image using BPSK modulation and demodulation, employing a maximum likelihood decoder and analyzing the bit error rate (BER) against signal-to-noise ratio (SNR). The process involves reading an image, converting it to bits, adding AWGN noise, and reconstructing the image while plotting the BER vs SNR curve. Results indicate that higher SNR improves communication reliability and the practical BER aligns closely with theoretical predictions.

Uploaded by

Ashwin Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Exp 4

The experiment aims to reconstruct a transmitted image using BPSK modulation and demodulation, employing a maximum likelihood decoder and analyzing the bit error rate (BER) against signal-to-noise ratio (SNR). The process involves reading an image, converting it to bits, adding AWGN noise, and reconstructing the image while plotting the BER vs SNR curve. Results indicate that higher SNR improves communication reliability and the practical BER aligns closely with theoretical predictions.

Uploaded by

Ashwin Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Experiment No 4: BPSK MODULATION AND DEMODULATION(SIMULATION)

Date of Experiment: 27/02/2025

AIM

The aim of the experiment is to reconstruct a transmi ed image, modulated by BPSK scheme, at the
receiver. The maximum likelihood decoder will be used at the receiver to recover the symbols. To
model a channel for transmission AWGN noise will be added to transmi ed signal before processing
at the receiver. The bit error rate (BER) vs SNR(in dB) curve will be plo ed for different values of SNR
and will be compared with the theore cal value. Note that we are a using the baseband transmission
for simula on. Following are the steps to be followed for the simula on experiment.

1. Read the image cameraman.png. You can get the image by clicking here. The image is of size 256 ×
256. Use suitable python package for reading the image (imageio, opencv etc).

2. Convert the pixel values to bits and map to BPSK symbols. Make sure to use same number of bits
for all the values. Plot the constella on diagram of the BPSK symbols.

3. Set an SNR value for the transmission and generate a complex Gaussian noise with enough number
of samples for the required SNR.

4. The received signal which is the combina on of BPSK symbol and the noise samples shall be
passed through an ML decoder to do the demapping. The constella on diagram of the received
signal shall be plo ed. 1

5. Convert the demapped symbols to bits and then to pixel values. Also find the BER.

6. Reconstruct the image.

7. Iterate the above steps for SNR (in dB) values from -10 to 10 with increments of 1 and plot the
BER. Also plot the theore cal BER value for BPSK Modula on. Compare them.

THEORETICAL BACKGROUND

1.Binary Phase Shi Keying (BPSK) Modula on

BPSK is a digital modula on scheme where the phase of the carrier signal is varied to represent binary
data. In BPSK:

• Binary 0 is represented by a phase shi of 0 (symbol +1).

• Binary 1 is represented by a phase shi of 180 (symbol −1).

The BPSK signal can be represented as:

where:
• A is the amplitude of the carrier signal.

• Fcf is the carrier frequency.

• ϕi is the phase (0 or 180 ) corresponding to the binary data.

For baseband transmission, the BPSK symbols are represented as:

s0=+1(for binary 0) s

=−1(for binary 1)

2. Addi ve White Gaussian Noise (AWGN) Channel

The transmi ed signal is corrupted by AWGN noise during transmission. The received signal r(t)r(t) is
given by: r(t)=s(t)+n(t)

where n(t) is the AWGN noise with zero mean and variance σ2σ2.

3. Maximum Likelihood (ML) Decoder

The ML decoder is used to recover the transmi ed symbols from the noisy received signal. For BPSK,
the decision rule is:

4. Bit Error Rate (BER)

The BER is the probability of incorrect symbol detec on. For BPSK in AWGN, the theore cal BER is
given by:

where:

• Eb is the energy per bit.

• N0 is the noise power spectral density.

• Q(x) is the Q-func on, defined as:

The SNR (signal-to-noise ra o) in dB is given by:


5. Image Transmission and Reconstruc on

• The image is converted into a binary bit stream.

• The bits are mapped to BPSK symbols (+1 or −1).

• The symbols are transmi ed over an AWGN channel.

• At the receiver, the noisy symbols are decoded using the ML decoder.

• The decoded bits are converted back into pixel values to reconstruct the image.

CODE

"""

EXPERIMENT 5

BPSK MODULATION AND DEMODULATION SIMULATION

Program to-

1. Read an image "cameraman.png", convert it to a binary bit stream and plot its constella on
diagram.

2. Transmit the image's binary data using BPSK over an AWGN channel and plot received
constella on diagrams.

3. Reconstruct the original image from the received bits and compute BER.

4. Repeat for SNR values from -10dB to +10dB, plot SNR vs BER and compare theore cal vs prac cal
BER.

Author: M NIHALRAHMAN

Date: 27/02/2025

"""

# Student Informa on

print("Student M NIHALRAHMAN")

print("ROLL NO:47")

print("ECE")
import cv2 import numpy as

np import matplotlib.pyplot as

plt from scipy import special

# Func on to add AWGN noise def

add_awgn_noise(signal, snr_db):

snr_linear = 10 ** (snr_db / 10) # Convert SNR from dB to linear scale

noise_power = np.var(signal) / snr_linear

noise = np.sqrt(noise_power / 2) * (np.random.randn(len(signal)) + 1j *


np.random.randn(len(signal)))

return signal + noise

# Step 1: Read and process the image image =

cv2.imread('/content/drive/MyDrive/cameraman.png', cv2.IMREAD_GRAYSCALE)

plt.imshow(image, cmap='gray') plt. tle('Original Image') plt.axis('off')

plt.show()

# Convert image to binary bit stream fla ened_image = image.fla en() #

Convert 2D image to 1D array bit_array = np.unpackbits(fla ened_image) #

Convert pixel values to binary bits

# Step 2: BPSK Modula on (Mapping bits: 0 → 1, 1 → -1) modulated_signal

= -2 * bit_array + 1

# Plot constella on diagram of transmi ed BPSK signal

plt.sca er(np.real(modulated_signal), np.imag(modulated_signal))

plt. tle('Constella on Diagram (BPSK Transmi ed Signal)')

plt.grid() plt.show()

# Step 3: Transmission over AWGN Channel and BER Calcula on

snr_db_values = np.arange(-9, 11, 1) # SNR from -10dB to 10dB

ber_values = [] theore cal_ber = []


# Create a figure for constella on diagrams fig1, axes1 = plt.subplots(5, 4,

figsize=(20, 20)) fig1.sup tle('Constella on Diagrams for Different SNR

Values', fontsize=16)

# Create a figure for reconstructed images fig2, axes2 = plt.subplots(5, 4,

figsize=(20, 20)) fig2.sup tle('Reconstructed Images for Different SNR

Values', fontsize=16)

# Fla en the axes arrays for easy itera on

axes1 = axes1.fla en() axes2 =

axes2.fla en()

# Loop through SNR values for i, snr_db in

enumerate(snr_db_values): # Transmit signal with AWGN

received_signal = add_awgn_noise(modulated_signal, snr_db)

# Plot received constella on diagram for each SNR value

axes1[i].sca er(np.real(received_signal), np.imag(received_signal)) axes1[i].set_ tle(f'SNR

= {snr_db} dB')

axes1[i].grid()

# Step 4: Demodula on and BER Calcula on

received_bits = (np.real(received_signal) <= 0).astype(int)

bit_errors = np.sum(bit_array != received_bits) ber =

bit_errors / len(bit_array) ber_values.append(ber)

# Theore cal BER for BPSK in AWGN theore cal_ber.append(0.5 *

special.erfc(np.sqrt(10 ** (snr_db / 10))))

# Reconstruct the image for each SNR value

received_pixels = np.packbits(received_bits)[:image.size]

received_image = received_pixels.reshape(image.shape)
# Plot reconstructed image for each SNR value

axes2[i].imshow(received_image, cmap='gray')

axes2[i].set_ tle(f'SNR = {snr_db} dB') axes2[i].axis('off')

# Adjust layout for both figures

fig1. ght_layout() fig2. ght_layout()

# Step 5: Plot SNR vs BER plt.figure(figsize=(10, 6))

plt.semilogy(snr_db_values, ber_values, 'o-', label='Prac cal BER')

plt.semilogy(snr_db_values, theore cal_ber, 's--', label='Theore cal BER')

plt.xlabel('SNR (dB)') plt.ylabel('Bit Error Rate (BER)') plt. tle('SNR vs

BER')

plt.grid(True, which='both')

plt.legend() plt.show()

# Display the figures plt.show()

OUTPUT
INFERENCE

1. BPSK Modula on and Demodula on:

- Successfully demonstrated image transmission using BPSK over an AWGN channel.

- Binary data mapped to BPSK symbols (+1for 0, -1 for 1), with AWGN noise added.

- ML decoder recovered symbols, and BER was computed for various SNR values.

2. Constella on Diagrams:

- Transmi ed BPSK signal showed dis nct clusters at \(+1\) and \(-1\).

- Received constella ons showed increased noise at lower SNR, making symbol dis nc on harder.

3. BER vs SNR:

- Prac cal BER closely matched theore cal BER, valida ng the implementa on.

- BER decreased with higher SNR, improving system reliability.

4. Image Reconstruc on:

- Image reconstructed successfully; high SNR (e.g., 5 dB) yielded near-iden cal images, while low
SNR (e.g., -10 dB) caused heavy distor on.

CONCLUSION

1. BPSK Modula on and Demodula on:

- Confirmed BPSK as a robust scheme for digital communica on in AWGN.

- ML decoder effec vely recovered symbols, with BER matching theore cal predic ons.
2. Impact of SNR on BER:

- Higher SNR reduced BER, enhancing communica on reliability.

- Prac cal and theore cal BER alignment validated the experimental setup.

3. Image Transmission:

- Demonstrated end-to-end image transmission using BPSK, with reconstruc on quality dependent
on SNR.

- Highlighted the importance of high SNR for reliable data transmission.

4. Prac cal Applica ons:

- Provided insights into digital communica on systems, especially for cri cal data transmission like
images and videos.

You might also like