0% found this document useful (0 votes)
15 views17 pages

PRogram CN

The document outlines several experiments conducted using MATLAB to analyze various aspects of wireless communication, including path loss modeling using the Hata model, Bit Error Rate (BER) performance over Rayleigh fading channels, Doppler shift calculations, and simulations of OFDM systems. It also includes simulations for cellular systems to evaluate user capacity and performance parameters in mobile environments. Each experiment is accompanied by MATLAB code for implementation and graphical output for analysis.
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)
15 views17 pages

PRogram CN

The document outlines several experiments conducted using MATLAB to analyze various aspects of wireless communication, including path loss modeling using the Hata model, Bit Error Rate (BER) performance over Rayleigh fading channels, Doppler shift calculations, and simulations of OFDM systems. It also includes simulations for cellular systems to evaluate user capacity and performance parameters in mobile environments. Each experiment is accompanied by MATLAB code for implementation and graphical output for analysis.
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/ 17

Expt 1.

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 to simulate Hata-Okumura Models


clc;clear all;
%----------Input Section---------------
Hbts= 50 ;%Height measured from the base of the BTS tower to the radiation
centerline
Tbts = 350 ;%Terrain elevation at the location of the BTS
Htav= 300;%Height of the average terrain (from 3 Km to 15 km distance from
the BTS)
Hm=3 ;%Height of the mobile antenna in meters
f=900 ;%100:100:3000; %Range of frequencies in MHz
d=0.5:0.5:15; %Range of Tx-Rx separation distances in Kilometers
Pt = 0.020; %Power transmitted by the BTS antenna in Watts
Gt= 10; %BTS antenna gain in dBi
%--------------------------------------
Hb=Hbts+Tbts-Htav ;%Effective Height of the BTS antenna in meters
%Cell array to store various model names
models = {'Big City (Urban model)';'Small & Medium City (Urban model)';'Sub-
urban environment';'Open Rural environment'};
display('Hata-Okumura Model');
display(['1 ' models{1,1}]);
display(['2 ' models{2,1}]);
display(['3 ' models{3,1}]);
display(['4 ' models{4,1}]);
reply = input('Select Your choice of environment : ','s');
if 0<str2num(reply)<4
modelName = models{str2num(reply),1};
display(['Chosen Model : ' modelName])
else
error('Invalid Selection');
end
switch reply
case '1',
C=0;
if f<=200
aHm=8.29*(log10(1.54*Hm))^2-1.1;
else
aHm=3.2*(log10(11.75*Hm))^2-4.97;
end
case '2',
C=0;
aHm = (1.1*log10(f)-0.7)*Hm-(1.56*log10(f)-0.8);
case '3',
aHm = (1.1*log10(f)-0.7)*Hm-(1.56*log10(f)-0.8);
C=-2*(log10(f/28))^2-5.4;
case '4',
aHm = (1.1*log10(f)-0.7)*Hm-(1.56*log10(f)-0.8);
C=-4.78*(log10(f))^2+18.33*log10(f)-40.98;
otherwise ,
error('Invalid model selection');
end

A = 69.55 + 26.16*log10(f) - 13.82*log10(Hb)-aHm;


B = 44.9 - 6.55*log10(Hb);
PL=A+B*log10(d)+C;
subplot(2,1,1)
plot(d,PL,'r','LineWidth',2);
title(['Hata-Okumura Path Loss Model for : ' modelName]);
xlabel('Distance - Kilometers');
ylabel('Path Loss (dB)');
%Compute Received Signal Level
Pr = 10*log10(Pt*1000)+Gt-PL
subplot(2,1,2)
plot(d,Pr,'r','LineWidth',2);
title(['Hata-Okumura Model for : ' modelName]);
xlabel('Distance - Kilometers');
ylabel('Received Signal Level (dBm)');
Output
Expt 2 Simulate BER performance over a Rayleigh fading wireless channel
with BPSK transmission for SNR: 0 to 50 dB.

Matlab Code
% MATLAB Script for computing the BER for BPSK modulation in a
% Rayleigh fading channel and compred to AWGN Channel

% Clear all the previously used variables


clear all;

format long;

% Frame Length
bit_count = 10000;

%Range of SNR over which to simulate


SNR = 0: 1: 40;

% Start the main calculation loop


for aa = 1: 1: length(SNR)

% Initiate variables
T_Errors = 0;
T_bits = 0;

% Keep going until you get 100 errors


while T_Errors < 100

% Generate some random bits


uncoded_bits = round(rand(1,bit_count));

% BPSK modulator
tx = -2*(uncoded_bits-0.5);

% Noise variance
N0 = 1/10^(SNR(aa)/10);

% Rayleigh channel fading


h = 1/sqrt(2)*[randn(1,length(tx)) + 1j*randn(1,length(tx))];

% Send over Gaussian Link to the receiver


rx = h.*tx + sqrt(N0/2)*(randn(1,length(tx))+1j*randn(1,length(tx)));

%---------------------------------------------------------------

% Equalization to remove fading effects. Ideal Equalization


% Considered
rx = rx./h;

% BPSK demodulator at the Receiver


rx2 = rx < 0;
% Calculate Bit Errors
diff = uncoded_bits - rx2;
T_Errors = T_Errors + sum(abs(diff));
T_bits = T_bits + length(uncoded_bits);

end
% Calculate Bit Error Rate
BER(aa) = T_Errors / T_bits;
disp(sprintf('bit error probability = %f',BER(aa)));

end

%------------------------------------------------------------

% Finally plot the BER Vs. SNR(dB) Curve on logarithmic scale


% Calculate BER through Simulation

% Rayleigh Theoretical BER


SNRLin = 10.^(SNR/10);
theoryBer = 0.5.*(1-sqrt(SNRLin./(SNRLin+1)));

% 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;

v=26.82; %velocity in m/s, 60miles/hr


f=50000000:50000000:300000000; % frequencies in MHz

C=0.866; %cos30

s = 3*10^8; %speed of light

for aa = 1: 1: length(f)
lamda= s./f; % wavelength for each frequency
a = v./lamda;

deltaf= a.*C; % doppler shift

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;

n =48; %input('enter N ');


Pb= 0.02; %input('Enter Pb ');
t = 0.04; %input('Per user traffic ');
%cellr = input('Enter Cell radius ');
area = 603; %input('Enter area ');
A = input('Enter total traffic 38.4 for n=48 and pb=0.02');
N=A/t;
disp(N);
cellr = 0.500: 0.100 : 1.500;

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.

# Simulation parameters setup


set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 7 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1151 ;# X dimension of
topography
set val(y) 900 ;# Y dimension of
topography
set val(stop) 10.0 ;# time of simulation end

# Initialization
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

# Mobile node parameter setup


$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

# 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

set n1 [$ns node]


$n1 set X_ 527
$n1 set Y_ 300
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20

set n2 [$ns node]


$n2 set X_ 672
$n2 set Y_ 305
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20

set n3 [$ns node]


$n3 set X_ 867
$n3 set Y_ 304
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20

set n4 [$ns node]


$n4 set X_ 1051
$n4 set Y_ 302
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20

set n5 [$ns node]


$n5 set X_ 292
$n5 set Y_ 438
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

set n6 [$ns node]


$n6 set X_ 349
$n6 set Y_ 58
$n6 set Z_ 0.0
$ns initial_node_pos $n6 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
}

for {set i 0} {$i < $val(nn) } { incr i } {


$ns at $val(stop) "\$n$i reset"
}

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"


$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
OUTPUT

You might also like