You are on page 1of 11

Experiment-7

Aim: Power Delay profile metrices computation in MATLAB.

Code:
% Power Delay profile metrices

clear all;
close all;
clc;

L = 4;
Delay = [0, 1, 3, 5];
Gains = [-20, -10, 0, -10];
Gains_linear = 10.^(Gains./10);
Delay_spread = max(Delay) - min(Delay);
disp(Delay_spread);
Summ = sum(Delay .* Gains_linear);
gains_sum = sum(Gains_linear);
Mean_Delay = Summ / gains_sum;
disp(Mean_Delay);
square_root_gains = sqrt(gains_sum);

new_array_delay = (Delay - Mean_Delay).^2;


square_num = sqrt(sum(new_array_delay .* Gains_linear));
RMS = square_num / square_root_gains;
disp(RMS);

figure;
stem(Delay, Gains);
xlabel("Delay in us");
ylabel("Gains in dB");
title("PDP Plot");
Output:
Experiment-8
Aim: Simulation of log distance and log normal shadowing path loss model in
MATLAB for different path loss exponent

% Log normal and log distance comparison


close all;
clear all;
clc;
do=100;
PL_do=60;
d=1:0.1:1000;
n=[2,3.5,5,1.8,6,3];
%Log Distance model
PL1= PL_do+ 10*n(1)*log10(d/do);
PL2= PL_do+ 10*n(2)*log10(d/do);
PL3= PL_do+ 10*n(3)*log10(d/do);
PL4= PL_do+ 10*n(4)*log10(d/do);
PL5= PL_do+ 10*n(5)*log10(d/do);
PL6= PL_do+ 10*n(6)*log10(d/do);
figure;
plot(d,PL1,d,PL2,d,PL3,d,PL4,d,PL5,d,PL6,'linewidth',1.4);
legend('n=2','n=3.5','n=5','n=1.8','n=6','n=3');
xlabel('Distance (m)');
ylabel('PL (dBm)');

title('Log Distance Shadowing Model');


%Log Normal Distance model
Xo = abs(randn)*6;
PLN1= PL_do+ 10*n(1)*log10(d/do)+Xo;
PLN2= PL_do+ 10*n(2)*log10(d/do)+Xo;
PLN3= PL_do+ 10*n(3)*log10(d/do)+Xo;
PLN4= PL_do+ 10*n(4)*log10(d/do)+Xo;
PLN5= PL_do+ 10*n(5)*log10(d/do)+Xo;
PLN6= PL_do+ 10*n(6)*log10(d/do)+Xo;
figure;
plot(d,PLN1,d,PLN2,d,PLN3,d,PLN4,d,PLN5,d,PLN6,'linewidth',1.4);
legend('n=2','n=3.5','n=5','n=1.8','n=6','n=3');
xlabel('Distance (m)'); ylabel('PL (dBm)');
title('Log Normal Shadowing Model');
%Log Normal Shadowing Model vs Log Distance Shadowing
Model figure;
plot(d,PLN1,'--',d,PLN2,'--',d,PLN3,'-',d,PL1,d,PL2,d,PL3,'linewidth',1.4);
legend('n=2 (LN)','n=3.5 (LN)','n=5 (LN)','n=2 (LD)','n=3.5 (LD)','n=5 (LD)');
xlabel('Distance (m)');
ylabel('PL (dBm)');
title('Log_Normal_Shadowing Model vs Log_Distance_Shadowing Model');
%Log Distance
clear all ;
close all ;
clc;
d=0:0.1:1000;
d0=100;
n1=2;
n2=3;
n3=4;
n4=5;
pl=60;
pl_log_distance1=pl+10*n1*log(d/d0);
pl_log_distance2=pl+10*n2*log(d/d0);
pl_log_distance3=pl+10*n3*log(d/d0);
pl_log_distance4=pl+10*n4*log(d/d0);
figure;
plot(d,pl_log_distance1,'r')
hold on
plot(d,pl_log_distance2,'b')
hold on
plot(d,pl_log_distance3,'g')
hold on
plot(d,pl_log_distance4,'y')
title("LOG DISTANCE PATH LOSS MODEL") ;
xlabel("Distance") ;
ylabel("Path Loss") ;

% Log normal Shadowing model


close all;
clear all;
clc;
do=100;
PL_do=60;
d=1:0.1:1000;
n=[2,3.5,5,1.8,6,3];
%Log Distance model
PL1= PL_do+ 10*n(1)*log10(d/do);
PL2= PL_do+ 10*n(2)*log10(d/do);
PL3= PL_do+ 10*n(3)*log10(d/do);
PL4= PL_do+ 10*n(4)*log10(d/do);
PL5= PL_do+ 10*n(5)*log10(d/do);
PL6= PL_do+ 10*n(6)*log10(d/do);
plot(d,PL1,d,PL2,d,PL3,d,PL4,d,PL5,d,PL6,'linewidth',2);
legend('n=2','n=3.5','n=5','n=1.8','n=6','n=3');
xlabel('Distance (m)');
ylabel('PL (dBm)');
title('Log Normal Shadowing Model');
Experiment-9
Aim: Implementation of Analytical BER for AWGN channel and Rayleigh
channel with BPSK modulation

Code:
% BER for AWGN

clear all;
close all;
clc;

snr = -4:2:10;
snr_linear = 10.^(snr/10);
ber_awgn_exact = qfunc(sqrt(snr_linear));
ber_awgn_approx = 0.5*exp(-snr_linear./2);
ber_rayleigh_exact = (0.5 - 0.5*sqrt(snr_linear./(snr_linear + 2)));

figure;
semilogy(snr, ber_awgn_exact, ':', 'linewidth', 3);
title("AWGN Exact and Approx BER and Rayleigh");
xlabel("SNR (dB)");
ylabel("BER");
hold on;
semilogy(snr, ber_awgn_approx, '--');
hold on;
semilogy(snr, ber_rayleigh_exact, 'g');
legend("AWGN Exact", "AWGN Approx", "Rayleigh Exact");
Output:
Experiment-10
Aim:Simulate the wired as well as wireless communication system in terms
of BER using MATLAB

Code:
% Simulate Wired and Wireless Communication Systems (Binary PAM and BPSK)
clear all;
close all;
clc;

% Parameters
SNR_dB = 0:1:10;
N_bits = 1e5;
M = 2;
Eb = 1;

% Generate binary data


data = randi([0,1],1,N_bits);

% Modulation (Binary PAM)


symbols_pam = 2*data - 1; % Binary PAM modulation

% Modulation (BPSK)
symbols_bpsk = 2*data - 1; % BPSK modulation

% Initialization
BER_pam = zeros(size(SNR_dB));
BER_bpsk = zeros(size(SNR_dB));
% Noise variance calculation (assuming AWGN channel)
for i = 1:length(SNR_dB)
SNR_linear = 10^(SNR_dB(i)/10);
sigma_pam = sqrt(Eb/(2*SNR_linear));
sigma_bpsk = sqrt(Eb/SNR_linear);

% Add noise for Binary PAM


noise_pam = sigma_pam * randn(size(symbols_pam));
received_pam = symbols_pam + noise_pam;
demodulated_pam = received_pam > 0;
BER_pam(i) = sum(demodulated_pam ~= data)/N_bits;

% Add noise for BPSK


noise_bpsk = sigma_bpsk * randn(size(symbols_bpsk));
received_bpsk = symbols_bpsk + noise_bpsk;
demodulated_bpsk = received_bpsk > 0;
BER_bpsk(i) = sum(demodulated_bpsk ~= data)/N_bits;
end

% Plot
figure;
semilogy(SNR_dB,BER_pam,'b-o',SNR_dB,BER_bpsk,'r-o');
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('Bit Error Rate Comparison for Binary PAM and BPSK');
legend('Binary PAM (Wired)', 'BPSK (Wireless)');
grid on;
Output:

You might also like