0% found this document useful (0 votes)
10 views32 pages

2021UIT3140_MC_file

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 32

MOBILE COMPUTING

Practical File

Name: Rahul Batra


Roll No.: 2021UIT3140
Branch: IT-2
Submitted to:
INDEX
SNO EXPERIMENT DATE SIGN

1 Steps to Install MATLAB R2023b on Windows

2 Program to Implement a Network of 10 Nodes in


MATLAB

3 Implement a point-to-point network consisting of 10


nodes using MATLAB with duplex links between
them. Initiate a communication between these
nodes. Set the queue size, vary the bandwidth and
find the number of packets dropped. Finally plot the
graph showing the performance of this network in
terms of number of packets dropped with varying
bandwidth.

4 Implement FDMA, TDMA & and CDMA using


MATLAB and show the results using a graph for 10
users using clustering techniques.

5 Implement GSM using MATLAB

6 Implement GPRS using MAC layer in MATLAB

7 Implement LTE using MATLAB

8 Implement snooping and analysing the traffic using


Wireshark
Practical 1: Steps to Install MATLAB R2023b on
Windows

Step 1: Obtain the MATLAB Installation File


Visit the MathWorks website www.mathworks.com and log
in using your MathWorks account. If you don't have an
account, create one.
After logging in, navigate to the MATLAB product page and
locate the download link for MATLAB R2023b for
Windows.

Step 2: Run the Installation File


(matlab_R2023b_win64.exe)
Find the downloaded installation file, typically named
"matlab_R2023b_win64.exe," and double-click on it to start
the
installation process.

Step 3: Log in with Your MathWorks Account


During the installation, you may be prompted to log in again
with your MathWorks account. Use your college email
ID associated with MathWorks, or the credentials provided
by your college for MATLAB access.

Step 4: Accept the License Agreement


Read and accept the MathWorks Software License
Agreement to continue with the installation. Click the "Next"
or
"Agree" button to proceed.

Step 5: Select Your License


In this step, you will be presented with license details. If no
further configuration or selection is required, simply
review the license details and click "Next" to continue with
the installation.

Step 6: Select Destination Folder


Choose the folder where you want MATLAB to be installed.
The default installation path is usually recommended. Click
"Next" to move on.

Step 7: Select Products to Install


In this step, you can select which MATLAB products you want
to install. For the initial installation, it's fine to select
"MATLAB" and "Simulink." You can always install additional
toolboxes later if needed.

Step 8: Confirm and Begin Installation


Review your selections to ensure they are correct. If
everything looks good, click "Next" to start the installation
process.

Step 9: Wait for Installation to Complete


The installation process may take some time, depending on
your computer's performance and the selected
components. Be patient and wait for the installation to finish.

Step 10: Installation Completed


Once the installation is complete, you will see a confirmation
message. MATLAB R2023b is now installed on your
Windows system.
Practical 2: Program to Implement a Network of
10 Nodes in MATLAB

Source Code:-
clear;
numNodes = 10;

G = graph;
G = addnode(G, numNodes);
centralNode = 1;
for i = 2:numNodes
G = addedge(G, centralNode, i);
end

h = plot(G, 'Layout', 'force');


title('Network of 10 Nodes');
labelnode(h,1:numNodes,cellstr(num2str((1:numNodes)')));

Output:-
Practical 3: Implement a point-to-point network
consisting of 10 nodes using MATLAB with duplex
links between them. Initiate a communication
between these nodes. Set the queue size, vary the
bandwidth and find the number of packets
dropped. Finally plot the graph showing the
performance of this network in terms of number
of packets dropped with varying bandwidth.

Network Assumptions:-
• All 10 nodes have equal bandwidth.
• All nodes have a constant queue size
• Constant packet size, and packet arrival time of 1 ms.

Constants:-
queue_size = 50;
bandwidth = 16; % 16 Mbps
packet_size = 2000; % bytes
max_packet_size = 1000; % bytes
stop_time = 1100; % 1100 ms
arrival_time = 1e-3; % 1 ms
propagation_delay = 5e-3; % 5 ms

Data Collection and Analysis:-


Packet drop ideally occurs only at Node 0, as for all other
nodes, inRate equals outRate. The program initializesarrays
to store bandwidth and packets dropped, as well as inRates,
outRates, and transmissionDelays. It theniterates through
varying bandwidth values, calculating transmission delays,
inRates, outRates, and packet drops.Results are stored in
arrays and printed for analysis.
% Initialize arrays to store data
bandwidth_values = [];
packets_dropped = [];
inRates = [];
outRates = [];
transmissionDelays = [];

% Loop through varying bandwidth values


while bandwidth >= 1
% Calculate transmission delay
transmission_delay = (max_packet_size * 8) /
(bandwidth * 1e6);

% Calculate inRate and outRate


inRate = packet_size / max_packet_size;
outRate = 1e-3 / transmission_delay;
% Calculate firstDrop and PacketsDropped
if inRate <= outrate
PacketsDropped = 0;
else
firstDrop = queue_size / (inRate - outRate);
PacketsDropped = ceil((stop_time - firstDrop) *
(inRate - outRate)) + 1;
end

% Store the results in arrays


bandwidth_values = [bandwidth_values, bandwidth];
packets_dropped = [packets_dropped, PacketsDropped];
inRates = [inRates, inRate]; outRates = [outRates,
outRate]; transmissionDelays = [transmissionDelays,
transmission_delay];

% Print the results


fprintf('Bandwidth: %.2f bps\n', bandwidth);
fprintf('InRate: %.2f\n', inRate);
fprintf('OutRate: %.2f\n', outRate);
fprintf('Transmission Delay: %.6f s\n',
transmission_delay);
fprintf('Packets Dropped: %d\n\n', PacketsDropped);

% Reduce bandwidth by half for the next iteration


bandwidth = bandwidth / 2;
Data Visualization:-
The program plots a graph showing the relationship between
bandwidth and packets dropped. Text annotationsare added
to the graph to display the values of bandwidth and packets
dropped for each data point.

% Plot the graph


plot(bandwidth_values, packets_dropped, '-o');
xlabel('Bandwidth (Mbps)');
ylabel('Packets Dropped');
title('Packets Dropped vs. Bandwidth');
grid on;

% Add text annotations to the graph


for i = 1:length(bandwidth_values)
x = bandwidth_values(i);
y = packets_dropped(i);
text(x,y,sprintf('(%.2f,%d)',x,y),'VerticalAlignment'
, 'bottom', 'HorizontalAlignment', 'left')
end

Output:-
>> pract2
Bandwidth: 16.00 bps
InRate: 2.00
OutRate: 2.00
Transmission Delay: 0.000500 s
Packets Dropped: 0

Bandwidth: 8.00 bps


InRate: 2.00OutRate: 1.00
Transmission Delay: 0.001000 s
Packets Dropped: 1051

Bandwidth: 4.00 bps


InRate: 2.00OutRate: 0.50Transmission Delay: 0.002000 s
Packets Dropped: 1601

Bandwidth: 2.00 bps


InRate: 2.00OutRate: 0.25Transmission Delay: 0.004000 s
Packets Dropped: 1876

Bandwidth: 1.00 bps


InRate: 2.00OutRate: 0.12Transmission Delay: 0.008000 s
Packets Dropped: 2014
Practical 4: Implement FDMA, TDMA & and
CDMA using MATLAB and show the results using
a graph for 10 users using clustering techniques.

MATLAB Code for TDMA:-

% TDMA Implementation for 10 users


num_users = 10;
time_slots = 10;
signals_tdma = zeros(num_users, time_slots);

% Generate signals for each user in different time slots


for i = 1:num_users
signals_tdma(i, :) = randn(1, time_slots);
end

% Plot signals for TDMA


figure; bar(signals_tdma');
title('TDMA Signals for 10 Users');
xlabel('Time Slot');
ylabel('Amplitude');
legend('User 1', 'User 2', 'User 3', 'User 4', 'User 5',
'User 6', 'User 7', 'User 8', 'User 9', 'User 10');

Output:-
MATLAB Code for FDMA:-

% FDMA Implementation for 10 users


num_users = 10;
frequency_bands = linspace(1, 10, num_users);

% Generate signals for each user


t = 0:0.001:1; % Time vector
signals_fdma = zeros(num_users, length(t));

for i = 1:num_users
signals_fdma(i, :) = sin(2*pi*frequency_bands(i)*t);
end

% Plot signals for FDMA


figure;
for i = 1:num_users
plot(t, signals_fdma(i, :));
hold on;
end
title('FDMA Signals for 10 Users');
xlabel('Time');
ylabel('Amplitude');
legend('User 1', 'User 2', 'User 3', 'User 4', 'User 5',
'User 6', 'User 7', 'User 8', 'User 9', 'User 10')

Output:-
MATLAB Code for CDMA:-

% CDMA Implementation for 10 users


num_users = 10;
code_length = 100;
codes = randi([0, 1],
num_users, code_length)*2 - 1;

% Generate CDMA signals for each user


t = 1:code_length;
signals_cdma = zeros(num_users, code_length);
for i = 1:num_users
signals_cdma(i, :) = codes(i, :) .* t;
end

% Plot signals for CDMA


figure;
for i = 1:num_users
plot(signals_cdma(i, :));
hold on;
end
title('CDMA Signals for 10 Users');
xlabel('Time');
ylabel('Amplitude');
legend('User 1', 'User 2', 'User 3', 'User 4', 'User 5',
'User 6', 'User 7',

Output:-
Practical 5: Implement GSM using MATLAB

MATLAB Code for GSM Uplink Waveform:-

cfggsmul = gsmUplinkConfig
wfInfo = gsmInfo(cfggsmul)
Rs = wfInfo.SampleRate;
waveform = gsmFrame(cfggsmul);

t = (0:length(waveform)-1)/Rs*1e3;
subplot(2,1,1)
plot(t, abs(waveform))
grid on
axis([0 5 0 1.2])
title('GSM Uplink Waveform - Amplitude')
xlabel('Time (ms)') ylabel('Amplitude')
subplot(2,1,2)
plot(t, unwrap(angle(waveform)))
grid on
title('GSM Uplink Waveform - Phase')
xlabel('Time (ms)')
ylabel('Phase (rad)')

Output:-
MATLAB Code for GSM Downlink Waveform:-

cfggsmdl = gsmDownlinkConfig;
wfInfo = gsmInfo(cfggsmdl);
Rs = wfInfo.SampleRate;
waveform = gsmFrame(cfggsmdl);

t = (0:length(waveform)-1)/Rs*1e3;
subplot(2,1,1)
plot(t, abs(waveform))
grid on
axis([0 5 0 1.2])
title('GSM Downlink Waveform - Amplitude')
xlabel('Time (ms)')
ylabel('Amplitude')
subplot(2,1,2)
plot(t, unwrap(angle(waveform)))
grid on
title('GSM Downlink Waveform - Phase')
xlabel('Time (ms)')
ylabel('Phase (rad)')
Output:-
Practical 6: Implement GPRS using MAC layer in
MATLAB

MATLAB Code for GPRS using MAC Layer: -

% Constants for the MAC layer


frame_size = 100; % Frame size in bits
num_frames = 10; % Number of frames

% Generate random data


data = randi([0, 1], 1, frame_size * num_frames);

% MAC Layer: Frame segmentation and interleaving


frames = reshape(data, frame_size, num_frames); % Divide
data into frames
interleaved_frames = frames(:, randperm(num_frames)); %
Interleave frames

% Transmitter
% Use BPSK modulation (you can replace this with your
modulation scheme)
modulated_data = 2 * interleaved_frames - 1; % BPSK
modulation

% Display the transmitted data


figure;
subplot(2, 1, 1);
plot(modulated_data, 'b');
title('Transmitted Data');
xlabel('Time');
ylabel('Amplitude');

% Simulate received signal


received_signal = awgn(modulated_data, 10); % Add AWGN

% MAC Layer: De-interleaving and reassembly


deinterleaved_frames = reshape(received_signal,
frame_size, num_frames);
reconstructed_data = deinterleaved_frames(:,
randperm(num_frames));
received_data = reconstructed_data(:);

% Display the received data


subplot(2, 1, 2);
plot(received_data, 'r');
title('Received Data');
xlabel('Time');
ylabel('Amplitude');

% Display results
error_rate = biterr(data, received_data);
disp(['Bit Error Rate: ', num2str(error_rate)]);

Output:-
Practical 7: Implement LTE using MATLAB

enb.NDLRB = 15; % Number of resource


blocks
enb.CellRefP = 1; % One transmit antenna
port
enb.NCellID = 10; % Cell ID
enb.CyclicPrefix = 'Normal'; % Normal cyclic prefix
enb.DuplexMode = 'FDD'; % FDD
SNRdB = 22; % Desired SNR in dB
SNR = 10^(SNRdB/20); % Linear SNR
rng('default'); % Configure random number
generators
cfg.Seed = 1; % Channel seed
cfg.NRxAnts = 1; % 1 receive antenna
cfg.DelayProfile = 'EVA'; % EVA delay spread
cfg.DopplerFreq = 120; % 120Hz Doppler frequency
cfg.MIMOCorrelation = 'Low'; % Low (no) MIMO
correlation
cfg.InitTime = 0; % Initialize at time zero
cfg.NTerms = 16; % Oscillators used in
fading model
cfg.ModelType = 'GMEDS'; % Rayleigh fading model
type
cfg.InitPhase = 'Random'; % Random initial phases
cfg.NormalizePathGains = 'On'; % Normalize delay profile
power
cfg.NormalizeTxAnts = 'On'; % Normalize for transmit
antennas
cec.PilotAverage = 'UserDefined'; % Pilot averaging
method
cec.FreqWindow = 9; % Frequency averaging
window in REs
cec.TimeWindow = 9; % Time averaging
window in REs
cec.InterpType = 'Cubic'; % Cubic interpolation
cec.InterpWinSize = 3; % Interpolate up to 3
subframes
% simultaneously
cec.InterpWindow = 'Centred'; % Interpolation
windowing method
gridsize = lteDLResourceGridSize(enb);
K = gridsize(1); % Number of subcarriers
L = gridsize(2); % Number of OFDM symbols in one
subframe
P = gridsize(3); % Number of transmit antenna ports
txGrid = [];
% Number of bits needed is size of resource grid (K*L*P)
* number of bits
% per symbol (2 for QPSK)
numberOfBits = K*L*P*2;

% Create random bit stream


inputBits = randi([0 1], numberOfBits, 1);

% Modulate input bits


inputSym = lteSymbolModulate(inputBits,'QPSK');
% For all subframes within the frame
for sf = 0:10

% Set subframe number


enb.NSubframe = mod(sf,10);

% Generate empty subframe


subframe = lteDLResourceGrid(enb);

% Map input symbols to grid


subframe(:) = inputSym;

% Generate synchronizing signals


pssSym = ltePSS(enb);
sssSym = lteSSS(enb);
pssInd = ltePSSIndices(enb);
sssInd = lteSSSIndices(enb);

% Map synchronizing signals to the grid


subframe(pssInd) = pssSym;
subframe(sssInd) = sssSym;

% Generate cell specific reference signal symbols


and indices
cellRsSym = lteCellRS(enb);
cellRsInd = lteCellRSIndices(enb);

% Map cell specific reference signal to grid


subframe(cellRsInd) = cellRsSym;

% Append subframe to grid to be transmitted


txGrid = [txGrid subframe]; %#ok

end
[txWaveform,info] = lteOFDMModulate(enb,txGrid);
txGrid = txGrid(:,1:140);
cfg.SamplingRate = info.SamplingRate;
% Pass data through the fading channel model
rxWaveform = lteFadingChannel(cfg,txWaveform);
% Calculate noise gain
N0 = 1/(sqrt(2.0*enb.CellRefP*double(info.Nfft))*SNR);

% Create additive white Gaussian noise


noise =
N0*complex(randn(size(rxWaveform)),randn(size(rxWaveform
)));

% Add noise to the received time domain waveform


rxWaveform = rxWaveform + noise;
offset = lteDLFrameOffset(enb,rxWaveform);
rxWaveform = rxWaveform(1+offset:end,:);
rxGrid = lteOFDMDemodulate(enb,rxWaveform);
enb.NSubframe = 0;
[estChannel, noiseEst] =
lteDLChannelEstimate(enb,cec,rxGrid);
eqGrid = lteEqualizeMMSE(rxGrid, estChannel, noiseEst);
% Calculate error between transmitted and equalized grid
eqError = txGrid - eqGrid;
rxError = txGrid - rxGrid;

% Compute EVM across all input values


% EVM of pre-equalized receive signal
EVM = comm.EVM;
EVM.AveragingDimensions = [1 2];
preEqualisedEVM = EVM(txGrid,rxGrid);
fprintf('Percentage RMS EVM of Pre-Equalized signal:
%0.3f%%\n', ...
preEqualisedEVM);
% EVM of post-equalized receive signal
postEqualisedEVM = EVM(txGrid,eqGrid);
fprintf('Percentage RMS EVM of Post-Equalized signal:
%0.3f%%\n', ...
postEqualisedEVM);
% Plot the received and equalized resource grids
hDownlinkEstimationEqualizationResults(rxGrid,eqGrid);

hDownlinkEstimationEqualizationResults:
%hDownlinkEstimationEqualizationResults Plot the
resource grids
% hDownlinkEstimationEqualizationResults(RXGRID,
EQGRID) plots the
% received and equalized resource grids. This requires
the receive grid
% RXGRID and equalized grid EQGRID.

% Copyright 2009-2014 The MathWorks, Inc.

function hDownlinkEstimationEqualizationResults(rxGrid,
eqGrid)

% Plot received grid error on logarithmic scale


figure;
dims = size(rxGrid);
surf(20*log10(abs(rxGrid)));
title('Received resource grid');
ylabel('Subcarrier');
xlabel('Symbol');
zlabel('absolute value (dB)');
axis([1 dims(2) 1 dims(1) -40 10]);

% Plot equalized grid error on logarithmic scale


figure
surf(20*log10(abs(eqGrid)));
title('Equalized resource grid');
ylabel('Subcarrier');
xlabel('Symbol');
zlabel('absolute value (dB)');
axis([1 dims(2) 1 dims(1) -40 10]);

end
Practical 8: Implement snooping and analysing
the traffic

Getting Wireshark:-
In order to run Wireshark, you will need to have access to
a computer that supports both Wireshark and the libpcap
or WinPCap packet capture library. The libpcap software
will be installed for you, if it is not installed within your
operating system, when you install Wireshark.
See http://www.wireshark.org/download.html for a list of
supported operating systems and download sites.

Download and install the Wireshark software:-


• Go to http://www.wireshark.org/download.html and
download and install the Wireshark binary for your
computer.
• Download the Wireshark user guide. The Wireshark FAQ
has several helpful hints and interesting tidbits of
information, particularly if you have trouble installing or
running Wireshark.

Running Wireshark:-
When you run the Wireshark program, the Wireshark
graphical user interface shown in Figure 2 will de displayed.
Initially, no data will be displayed in the various windows.
The Wireshark interface has five major components:-
1. The command menus are standard pulldown menus
located at the top of the window. Of interest to us now
are the File and Capture menus. The File menu allows
you to save captured packet data or open a file
containing previously captured packet data, and exit the
Wireshark application. The Capture menu allows you to
begin packet capture.
2. The packet-listing window displays a one-line summary
for each packet captured, including the packet number
(assigned by Wireshark; this is not a packet number
contained in any protocol’s header), the time at which
the packet was captured, the packet’s source and
destination addresses, the protocol type, and protocol-
specific information contained in the packet. The packet
listing can be sorted according to any of these categories
by clicking on a column name. The protocol type field
lists the highest-level protocol that sent or received this
packet, i.e., the protocol that is the source or ultimate
sink for this packet.
3. The packet-header details window provides details
about the packet selected (highlighted) in the packet
listing window. (To select a packet in the packet listing
window, place the cursor over the packet’s one-line
summary in the packet listing window and click with the
left mouse button.). These details include information
about the Ethernet frame (assuming the packet was
sent/receiverd over an Ethernet interface) and IP
datagram that contains this packet. The amount of
Ethernet and IP-layer detail displayed can be expanded
or minimized by clicking on the plus minus boxes to the
left of the Ethernet frame or IP datagram line in the
packet details window. If the packet has been carried
over TCP or UDP, TCP or UDP details will also be
displayed, which can similarly be expanded or
minimized. Finally, details about the highest-level
protocol that sent or received this packet are also
provided.
4. The packet-contents window displays the entire
contents of the captured frame, in both ASCII and
hexadecimal format.
5. Towards the top of the Wireshark graphical user
interface, is the packet display filter field, into which a
protocol name or other information can be entered in
order to filter the information displayed in the packet-
listing window (and hence the packet-header and
packet-contents windows). In the example below, we’ll
use the packet-display filter field to have Wireshark hide
(not display) packets except those that correspond to
HTTP messages.

Taking Wireshark for a Test Run:-


The best way to learn about any new piece of software is to
try it out! We’ll assume that your computer is connected to
the Internet via a wired Ethernet interface. Do the following:

1. Start up your favorite web browser, which will display your


selected homepage.

2. Start up the Wireshark software. You will initially see a


window similar to that shown in Figure 2, except that no
packet data will be displayed in the packetlisting, packet-
header, or packet-contents window, since Wireshark has not
yet begun capturing packets.
3. To begin packet capture, select the Capture pull down
menu and select Options. This will cause the “Wireshark:
Capture Options” window to be displayed, as shown in Figure
3.

4. You can use most of the default values in this window, but
uncheck “Hide capture info dialog” under Display Options.
The network interfaces (i.e., the physical connections) that
your computer has to the network will be shown in the
Interface pull down menu at the top of the Capture Options
window. In case your computer has more than one active
network interface (e.g., if you have both a wireless and a
wired Ethernet connection), you will need to select an
interface that is being used to send and receive packets
(mostly likely the wired interface). After selecting the
network interface (or using the default interface chosen by
Wireshark), click Start. Packet capture will now begin - all
packets being sent/received from/by your computer are now
being captured by Wireshark!

5. Once you begin packet capture, a packet capture summary


window will appear, as shown in Figure 4. This window
summarizes the number of packets of various types that are
being captured, and (importantly!) contains the Stop button
that will allow you to stop packet capture. Do not stop packet
capture yet.

You might also like