Digicomlab2 210401005
Digicomlab2 210401005
COMMUNICATION
LAB 2
Section : EE-20B
NAME ROLL NO
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:
Tb = 1;
fs = 100;
fc = 5;
N = 100;
E=1;
A1 = sqrt(2*E/Tb);
A0 = 0;
SNR_range = -20:5:20;
t = 0:1/fs:Tb-1/fs;
carrier = sin(2*pi*fc*t);
% ASK Modulation
for i = 1:N
if binary_data(i) == 1
ask_symbol = A1 * carrier;
else
ask_symbol = A0 * carrier;
end
ask_signal = [ask_signal, ask_symbol];
end
% Plot signals
figure;
subplot(4,1,1);
stairs(0:N-1,binary_data,'LineWidth',2);
title('Binary Data');
xlabel('Bit Index');
ylabel('Amplitude');
axis([0 N -0.5 1.5])
subplot(4,1,2);
plot(t, carrier,'LineWidth',2);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,3);
plot(ask_signal);
title('ASK Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,4)
plot(noisy_signal);
title('ASK Modulated Signal with awgn added');
xlabel('Time (s)');
ylabel('Amplitude');
% ASK Demodulation
for i = 1:N
received_symbol_energy = sum(noisy_signal((i-1)*length(t) + 1 : i*(length(t))).^2);
if received_symbol_energy > thresh^2 * length(t)
received_bits(i) = 1;
else
received_bits(i) = 0;
end
end
figure;
subplot(2,1,1)
stairs(0:N-1,received_bits,'LineWidth',2);
title('Recieved Data');
xlabel('Bit Index');
ylabel('Amplitude');
axis([0 N -0.5 1.5])
subplot(2,1,2)
stairs(0:N-1,binary_data,'LineWidth',2);
title('Binary Data');
xlabel('Bit Index');
ylabel('Amplitude');
axis([0 N -0.5 1.5])
% SNR vs PB curve
PB_values = zeros(size(SNR_range));
for idx = 1:length(SNR_range)
noisy_signal = awgn(ask_signal, SNR_range(idx), 'measured');
received_bits = zeros(1, N);
for i = 1:N
received_symbol = noisy_signal((i-1)*fs*Tb + 1 : i*fs*Tb);
energy = sum(received_symbol .* carrier);
received_bits(i) = energy > thresh;
end
PB_values(idx) = sum(received_bits ~= binary_data) / N;
end
% Plot SNR vs PB
figure;
semilogy(SNR_range, PB_values, '-o');
grid on;
title('SNR vs Bit Error Probability');
xlabel('SNR (dB)');
ylabel('Probability of Bit Error (PB)');
OUTPUT:
Task 1:
Task 2:
Task 3:
CONCLUSION:
In the ASK modulation MATLAB lab, we successfully implemented and
analyzed Amplitude Shift Keying (ASK) modulation and demodulation. The
results demonstrated how binary data is represented through amplitude variations
in the carrier signal, confirming the effectiveness of ASK for digital
communication systems.