0% found this document useful (0 votes)
18 views25 pages

Digitalcomm Project

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)
18 views25 pages

Digitalcomm Project

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/ 25

EEC 481 - Digital Communications

Project

Mariam Mohamed Hassan


20011898

Nouran Mostafa Mohamed


20012140

Shrook Abdelkhalek
20010726

December 19, 2024


EEC 481 - Digital Communications Project

Contents
1 Part I: Performance of Matched Filters and Correlators. 2
1.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 m = 20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 Simple Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.3 Matched Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.4 Correlator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.5 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.6 Grouped Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.7 Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 m = 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.1 Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.2 Simple Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.3 Matched Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.4 Correlator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.5 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.6 Grouped Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.7 Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4 m = 100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4.1 Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4.2 Simple Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4.3 Matched Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.4.4 Correlator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.4.5 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.6 Grouped Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.7 Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2 Part II: Performance of Different Modulation Techniques in AWGN Channel 15


2.1 Code: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2 Results: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.3 Comment: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3 Part III: Performance of Different Modulation Techniques in Binary Symmetric Channel 22


3.1 Code: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2 Results: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Comment: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

1
EEC 481 - Digital Communications Project

1 Part I: Performance of Matched Filters and Correlators.


1.1 Code
clc; close all;
% Simulation parameters
num_bits = 1e5; % Number of bits
SNR = 0:2:30; % SNR range in dB
% Prompt user for input of m or set default value to 20
m_input = input(’Please enter a value for m, or press Enter to use the default value (20): ’, ’s’);
% Check if the input is empty (user pressed Enter)
if isempty(m_input)
m = 20; % Set default value to 20
else
% Convert the user input to a number
m = str2double(m_input);
% Check if the conversion was successful
if isnan(m)
disp(’Invalid input. Using default value (20).’);
m = 20; % Set default value to 20
end
end

% Prompt user for input of T or set default value to m


t_input = input(’Please enter a value for T(sampling instant),
or press Enter to use the default value (20): ’, ’s’);
% Check if the input is empty (user pressed Enter)
if isempty(t_input)
T = m; % Set default value to m
else
% Convert the user input to a number
T = str2double(t_input);
% Check if the conversion was successful
if isnan(m)|| T>m
disp(’Invalid input. Using default value (20).’);
T = m; % Set default value to m
end
end
% Generate rectangular pulse s1(t)
prompt = ’Enter s1(t) as an amplitude number (default = 1 ): ’;
A = input(prompt);
zeroSignal = zeros(1, m);
rectangularPulse = ones(1, m);
if isempty(A)
s1 = 1 * rectangularPulse;
else
s1 = A * rectangularPulse;
end
% Generate zero signal s2(t)
prompt = ’Enter s2(t) as an amplitude number (default = 0 ): ’;
A = input(prompt);
if isempty(A)
s2 = 1 * zeroSignal;
else
s2 = A * rectangularPulse;
end
% Generate random binary bits vector
bits = randi([0, 1],1,num_bits);
% Modulate bits with waveform
% Initialize the waveform vector
waveform = zeros(1, num_bits * m);
% Repeat each bit in bits m times and concatenate them
for i = 0:num_bits-1

2
EEC 481 - Digital Communications Project

if bits(i+1) == 1
symb = s1;
else
symb = s2;
end
waveform((m*i)+1:m*i+length(symb)) = symb;
end
% Add noise to samples
ber1 = zeros(1,length(SNR));
ber2 = zeros(1,length(SNR));
ber3 = zeros(1,length(SNR));
% Calculate transmitted signal power
pwr = sum(abs(waveform).^2)/length(waveform);
fprintf(’Transmitted Power = %f Watts(W)\n’,pwr);
for j = 1:length(SNR)
selected_SNR = SNR(j);
% Add white Gaussian noise to waveform
waveformNoise = awgn(waveform, selected_SNR, ’measured’);
% simple detector
Vth = (s1(T) + s2(T))/2;
detected = waveformNoise(1:T:end) > Vth;
error = sum(bits ~= detected) / num_bits;
ber1(1,j) = error;
% Apply convolution process in the receiver
% creates impulse response for the matched filter.
% reflection and shift with t=T
% reverses the order of the diff array
g = s1(end:-1:1) - s2(end:-1:1);
rcvd = zeros(1,num_bits);
convolution_res = zeros(1, ((2*m)-1)*num_bits);
% calculate Vth
E1 = sum(abs(s1.^2));
E2 = sum(abs(s2.^2));
Vth = (E1 - E2)/2;
% calculating BER for MF
for i = 0 : length(bits)-1
symb = waveformNoise((m*i)+1:m*(i+1));
Y = conv(symb,g);
rcvd(i+1) = Y(T);
end
received_mf = rcvd > Vth;
error = sum(bits ~= received_mf) / num_bits;
ber2(1,j) = error;
% Correlator
received_corr = zeros(1, num_bits);
rcvd = zeros(1,m*num_bits);
% calculating BER for Correlator
for i = 0 : num_bits-1
rcvd((i*m)+1:(i*m)+m) = sum(waveformNoise((i*m)+1:(i*m)+m).*conj(s1)) -
sum(waveformNoise((i*m)+1:(i*m)+m).*conj(s2));
end
for i = 1 : length(rcvd)/m
received_corr(i) = rcvd(i*T) > Vth;
end
error = sum(bits ~= received_corr)/ num_bits;
ber3(1,j) = error;
end
% Plot BER vs SNR curves for matched filter and correlator
figure;
semilogy(SNR, ber1(1,:), ’LineWidth’, 1,’color’, ’r’);
xlim([0 30])
xlabel(’SNR (dB)’);

3
EEC 481 - Digital Communications Project

ylabel(’BER’);
title(’Simple Detector’);
figure;
semilogy(SNR, ber2(1,:), ’LineWidth’, 1, ’color’, ’b’);
xlim([0 30])
xlabel(’SNR (dB)’);
ylabel(’BER’);
title(’Matched Filter’);
figure;
semilogy(SNR, ber3(1,:), ’LineWidth’, 1, ’color’, ’g’);
xlim([0 30])
xlabel(’SNR (dB)’);
ylabel(’BER’);
title(’Correlator’);
figure;
semilogy(SNR, ber1(1,:), ’o-’, ’LineWidth’, 1, ’MarkerSize’, 2);
hold on
semilogy(SNR, ber2(1,:), ’o-’, ’LineWidth’, 1, ’MarkerSize’, 2);
hold on;
xlabel(’SNR (dB)’);
ylabel(’BER’);
semilogy(SNR, ber3(1,:), ’o-’, ’LineWidth’, 1, ’MarkerSize’, 2);
hold off;
xlim([0 30]);
title(’Comparison’);
legend(’SD’,’MF’,’Corr’);
figure;
subplot(4,1,1)
semilogy(SNR, ber1(1,:), ’LineWidth’, 1,’color’, ’r’);
xlim([0 30]);
xlabel(’SNR (dB)’);
ylabel(’BER’);
title(’Simple Detector’);
subplot(4,1,2)
semilogy(SNR, ber2(1,:), ’LineWidth’, 1, ’color’, ’b’);
xlim([0 30]);
xlabel(’SNR (dB)’);
ylabel(’BER’);
title(’Matched Filter’);
subplot(4,1,3)
semilogy(SNR, ber3(1,:), ’LineWidth’, 1, ’color’, ’g’);
xlabel(’SNR (dB)’);
xlim([0 30]);
ylabel(’BER’);
title(’Correlator’);
subplot(4,1,4)
semilogy(SNR, ber1(1,:), ’o-’, ’LineWidth’, 1, ’MarkerSize’, 2);
hold on
semilogy(SNR, ber2(1,:), ’o-’, ’LineWidth’, 1, ’MarkerSize’, 2);
hold on;
xlabel(’SNR (dB)’);
ylabel(’BER’);
semilogy(SNR, ber3(1,:), ’o-’, ’LineWidth’, 1, ’MarkerSize’, 2);
hold off;
xlim([0 30]);
title(’Comparison’);
legend(’SD’,’MF’,’Corr’);

%SNR At Which The simple detector Receiver Has The Lowest BER:
[Min_BER_simple, Min_index_simple] = min(ber1);
SNR_min_BER_simple = SNR(Min_index_simple);
fprintf("SNR At Which simple detector Receiver Has Lowest BER: %f\n", SNR_min_BER_simple);

4
EEC 481 - Digital Communications Project

%SNR At Which The Matched Filter Receiver Has The Lowest BER:
[Min_BER, Min_index] = min(ber2);
SNR_min_BER = SNR(Min_index);
fprintf("SNR At Which Matched Filter Receiver Has Lowest BER: %f\n", SNR_min_BER);

%SNR At Which The correlator Receiver Has The Lowest BER:


[Min_BER_c, Min_index_c] = min(ber3);
SNR_min_BER_c = SNR(Min_index_c);
fprintf("SNR At Which correlator Receiver Has Lowest BER: %f\n", SNR_min_BER_c);

1.2 m = 20
1.2.1 Inputs

Figure 1: Inputs of m=20

1.2.2 Simple Detector

Figure 2: Simple Detector of m=20

5
EEC 481 - Digital Communications Project

1.2.3 Matched Filter

Figure 3: Matched Filter of m=20

1.2.4 Correlator

Figure 4: Matched Filter of m=20

6
EEC 481 - Digital Communications Project

1.2.5 Comparison

Figure 5: Comparison of all three receivers with m=20

1.2.6 Grouped Comparison

Figure 6: Collective comparison of all three receivers with m=20

7
EEC 481 - Digital Communications Project

1.2.7 Outputs

Figure 7: Output of program at m=20

1.3 m = 10
1.3.1 Inputs

Figure 8: Inputs of m=10

1.3.2 Simple Detector

Figure 9: Simple Detector of m=10

8
EEC 481 - Digital Communications Project

1.3.3 Matched Filter

Figure 10: Matched Filter of m=10

1.3.4 Correlator

Figure 11: Matched Filter of m=10

9
EEC 481 - Digital Communications Project

1.3.5 Comparison

Figure 12: Comparison of all three receivers with m = 10

1.3.6 Grouped Comparison

Figure 13: Collective comparison of all three receivers with m = 10

10
EEC 481 - Digital Communications Project

1.3.7 Outputs

Figure 14: Output of program at m=10

1.4 m = 100
1.4.1 Inputs

Figure 15: Inputs of m=100

1.4.2 Simple Detector

Figure 16: Simple Detector of m=100

11
EEC 481 - Digital Communications Project

1.4.3 Matched Filter

Figure 17: Matched Filter of m=100

1.4.4 Correlator

Figure 18: Matched Filter of m=100

12
EEC 481 - Digital Communications Project

1.4.5 Comparison

Figure 19: Comparison of all three receivers with m = 100

1.4.6 Grouped Comparison

Figure 20: Collective comparison of all three receivers with m = 100

13
EEC 481 - Digital Communications Project

1.4.7 Outputs

Figure 21: Output of program at m=100

14
EEC 481 - Digital Communications Project

2 Part II: Performance of Different Modulation Techniques in AWGN


Channel
2.1 Code:
close all; clearvars; clc;

% Simulation Parameters
numBits = 1e6; % Number of bits
SNR_dB = 0:2:30; % Range of SNR in dB
SNR_linear = 10.^(SNR_dB / 10); % Convert SNR from dB to linear scale

% Initialize BER Arrays for each modulation scheme


berOOK = zeros(1, length(SNR_dB));
berPRK = zeros(1, length(SNR_dB));
berFSK = zeros(1, length(SNR_dB));
berOOK_builtin = zeros(1, length(SNR_dB));
berPRK_builtin = zeros(1, length(SNR_dB));
berFSK_builtin = zeros(1, length(SNR_dB));
berQAM_builtin = zeros(1, length(SNR_dB));

% Generate Random Binary Data Vector


binaryData = randi([0, 1], 1, numBits); % Random binary data for modulation

% Define Modulation Schemes

% On-Off Keying: 0 -> 0, 1 -> 1


signalOOK = binaryData;
% Phase Reversal Keying: 0 -> -1, 1 -> 1
signalPRK = (binaryData.*2) - 1;
% Frequency Shift Keying: 0 -> 1, 1 -> i
% Frequency Shift Keying: 0 -> 1, 1 -> i
signalFSK = zeros(1, numBits);
signalFSK(binaryData==1) = 1i;
signalFSK(binaryData==0) = 1;

% Modulation Using Built-in Functions


% Built-in OOK modulation (2 symbols)
modOOK_builtin = genqammod(binaryData, [0 1]);
% Built-in Phase Shift Keying modulation
modPRK_builtin = pskmod(binaryData, 2);
% Built-in FSK modulation
modFSK_builtin = genqammod(binaryData,[1 1i]);
% Random symbols for 16-QAM
qamSymbols = randi([0, 15], 1, numBits);
% Built-in QAM modulation (16-QAM)
modQAM_builtin = qammod(qamSymbols, 16);
runs = 5;
% Simulation Over SNR Range
for snrIndex = 1:length(SNR_dB)
iteration = snrIndex
cumulative_errors_OOK = 0;
cumulative_errors_PRK = 0;
cumulative_errors_FSK = 0;
cumulative_errors_OOK_builtin = 0;
cumulative_errors_PRK_builtin = 0;
cumulative_errors_FSK_builtin = 0;
cumulative_errors_QAM = 0;
for i = 1:runs
run = i
% OOK Modulation Simulation

15
EEC 481 - Digital Communications Project

power_OOK = mean(abs(signalOOK).^2);
%applying the noise on OOK sequence
noise_ook = (sqrt(power_OOK/(2*SNR_linear(snrIndex))))...
*(randn(1,numBits)+(1j*randn(1,numBits)));
% Add noise
receivedOOK = signalOOK+noise_ook;
% Demodulate OOK
demodOOK = (real(receivedOOK) >= 0.5);

% Calculate BER
[~,err] = biterr(binaryData, demodOOK);
cumulative_errors_OOK = cumulative_errors_OOK + err;

% PRK Modulation Simulation


power_PRK=mean(abs(signalPRK.^2));

%applying the noise on PRK sequence


noise_prk= (sqrt(power_PRK/(2*SNR_linear(snrIndex))))...
*(randn(1,numBits)+(1j*randn(1,numBits)));

% Add noise
receivedPRK = signalPRK+ noise_prk;

% Demodulate PRK
demodPRK = (real(receivedPRK) >= 0);

% Calculate BER
[~,err] = biterr(binaryData, demodPRK);
cumulative_errors_PRK = cumulative_errors_PRK + err;

% FSK Modulation Simulation


power_FSK = mean(abs(signalFSK).^2);
noise_fsk = (sqrt(power_FSK/(2*SNR_linear(snrIndex))))...
* (randn(1, numBits) + (1j * randn(1, numBits)));
receivedFSK = signalFSK + noise_fsk; % Add noise
% Demodulate FSK
demodFSK = real(receivedFSK) < abs(imag(receivedFSK));
% Calculate BER
[~,err] = biterr(binaryData, demodFSK);
cumulative_errors_FSK = cumulative_errors_FSK + err;

% OOK Modulation Using Built-in Functions


power_OOK_builtin = mean(abs(modOOK_builtin).^2);
noise_ook_builtin = (sqrt(power_OOK_builtin/(2*SNR_linear(snrIndex))))...
*(randn(1,numBits)+(1j*randn(1,numBits)));
% Add noise
receivedOOK_builtin = modOOK_builtin + noise_ook_builtin;
% Demodulate OOK
demodOOK_builtin = genqamdemod(receivedOOK_builtin, [0 1]);
% Calculate BER
[~,err] = biterr(binaryData, demodOOK_builtin);
cumulative_errors_OOK_builtin = cumulative_errors_OOK_builtin...
+ err;

% PRK Modulation Using Built-in Functions


power_PRK_builtin = mean(abs(modPRK_builtin).^2);
noise_prk_builtin = (sqrt(power_PRK_builtin/...
(2*SNR_linear(snrIndex))))*(randn(1,numBits)+(1j*randn(1,numBits)));
receivedPRK_builtin = modPRK_builtin + noise_prk_builtin;
% Demodulate PRK
demodPRK_builtin = pskdemod(receivedPRK_builtin, 2);
[~,err] = biterr(binaryData, demodPRK_builtin);

16
EEC 481 - Digital Communications Project

cumulative_errors_PRK_builtin = cumulative_errors_PRK_builtin...
+ err; % Calculate BER

% FSK Modulation Using Built-in Functions


power_FSK_builtin = mean(abs(modFSK_builtin).^2);
noise_fsk_builtin = (sqrt(power_FSK_builtin/...
(2*SNR_linear(snrIndex))))*...
(randn(1,numBits)+(1j*randn(1,numBits)));
% Add noise
receivedFSK_builtin = modFSK_builtin + noise_fsk;
% Demodulate FSK
demodFSK_builtin = genqamdemod(receivedFSK_builtin,[1 1i]);
% Calculate BER
[~,err] = biterr(binaryData, demodFSK_builtin);
cumulative_errors_FSK_builtin = ...
cumulative_errors_FSK_builtin + err;

% QAM Modulation Using Built-in Functions (16-QAM)


power_QAM = mean(abs(modQAM_builtin).^2);
%applying the noise on QAM sequence
noise_qam=(sqrt(power_QAM/(2*SNR_linear(snrIndex))))...
*(randn(1,numBits)+(1j*randn(1,numBits)));
% Add noise
receivedQAM_builtin = modQAM_builtin+noise_qam;
% Demodulate QAM
demodQAM_builtin = qamdemod(receivedQAM_builtin, 16);
[~,err] = symerr(qamSymbols, demodQAM_builtin);
% Calculate SER
cumulative_errors_QAM = cumulative_errors_QAM + err;
end
berOOK(snrIndex) = cumulative_errors_OOK/runs;
berPRK(snrIndex) = cumulative_errors_PRK/runs;
berFSK(snrIndex) = cumulative_errors_FSK/runs;
berOOK_builtin(snrIndex) = cumulative_errors_OOK_builtin/runs;
berPRK_builtin(snrIndex) = cumulative_errors_PRK_builtin/runs;
berFSK_builtin(snrIndex) = cumulative_errors_FSK_builtin/runs;
berQAM_builtin(snrIndex) = cumulative_errors_QAM/runs;
end
% Constellation Diagram for 16-QAM (for visualization at SNR = 15 dB)
% SNR for the constellation diagram
snrForConstellation = 15;
% Reference constellation for 16-QAM
constellationReference = qammod(0:15, 16);
constellationViewer = comm.ConstellationDiagram(’ReferenceConstellation’,...
constellationReference, ’XLimits’, [-4 4], ’YLimits’, [-4 4]);
% Generate random QAM data
qamData = randi([0, 15], numBits, 1);
% Modulate data using 16-QAM
qamSymbols = qammod(qamData, 16);
% Add AWGN to the QAM symbols
receivedSymbols = awgn(qamSymbols, snrForConstellation);
% Display the constellation diagram
step(constellationViewer, receivedSymbols);

% ------------------------
% Find SNR at Target BER
% ------------------------
targetBER = 1e-5; % nearly without error

% Function to find the first SNR where BER is <= targetBER


findSNRatTargetBER = @(berArray) find(berArray <= targetBER, 1, ’first’);

17
EEC 481 - Digital Communications Project

% Find SNR index for each modulation type


snrIndexOOK = findSNRatTargetBER(berOOK);
snrIndexPRK = findSNRatTargetBER(berPRK);
snrIndexFSK = findSNRatTargetBER(berFSK);
snrIndexOOK_builtin = findSNRatTargetBER(berOOK_builtin);
snrIndexPRK_builtin = findSNRatTargetBER(berPRK_builtin);
snrIndexFSK_builtin = findSNRatTargetBER(berFSK_builtin);
snrIndexQAM_builtin = findSNRatTargetBER(berQAM_builtin);

% Display the results


fprintf(’SNR for OOK (manual) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexOOK));
fprintf(’SNR for PRK (manual) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexPRK));
fprintf(’SNR for FSK (manual) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexFSK));
fprintf(’SNR for OOK (built-in) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexOOK_builtin));
fprintf(’SNR for PRK (built-in) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexPRK_builtin));
fprintf(’SNR for FSK (built-in) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexFSK_builtin));
fprintf(’SNR for QAM (built-in) to reach BER <= %.0e: %.2f dB\n’,...
targetBER, SNR_dB(snrIndexQAM_builtin));

% ----------------------------
% Theoretical Pe for 16 QAM
% ----------------------------
M = 16; % Size of the QAM modulation alphabet

% Define the Q function


Q = @(x) 0.5*erfc(x/sqrt(2));

% Initialize a vector to store the theoretical probability of error values


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

% Calculate Pe for each SNR value


for snr_index = 1:length(SNR_dB)
Pe_QAM(snr_index) = ...
4 * Q(sqrt(3 * SNR_linear(snr_index) / (M-1))); % Symbol error rate.
end

% Print the Pe for 16-QAM for each SNR


fprintf(’\n----- Theoretical Probability of Error (Pe) for 16-QAM -----\n’);
fprintf(’SNR (dB) | Pe \n’);
fprintf(’-------------------------\n’);
for snr_index = 1:length(SNR_dB)
fprintf(’%8.2f | %12.4e\n’, SNR_dB(snr_index), Pe_QAM(snr_index));
end

% Plot BER vs. SNR for all modulation schemes


figure;
semilogy(SNR_dB, berOOK, ’r-*’, ’LineWidth’,1.5);hold on; % Plot OOK BER
semilogy(SNR_dB, berOOK_builtin, ’b--o’,...
’LineWidth’, 1.5); % Plot OOK (built-in) BER
semilogy(SNR_dB, berPRK, ’g-*’, ’LineWidth’, 1.5); % Plot PRK BER
semilogy(SNR_dB, berPRK_builtin, ’m--+’,...
’LineWidth’, 1.5); % Plot PRK (built-in) BER
semilogy(SNR_dB, berFSK, ’c-*’, ’LineWidth’, 1.5); % Plot FSK BER
semilogy(SNR_dB, berFSK_builtin, ’k--s’,...
’LineWidth’, 1.5); % Plot FSK (built-in) BER
semilogy(SNR_dB, berQAM_builtin, ’color’,...

18
EEC 481 - Digital Communications Project

[237/255, 177/255, 200/255], ’LineWidth’, 1.5); % Plot QAM (built-in) BER


title(’BER vs. SNR for QAM’);
xlabel(’SNR (dB)’); ylabel(’Bit Error Rate (BER)’);
title(’BER vs. SNR for Various Modulation Schemes’);
xlabel(’SNR (dB)’); ylabel(’Bit Error Rate (BER)’);
legend(’OOK (Manual)’, ’OOK (Built-in)’, ’PRK (Manual)’,...
’PRK (Built-in)’, ’FSK (Manual)’, ’FSK (Built-in)’, ’QAM (Built-in)’);
grid on;

figure;
semilogy(SNR_dB, Pe_QAM, ’color’, [0.75, 0.5, 0.5],...
’LineWidth’, 2, ’LineStyle’,’--’); % Plot theoretical Pe for QAM
legend(’Theoratical Pe 16-QAM’);
grid on;
title(’Theoratical Pe vs. SNR for 16-QAM Modulation’);
xlabel(’SNR (dB)’); ylabel(’Pe’);

2.2 Results:

Figure 22: BER vs. SNR for Various Modulation Schemes

19
EEC 481 - Digital Communications Project

Figure 23: Probability of Error for 16-QAM

Figure 24: 16-QAM Constellation Diagram

20
EEC 481 - Digital Communications Project

SNR for OOK (manual) to reach BER <= 1e-05: 14.00 dB


SNR for PRK (manual) to reach BER <= 1e-05: 10.00 dB
SNR for FSK (manual) to reach BER <= 1e-05: 14.00 dB
SNR for OOK (built-in) to reach BER <= 1e-05: 14.00 dB
SNR for PRK (built-in) to reach BER <= 1e-05: 10.00 dB
SNR for FSK (built-in) to reach BER <= 1e-05: 14.00 dB
SNR for QAM (built-in) to reach BER <= 1e-05: 22.00 dB

----- Theoretical Probability of Error (Pe) for 16-QAM -----


SNR (dB) | Pe
-------------------------
0.00 | 1.3094e+00
2.00 | 1.1469e+00
4.00 | 9.5691e-01
6.00 | 7.4446e-01
8.00 | 5.2258e-01
10.00 | 3.1460e-01
12.00 | 1.5002e-01
14.00 | 5.0003e-02
16.00 | 9.5532e-03
18.00 | 7.6363e-04
20.00 | 1.5488e-05
22.00 | 3.6024e-08
24.00 | 2.7241e-12
26.00 | 9.0696e-19
28.00 | 5.5841e-29
30.00 | 4.1770e-45

2.3 Comment:
The PRK modulation scheme the best performance over AWGN channels. The system starts to be error free at
≈ 10.00dB.
PRK’s robustness stems from its focus on phase modulation, which aligns well with the characteristics of AWGN.
The simplicity of detection, energy efficiency, and resistance to amplitude distortions make PRK particularly effective
in these environments.
Next is the FSK modulation scheme: system starts to be error free at ≈ 14.00dB, followed by OOK modulation
scheme, where system starts to be error free at ≈ 16dB. Last is 16-QAM, where system starts to be error free at
≈ 22dB.

21
EEC 481 - Digital Communications Project

3 Part III: Performance of Different Modulation Techniques in Binary


Symmetric Channel
3.1 Code:
clc; close all;

%% Performance of Different Modulation Types in BSC

% Parameters
NumberOfBits = 1e6; % Number of bits
p_values = 0:0.1:1; % Crossover probabilities for BSC
BinaryBits = randi([0 1], 1, NumberOfBits); % Generate binary data

% BER Storage
BER_OOK_BSC = zeros(1, length(p_values));
BER_PRK_BSC = zeros(1, length(p_values));
BER_FSK_BSC = zeros(1, length(p_values));

%% BSC Implementation
sequence_length = NumberOfBits;
simulation_runs = 5; % Single simulation run for simplicity in this case

for idx = 1:length(p_values)


current_prob = p_values(idx);
cumulative_errors_OOK = 0;
cumulative_errors_PRK = 0;
cumulative_errors_FSK = 0;

for run = 1:simulation_runs


% Generate source bits
source_sequence = BinaryBits;

% Channel effect simulation


if current_prob == 0 || current_prob == 1
% Perfect channel (no distortion)
received_sequence = source_sequence;
elseif current_prob <= 0.5
channel_distortion = rand(1, sequence_length) < current_prob;
received_sequence = xor(source_sequence, channel_distortion);
else
% Inverter logic for high probabilities (p > 0.5)
inverted_prob = 1 - current_prob;
channel_distortion = rand(1, sequence_length) < inverted_prob;
received_sequence = xor(~source_sequence, channel_distortion); % Inverted reception
received_sequence = ~received_sequence; % Revert sequence to original logic
end

% OOK Errors
cumulative_errors_OOK = cumulative_errors_OOK + sum(source_sequence ~= received_sequence);

% PRK Errors
signal_PRK = 2 * source_sequence - 1;
received_PRK = 2 * received_sequence - 1;
cumulative_errors_PRK = cumulative_errors_PRK + sum(signal_PRK ~= received_PRK);

% Orthogonal-FSK Errors
signal_FSK = zeros(1, sequence_length);
for n = 1:sequence_length
if source_sequence(n) == 0
signal_FSK(n) = 1;
else

22
EEC 481 - Digital Communications Project

signal_FSK(n) = 1i;
end
end
received_FSK = zeros(1, sequence_length);
for n = 1:sequence_length
if received_sequence(n) == 0
received_FSK(n) = 1;
else
received_FSK(n) = 1i;
end
end
cumulative_errors_FSK = cumulative_errors_FSK + sum(signal_FSK ~= received_FSK);
end

% Calculate BER
BER_OOK_BSC(idx) = cumulative_errors_OOK / (sequence_length * simulation_runs);
BER_PRK_BSC(idx) = cumulative_errors_PRK / (sequence_length * simulation_runs);
BER_FSK_BSC(idx) = cumulative_errors_FSK / (sequence_length * simulation_runs);
end

%% Plot BER for All Modulation Schemes


figure;
subplot(1,3,1)
plot(p_values, BER_OOK_BSC, ’-o’, ’DisplayName’, ’OOK’);
ylim([0 1]); % Y-axis range: 0 to 1
yticks(0:0.1:1); % Uniform y-ticks (0 to 1 at 0.1 intervals)
grid on; % Display grid for readability
xlabel(’Crossover Probability (p)’);
ylabel(’Bit Error Rate (BER)’);
grid on;
legend show;
subplot(1,3,2)
plot(p_values, BER_PRK_BSC, ’-s’, ’DisplayName’, ’PRK’);
ylim([0 1]); % Y-axis range: 0 to 1
yticks(0:0.1:1); % Uniform y-ticks (0 to 1 at 0.1 intervals)
grid on; % Display grid for readability
xlabel(’Crossover Probability (p)’);
ylabel(’Bit Error Rate (BER)’);
grid on;
legend show;
subplot(1,3,3)
plot(p_values, BER_FSK_BSC, ’-^’, ’DisplayName’, ’FSK’);
ylim([0 1]); % Y-axis range: 0 to 1
yticks(0:0.1:1); % Uniform y-ticks (0 to 1 at 0.1 intervals)
grid on; % Display grid for readability
xlabel(’Crossover Probability (p)’);
ylabel(’Bit Error Rate (BER)’);
grid on;
legend show;
sgtitle(’BER vs. Crossover Probability for Different Modulation Schemes’);

23
EEC 481 - Digital Communications Project

3.2 Results:

3.3 Comment:
All modulation schemes perform equally in a binary symmetric channel since it only transmits either a 0 or a 1.
Performance depends on Flipping probability p which is a channel characteristic and is independent of the input
sequence.

24

You might also like