PRogram CN
PRogram CN
Compute and compare the median loss by employing Hata model for various
distance for carrier frequencies of 2.1 GHz and 6 GHz. Assume transmit and receive
antenna heights of 40 m and 2 m in a large city. Plot the graph of path loss vs distance.
Matlab Code
Matlab Code
% MATLAB Script for computing the BER for BPSK modulation in a
% Rayleigh fading channel and compred to AWGN Channel
format long;
% Frame Length
bit_count = 10000;
% Initiate variables
T_Errors = 0;
T_bits = 0;
% BPSK modulator
tx = -2*(uncoded_bits-0.5);
% Noise variance
N0 = 1/10^(SNR(aa)/10);
%---------------------------------------------------------------
end
% Calculate Bit Error Rate
BER(aa) = T_Errors / T_bits;
disp(sprintf('bit error probability = %f',BER(aa)));
end
%------------------------------------------------------------
% Start Plotting
% Rayleigh Theoretical BER
figure(1);
semilogy(SNR,theoryBer,'-','LineWidth',2);
hold on;
% Simulated BER
figure(1);
semilogy(SNR,BER,'or','LineWidth',2);
hold on;
xlabel('SNR (dB)');
ylabel('BER');
title('SNR Vs BER plot for BPSK Modualtion in Rayleigh Channel');
% Theoretical BER
figure(1);
theoryBerAWGN = 0.5*erfc(sqrt(10.^(SNR/10)));
semilogy(SNR,theoryBerAWGN,'blad-','LineWidth',2);
legend('Rayleigh Theoretical','Rayleigh Simulated', 'AWGN Theoretical');
axis([0 40 10^-5 0.5]);
grid on;
Expt. 6 Compute doppler shift of the received signal for different carrier
frequency of mobile generations by considering vehicle is moving at 60 miles
per hour at an angle of 30 degree with the line joining the base station.
MATLAB Code
clear;
C=0.866; %cos30
for aa = 1: 1: length(f)
lamda= s./f; % wavelength for each frequency
a = v./lamda;
disp(deltaf);
F=f+deltaf;
end
plot(f,deltaf,'r-o')
grid on;
title('Frequency Vs. Doppler Shift');
xlabel('Frequency in MHz');ylabel('Doppler shift');
OUTPUT
Expt. 7 Program to implement OFDM and evaluate frame
error rate against SNR
MATLAB Code
%IEEE 802.11 specification
clear; clc;
%--------Simulation parameters----------------
nSym=10^4; %Number of OFDM Symbols to transmit
EbN0dB = -20:2:8; % bit to noise ratio
%-----------------------------------
%--------OFDM Parameters - Given in IEEE Spec--
N=64; %FFT size or total number of subcarriers (used + unused) 64
Nsd = 48; %Number of data subcarriers 48
Nsp = 4 ; %Number of pilot subcarriers 4
ofdmBW = 20 * 10^6 ; % OFDM bandwidth
%----------------------------------------------
%--------Derived Parameters--------------------
deltaF = ofdmBW/N; %=20 MHz/64 = 0.3125 MHz
Tfft = 1/deltaF; % IFFT/FFT period = 3.2us
Tgi = Tfft/4;%Guard interval duration - duration of cyclic prefix
Tsignal = Tgi+Tfft; %duration of BPSK-OFDM symbol
Ncp = N*Tgi/Tfft; %Number of symbols allocated to cyclic prefix
Nst = Nsd + Nsp; %Number of total used subcarriers
nBitsPerSym=Nst; %For BPSK the number of Bits per Symbol is same as num of
subcarriers
%----------------------------------------------
EsN0dB = EbN0dB + 10*log10(Nst/N) + 10*log10(N/(Ncp+N)); % converting to
symbol to noise ratio
errors= zeros(1,length(EsN0dB));
theoreticalBER = zeros(1,length(EsN0dB));
%Monte Carlo Simulation
for i=1:length(EsN0dB),
for j=1:nSym
%-----------------Transmitter--------------------
s=2*round(rand(1,Nst))-1; %Generating Random Data with BPSK modulation
%IFFT block
%Assigning subcarriers from 1 to 26 (mapped to 1-26 of IFFT input)
%and -26 to -1 (mapped to 38 to 63 of IFFT input); Nulls from 27 to 37
%and at 0 position
X_Freq=[zeros(1,1) s(1:Nst/2) zeros(1,11) s(Nst/2+1:end)];
% Pretending the data to be in frequency domain and converting to time domain
x_Time=N/sqrt(Nst)*ifft(X_Freq);
%Adding Cyclic Prefix
ofdm_signal=[x_Time(N-Ncp+1:N) x_Time];
%--------------Channel Modeling ----------------
noise=1/sqrt(2)*(randn(1,length(ofdm_signal))+1i*randn(1,length(ofdm_signal))
);
r= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;
%-----------------Receiver----------------------
%Removing cyclic prefix
r_Parallel=r(Ncp+1:(N+Ncp));
%FFT Block
r_Time=sqrt(Nst)/N*(fft(r_Parallel));
%Extracting the data carriers from the FFT output
R_Freq=r_Time([(2:Nst/2+1) (Nst/2+13:Nst+12)]);
%BPSK demodulation / Constellation Demapper.Force +ve value --> 1, -ve value
--> -1
R_Freq(R_Freq>0) = +1;
R_Freq(R_Freq<0) = -1;
s_cap=R_Freq;
numErrors = sum(abs(s_cap-s)/2); %Count number of errors
%Accumulate bit errors for all symbols transmitted
errors(i)=errors(i)+numErrors;
end
theoreticalBER(i)=(1/2)*erfc(sqrt(10.^(EbN0dB(i)/10))); %Same as BER for BPSK
over AWGN
end
simulatedBER = errors/(nSym*Nst);
plot(EbN0dB,log10(simulatedBER),'r-o');
hold on;
plot(EbN0dB,log10(theoreticalBER),'k*');
grid on;
title('BER Vs EbNodB for OFDM with BPSK modulation over AWGN');
xlabel('Eb/N0 (dB)');ylabel('BER');legend('simulated','theoretical');
Expt. 8 Simulate a cellular system with 48 channels per cell and blocking probability of 2%. Assume
traffic per user is 0.04 E. What is the number pf users that can be supported in a city of 603 km 2 area if
cell radios are changed in the steps of 500 m, 700m, 900 m, 1000 m 1200 m and 1500 m
MATLAB Code
clear;
for aa = 1: 1: length(cellr)
cellarea = 6*cellr.*cellr./sqrt(3); %(3.^(-1/2));
%disp(cellarea);
cells = area./cellarea;
%disp(cells);
users = N * cells;
%disp('No of users = ')
%disp(users);
end
plot(cellr,users,'r-o')
title('Cell Radius Vs. Number of Users supported');
xlabel('Cell Radius in meter');ylabel('Number of Users');
Output
Expt 9 Simulate mobile environment to evaluate performance parameters using any
open source Network Simulator tool.
# Initialization
#Create a ns simulator
set ns [new Simulator]
# Nodes Definition
#Create 7 nodes
set n0 [$ns node]
$n0 set X_ 338
$n0 set Y_ 305
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
# Generate movement
$ns at 1 " $n6 setdest 890 58 75 "
# Agents Definition
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n5 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n6 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
# Applications Definition
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 10.0 "$ftp0 stop"
# Termination
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}