Digitalcomm Project
Digitalcomm Project
Project
Shrook Abdelkhalek
20010726
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
1
EEC 481 - Digital Communications Project
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);
1.2 m = 20
1.2.1 Inputs
5
EEC 481 - Digital Communications Project
1.2.4 Correlator
6
EEC 481 - Digital Communications Project
1.2.5 Comparison
7
EEC 481 - Digital Communications Project
1.2.7 Outputs
1.3 m = 10
1.3.1 Inputs
8
EEC 481 - Digital Communications Project
1.3.4 Correlator
9
EEC 481 - Digital Communications Project
1.3.5 Comparison
10
EEC 481 - Digital Communications Project
1.3.7 Outputs
1.4 m = 100
1.4.1 Inputs
11
EEC 481 - Digital Communications Project
1.4.4 Correlator
12
EEC 481 - Digital Communications Project
1.4.5 Comparison
13
EEC 481 - Digital Communications Project
1.4.7 Outputs
14
EEC 481 - Digital Communications Project
% 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
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;
% 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;
16
EEC 481 - Digital Communications Project
cumulative_errors_PRK_builtin = cumulative_errors_PRK_builtin...
+ err; % Calculate BER
% ------------------------
% Find SNR at Target BER
% ------------------------
targetBER = 1e-5; % nearly without error
17
EEC 481 - Digital Communications Project
% ----------------------------
% Theoretical Pe for 16 QAM
% ----------------------------
M = 16; % Size of the QAM modulation alphabet
18
EEC 481 - Digital Communications Project
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:
19
EEC 481 - Digital Communications Project
20
EEC 481 - Digital Communications Project
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
% 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
% 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
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