Professional Documents
Culture Documents
LABORATORY MANUAL
DEPARTMENT OF
ELECTRONICS & COMMUNICATION
ENGINEERING
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -2-
DEPARTMENT OF
ELECTRONICS & COMMUNICATION
ENGINEERING
CERTIFICATE
Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal for ……… Semester of the Electronics and Communication
Signature of
Faculty In-charge
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -3-
LIST OF EXPERIMENTS
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -4-
DIRECT SEQUENCE SPREAD SPECTRUM
Software Tool:
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= =
𝑇𝐶 𝑅𝑠
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -5-
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.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 10 -
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.
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)');
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)');
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
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY - 18 -
OFDM ARCHITECTURE
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.
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;
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:
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-
Flow Chart:
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)
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.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
ADVANCED COMMUNICATION SYSTEM LABORATORY -9-
DISTANCE VECTOR ROUTING ALGORITHM
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 -
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 -
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
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.
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.
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:
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.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.