2021UIT3140_MC_file
2021UIT3140_MC_file
2021UIT3140_MC_file
Practical File
Source Code:-
clear;
numNodes = 10;
G = graph;
G = addnode(G, numNodes);
centralNode = 1;
for i = 2:numNodes
G = addedge(G, centralNode, i);
end
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
Output:-
>> pract2
Bandwidth: 16.00 bps
InRate: 2.00
OutRate: 2.00
Transmission Delay: 0.000500 s
Packets Dropped: 0
Output:-
MATLAB Code for FDMA:-
for i = 1:num_users
signals_fdma(i, :) = sin(2*pi*frequency_bands(i)*t);
end
Output:-
MATLAB Code for CDMA:-
Output:-
Practical 5: Implement GSM using MATLAB
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
% Transmitter
% Use BPSK modulation (you can replace this with your
modulation scheme)
modulated_data = 2 * interleaved_frames - 1; % BPSK
modulation
% Display results
error_rate = biterr(data, received_data);
disp(['Bit Error Rate: ', num2str(error_rate)]);
Output:-
Practical 7: Implement LTE using MATLAB
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);
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.
function hDownlinkEstimationEqualizationResults(rxGrid,
eqGrid)
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.
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.
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!