WC Manual
WC Manual
WC Manual
Aim:
To implement Two ray channel Modeling of wireless communication systems using MATLAB.
Software Required:
• MATLAB
Theory:
The two-rays ground-reflection model is a multipath radio propagation model which predicts
the path losses between a transmitting antenna and a receiving antenna when they are in line of sight
(LOS). Generally, the two antenna each have different height. The received signal has two components,
the LOS component and the reflection component formed predominantly by a single ground reflected
wave.
This model takes into account line-of-sight and ground reflection. It is a good approximation for
propagation over a smooth well-reflecting terrain, as modeled by the plane-earth model, with
Matlab Code:
lambda = 0.3;
ht100=100;
ht30=30;
ht2=2;
hr=2;
axis=[];
p100=[];
p30=[];
p2=[];
pfsl=[];
for i=1000:5000
d=10^(i/1000);
axis =[axis d];
fspower = (lambda/(4*3.1415*d))^2 ;
power100 = fspower * 4 *(sin(2*3.1415*hr*ht100/(lambda*d)))^2;
power30 = fspower* 4 *(sin(2*3.1415*hr*ht30/(lambda*d)))^2;
power2 = fspower * 4 *(sin(2*3.1415*hr*ht2/(lambda*d)))^2;
1
p2 =[p2, 10*log10(power2)];
pfsl=[pfsl, 10*log10(fspower)];
end
text('FontSize',18)
xlabel('distance in m');
ylabel('pathloss');
text(1000,-66,'blue : hr=30m');
text(1000,-74,'red : hr=2m');
text(1000,-58,'red : hr=100m');
text(1000,-50,'yellow: free space');
Model Output:
Result :
Thus the two ray channel Modeling of wireless communication systems using MATLAB is
implemented and its path loss is plotted.
2
Ex No : DATE:
Software Required:
• MATLAB
Theory:
The Okumura model is a radio propagation model that was built using the data collected in the city
of Tokyo, Japan. The model is ideal for using in cities with many urban structures but not many tall
blocking structures. The model served as a base for the Hata model.
Okumura model was built into three modes. The ones for urban, suburban and open areas. The model for
urban areas was built first and used as the base for others.
Coverage:
Frequency = 150–1920 MHz
Mobile station antenna height: between 1 m and 3 m
Base station antenna height: between 30 m and 100 m
Link distance: between 1 km and 100 km
The Hata model is a radio propagation model for predicting the path loss of cellular transmissions in
exterior environments, valid for microwave frequencies from 150 to 1500 MHz. It is an empirical
formulation based on the data from the Okumura model, and is thus also commonly referred to as
the Okumura–Hata model. The model incorporates the graphical information from Okumura model and
develops it further to realize the effects of diffraction, reflection and scattering caused by city structures.
Additionally, the Hata Model applies corrections for applications in suburban and rural environments.
for i=1:length(f)
Lfsl = 20*log((4*pi*d)/((3*10^8)/((f(i))*10^6)));
%free space loss
Ghte = 20*log(Hte/200);
%Base station antenna height gain factor
if(Hre>3)
%conditional Statement
Ghre = 20*log(Hre/3);
%Mobile station antenna height gain factor
else
Ghre = 10*log(Hre/3);
end
L(i) = Lfsl+Amu(i)-Ghte-Ghre-Kcor(i);
%formula for path loss
end
disp(L)
%prints the Loss Array
% plot of Frequency vs Loss (dB) for open area
figure(1)
%Enables the figure
plot(f,L);
%versus plotting command
title('Frequency vs Loss (dB) for open area for Okumura Model');
%title of the plot
xlabel('Frequency(MHz)');
%label for X-axis
ylabel('Propagation Path loss(dB)');
%label for Y-axis
grid on;
%Enables Grid feature in plot
Sample Inputs
% 50
4
% 5
% 10
% [200 300 400 500 600 700 800 900 1000 1100]
% [20.4 20.45 20.5 20.55 20.6 20.65 20.7 20.75 20.8 20.85]
% [23 24 25 25.5 26 27 27.5 28 28.75 29]
Sample Output:
Sample Output:
Result:
Thus, the Okumura- Hata Modeling of wireless communication systems using MATLAB is
implemented and its path loss is plotted.
6
Ex No : DATE:
Aim:
Software Required:
• MATLAB
Theory:
Multipath fading occurs when signals reach a receiver via many paths & their relative strengths & phases
change. Multipath fading is a feature that needs to be taken into account when designing or developing a
radio communications system. In any terrestrial radio communications system, the signal will reach the
receiver not only via the direct path, but also as a result of reflections from objects such as buildings,
hills, ground, water, etc that are adjacent to the main path.
• Multipath fading affects most forms of radio communications links in one form or another.
• Multipath fading can affect signals on frequencies from the LF portion of the spectrum and below
right up into the microwave portion of the spectrum.
• Multipath fading occurs in any environment where there is multipath propagation and the paths
change for some reason. This will change not only their relative strengths but also their phases, as the
path lengths will change
• Multipath fading affects most forms of radio communications links in one form or another.
• Multipath fading can affect signals on frequencies from the LF portion of the spectrum and below
right up into the microwave portion of the spectrum.
• Multipath fading occurs in any environment where there is multipath propagation and the paths
change for some reason. This will change not only their relative strengths but also their phases, as the
path lengths will change.
Matlab Code:
7
clear
f_c=1e3;%carrier frequency(no modulation)
time_1 = (linspace (0, 10, 1000));%time
signal_in = sin (2 * pi *f_c* time_1);%sine wave
plot (time_1,(signal_out),'r')%red=signal_out
pause (2)%~ seconds
end
hold off
Sample Output:
Result:
Thus the multipath fading channel is modelled and simulated using MATLAB.
8
Ex No : DATE:
Design, analyze and test Wireless standards and evaluate the performance
measurements such as BER, PER, BLER, throughput, capacity, ACLR,
EVM for 4G using Matlab
Aim:
To Design, analyze and test Wireless standards and evaluate the performance measurements such
as BER, PER, BLER, throughput, capacity, ACLR, EVM for 4G using Matlab.
Software Required:
• MATLAB
Theory:
LTE is a standard of mobile communication developed by 3GPP that has the goal of being the
next generation of mobile communication. It was submitted as 4G system candidate and approved by the
ITU (International Telecommunication Union) as meeting 4G requirements on the release 10, also known
as LTE-A.
Different from 2G, using TDMA and FDMA, and 3G, using CDMA, LTE uses OFDMA
(Orthogonal Frequency-Division Multiplexing Access) as multiple access technology. On OFDM
(Orthogonal Frequency-Division Multiplexing) the signal to be transmitted is decomposed on 'n' signal (it
can be done using a serial/parallel converter).Other advance that LTE systems have is the use of multiple
antenna technique. LTE is the first global mobile cellular system to use MIMO (Multiple-Input Multiple-
Output) technology. The use of multiple antennas can improve significantly the communication
performance through a greater channel capacity.
Bit Error Rate (BER) is a measure of the number of erroneous bits which can be expected in a
specified number of bits in a serial stream.
Packet Error Rate (PER) is a measure of the number of erroneous packets which can be
expected in a specified number of bits in a serial stream.
Block Error Rate (BLER) is defined as the number of erroneous received code blocks/total
number of received code blocks. The code block is considered to be error-free if its attached CRC code
matches the one calculated by the receiver.
9
The channel capacity, C, is defined to be the maximum rate at which information can be
transmitted through a channel.
Adjacent Channel Leakage Ratio (ACLR) or Adjacent Channel Power Ratio (ACPR) is
defined the ratio of the transmitted power on the assigned channel to the power received in the adjacent
radio channel after a receive filter.
The error vector magnitude or EVM (sometimes also called relative constellation error or RCE)
is a measure used to quantify the performance of a digital radio transmitter or receiver.
Matlab Code:
clear all ;
clc ;
%% Defining the antenna arrays
Arrays = arrayparset ;
%% Defining the scenerio with BS , MS , Relays
BsAAIdxCell = {[1]; [2]} ;
MsAAIdx = [2 3];
L =3; % Number of links
S =12; % Identification number of the Scenario
layoutpar = layoutparset ( MsAAIdx , BsAAIdxCell , L, Arrays );
layoutpar . ScenarioVector = S* ones (1,L);
layoutpar . Stations (1) . Pos = [0;0;32]; % Position of BS1
layoutpar . Stations (2) . Pos = [250;250;32]; % Position of BS2
layoutpar . Stations (3) . Pos = [250;250;32]; % Position of MS1
layoutpar . Stations (4) . Pos = [0;500;1.5]; % Position of MS2
%% Defining the pairing of BS , MS , Relays
layoutpar . Pairing = [1 2 1;3 4 4];
%% Defining the initial conditions for the iteration
SER_tot_nc = zeros (11 ,1) ;
SER_tot_c = zeros (11 ,1) ;
SER_tot_wor = zeros (11 ,1) ;
for n =1:5000
wimpar = wimparset ; % Generation the Winner
parameters
[H, delays , out ]= wim ( wimpar , layoutpar ) % Generation
of all the radio links according to the layout
% Processing the bits for Calculation
SP. FFTsize = 512; % The size of the FFT and IFFT
SP. CPsize = 20; % CP length
SP. SNR = [0:4:40]; % Simulated SNR range is from 0
dB to 40 dB with an increament of 4 dB.
SP. numRun = 10^4; % The number of simulation
iterations is 10^4
a= isnan ( out . path_powers );
out . path_powers (a) =0;
% Calculation of path powers for Non - cooperative
h_1 = out . path_powers (1 ,:); % Relay Link
SP. channel_1 = h_1 ;
10
SP. channel_1 = h_1 / sqrt ( sum ( h_1 .^2) );
h_2 = out . path_powers (2 ,:); % Access Link
SP. channel_2 = h_2 ;
SP. channel_2 = h_2 / sqrt ( sum ( h_2 .^2) );
% Calculation of BER
SER_ofdm_nc = ofdm_wr_nc (SP);
SER_tot_nc = SER_tot_nc + SER_ofdm_nc ;
% Calculation of path powers for Cooperative
h_1 = out . path_powers (1 ,:); % Relay Link
SP. channel_1 = h_1 ;
SP. channel_1 = h_1 / sqrt ( sum ( h_1 .^2) );
h_2 = out . path_powers (2 ,:); % Access Link
SP. channel_2 = h_2 ;
SP. channel_2 = h_2 / sqrt ( sum ( h_2 .^2) );
h_3 = out . path_powers (3 ,:); % Direct Link
SP. channel_3 = h_3 ;
SP. channel_3 = h_3 / sqrt ( sum ( h_3 .^2) );
h_4 = out . path_powers (2 ,:)+ out . path_powers (3 ,:);
SP. channel_4 = h_4 ;
SP. channel_4 = h_4 / sqrt ( sum ( h_4 .^2) );
% Calculation of BER
SER_ofdm_c = ofdm_wr_c (SP);
SER_tot_c = SER_tot_c + SER_ofdm_c ;
% Calculation of path powers Without relay
h= out . path_powers (3 ,:); % Direct Link
SP. channel = h;
SP. channel = h/ sqrt ( sum (h .^2) );
% Calculation of BER
SER_ofdm_wor = ofdm (SP);
SER_tot_wor = SER_tot_wor + SER_ofdm_wor ;
end
%% Taking Average of the data
SER_wor = SER_tot_wor /n; % SER for without relay
environment
SER_nc = SER_tot_nc /n; % SER for non co - operative
environment
SER_c = SER_tot_c /n; % SER for co - operative environment (
with one relay )
%% Defining the MS and BS positions for the co - operative
environments with 2 relays
BsAAIdxCell = {[1];[2];[2]};
MsAAIdx = [2 2 3];
L =5;
layoutpar = layoutparset ( MsAAIdx , BsAAIdxCell , L, Arrays );
layoutpar . ScenarioVector = S* ones (1,L);
layoutpar . Stations (1) . Pos = [0;250;32]; % BS1
layoutpar . Stations (2) . Pos = [500;500;25]; % BS2
layoutpar . Stations (3) . Pos = [500;0;25]; % BS3
layoutpar . Stations (4) . Pos = [500;500;25]; % MS1
layoutpar . Stations (5) . Pos = [500;0;25]; % MS2
11
layoutpar . Stations (6) . Pos = [1000;250;1.5]; % MS3
layoutpar . Pairing = [1 1 2 1 3 ; 6 4 6 5 6];
% Defining the initial condictions for the iteration
SER_tot_c_two = zeros (11 ,1) ;
for n =1:5000
% Generation the Winner parameters
wimpar = wimparset ;
[H2 , delays2 , out2 ]= wim ( wimpar , layoutpar )
% Processing the bits for Calculation
SP. FFTsize = 512;
SP. CPsize = 20;
SP. SNR = [0:4:40];
SP. numRun = 10^4;
a= isnan ( out2 . path_powers );
out2 . path_powers (a) =0;
Output Graph:
Result:
Thus the Design, analyze and test Wireless standards and evaluate the performance measurements such
as BER, PER, BLER, throughput, capacity, ACLR, EVM for 4G using Matlab is completed successfully.
13
Ex No : DATE:
Design, analyze and test Wireless standards and evaluate the performance
measurements such as BER, PER, BLER, throughput, capacity, ACLR,
EVM for 5G using MATLAB
Aim:
To Design, analyze and test Wireless standards and evaluate the performance measurements such
as BER, PER, BLER, throughput, capacity, ACLR, EVM for 5G using Matlab.
Software Required:
• MATLAB
Theory:
5G is the 5th generation mobile network. It is a new global wireless standard after 1G, 2G, 3G,
and 4G networks. 5G enables a new kind of network that is designed to connect virtually everyone and
everything together including machines, objects, and devices.
5G wireless technology is meant to deliver higher multi-Gbps peak data speeds, ultra low latency,
more reliability, massive network capacity, increased availability, and a more uniform user experience to
more users. Higher performance and improved efficiency empower new user experiences and connects
new industries.
Bit Error Rate (BER) is a measure of the number of erroneous bits which can be expected in a
specified number of bits in a serial stream.
Packet Error Rate (PER) is a measure of the number of erroneous packets which can be
expected in a specified number of bits in a serial stream.
Block Error Rate (BLER) is defined as the number of erroneous received code blocks/total
number of received code blocks. The code block is considered to be error-free if its attached CRC code
matches the one calculated by the receiver.
The channel capacity, C, is defined to be the maximum rate at which information can be
transmitted through a channel.
14
Adjacent Channel Leakage Ratio (ACLR) or Adjacent Channel Power Ratio (ACPR) is
defined the ratio of the transmitted power on the assigned channel to the power received in the adjacent
radio channel after a receive filter.
The error vector magnitude or EVM (sometimes also called relative constellation error or RCE)
is a measure used to quantify the performance of a digital radio transmitter or receiver.
Simulink Model:
Sample Output:
15
Result:
Thus the Design, analyze and test Wireless standards and evaluate the performance measurements such
as BER, PER, BLER, throughput, capacity, ACLR, EVM for 5G using MATLAB is completed
successfully.
16
Ex No : DATE:
Software Required:
• MATLAB
Theory:
The first example of this technique was introduced by actress Hedy Lamarr and pianist George
Antheil. Their patent for a "secret communications system" was filed in 1941. The design was inspired by
the scrolls of mechanical player pianos and tested using a similar, miniaturized device to modulate a
continuous signal across a spread of frequencies. Swiss inventor, Gustav Guanella proposed an
alternative "means for and method of secret signals" soon after. With DSSS, the message bits are
modulated by a pseudorandom bit sequence known as a spreading sequence. Each spreading-sequence
bit, which is known as a chip, has a much shorter duration (larger bandwidth) than the original message
bits. The modulation of the message bits scrambles and spreads the pieces of data, and thereby results in
a bandwidth size nearly identical to that of the spreading sequence. The smaller the chip duration, the
larger the bandwidth of the resulting DSSS signal; more bandwidth multiplexed to the message signal
results in better resistance against interference.
Some practical and effective uses of DSSS include the code-division multiple access (CDMA)
method, the IEEE 802.11b specification used in Wi-Fi networks, and the Global Positioning System.
Matlab Code:
17
pattern=[pattern sig];
end
subplot(4,1,1)
plot(pattern);
axis([-1 620 -1.5 1.5]);
title('Original Bit Sequence');
% Generating the pseudo random bit pattern for spreading
d=round(rand(1,120));
pn_seq=[];
carrier=[];
t=[0:2*pi/4:2*pi]; % Creating 5 samples for one cosine
for k=1:120
if d(1,k)==0
sig=-ones(1,5);
else
sig=ones(1,5);
end
c=cos(t);
carrier=[carrier c];
pn_seq=[pn_seq sig];
end
% Spreading of sequence
spreaded_sig=pattern.*pn_seq;
subplot(4,1,2)
plot(spreaded_sig)
axis([-1 620 -1.5 1.5]);
title('Spreaded signal');
Sample Output:
19
Result:
Thus the Spread Spectrum – DSSS Modulation & Demodulation is implemented and simulated
successfully.
20
Ex No : DATE:
Software Required:
• MATLAB
Theory:
Equalizers are critical to the successful operation of electronic systems such as analog broadcast
television. In this application the actual waveform of the transmitted signal must be preserved, not just its
frequency content. Equalizing filters must cancel out any group delay and phase delay between different
frequency components.
Y=conv(g,x);
21
%%%% Adding Noise
SNRdB=100;
r=awgn(Y,SNRdB);
%%%% Linear Zero Forcing at Transmitter
Xh = ZF(g,r);
%%%Hard-decision Decoding
Xh(find(Xh>0))=1;
Xh(find(Xh<0))=-1;
Xh
Sample Output:
MMSE Equalizer(MMSEE)
clc
clear
format long
N=100000;
SNRDB=6:2:16;
I_da=sign(rand(1,N)-0.5);
Q_da=sign(rand(1,N)-0.5);
s=I_da+1i*Q_da;
for i=1:length(SNRDB)
SNRLIN=10^(SNRDB(i)/10);
n=1/sqrt(2*10^(SNRDB(i)/10))*(randn(1,N)+1i*randn(1,N));
h=1/sqrt(2)*(randn(1,N)+1i*randn(1,N));
y=h.*s+n;
for j=1:3
22
if j==1
W(1,:) = ones(size(h));
elseif j==2
W(2,:)= 1./h;
elseif j==3
W(3,:)= conj(h)./((abs(h)).^2+n);
else
error('Unimplemented Equalizer');
end
z = W .* y;
z_=sign(real(z))+1i*sign(imag(z));
end
BER_no(i)=sum(s~=z_(1,:))/N;
BER_ZF(i)=sum(s~=z_(2,:))/N;
BER_MMSE(i)=sum(s~=z_(3,:))/N;
end
ax = [6 16 1e-04 8e-01];
axis(ax)
semilogy( SNRDB, BER_no, '*-k', SNRDB,BER_ZF, 'o--r',SNRDB, BER_MMSE, '>-b');
xlabel('E_b/N_0 [dB]');
ylabel('BER');
title('Equalizer for OFDM system');
legend('No Equalizer','ZF Equalizer','MMSE Equalizer');
grid on;
Sample Output:
end
% Plot results
figure(10);
semilogy(abs(e));
title(['LMS Adaptation Learning Curve Using Mu = ', num2str(Mu)]);
24
xlabel('Iteration Number');
ylabel('Output Estimation Error in dB');
Sample Output:
% snr parameters
snr = 10^(0.1*snr_dB);
noise_var = 1/(2*snr); % noise variance
% --------------- training phase ------------------------------------------
% source
training_a = randi([0 1],1,training_len);
% bpsk mapper
training_seq = 1-2*training_a;
25
fade_chan = fade_chan/norm(fade_chan);
chan_len = length(fade_chan);
% awgn
noise = normrnd(0,sqrt(noise_var),1,training_len+chan_len-1);
% channel output
chan_op = conv(fade_chan,training_seq)+noise;
for i1=1:training_len-ff_filter_len+1
ff_filter_ip = fliplr(chan_op(i1:i1+ff_filter_len-1));%equalizer input
error = ff_filter*ff_filter_ip.' -training_seq(i1+ff_filter_len-1);% instantaneous error
ff_filter = ff_filter - step_size*error*ff_filter_ip;
end
for i1=1:training_len
quantizer_ip = u(i1)-fb_filter*fb_filter_ip.';
% hard decision
quantizer_op = 1-2*(quantizer_ip<0);
error = quantizer_ip-training_seq(i1);
fb_filter = fb_filter+step_size*fb_filter_ip*error;
fb_filter_ip = [(u(i1)-quantizer_op) fb_filter_ip(1:end-1)];
end
% bpsk mapper
data_seq = 1-2*data_a;
% awgn
noise = normrnd(0,sqrt(noise_var),1,data_len+chan_len-1);
% channel output
chan_op = conv(fade_chan,data_seq)+noise;
26
% equalization
ff_filter_ip = zeros(1,ff_filter_len); % feedforward input vector
fb_filter_ip = zeros(1,fb_filter_len); % feedback input vector
fb_filter_op = 0; % feedback filter output symbol
dec_data_seq = zeros(1,data_len);
for i1=1:data_len
ff_filter_ip = [chan_op(i1) ff_filter_ip(1:end-1)];
ff_filter_op = ff_filter*ff_filter_ip.';
quantizer_ip = ff_filter_op - fb_filter_op;
% hard decision
dec_data_seq(i1) = 1-2*(quantizer_ip<0);
fb_filter_ip = [ff_filter_op-dec_data_seq(i1) fb_filter_ip(1:end-1)];
fb_filter_op = fb_filter*fb_filter_ip.';
end
Result:
27
Ex No : DATE:
Aim:
Software Required:
• MATLAB
Theory:
Time Division Multiple Access (TDMA) is a digital modulation technique used in digital cellular
telephone and mobile radio communication. TDMA is one of two ways to divide the limited spectrum
available over a radio frequency (RF) cellular channel. The other is known as frequency division multiple
access (FDMA).
In simplest terms, TDMA enables multiple users to share the same frequency by dividing each
cellular channel into different time slots. In effect, a single frequency supports multiple and simultaneous
data channels. So, with a two-time slot TDMA, two users can share the same frequency. With a three-
time slot TDMA, three users can share the same frequency and so on.
Time Division Multiple Access (TDMA) is a digital modulation technique used in digital cellular
telephone and mobile radio communication. TDMA is one of two ways to divide the limited spectrum
available over a radio frequency (RF) cellular channel. The other is known as frequency division multiple
access (FDMA).
In simplest terms, TDMA enables multiple users to share the same frequency by dividing each
cellular channel into different time slots. In effect, a single frequency supports multiple and simultaneous
data channels. So, with a two-time slot TDMA, two users can share the same frequency. With a three-
time slot TDMA, three users can share the same frequency and so on.
Matlab Code:
1. Generate Cluster head:
function [cluster_heads,cluster_loc]=cluster_head_find(number_nodes,num_of_trans,xm,ym,zm)
%function
%[cluster_heads,cluster_loc]=cluster_head_find(number_nodes,num_of_trans,xm
%,ym,zm) is return cluster_head and location of cluster head location
%according to
28
%number_nodes= total number of nodes in the network
%num_of_trans= total number of cluster in network
%xm,ym,zm= maximum x,y,z coordinates in the network over which nodes are
%placed
%for ex:
% number_nodes =50;
% num_cluster_head=5;
%xm=500;ym=500;zm=10;
%[head,loc]=function
%[cluster_heads,cluster_loc]=cluster_head_find(number_nodes,num_cluster,xm,
%..ym,zm);
%% find the location each node
for k=1:number_nodes
[x(k),y(k),z(k)]=locate_node(xm,ym,zm);
end
%% find location of cluster head and id of cluster head
for k=1:number_nodes
loc(k,1:3)=[x(k),y(k),z(k)];
end
for k=1:num_of_trans
cluster_heads(k)=randi(number_nodes,1,1);
cluster_loc(k,1:3)=loc(k,:);
end
end
2. Create Cluster:
function
[cluster_members,cluster_id]=create_cluster(number_nodes,num_transmission,xm,ym,zm)
% Writter: Pankaj Joshi India
% [cluster_members,cluster_id]=create_cluster(number_nodes,num_transmission
% ,xm,ym,zm) is return cluster members in matrix form 1st coloum of each
% raw show cluster head and remaining value of regarding row show cluster member value '0' is
not a node
% cluster id represtes row vecter containg cluster id of each cluster, for
% this function create_cluster required number of nodes in network
29
% (num_nodes), number of clusters (num_transmission), maximum x-cordinate
% maximum y-codinate and maximum z-cordinate (xm,ym,zm) to locate node in
% of ground of ad-hoc network
%find of cluster heads and their location
[cluster_head,cluster_loc]=cluster_head_find(number_nodes,num_transmission,xm,ym,zm);
%%
%define cluster id for each cluster head
for k=1:num_transmission
cluster_id(k)=k;
cluster_members(k,1)=cluster_head(k);
end
%% Locate ordinary nodes
num_of_ord_node=number_nodes-num_transmission;
p=1;
while p<=number_nodes
if p~=cluster_head
[x(p),y(p),z(p)]=locate_node(xm,ym,zm);
end
p=p+1;
end
%% Cluster Head and Cluster Members
for l=1:number_nodes
if (l~=cluster_head)
for m=1:num_transmission
dist(l,m)=distance(x(l),y(l),cluster_loc(m,1),cluster_loc(m,2));
end
dist_min=min(dist(l,:));
indx=find(dist(l,:)==dist_min);
cluster_head_c=cluster_head(indx);
temp1=find(cluster_members(:,1)==cluster_head_c);
temp2=length(cluster_members(temp1,:));
cluster_members(temp1,temp2+1)=l;
end
end
30
end
3. Locate Node:
function [x_loc,y_loc,z_loc]=locate_node(x_lim,y_lim,z_lim)
%% Writter Pankaj Joshi India
%generate location of a node according to maximum avalable x_lim y_lim and
%z_lim, for example in aria of 500 X 500 X 200 required to place 50 nodes
%than
% for k=1:50
%[x(k),y(k),z(k)]=locate_node(500,500,200)
%end
x_loc=randi(x_lim,1,1);
y_loc=randi(y_lim,1,1);
z_loc=randi(z_lim,1,1);
end
4. TDMA
% Writter: Pankaj Joshi India
%This Progame Use for defining Multicast Ad-hoc Network by finding cluster
%head and cluster id and members of cluster
clc;
clear all;
close all;
%%
%Define Network Parameters
num_node=input('Enter number of node for network=');
num_cluster=input('Enter number of cluster head required in network=');
xm=input('maximum x-lim for network land=');
ym=input('enter maximum y-lim for network land=');
zm=input('enter hight coordinate system or z-lim for network=');
[cluster_mems,cluster_id]=create_cluster(num_node,num_cluster,xm,ym,zm);
for k=1:num_cluster
len(k)=length(find(cluster_mems(k,:))~=0);
end
31
num_reciv=input('Enter number of receivers=');
net_time=input('Define total time in sec for network analysis');
net_time=net_time/1000;
for m=1:num_reciv
reciv_id(m)=randi(num_node,1,1);
end
%%
%Define data
data_len=64*net_time;%considering data generated by 64kbps
tot_data=data_len*num_cluster;
orig_data=rand(1,tot_data)>0.5;
h=commsrc.nrz('OutputLevels',[-2 2]);
tr_data=generate(h,orig_data');
plot(tr_data);
ylim([-2.2 2.2]);
title('transmitted data');
%% Defining Cluster Id and Cluster Members
for n=1:num_reciv
[row(n),col(n)]=find(cluster_mems==reciv_id(n));
clust_id(n)=row(n);
end
uni=unique(clust_id);
recv_per_cluster=histc(clust_id,uni);
for n=1:length(recv_per_cluster)
if recv_per_cluster(n)>1
time_slot_per_recv(n)=fix(100/recv_per_cluster(n));
else
time_slot_per_recv(n)=100;
end
end
%% Find Out Time Slot in a Cluster
time_slot_diff_cluster=time_slot_per_recv;
for k=1:num_cluster
num_of_hop_per_cluster(k)=randi(len(k),1,1);
32
end
%% Calculation of Data Loss for network
avg_dist=xm*ym/num_node;
g_tx_ant=input('Enter the gain of transmitting antenna=');
g_rx_ant=input('Enter the gain of receiving antenna=');
rx_pwd=tr_data.*(g_tx_ant*g_rx_ant/4*pi*(avg_dist^2));
for k=1:num_cluster
for l=1:num_of_hop_per_cluster(k)
rx_pwd_db=20*log((g_tx_ant*g_rx_ant/4*pi*(avg_dist^2)));
end
end
data_loss_wc=length(find(rx_pwd_db>3));
snr=(num_cluster/num_node)*1000;
rx_sig=awgn(tr_data,snr,'measured');
rx_sig_db=20*log(rx_sig./tr_data);
data_loss=length(find(rx_sig_db>3));
Result:
Thus the Modeling and simulation of TDMA for wireless communication is done successfully.
33
Ex No : DATE:
Aim:
Software Required:
• MATLAB
Theory:
FDMA is another way to enable multiple users to share an entire communication resource. In
FDMA (short for frequency division multiple access) each user uses a different band of frequencies to
communicate his or her information.
Matlab Code:
close all;
clear all;
clc;
n1=1;
n2=14;
FFT_SIZE=256;
%CP=16;
%% Data Generator
Data_gen = randint(1,23,255)
D=dec2bin(Data_gen);
s=0;
%% BER PARAMETERS
EbNo=0:1:15;
BER = zeros(1,length(EbNo));
numPackets=15;
34
frmLen = 1000;
for idx = 1: length(EbNo)
for packetidx = 1 : numPackets
%% Convolution Encoder
conv_in=[];
for index =1:23
conv_in=[conv_in double(D(index,:))-48];
end
conv_in=[conv_in 0 0 0 0 0 0 0 0]; %%8 bits padding
DIN=conv_in;
trel = poly2trellis(7, [171 133]); % Define trellis.
code = convenc(conv_in,trel);
clear conv_in;
inter_out=code;
%% BPSK Data Mapping
mapper_out=mapping(inter_out',2,0.7071);
clear inter_out;
mapper_out=fft(mapper_out);
%D=mapper_out;
ifft_in=[0,mapper_out(1:96),zeros(1,32),zeros(1,31),mapper_out(97:192)]
tx_data=ifft(ifft_in);
clear ifft_in;
%rx_data=awgn(tx_data,10,'measured');
%rx_data=awgn(tx_data,10,'measured');
%rx_data=awgn(tx_data,2,'measured');
%rx_data=awgn(tx_data,1,'measured');
rx_data=fft(rx_data);
35
clear tx_data;
rx_data1=[rx_data(1,2:97) rx_data(1,161:256)]; % taking out symbols for demapping
% rx_data1=RECON;
rx_data1=ifft(rx_data1);
Demap_out=demapper(rx_data1,2,0.7071);
%%viterbi decoder
vit_out=vitdec(Demap_out,trel,7,'trunc','hard');
clear Demap_out;
DOUT=vit_out;
%figure;plot(DOUT-DIN);
[number,ratio] = biterr(DIN,vit_out);
error(packetidx) = biterr(DIN,vit_out);
%error=biterr(DOUT,DIN);
%Grouping Bits and converting to Dec for RS Decoder
36
Sample Output:
Result:
Thus the Modeling and simulation of FDMA for wireless communication is done successfully.
37
Ex No : DATE:
Aim:
Software Required:
• MATLAB
Theory:
CDMA (Code-Division Multiple Access) refers to any of several protocols used in second-
generation (2G) and third-generation (3G) wireless communications. As the term implies, CDMA is a
form of multiplexing, which allows numerous signals to occupy a single transmission channel,
optimizing the use of available bandwidth.
CDMA Capacity
The factors deciding the CDMA capacity are −
Processing Gain
Signal to Noise Ratio
Voice Activity Factor
Frequency Reuse Efficiency
Capacity in CDMA is soft, CDMA has all users on each frequency and users are separated by
code. This means, CDMA operates in the presence of noise and interference.
In addition, neighboring cells use the same frequencies, which means no re-use. So, CDMA
capacity calculations should be very simple. No code channel in a cell, multiplied by no cell. But it is not
that simple. Although not available code channels are 64, it may not be possible to use a single time,
since the CDMA frequency is the same.
Centralized Methods
The band used in CDMA is 824 MHz to 894 MHz (50 MHz + 20 MHz separation).
Frequency channel is divided into code channels.
1.25 MHz of FDMA channel is divided into 64 code channels.
Processing Gain
CDMA is a spread spectrum technique. Each data bit is spread by a code sequence. This means,
38
energy per bit is also increased. This means that we get a gain of this.
P (gain) = 10log (W/R)
W is Spread Rate
R is Data Rate
For CDMA P (gain) = 10 log (1228800/9600) = 21dB
Matlab Code:
% 4 user CDMA system (BPSK modulation)
clear all
close all
clc
N = 4; % number of users in the CDMA system ( donot change this number)
level = ceil(log2(N)); % leven in OVSF code generation
codes = Gen_OVSF(level); % generate orthogonal variable spread factor codes
% Spreading operation
user1_bpsk_seq_rep = repmat(bpsk_seq1,2^level,1);
user2_bpsk_seq_rep = repmat(bpsk_seq2,2^level,1);
39
user3_bpsk_seq_rep = repmat(bpsk_seq3,2^level,1);
user4_bpsk_seq_rep = repmat(bpsk_seq4,2^level,1);
user1_code_rep = repmat(codes(1,:).',1,num_bit);
user2_code_rep = repmat(codes(2,:).',1,num_bit);
user3_code_rep = repmat(codes(3,:).',1,num_bit);
user4_code_rep = repmat(codes(4,:).',1,num_bit);
% summing operation
trans_sig = user1_trans_sig + user2_trans_sig + user3_trans_sig + user4_trans_sig;
% AWGN
SNR = 10^(0.1*SNR_dB); % SNR in linear scale
noise_var = (2^level)/(2*SNR); % awgn variance
noise = normrnd(0,sqrt(noise_var),2^level,num_bit);
% channel output
Chan_Op = trans_sig + noise;
% ML decoding
dec_a1 = user1_rec_sig<0;
Result:
Thus the Modeling and simulation of CDMA for wireless communication is done successfully.
41
Ex No : DATE:
Aim:
Software Required:
• MATLAB
Theory:
Minimum Shift Key Modulation is another type of digital modulation technique used to convert a
digital signal into analog signals. It is also called Minimum-shift keying (MSK) or Advance Frequency
Shift Keying because it is a type of continuous-phase frequency-shift keying.
Key features of Minimum Shift Key Modulation or Minimum-shift keying (MSK)
• Minimum-shift keying or MSK was first developed by the Collins Radio employees Melvin L.
Doelz and Earl T. Heald in the late 1950s.
• It is encoded with bits alternating between quadrature components, with the Q component delayed
by half the symbol period.
• Minimum Shift Keying is the most effective digital modulation technique. It can be implemented
for almost every stream of bits much easier than the Phase Shift Key, Frequency Shift Key and
Amplitude Shift Key of digital modulation technique.
• The Minimum Shift Keying's concept is based on the positioning of bits such as even bits and odd
bits for the given bitstream and the bit positioning frequency generating table.
• MSK is the most widely used digital modulation technology because of its ability and flexibility to
handle "One(1)" and "Zero(0)" transition of binary bits.
Matlab Code:
clear
N = 5*10^5; % number of bits or symbols
42
Eb_N0_dB = [0:10]; % multiple Eb/N0 values
ct = cos(pi*[-T:N*T-1]/(2*T));
st = sin(pi*[-T:N*T-1]/(2*T));
for ii = 1:length(Eb_N0_dB)
% MSK Transmitter
ipBit = rand(1,N)>0.5; % generating 0,1 with equal probability
ipMod = 2*ipBit - 1; % BPSK modulation 0 -> -1, 1 -> 0
ai = [ai zeros(1,T) ]; % padding with zero to make the matrix dimension match
aq = [zeros(1,T) aq ]; % adding delay of T for Q-arm
% Noise addition
yt = xt + 10^(-Eb_N0_dB(ii)/20)*nt; % additive white gaussian noise
%% MSK receiver
% multiplying with cosine and sine waveforms
xE = conv(real(yt).*ct,ones(1,2*T));
xO = conv(imag(yt).*st,ones(1,2*T));
bHat = zeros(1,N);
bHat(1:2:end) = xE(2*T+1:2*T:end-2*T) > 0 ; % even bits
bHat(2:2:end) = xO(3*T+1:2*T:end-T) > 0 ; % odd bits
43
% counting the errors
nErr(ii) = size(find([ipBit - bHat]),2);
end
% plot
close all
figure
semilogy(Eb_N0_dB,theoryBer,'bs-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);
axis([0 10 10^-5 0.5])
grid on
legend('theory - bpsk', 'simulation - msk');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for MSK modulation');
44
Model Output:
Result:
Thus, the modulation and demodulation of MSK is performed using Matlab.
45
Ex No : DATE:
Aim:
Software Required:
• MATLAB
Theory:
In wireless microphone applications, diversity receivers are often used to improve reception of RF
signals. A diversity receiver utilizes two separate, independent antenna systems. The receiver looks at the
signal coming in from the each antenna, and determines which one is the stronger. It then switches to that
stronger signal. The receiver is constantly comparing to see which antenna is providing the better signal,
and can quickly switch from one to the other as signal strength changes.
Matlab Code
N=10^3;
data=randi([0,1],1,N);
x=2*data-1;
nRx_max=20;
nRx=[1:nRx_max];
snr_dB=1:5;
snr_sim_EGC=zeros([length(snr_dB) nRx_max]);
for j=1:nRx_max
46
for k=1:length(snr_dB)
h=randn(j,N)+(randn(j,N)*1i);
x_kron=kron(ones(nRx(j),1),x);
c_in=h.*x_kron;
y=awgn(c_in,snr_dB(k),'measured');
%y_rec =sum(conj(h).*y,1);
y_rec = y.*exp(-1i*angle(h)); % removing the phase of the channel
y_rec = sum(y_rec,1); % adding values from all the receive chains
snr_sim_EGC(k,j) = mean(y_rec.*conj(y_rec))/nRx(j);
end
end
snr_sim_log_EGC=10*log10(snr_sim_EGC);
figure;
plot(nRx,snr_sim_log_EGC);
xlabel('Number of receive antenna');
ylabel('SNR, dB');
title('Equal Gain Combining');
2. Selection Combining:
N=10^3;
data=randi([0,1],1,N);
x=2*data-1;
nRx_max=20;
nRx=[1:nRx_max];
snr_dB=1:5;
snr_sim_SC=zeros([length(snr_dB) nRx_max]);
47
for j=1:nRx_max
for k=1:length(snr_dB)
h=randn(j,N)+(randn(j,N)*1i);
x_kron=kron(ones(nRx(j),1),x);
c_in=h.*x_kron;
y=awgn(c_in,snr_dB(k),'measured');
% y_rec =sum(conj(h).*y,1);
hPower = h.*conj(h);
% finding the maximum power
[hMaxVal ,ind] = max(hPower,[],1);
hMaxValMat = kron(ones(nRx(j),1),hMaxVal);
% effective SNR
snr_sim_SC(k,j) = mean(hSel.*conj(hSel));
end
end
snr_sim_log_SC=10*log10(snr_sim_SC);
figure;
plot(nRx,snr_sim_log_SC);
xlabel('Number of receive antenna');
ylabel('SNR, dB');
title('Selection Combining');
48
3. Maximal Ratio Combining:
N=10^3;
data=randi([0,1],1,N);
x=2*data-1;
nRx_max=20;
nRx=[1:nRx_max];
snr_dB=1:5;
snr_sim_MRC=zeros([length(snr_dB) nRx_max]);
for j=1:nRx_max
for k=1:length(snr_dB)
h=randn(j,N)+(randn(j,N)*1i);
x_kron=kron(ones(nRx(j),1),x);
c_in=h.*x_kron;
y=awgn(c_in,snr_dB(k),'measured');
y_rec =sum(conj(h).*y,1);
snr_sim_MRC(k,j)=mean(abs(y_rec));
end
end
snr_sim_log_MRC=10*log10(snr_sim_MRC);
figure;
plot(nRx,snr_sim_log_MRC);
Sample Output:
49
Result:
50