0% found this document useful (0 votes)
7 views6 pages

digicomlab4_210401005

The document outlines a lab task for digital communication focusing on ASK modulation and demodulation. It includes steps for generating and plotting signals, adding noise, and calculating the Bit Error Rate (BER) for BPSK modulation. The conclusion emphasizes BPSK's robustness and efficiency in low-SNR environments, highlighting its importance in digital communications.

Uploaded by

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

digicomlab4_210401005

The document outlines a lab task for digital communication focusing on ASK modulation and demodulation. It includes steps for generating and plotting signals, adding noise, and calculating the Bit Error Rate (BER) for BPSK modulation. The conclusion emphasizes BPSK's robustness and efficiency in low-SNR environments, highlighting its importance in digital communications.

Uploaded by

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

DIGITAL

COMMUNICATION

LAB 2

Section : EE-20B

NAME ROLL NO

M. Talha Zulfiqar 210401005

Raees Abdullah 210401019


LAB TASKS:
ASK Modulation
1. Initialize variables
2. Generate carrier signal
3. Generate binary message
4. Start FOR Loop
5. Generate ASK modulated signal
6. Add AWGN
7. End FOR Loop
8. Plot the binary data, carrier and ASK signal

ASK Demodulation
1. Start FOR Loop
2. Compute energy of each symbol as a test statistic z (T ).
3. Make a decision by comparing with a threshold. Set the threshold in the middle of the test
statistics of the two symbols.
4. Plot the conditional probability density functions for both symbols at a low SNR value where
they have some overlap.
5. Compare the received binary message with the original message and compute probability of bit
error (PB)
6. Plot the SNR vs PB curve for several values of SNR, from 10dB to -15dB with a step of 5dB (-
15 : 5 : 10). The SNR should be varied by varying the signal amplitude. The figure below is a
representation of this plot.

CODE:

% Initialize Variables
N = 1000;
Eb = 1;
Tb = 1;
fc = 5;
fs = 1000;
SNR_dB = -35:1:30;

% Generate Random Binary Message


bits = randi([0 1], 1, N);

% BPSK Modulation
T = Tb/fs;
bit_time = 0:T:Tb-T;
carrier = sqrt(2*Eb/Tb) * cos(2*pi*fc*bit_time);
modulated_signal = [];

for i = 1:N
if bits(i) == 0
modulated_signal = [modulated_signal, -carrier];
else
modulated_signal = [modulated_signal, carrier];
end
end
time = 0:T:(N*Tb)-T;
figure;
subplot(3,1,1);
stairs(0:N-1,bits,'LineWidth',2);
title('Binary Message');
xlabel('Bit Index');
ylabel('Amplitude');
subplot(3,1,2);
plot(carrier,'LineWidth',2)
title('Carrier Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,3);
plot(modulated_signal,'LineWidth',1);
title('BPSK Modulated Signal');
xlabel('Time');
ylabel('Amplitude');

% Add AWGN
snr = 20; % Moderate SNR value
y_noisy = awgn(modulated_signal, snr, 'measured');

% BPSK Demodulation
received_bits = zeros(1, N);
index = 1;
for i = 1:N
test_stat = sum(y_noisy(index:index+fs-1) .* carrier);
if test_stat > 0
received_bits(i) = 1;
else
received_bits(i) = 0;
end
index = index + fs;
end

% Plot Decoded Signal


figure
subplot(2,1,1)
stairs(0:N-1, received_bits, 'LineWidth',2);
title('Decoded Binary Message');
xlabel('Bit Index');
ylabel('Amplitude');
subplot(2,1,2)
plot(y_noisy)
title('BPSK Modulated Signal with Noise Added');
xlabel('Time');
ylabel('Amplitude');

BER = zeros(1, length(SNR_dB));


BER_theory = zeros(1, length(SNR_dB)); % Theoretical BER for validation
for j = 1:length(SNR_dB)
snr = SNR_dB(j);
% Compute signal power and add AWGN
signal_power = mean(abs(modulated_signal).^2);
noise_power = signal_power / (10^(snr/10));
noise = sqrt(noise_power) * randn(size(modulated_signal));
y_noisy = modulated_signal + noise;

% BPSK Demodulation (Fixed Indexing)


received_bits = zeros(1, N);
for i = 1:N
start_idx = (i-1) * length(carrier) + 1;
end_idx = start_idx + length(carrier) - 1;
if end_idx > length(y_noisy)
break; % Ensure no out-of-bounds indexing
end

test_stat = sum(y_noisy(start_idx:end_idx) .* carrier); % Correlation


if test_stat > 0
received_bits(i) = 1;
else
received_bits(i) = 0;
end
end

% Compute Bit Error Rate (BER)


bit_errors = sum(bits ~= received_bits);
BER(j) = bit_errors / N;

end

% Plot BER vs SNR Curve


figure;
semilogy(SNR_dB, BER, '-o', 'LineWidth', 2);
title('BER vs SNR Curve');
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
legend('Simulated BER', 'Theoretical BER');
OUTPUT:

Task 1:

Task 2:
Task 3:

CONCLUSION:
BPSK is a simple and robust digital modulation technique that uses two phase shifts (0° and
180°) for data transmission. It offers strong resistance to noise, making it ideal for reliable
communication in low-SNR environments. While less spectrally efficient than higher-order
schemes, BPSK is power-efficient and widely used in satellite and wireless systems. Its
simplicity and reliability make it a foundational choice in digital communications.

You might also like