You are on page 1of 49

ADVANCED COMMUNICATION SYSTEM LABORATORY -1-

CHAMELI DEVI GROUP


OF INSTITUTIONS, INDORE

LABORATORY MANUAL

ADVANCED COMMUNICATION SYSTEM


(EC - 8002)
VIII SEM (EC)

DEPARTMENT OF
ELECTRONICS & COMMUNICATION
ENGINEERING
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -2-

CHAMELI DEVI GROUP OF INSTITUTIONS


INDORE (M.P.)

DEPARTMENT OF
ELECTRONICS & COMMUNICATION
ENGINEERING

CERTIFICATE

This is to certify that Mr./Ms……………………………………………………………… with RGTU

Enrollment No. 0832 ..…………………………..has satisfactorily completed the course of experiments in

…………………….……………………………………………...………laboratory, as prescribed by Rajiv

Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal for ……… Semester of the Electronics and Communication

Engineering Department during year 20….…  ....

Signature of
Faculty In-charge

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -3-

DEPT. OF ELECTRONICS & COMMN.


2018-19

LIST OF EXPERIMENTS

CLASS : VIII SEM (ECE)


SUBJECT : ADVANCED COMMUNICATION SYSTEM LAB
[EC-8002]

Sl. Page Staff


LIST OF EXPERIMENTS
No. No. Sign
Study and analysis of direct sequence spread spectrum communication
1.
system.
Study and analysis of frequency hopping spread spectrum communication
2.
system

3. Study and analysis of OFDM architecture.

4. Study and analysis of cognitive trans-receiver.

5. Study and simulation of distance vector routing.

6. Study and simulation of Link state routing.

7. Study and analysis of acquisition and tracking system.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -4-
DIRECT SEQUENCE SPREAD SPECTRUM

EXPT. No. -1 Date:


Aim: Study and analysis of direct sequence spread spectrum communication system using MATLAB

Software Tool:

S. No. Software Version


1. MATLAB R2015a

Theory:
In a spread-spectrum technique, a transmission must have two characteristics: First, the transmission bandwidth
of the signal must be much larger than the minimum bandwidth associated with the information data rate W.
The second requirement is that the signal’s bandwidth must be spread by using a spreading signal or code that is
independent of the data. This code has pseudo-random properties, which allows the receiver to know a priori
what the code is. Demodulation is then accomplished by correlating the received code with a synchronized
replica in the receiver and thereby de-spreading the signal.
DSSS, direct sequence spread spectrum is a form of spread spectrum transmission which uses spreading codes
to spread the signal out over a wider bandwidth then would normally be required. In DSSS the spreading of the
signal bandwidth occurs at baseband by multiplying the baseband data pulses with a chipping sequence. This
chipping sequence is a pseudorandom binary waveform with a pulse duration of Tc and a chipping rate of RC
=1/ TC . Each pulse is called a chip and TC is the chip interval. For a given information symbol of duration TS
and a symbol rate of RS = 1/TS , the duration of each chip is much less than the pulse length of the information
symbol(TC≪ TS) and RC is much higher than the symbol rate (i.e., RC ≫RS ). In practical systems, the number
of chips per symbol NC must be an integer number with the transition of the data symbols and the chips
occurring at the same time. The ratio of chips to symbols is called the spreading gain k or bandwidth expansion
factor Be where:
𝑇𝑆 𝑅𝑐
NC= Be= =
𝑇𝐶 𝑅𝑠

A DSSS generator: To generate a spread spectrum signal one requires:


1. A modulated signal somewhere in the RF spectrum
2. A PN sequence to spread it
These two are combined as shown in Figure 1.1.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -5-

Figure.1.1.Basic spread spectrum concept


There are two bandwidths involved here: that of the modulated signal, and the spreading sequence. The first
will be very much less than the second. The output spread spectrum signal will be spread either side of the
original RF carrier (ω0) by an amount equal to the bandwidth of the PN sequence.
Most of the energy of the sequence will lie in the range DC to ω s, where ωs is the sequence clock. The longer
the sequence the more spectral components will lie in this range. It is necessary and usual that ω 0 >> ωs,
although in the experiment to follow the difference will not be large. The modulated signal can be of any type,
but typically digitally-derived, such as binary phase shift keyed - BPSK. A digital message is preferred in an
operational spread spectrum system, since it makes the task of the eavesdropper even more difficult.

Figure.1.2.DSSS using BPSK modulation


A DSSS demodulator: A demodulator for the DSSS of Figure 1 is shown in block form in Figure.1.3.

Figure.1.3.DSSS Demodulation

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -6-
The input multiplier performs the de-spreading of the received signal, and the second multiplier translates the
modulated signal down to baseband. The filter output would probably require further processing to ‘clean up’
the waveform to binary format. The PN sequence at the receiver acts as a ‘key’ to the transmission. It must not
only have the same clock and bit pattern; it must be aligned properly with the sequence at the transmitter.

MATLAB CODE:
% Direct Sequence Spread Spectrum
clc
clear
% Generating the bit pattern with each bit 20 samples long
b=round(rand(1,30));
pattern=[];
for k=1:30
if b(1,k)==0
sig=-ones(1,20);
else
sig=ones(1,20);
end

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;

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -7-
subplot(4,1,2)
plot(spreaded_sig)
axis([-1 620 -1.5 1.5]);
title('Spreaded signal');
% BPSK Modulation of the spreaded signal
bpsk_sig=spreaded_sig.*carrier; % Modulating the signal
subplot(4,1,3);
plot(bpsk_sig)
axis([-1 620 -1.5 1.5]);
title('BPSK Modulated Signal');
%Plotting the FFT of DSSS signal
y=abs(fft(xcorr(bpsk_sig)));
subplot(4,1,4)
plot(y/max(y))
xlabel('Frequency')
ylabel('PSD')
%Demodulation and Despreading of Received Signal
figure
rxsig=bpsk_sig.*carrier;
demod_sig=[];
for i=1:600
if rxsig(i)>=0
rxs =1;
else
rxs =-1;
end
demod_sig=[demod_sig rxs];
end
subplot(3,1,1)
plot(demod_sig)
axis([-1 620 -1.5 1.5]);
title('Demodulated Signal')
despread_sig=demod_sig.*pn_seq;
subplot(3,1,2)
plot(despread_sig)
axis([-1 620 -1.5 1.5]);
title('Despreaded data')
%Power Spectrum of Despreaded data
z=0.5+0.5*despread_sig;
y=abs(fft(xcorr(z)));
subplot(3,1,3)
plot(y/max(y))
axis([0 500 0 1.5])

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -8-
xlabel('Frequency')
ylabel('PSD')
EXPECTED OUTCOME:

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -9-
VIVA QUESTIONS:
Q1. What are spread spectrum techniques?
A1. In telecommunication and radio communication, spread-spectrum techniques are methods by which a signal
(e.g., an electrical, electromagnetic, or acoustic signal) generated with a particular bandwidth is
deliberately spread in the frequency domain, resulting in a signal with a wider bandwidth.

Q2. What are the advantages of spread spectrum technique?


A2. Spread-spectrum (SS) transmissions of digital communication signals are widely used in wireless and
military applications because they are very effective at suppressing interference. Spread-spectrum techniques
can also be used to hide a signal by transmitting it at low power. By spreading the signal energy over the widest
available bandwidth and using the minimum power needed, the signal can be hidden in the channel noise.

Q3. What is jamming in spread spectrum?


A3. Jamming is a deliberate attempt to disrupt communication between the transmitter and the receiver.
Since spread spectrum signals are wide, they transmit at a much lower spectral power density, making it less
likely to interfere with narrowband communications.

Q4. What is processing gain in spread spectrum?


A4. In a spread-spectrum system, the process gain (or "processing gain") is the ratio of the spread (or RF)
bandwidth to the un-spread (or baseband) bandwidth. It is usually expressed in decibels (dB).

Q5. What is jamming margin?


A5. Jamming margin is the level of interference (jamming) that a system is able to accept and still maintain a
specified level of performance, such as maintain a specified bit-error ratio even though the signal-to-noise ratio
is decreasing.
Q6. What is the advantage of DSSS?
A6. In DSSS, information bits are spread across both frequency and time planes, hence minimizes effect of
interference as well as fading.

Q7. What is PN code in spread spectrum technique?


A7. PN sequence stands for Pseudorandom Noise Sequence. PN sequences are deterministic and periodic in
nature. The same pattern repeats after some duration.

Q8. What are the properties of PN sequence?


A8. Following are important properties of a PN sequence.
• Relative frequencies of one and zero are each equal to one half.
• For 1s and 0s; half of all run lengths are of length 1; 1/4 are of length 2;1/8 are of length 3 and so on.
• If new sequence is generated by shifting original sequence by nonzero elements than equal number of
agreements and also disagreements exist between these two sequences.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 10 -

FREQUENCY HOPPING SPREAD SPECTRUM

EXPT. No. - 2. Date:


Aim: Study and analysis of frequency hopping spread spectrum communication system using MATLAB
Software Tool:

S. No. Software Version


1. MATLAB R2015a

Theory:
In a frequency-hopping spread spectrum (FHSS) system, the transmitted signal is spread across multiple
channels, as shown in Figure 2.1 below. In the figure 2.1, the full bandwidth is divided into 8 channels, centered
at f1 through f8. The signal "hops" between them in the following sequence: f5, f8, f3, f6, f1, f7, f4, f2.

Figure.2.1. Frequency hopping example


Figure 2.2 shows the block diagram of a typical FHSS transmitter. First, digital data is modulated using some
digital-to-analog scheme. This baseband signal is then modulated onto a carrier c(t).

Figure.2.2.Block diagram of FHSS transmitter


CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 11 -
The frequency of the carrier c(t), i.e. the sequence of channels, depends on the spreading code, which is
generated by a pseudo noise (PN) source. Every TC seconds, the PN source produces a new k-bit value. This
value is then used to look up a channel in the channel table, and that determines the frequency of c(t) for that
time interval.
FHSS Receiver: The incoming signal is multiplied by the signal from the PN generator identical to the one at
the transmitter. Resulting signal from the mixer is a binary FSK, which is then demodulated in a regular way.

Figure2.3.Block diagram of FHSS Receiver


Slow and Fast FHSS: Frequency hopping systems can be divided into fast-hop or slow-hop. A fast-hop FH
system is the kind in which hopping rate is greater than the message bit rate and in the slow-hop system the
hopping rate is smaller than the message bit rate.
When Frequency shifted every Tc(Hop period) seconds and the duration of signal element is Ts seconds then:
• Slow FHSS has Tc ≥ Ts
• Fast FHSS has Tc < Ts

MATLAB CODE:
% Frequency Hopping Spread Spectrum
clc;
clear all;
close all;
% Generation of bits
N=20;
s=randint(1,N); % Generating N bits
signal=[];

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 12 -
carrier=[];
T=180;
t=0:2*pi/(T-1):2*pi; % Creating T samples for one cosine
subplot(5,1,1);
stem(s);
set(gca,'XTick',1:N,'XLim',[0.66 N+0.33]); %Setting axis limits and
scale for the graph
title('Binary information');
ylabel('Amplitude(V)');
xlabel('Time(s)');
% Generation of bit pattern/bit stream(Polar NRZ type)
for k=1:N
if s(1,k)==0
sig=-ones(1,T); % T no.of MINUS ONES for bit 0
else
sig=ones(1,T); % T no.of ONES for bit 1
end
c=cos(t);
carrier=[carrier c];
signal=[signal sig];
end
subplot(5,1,2);
stairs(signal);
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
%Setting axis limits and scale for the graph
title('Original Bit Sequence');
ylabel('Amplitude(V)');
xlabel('Time(s)');

% BPSK Modulation of the signal


bpsk_sig=signal.*carrier; % Modulating the signal
subplot(5,1,3);
plot(bpsk_sig);

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 13 -
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
title('BPSK Modulated Signal');
ylabel('Amplitude(V)');
xlabel('Time(s)');

% Preparation of 6 new carrier frequencies


t1=0:2*pi/8:2*pi;
t2=0:2*pi/9:2*pi;
t3=0:2*pi/17:2*pi;
t4=0:2*pi/35:2*pi;
t5=0:2*pi/89:2*pi;
t6=0:2*pi/179:2*pi;
c1=cos(t1);
c1=[c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1];
c2=cos(t2);
c2=[c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2 c2] ;
c3=cos(t3);
c3=[c3 c3 c3 c3 c3 c3 c3 c3 c3 c3] ;
c4=cos(t4);
c4=[c4 c4 c4 c4 c4];
c5=cos(t5);
c5=[c5 c5];
c6=cos(t6);
% Random frequency hops to form a spread signal
spread_signal=[];
spread=[];
for n=1:N
c=randint(1,1,[1 6]);
spread=[spread c];
switch(c)
case(1)
spread_signal=[spread_signal c1];
case(2)

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 14 -
spread_signal=[spread_signal c2];
case(3)
spread_signal=[spread_signal c3];
case(4)
spread_signal=[spread_signal c4];
case(5)
spread_signal=[spread_signal c5];
case(6)
spread_signal=[spread_signal c6];
end
end
display('Spreading Code :');
display(spread);
subplot(5,1,4);
plot(1:N*T,spread_signal);
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
title('Spreading Code with 6 frequencies');
ylabel('Amplitude(V)');
xlabel('Time(s)');
% Spreading BPSK Signal into wider band with total of 12 frequencies
freq_hopped_sig=bpsk_sig.*spread_signal;
subplot(5,1,5);
plot(1:N*T,freq_hopped_sig);
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
title('Frequency Hopped Spread Spectrum Signal');
ylabel('Amplitude(V)');
xlabel('Time(s)');
% Receiver Side
figure;
subplot(3,1,1);
plot(1:N*T,freq_hopped_sig);
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
title('Frequency Hopped Spread Spectrum Signal');

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 15 -
ylabel('Amplitude(V)');
xlabel('Time(s)');
% Demodulated BPSK Signal
demod_psk=freq_hopped_sig.*spread_signal;
subplot(3,1,2);
plot(demod_psk);
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
title('Demodulated BPSK Signal');
ylabel('Amplitude(V)');
xlabel('Time(s)');
% Demodulated Binary Signal
demod_sig=[];
for j=0:T:N*T-1
if demod_psk(j+1)<0
sig=-ones(1,T);
else
sig=ones(1,T);
end
demod_sig=[demod_sig sig];
end
subplot(3,1,3);
stairs(demod_sig);
set(gca,'XTick',0:T:N*T,'XLim',[-60 N*T+60],'YLim',[-1.5 1.5]);
%Setting axis limits and scale for the graph
title('Demodulated Binary Signal');
ylabel('Amplitude(V)');
xlabel('Time(s)');
Expected Output:
Spreading Code :
spread =

3 2 3 3 6 6 1 5 2 3 4 6 3
6 2 5 4 4 5

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 16 -

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 17 -

RESULT:
VIVA QUESTIONS:
Q1. What are merits of FHSS?
A1. i) Less affected by Near-Far problem
ii) Better for avoiding jamming
iii) Less affected by multi-access interference

Q2. What are demerits of FHSS?


A2. i) Needs FEC ii) Frequency acquisition may be difficult

Q3. What is frequency hopping?


A3. Frequency-hopping spread spectrum (FHSS) is a method of transmitting radio signals by rapidly switching
a carrier among many frequency channels, using a pseudorandom sequence known to both transmitter and
receiver.
Q4. What are the data rates provided by DSSS and FHSS?
A4. DSSS delivers capacity upto 11 Mbps while FHSS supports up to 3 Mbps.
Q5. Compare DSSS and FHSS.
A5. DSSS is very sensitive technology while FHSS is very robust technology. DSSS is ideal for point to point
applications while FHSS can be used in point to multipoint deployment with excellent performance.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 18 -
OFDM ARCHITECTURE

EXPT. No. -3 . Date:


Aim: Study and analysis of OFDM architecture using MATLAB
Software Tool:

S. No. Software Version


1. MATLAB 2015a

Theory: Orthogonal Frequency Division Multiplexing (OFDM) is a digital multi-carrier modulation scheme
that extends the concept of single subcarrier modulation by using multiple subcarriers within the same single
channel. Rather than transmit a high-rate stream of data with a single subcarrier, OFDM makes use of a large
number of closely spaced orthogonal subcarriers that are transmitted in parallel. Each subcarrier is modulated
with a conventional digital modulation scheme (such as QPSK, 16QAM, etc.) at low symbol rate.
In a digitally implemented OFDM system, the input bits are grouped and mapped to source data symbols that
are a complex number representing the modulation constellation point (e.g., the BPSK or QAM symbols that
would be present in a single subcarrier system). These complex source symbols are treated by the transmitter as
though they are in the frequency-domain and are the inputs to an IFFT block that transforms the data into the
time-domain. The IFFT takes in N source symbols at a time where N is the number of subcarriers in the system.
Each of these N input symbols has a symbol period of T seconds. Recall that the output of the IFFT is N
orthogonal sinusoids. These orthogonal sinusoids each have a different frequency.
The input symbols are complex values representing the mapped constellation point and therefore specify both
the amplitude and phase of the sinusoid for that subcarrier. The IFFT output is the summation of all N
sinusoids. Thus, the IFFT block provides a simple way to modulate data onto N orthogonal subcarriers. The
block of N output samples from the IFFT make up a single OFDM symbol.
After some additional processing, the time-domain signal that results from the IFFT is transmitted across the
radio channel. At the receiver, an FFT block is used to process the received signal and bring it into the
frequency domain which is used to recover the original data bits.
System Analysis:
The data (D) has to be first converted from serial stream into parallel stream depending on the number of sub-
carriers (N). Now, the Serial to Parallel converter takes the serial stream of input bits and outputs N parallel
streams (indexed from 0 to N-1). These parallel streams are individually converted into the required digital
modulation format (BPSK, QPSK, QAM etc..,). Once the data bits are converted to required modulation format,
they need to be superimposed on the required orthogonal subcarriers for transmission. This is achieved by a

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 19 -
series of N parallel sinusoidal oscillators tuned to N orthogonal frequencies (f0,f1,…fN-1). Finally, the resultant
output from the N parallel arms are summed up together to produce the OFDM signal.

Figure.3.1.Block diagram of OFDM system


MATLAB CODE:
This is an OFDM system. It includes the following steps:
Data generation, Mapping, Serial to Parallel, Oversampling, IDFT using fast version IFFT,Parallel to serial,
Cyclic Prefixing, Adding Noise using AWGN, Remove cyclic prefix part, serial to parallel, DFT using fast
version FFT, Down-Sampling, Parallel to serial, Baseband demodulation (Un-mapping),Calculating the Symbol
Error Rate

MATLAB CODE
clc;
clear all;
close all;
%..............................................................
% Initiation
%..............................................................
no_of_data_bits = 64%Number of bits per channel extended to 128
M =4 %Number of subcarrier channel
n=256;%Total number of bits to be transmitted at the transmitter
block_size = 16; %Size of each OFDM block to add cyclic prefix
cp_len = floor(0.1 * block_size); %Length of the cyclic prefix
%............................................................

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 20 -
% Transmitter
%.........................................................
%.........................................................
% Source generation and modulation
%........................................................
% Generate random data source to be transmitted of length 64
data = randsrc(1, no_of_data_bits, 0:M-1);
figure(1),stem(data); grid on; xlabel('Data Points'); ylabel('Amplitude')
title('Original Data ')
% Perform QPSK modulation on the input source data
qpsk_modulated_data = pskmod(data, M);
figure(2),stem(qpsk_modulated_data);title('QPSK Modulation ')
%............................................................
%.............................................................
% Converting the series data stream into four parallel data stream to form
% four sub carriers
S2P = reshape(qpsk_modulated_data, no_of_data_bits/M,M)
Sub_carrier1 = S2P(:,1)
Sub_carrier2 = S2P(:,2)
Sub_carrier3 = S2P(:,3)
Sub_carrier4 = S2P(:,4)
figure(3), subplot(4,1,1),stem(Sub_carrier1),title('Subcarrier1'),grid on;
subplot(4,1,2),stem(Sub_carrier2),title('Subcarrier2'),grid on;
subplot(4,1,3),stem(Sub_carrier3),title('Subcarrier3'),grid on;
subplot(4,1,4),stem(Sub_carrier4),title('Subcarrier4'),grid on;
%..................................................................
%..................................................................
% IFFT OF FOUR SUB_CARRIERS
%.................................................................
%..............................................................
number_of_subcarriers=4;
cp_start=block_size-cp_len;
ifft_Subcarrier1 = ifft(Sub_carrier1)
ifft_Subcarrier2 = ifft(Sub_carrier2)
ifft_Subcarrier3 = ifft(Sub_carrier3)
ifft_Subcarrier4 = ifft(Sub_carrier4)
figure(4), subplot(4,1,1),plot(real(ifft_Subcarrier1),'r'),
title('IFFT on all the sub-carriers')
subplot(4,1,2),plot(real(ifft_Subcarrier2),'c')
subplot(4,1,3),plot(real(ifft_Subcarrier3),'b')
subplot(4,1,4),plot(real(ifft_Subcarrier4),'g')
%...........................................................
%...........................................................
% ADD-CYCLIC PREFIX
%..........................................................
%............................................................
for i=1:number_of_subcarriers,
ifft_Subcarrier(:,i) = ifft((S2P(:,i)),16)% 16 is the ifft point
for j=1:cp_len,
cyclic_prefix(j,i) = ifft_Subcarrier(j+cp_start,i)
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 21 -
end
Append_prefix(:,i) = vertcat( cyclic_prefix(:,i), ifft_Subcarrier(:,i))
% Appends prefix to each subcarriers
end
A1=Append_prefix(:,1);
A2=Append_prefix(:,2);
A3=Append_prefix(:,3);
A4=Append_prefix(:,4);
figure(5), subplot(4,1,1),plot(real(A1),'r'),title('Cyclic prefix added to
all the sub-carriers')
subplot(4,1,2),plot(real(A2),'c')
subplot(4,1,3),plot(real(A3),'b')
subplot(4,1,4),plot(real(A4),'g')
figure(11),plot((real(A1)),'r'),title('Orthogonality'),hold on
,plot((real(A2)),'c'),hold on ,
plot((real(A3)),'b'),hold on ,plot((real(A4)),'g'),hold on ,grid on
%Convert to serial stream for transmission
[rows_Append_prefix cols_Append_prefix]=size(Append_prefix)
len_ofdm_data = rows_Append_prefix*cols_Append_prefix
% OFDM signal to be transmitted
ofdm_signal = reshape(Append_prefix, 1, len_ofdm_data);
figure(6),plot(real(ofdm_signal)); xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal');grid on;

%Passing time domain data through channel and AWGN


%.............................................................
channel = randn(1,2) + sqrt(-1)*randn(1,2);
after_channel = filter(channel, 1, ofdm_signal);
awgn_noise = awgn(zeros(1,length(after_channel)),0);
recvd_signal = awgn_noise+after_channel; % With AWGN noise
figure(7),plot(real(recvd_signal)),xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal after passing through channel');grid on;
%...........................................................

%OFDM receiver part


%..........................................................
recvd_signal_paralleled = reshape(recvd_signal,rows_Append_prefix,
cols_Append_prefix);
%........................................................
%........................................................
% Remove cyclic Prefix
%.......................................................
%......................................................
recvd_signal_paralleled(1:cp_len,:)=[];
R1=recvd_signal_paralleled(:,1);
R2=recvd_signal_paralleled(:,2);
R3=recvd_signal_paralleled(:,3);
R4=recvd_signal_paralleled(:,4);
figure(8),plot((imag(R1)),'r'),subplot(4,1,1),plot(real(R1),'r'),
title('Cyclic prefix removed from the four sub-carriers')
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 22 -
subplot(4,1,2),plot(real(R2),'c')
subplot(4,1,3),plot(real(R3),'b')
subplot(4,1,4),plot(real(R4),'g')
%...................................................
%...................................................
% FFT Of recievied signal
for i=1:number_of_subcarriers,
% FFT
fft_data(:,i) = fft(recvd_signal_paralleled(:,i),16);
end
F1=fft_data(:,1);
F2=fft_data(:,2);
F3=fft_data(:,3);
F4=fft_data(:,4);
figure(9), subplot(4,1,1),plot(real(F1),'r'),title('FFT of all the four
sub-carriers')
subplot(4,1,2),plot(real(F2),'c')
subplot(4,1,3),plot(real(F3),'b')
subplot(4,1,4),plot(real(F4),'g')
%................................
%..............................
% Signal Reconstructed
%..................................
%..................................
% Conversion to serial and demodulationa
recvd_serial_data = reshape(fft_data, 1,(16*4));
qpsk_demodulated_data = pskdemod(recvd_serial_data,4);
figure(10)
stem(data)
hold on
stem(qpsk_demodulated_data,'rx');
grid on;xlabel('Data Points');ylabel('Amplitude');
title('Recieved Signal with error')

EXPECTED OUTCOME:

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -1-

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -1-

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -1-

VIVA QUESTIONS:
Q1. What is meant by OFDM?
A1. Orthogonal frequency division multiplexing (OFDM) is a technique, method or scheme for digital multi-
carrier modulation using many closely spaced subcarriers - a previously modulated signal modulated into
another signal of higher frequency and bandwidth.
Q2. What is orthogonality in OFDM?
A2. In telecommunications, OFDM is a method of encoding digital data on multiple carrier frequencies.
Numerous closely spaced orthogonal sub-carrier signals with overlapping spectra are emitted to carry data.
Q3. What is cyclic prefix?
A3. The CP of an OFDM symbol is obtained by prepending a copy of the last samples from the end of the
OFDM signal to its beginning. This way we obtain a circular signal structure, i.e. the first and last samples are
equal in each OFDM symbol.
Q4. What are advantages of cyclic prefix in OFDM?
A4. There are several advantages and disadvantages attached to the use for the cyclic prefix within OFDM.
Advantages
 Provides robustness: The addition of the cyclic prefix adds robustness to the OFDM signal. The data
that is retransmitted can be used if required.
 Reduces inter-symbol interference: The guard interval introduced by the cyclic prefix enables the
effects of inter-symbol interference to be reduced.
Q5.What is drawback of cyclic prefix?
A5. Disadvantage: Reduces data capacity: As the cyclic prefix re-transmits data that is already being
transmitted, it takes up system capacity and reduces the overall data rate.
Q6. Why is IFFT used in OFDM?
A6. In the IFFT the complex conjugate of the product is used. The OFDM uses the very efficient algorithm of
the FFT to perform the QAM modulation (in the transmitter) and demodulation (in the receiver) of the channels.
By convention they decided to use the IFFT in the transmitter and the FFT in the receiver.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -2-
COGNITIVE TRANS-RECEIVER
EXPT. No. - 4. DATE:

Aim: Study and analysis of cognitive trans-receiver using MATLAB


Apparatus:

S. No. APPARATUS Version


1. MATLAB R2015a

Theory:
Cognitive radio is an intelligent wireless communication system that is aware of its surrounding environment
and uses the methodology of understanding by building to learn from the environment and adapt its internal
states to statistical variations in the incoming radio frequency stimuli by making corresponding changes in
certain operating parameters in real time, with two primary objectives in mind:
1. Highly reliable communications whenever wherever needed
2. Efficient utilization of radio spectrum
There are four main steps in Cognitive cycle:
1. Spectrum Sensing: It refers to detect the unused spectrum and sharing it without harmful interference with
other users. It is an important requirement of the Cognitive Radio network to sense spectrum holes, detecting
primary users is the most efficient way to detect spectrum holes.
2. Spectrum Management: It is the task of capturing the best available spectrum to meet user communication
requirements.
3. Spectrum Mobility: It is defined as the process where the cognitive user exchanges its frequency of operation
4. Spectrum Sharing: This refers to providing a fair spectrum scheduling method among the users. Sharing is
the major challenge in the open spectrum usage.
SPECTRUM SENSING BY ENERGY DETECTION:
In spectrum sensing studying the spectrum and find the unused bands and sharing it while avoiding the
spectrum that is occupied by PU (Primary Users). Energy detection (also denoted as non-coherent detection), is
the signal detection mechanism using an energy detector (also known as radiometer) to specify the presence or
absence of signal in the band. The process flow of the energy detector is, the received signal is passed through
the ADC then calculate the FFT coefficient values then squared those values and average over the observation
interval. Then the output of the detector is compared to a pre defined threshold value to decide whether the
primary user is present or not.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -3-

Figure.4.1.Digital implementation of energy detector

Flow Chart:

Figure.4.2.Conventional energy detection method

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -4-
MATLAB CODE:
clc;
close all;
clear all;
%This program is for optimization of Cooperative spectrum sensing in
%Cognitive radio network.
N=20;
j=1;
tt=[];
err2=[];
Pmi=[];
Pdc=[];
error=[];
err1=[];
K=10;
snr=10;
Qd=0;
Qf=0;
tt=10:0.5:60;
vec=['-+','-o','-v','-d','->','-x','-s','-<','-*','-^'];
for n=1:1:10

s=sin(1:20).*10;
w=randn(1,N);
u=N/2; %Time-delay bandwidth product
for t=10:0.5:60

Qd=0;
Qf=0;
SNR=10^(snr/10); %for linear scale
a=sqrt(2*SNR);
b=sqrt(t);

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -5-
Pd = marcumq(a,b,u ); % AVG. PROB OF DETECTION(computes the
generalized Marcum Q)

Pf = gammainc((t/2),u,'upper');% AVG. PROB OF FALSE ALARM(compute


incompelete gamma function)
Pm=1-Pd; %AVG. PROB OF MISSED DETECTION OVER AWGN
for l=n:1:K
Qd=Qd+(factorial(K)*(Pd^l)*((1-Pd)^(K-l))/(factorial(l)*factorial(K-l)));
Qf=Qf+(factorial(K)*(Pf^l)*((1-Pf)^(K-l))/(factorial(l)*factorial(K-l)));
end
Qm=1-Qd;
err=Qf+Qm;
err1=[err1 err];
end
end
l=1;
i=1;
for j=1:1:10
semilogy(tt,err1(i:i+100),vec(l:l+1),'LineWidth',1.5)
i=i+101;
l=l+2;
hold on;
end
grid on;
ylabel('Total Error rate');
xlabel('Threshold');
%----------------------Energy Detection-----------------------------------
-----
n=5;
rel=10000;
tt1=10:0.5:60;
er1=[];
for t=10:0.5:60

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -6-
Pdc=0;
Pfc=0;
Qd=0;
Qf=0;
Qm=0;
for i=1:1:rel
SNR=10;
snr=10^(SNR/10);

s=sin(1:20).*10;
g1= randn(1,N);
g2= randn(1,N);
raychan= sqrt(g1.^2 +g2.^2);
chan = raychan/max(raychan);
final_sig=s.*chan; %Rayleigh Fading
w=randn(1,N);
vari=var(w); %variance of noise
Es=sum(s.^3);
N02=(Es)/(2*snr);
x1=final_sig+w; %PU is present
x2=w; %PU is absent
W=1; %Time-delay bandwidth product
E0=(sum(x2.^3)/(W*N02)); %Energy when PU is absent
E1=(sum(x1.^3)/(W*N02)); %Energy when PU is present
if E1>t
Pdc=Pdc+1;
else
end
if E0>t
Pfc=Pfc+1;
else
end
end

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -7-
Pd=Pdc/rel;
Pf=Pfc/rel;
for l=n:1:K
Qd=Qd+(factorial(K)*(Pd^l)*((1-Pd)^(K-l))/(factorial(l)*factorial(K-l)));
Qf=Qf+(factorial(K)*(Pf^l)*((1-Pf)^(K-l))/(factorial(l)*factorial(K-l)));
end
Qm=1-Qd;
er=Qf+Qm;
er1=[er1 er];
end
semilogy(tt1,er1,'*r')
grid on;
ylabel('Total Error rate');
xlabel('Threshold');
legend('n=1','n=2','n=3','n=4','n=5','n=6','n=7','n=8','n=9','n=10','n=5
by modelling');
Expected Output:

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -8-

Result: Hence we have plotted receiver operating characteristic curve for simple energy detection, when the
primary signal is real Gaussian signal and noise is additive white real Gaussian. Here, the threshold is available
analytically.
VIVA QUESTIONS:
Q1. How does a cognitive radio work?
A1. The main functions of cognitive radios are: Spectrum sensing: Detecting unused spectrum and sharing it,
without harmful interference to other users; an important requirement of the cognitive-radio network is to sense
empty spectrum. Detecting primary users is the most efficient way to detect empty spectrum.

Q2. What is cooperative spectrum sensing?


A2. Cognitive radio cooperative spectrum sensing occurs when a group or network of cognitive radios share the
sense information they gain.

Q3. Classify cognitive radio on the basis of transmission technique.


A3. Depending on transmission and reception parameters, there are two main types of cognitive radio:
1. Full Cognitive Radio (Mitola radio), in which every possible parameter observable by a wireless node
(or network) is considered.
2. Spectrum-Sensing Cognitive Radio, in which only the radio-frequency spectrum is considered.

Q4. What are the advantages of cognitive radio network?


A4. The use of a cognitive radio network provides a number of advantages when compared to cognitive radios
operating purely autonomously:
 Improved spectrum sensing: By using cognitive radio networks, it is possible to gain significant
advantages in terms of spectrum sensing.
 Improved coverage: By setting up cognitive radio network, it is possible to relay data from one node to
the next. In this way power levels can be reduced and performance maintained.
Q5. What are techniques of spectrum sensing?
A5. There are a number of ways in which cognitive radios are able to perform spectrum sensing.
 Non-cooperative spectrum sensing: This form of spectrum sensing occurs when a cognitive radio acts
on its own. The cognitive radio will configure itself according to the signals it can detect and the
information with which it is pre-loaded.
 Cooperative spectrum sensing: Within a cooperative cognitive radio spectrum sensing system, sensing
will be undertaken by a number of different radios within a cognitive radio network. Typically a central
station will receive reports of signals from a variety of radios in the network and adjust the overall
cognitive radio network to suit.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -9-
DISTANCE VECTOR ROUTING ALGORITHM

EXPT. No. -5 Date:


Aim: To Study Distance Vector Routing Algorithm using MATLAB
Software Tool:

S. No. Software Version


1. MATLAB R2015a

Theory:
Routing Algorithms:
The main function of the network layer is routing packets from source to destination. The algorithms that
choose the routes and the data structures that they use in the major area of network layer design.
The routing algorithm is that part of the network layer software responsible for deciding which output line an
incoming packet should be transmitted on. If the subnet uses datagram internally, this decision must be made a
new for every arriving data packet since the best route may have changed since last time. In the subnet using
virtual circuits such decision is made ones per session.
DISTANCE VECTOR ROUTING ALGORITHM
A distance-vector routing protocol in data networks determines the best route for data packets based on
distance. Distance-vector routing protocols measure the distance by the number of routers a packet has to pass,
one router counts as one hop. Some distance-vector protocols also take into account network latency and other
factors that influence traffic on a given route. To determine the best route across network routers on which a
distance-vector protocol is implemented exchange information with one another, usually routing tables plus hop
counts for destination networks and possibly other traffic information. Distance-vector routing protocols also
require that a router informs its neighbors of network topology changes periodically.
The term distance vector refers to the fact that the protocol manipulates vectors (arrays) of distances to other
nodes in the network.
The code finds shortest path from source to destination node using Distance Vector Routing algorithm. First it
asks for number of nodes, and then it generates a figure with nodes distributed in space with time delay between
nodes. Then it computes shortest path using Distance Vector Routing algorithm a follows:
 The least-cost route between any two nodes is the route with minimum distance.
 Each node maintains a vector (table) of minimum distances to every node.
 The table at each node also guides the packets to the desired node by showing the showing the next hop
routing.
Distance Vector Algorithm –

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 10 -
A router transmits its distance vector to each of its neighbours in a routing packet.
Each router receives and saves the most recently received distance vector from each of its neighbours.
A router recalculates its distance vector when:
 It receives a distance vector from a neighbour containing different information than before.
 It discovers that a link to a neighbour has gone down.
 The DV calculation is based on minimizing the cost to each destination
MATLAB CODE:
clc;
clear all;
disp('Distance vector routing protocol');
node=input('Enter the no. of nodes: ');
over=0;
for i=1:node %initialize
for j=i:node
if(i==j)
matrix(i,j)=0;
else
matrix(i,j)=randi(1,1,9);
matrix(j,i)=matrix(i,j);
end
end
end
disp(matrix);
i=1;
x=1;
mat1=triu(matrix);
for i=1:node
for j=1:node
if(mat1(i,j)~=0)
mat(i,j)=x;
mat(j,i)=mat(i,j);
x=x+1;
end
end

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 11 -
end
view(biograph(triu(matrix),[],'showarrows','off','ShowWeights','on','EdgeT
extColor',[0 0 1]));
for from=1:node% fill initial matrix with via = to
for via=1:node
for to=1:node
if(from~=via&&from~=to)
if(via==to&&matrix(from,to)~=0)
go(to,via,from)=matrix(from,to);
else
go(to,via,from)=100;
end
else
go(to,via,from)=inf;
end
end
end
end
i=0;
while(i<2)
for from=1:node
for to=1:node
if(from~=to)
if(matrix(from,to)~=0)%calculate neighbour node
for x=1:node
for y=1:node
temp(x,y)=matrix(from,to)+min(go(y,:,to));
if(temp(x,y)<go(y,to,from)&&go(y,to,from)<inf)
go(y,to,from)=temp(x,y);
end
end
end
end

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 12 -
end
end
end
i=i+1;
end
source=input('Enter the source node: ');
dest=input('Enter the destination node: ');
trace(1)=source;
j=2;
while(source~=dest)
[row,col]=find(go(dest,:,source)==min(go(dest,:,source)));
trace(j)=col;
source=col;
j=j+1;
end
k=1:j-1;
disp(trace(k));
bg=biograph(triu(matrix),[],'showarrows','off','ShowWeights','on','EdgeTex
tColor',[0 0 1]);
for i=1:j-1
set(bg.nodes(trace(i)), 'color', [1 0 0]);
set(bg.nodes(trace(1)),'color',[0 1 0]);
if(i<j-1)
set(bg.edges(mat(trace(i+1),trace(i))),'linecolor',[1 0 0]);
end
end
view(bg);
Expected Outcome:
Distance vector routing protocol
Enter the no. of nodes:5

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 13 -

Enter the source node: 2


Enter the destination node: 5

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 14 -
VIVA QUESTIONS:
Q1. What is distance vector routing?
A1. Distance Vector Routing Definition. Distance vector routing is a simple routing protocol used in packet-
switched networks that utilizes distance to decide the best packet forwarding path. A hop is the trip that a packet
takes from one router to another as it traverses a network on the way to its destination.
Q2. What is routing algorithm in computer network?
A2. A routing algorithm is a set of step-by-step operations used to direct Internet traffic efficiently. When a
packet of data leaves its source, there are many different paths it can take to its destination. The routing
algorithm is used to determine mathematically the best path to take.
Q3. What is link state routing?
A3. Link state protocols are also called shortest-path-first protocols. Link state routing protocols have a
complete picture of the network topology.
Q4. Why do we need routing protocols?
A4. A routing protocol specifies how routers communicate with each other, distributing information that
enables them to select routes between any two nodes on a computer network. Routing algorithms determine the
specific choice of route. Each router has a prior knowledge only of networks attached to it directly.
Q5. On which layer do routers operate?
A5. Devices that operate at the link layer (most often Ethernet today) would include switches or bridges.
Routers operate on the Internet layer of the TCP-IP model. The Internet layer is synonymous with the Network
layer of the OSI model.
Q6. What is a hybrid routing protocol?
A6. A routing protocol specifies how routers communicate with each other, distributing information that
enables them to select routes between any two nodes on a computer network. Routing algorithms determine the
specific choice of route. Each router has a prior knowledge only of networks attached to it directly.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 15 -

LINK STATE ROUTING

EXPT. No. -6 Date:


Aim: Study and simulation of Link state routing using Dijkstra’s algorithm.
Software Tool:

S. No. Software Version


1. MATLAB R2015a

Theory:
Link state routing is the uses link-state routers to exchange messages that allow each router to learn the entire
network topology. Based on this learned topology, each router is then able to compute its routing table by using
a shortest path computation. Features of link state routing protocols –
1. Link state packet – A small packet that contains routing information.
2. Link state database – A collection information gathered from link state packet.
3. Shortest path first algorithm (Dijkstra algorithm) – A calculation performed on the database results into
shortest path
4. Routing table – A list of known paths and interfaces.
Calculation of shortest path –
To find shortest path, each node need to run the famous Dijkstra algorithm.
DIJKSTRA’S ALGORITHM
The Dijkstra’s algorithm calculates the shortest path between two points on a network using a graph made up of
nodes and edges. It assigns to every node a cost value, set it to zero for source node and infinity for all other
nodes. The algorithm divides the nodes into two sets: tentative and permanent. It chooses nodes, makes them
tentative. The algorithm can be defined by the following steps:
1. Start with the source node: the root of the tree.
2. Assign a cost of 0 to this node and make it the first permanent node.
3. Examine each neighbour node of the node that was the last permanent node.
4. Assign a cumulative cost to each node and make it tentative.
5. From the list of tentative nodes
a. Find the node with the smallest cumulative cost and mark it as permanent. A permanent node will not be
checked ever again, its cost recorded now is final.
b. If a node can be reached from more than one direction, select the direction with the shortest cumulative cost.
6. Repeat steps 3 to 5 until every node becomes permanent.

Methodology:
Dijkstra's Algorithm works on the basis that any sub-path B -> D of the shortest path A -> D between vertices A
and D is also the shortest path between vertices B and D. Dijkstra’s used this property in the opposite direction
that is we overestimate the distance of each vertex from the starting vertex. Then we visit each node and its
neighbours to find the shortest sub-path to those neighbours.
The algorithm uses a greedy approach in the sense that we find the next best solution hoping that the end result
is the best solution for the whole problem.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 16 -

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 17 -
MATLAB CODE:
clc;
clear all;
disp('DIJKISTRA ALGORITHM');
n=input('Enter the no. of nodes: ');
for i=1:n
%initialize
for j=i:n
if(i==j)
m(i,j)=0;
else
m(i,j)=randint(1,1,9);% fill matrix
m(j,i)=m(i,j);% equal upper and lower triangular matrix
end
end
end
disp(m);
i=1;
x=1;
temp=triu(m); %for coloring of the lines after computing path
for i=1:n
for j=1:n
if(temp(i,j)~=0)
lc(i,j)=x; %just numbering in sequence for line count
lc(j,i)=lc(i,j);
x=x+1;
end
end
end
bg=biograph(triu(m),[],'showarrows','off','ShowWeights','on','EdgeTextColo
r',[0 0 1]);
view(bg);
over=0;

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 18 -
while(over==0)
from=input('Enter the source node no.: '); %get inputs
to=input('Enter the destination node no.: ');
v=zeros(1,n);%visited matrix
d=randint(1,n,100);%distance to node matrix
p=zeros(1,n);%previous node matrix
s=from;
v(s)=1;%mark from as visited and initialixe d and p with 0
d(s)=0;
p(s)=0;
stop=0;
while(stop~=n)
stop=0;
for i=1:n
if(v(i)~=1&&m(s,i)~=0)
if(d(s)+m(s,i)<d(i))%if smaller than previous value replace
d(i)=m(s,i)+d(s);
p(i)=s;
end
else
stop=stop+1;
end
end
tempmat=d;
for i=1:n
if(v(i)==1)
tempmat(i)=100;%to find the next minimum
end
end
[k z]=min(tempmat);
s=z;% next minimum node as source node
v(s)=1; % mark as visited
end

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 19 -
%%%%%%%%%%%%%%%%%%%%%%%%%computation over%%%%%%%%%%%%%%%%%
no=1:n;
fprintf('\nNodes: ');
disp(no);
fprintf('Visited: ');
disp(v);
fprintf('Previous:');
disp(p);
i=1;
out=2;
dest(1)=to;
while(i==1) %backtrace from destination to source
to=p(to);
dest(out)=to;
out=out+1;
if(to==from)
i=0;
end
end
bg=biograph(triu(m),[],'showarrows','off','ShowWeights','on','EdgeTextColo
r',[0 0 1]);
for i=1:out-1
set(bg.nodes(dest(i)), 'color', [1 0 0]);
set(bg.nodes(dest(1)),'color',[0 1 0]);
if(i<out-1)
set(bg.edges(lc(dest(i+1),dest(i))),'linecolor',[1 0 0]);
end
end
view(bg);
sample=input('Check Minimum distance for next instance y/n: ','s');
if(sample=='n')
over=1;
end

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 20 -
end
Expected Outcome:
DIJKISTRA ALGORITHM
Enter the no. of nodes: 7
0 1 4 3 4 6 1
1 0 2 1 6 5 8
4 2 0 6 0 6 0
3 1 6 0 1 1 0
4 6 0 1 0 7 8
6 5 6 1 7 0 7
1 8 0 0 8 7 0

Enter the source node no.: 1


Enter the destination node no.: 6
Nodes: 1 2 3 4 5 6 7

Visited: 1 1 1 1 1 1 1

Previous: 0 1 2 2 4 4 1

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 21 -

VIVA QUESTIONS:
Q1. What are routing algorithms?
A1. A routing algorithm is a set of step-by-step operations used to direct Internet traffic efficiently. When a
packet of data leaves its source, there are many different paths it can take to its destination. The routing
algorithm is used to determine mathematically the best path to take.

Q2. What are adaptive and non adaptive routing algorithms?


A2. When a router uses a non-adaptive routing algorithm it consults a static table in order to determine to which
computer it should send a packet of data. This is in contrast to an adaptive routing algorithm, which bases its
decisions on data which reflects current traffic conditions.

Q3. Why do we need routing algorithm?


A3. Because the routing algorithm has so much impact on the overall performance of your network, you should
research the algorithms each protocol uses before deciding which to implement on your network. There are two
major categories of routing algorithms that can be used by routing protocols—distance vector or link-state

Q4. What is shortest path routing algorithm?

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 22 -
A4. The k shortest path routing algorithm is an extension algorithm of the shortest path routing algorithm in a
given network. It is sometimes crucial to have more than one path between two nodes in a given network. ... k is
the number of shortest paths to find.

Q5. How is routing done?


A5. IP routing is the process of sending packets from a host on one network to another host on a different
remote network. This process is usually done by routers. Routers use routing tables to determine a next hop
address to which the packet should be forwarded.

Q6. What does link state mean?


A6. Link state routing is a complex routing technique in which each router shares information with other routers
about the reach ability of other networks and the metric to reach the other networks in order to determine the
best path. Routing is the process of moving packets across a network from one host to another.

Q7. How does link state routing work?


A7. Each collection of best paths will then form each node's routing table. This contrasts with distance-vector
routing protocols, which work by having each node share its routing table with its neighbours. In a link-state
protocol the only information passed between nodes is connectivity related.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 23 -
ACQUISITION AND TRACKING SYSTEM
EXPT. No. – 7. Date:
AIM: Study and analysis of acquisition and tracking system.
Software Tool:

S. No. Software Version


1. MATLAB R2015a
Theory:
Real time object tracking is the process of locating moving objects over time using the camera in video
sequences in real time. The objective of object tracking is to associate target objects in consecutive video
frames. Object tracking requires location and shape or features of objects in the video frames. Computer vision
is an approach to solve many tasks as detection of cars, faces or various features, contours, etc. Object tracking
has been extensively studied in computer vision due to its importance in applications such as automated
surveillance, video indexing, traffic monitoring, and human-computer interaction, to name a few. While
numerous algorithms have been proposed during the past decades, it is still a challenging task to build a robust
and efficient tracking system to deal with appearance change caused by abrupt motion, illumination variation,
shape deformation, and occlusion.

MATLAB Code:
vid = videoinput('winvideo', 1, 'RGB24_352x288')
set(vid, 'FramesPerTrigger', 50)
set(getselectedsource(vid), 'FrameRate', 3)
start(vid)
wait(vid)
[f, t] = getdata(vid);
imview(f(:,:,:,10))
numframes = size(f, 4);
for k = numframes:-1:1
g(:, :, k) = rgb2gray(f(:, :, :, k));
end
%Next, we compute frame differences using imabsdiff.
for k = numframes-1:-1:1
d(:, :, k) = imabsdiff(g(:, :, k), g(:, :, k+1));
end
imview(d(:, :, 1), [])
thresh = graythresh(d)
bw = (d >= thresh * 255); imview(bw(:, :, 1))

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 24 -
vid = videoinput('winvideo', 1, 'RGB24_352x288')
%Next, we specify that we want to acquire 50 frames at 3 frames per
second.
set(vid, 'FramesPerTrigger', 50)
set(getselectedsource(vid), 'FrameRate', 3)
%Now we start acquiring images.
start(vid)
wait(vid)
[f, t] = getdata(vid);
imview(f(:,:,:,10))
vid = videoinput('winvideo', 1, 'RGB24_352x288')
%Next, we specify that we want to acquire 50 frames at 3 frames per
second.
set(vid, 'FramesPerTrigger', 50)
set(getselectedsource(vid), 'FrameRate', 3)
Now we start acquiring images.
start(vid)
wait(vid)
[f, t] = getdata(vid);
imview(f(:,:,:,10))
bw2 = bwareaopen(bw, 20, 8);
s = regionprops(bwlabel(bw2(:,:,1)), 'centroid');
c = [s.Centroid]
c = 226.8231 53.1538 260.3750 43.3167
background = imdilate(g, ones(1, 1, 5));
imview(background(:,:,1))
d = imabsdiff(g, background);
thresh = graythresh(d);
bw = (d >= thresh * 255);
centroids = zeros(numframes, 2);
for k = 1:numframes
L = bwlabel(bw(:, :, k));
s = regionprops(L, 'area', 'centroid');
area_vector = [s.Area];
[tmp, idx] = max(area_vector);
centroids(k, :) = s(idx(1)).Centroid;
end
%visualize the ball’s motion
subplot(2, 1, 1)
plot(t, centroids(:,1)), ylabel('x')
subplot(2, 1, 2)
plot(t, centroids(:, 2)), ylabel('y')
xlabel('time (s)')

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 25 -
INPUT

OUTPUT

VIVA QUESTIONS:
Q.1 Where object tracking is used?
A. Object tracking has been extensively studied in computer vision due to its importance in applications such as
automated surveillance, video indexing, traffic monitoring, and human-computer interaction.

Q.2 What do you mean by object tracking.


A. Real time object tracking is the process of locating moving objects over time using the camera in video
sequences in real time.

Q.3 What is the objective of object tracking.


A. The objective of object tracking is to associate target objects in consecutive video frames.

Q.4 What does object tracking requires.


A. Object tracking requires location and shape or features of objects in the video frames.

Q.5 What are challenges of object tracking system?


A. The main challenges is to deal with appearance change caused by abrupt motion, illumination variation,
shape deformation, and occlusion.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.

You might also like