Anda di halaman 1dari 49

Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 1



Exp No: 1
9/10/2013
DIGITAL MODULATION SCHEMES
AIM
To perform the BASK, BFSK, BPSK digital modulation schemes and compare the bit
error rate of these modulation schemes.
SOFTWARE USED
Matlab 7.1
THEORY
ASK refers to a type of amplitude modulation that assigns bit values to discrete
amplitude levels. The carrier signal is then modulated among the members of a set of discrete
values to transmit information. In Binary Amplitude Shift Keying the amplitude of carrier
signal is varied to represent binary 0 or 1.
FSK refers to a type of frequency modulation that assigns bit values to discrete
frequency levels. FSK is divided into non-coherent and coherent forms. In non-coherent
forms of FSK, the instantaneous frequency shifts between two discrete values termed the
"mark" and "space" frequencies. In coherent forms of FSK, there is no phase discontinuity in
the output signal. Binary Frequency Shift Keying (BFSK), the frequency of a constant
amplitude carrier signal is switched between two values according to the two possible
message states (called high and low tones) corresponding to a binary 1 or 0.
PSK in a digital transmission refers to a type of angle modulation in which the phase
of the carrier is discretely varied either in relation to a reference phase or to the phase of the
immediately preceding signal element to represent data being transmitted. Binary Phase Shift
Keying (BPSK) is a type of phase modulation using 2 distinct carrier phases to signal ones
and zeros. BPSK is the simplest form of PSK. It uses two phases which are separated by 180
and so can also be termed 2-PSK. Here each change of phase carries one bit of information,
that is, the bit rate equals the modulation rate.
Bit Error Rate
It is the number of bit errors divided by the total number of transferred bits during a
studied time interval. It is used to quantify a channel carrying data by counting the rate of
errors in a data string. It is used in telecommunications, networks and radio systems. It is a
unit less performance measure often expressed as percentage.
For BPSK system,
P
b
=
1
2
erfc(

E
b
N
0
)

Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 2


For BFSK system,

P
e
= Q(

E
b
N
0
)

For BASK system,

P
e
= Q(

E
b
N
0
)

FSK system has better BER than the PSK system for the same EIRP values. For
smaller values of EIRP, the BER offered by the FSK and PSK systems are similar. However,
as the EIRP increases, the BER of the FSK system drops at a much higher rate than the BER
of the PSK system.
PROCEDURE
1. Read the input bit stream and plot it.
2. Generate two carriers having different amplitudes and plot the corresponding
waveform.
3. Perform the amplitude modulation with the input bit stream by using the generated
carriers.
4. Calculate the bit error rate (BER) using the berawgn function.
5. Plot the corresponding BER in the logarithmic scale.
6. Repeat the above steps for BFSK with carriers having two different frequencies
7. Repeat the above steps for BPSK with carriers having two different frequencies
8. Compare the bit error rate of these modulation schemes and plot the performance
curve.
PROGRAM
BASK
x=input('enter the input stream ');
n=length(x);
a1=3;
a2=5;
f=3;
t=0:0.01:1;
time=[ ];
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 3

ask_sig=[ ];
dig_sig=[ ];
for i=1:n
dig_sig =[dig_sig (x(i)==0)*zeros(1,length(t))+(x(i)==1)*ones(1,length(t))];
ask_sig=[ask_sig (x(i)==0)*a1*sin(2*pi*f*t)+(x(i)==1)*a2*sin(2*pi*f*t)];
time=[time t];
t=t+1;
end;
%carrier
subplot(5,1,1);
plot(time,3*sin(2*pi*3*time));
xlabel('time');
ylabel('carrier 1');
title('carrier1');
axis([0 time(length(time)) -6 6]);
subplot(5,1,2);
plot(time,5*sin(2*pi*3*time));
xlabel('time');
ylabel('carrier 2');
title('carrier 2');
axis([0 time(length(time)) -6 6]);
%input bit stream
subplot(5,1,3);
plot(time,dig_sig);
xlabel('time');
ylabel('i/p');
axis([0 time(length(time)) -1 2]);
title('input bit stream');
%modulated carrier
subplot(5,1,4);
plot(time,ask_sig);
xlabel('time');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 4

ylabel('ask signal');
axis([0 time(length(time)) -6 6]);
title('ask with two amplitudes');
%bit error rate
Ebn=[0:.5:15];
BER= berawgn(Ebn,'pam',2);
subplot(5,1,5);
loglog(Ebn,BER,'r.-');
axis([0 20 0 5*10^(-1)]);
title('Eb/N0 vsber(bask)');
xlabel('Eb/N0');
ylabel('BER');

BFSK
x=input('enter the input stream ');
n=length(x);
f1=3;
f2=5;
t=0:0.01:1;
time=[];
fsk_sig=[];
dig_sig=[];
for i=1:n
dig_sig =[dig_sig (x(i)==0)*zeros(1,length(t))+(x(i)==1)*ones(1,length(t))];
fsk_sig=[fsk_sig (x(i)==0)*sin(2*pi*f1*t)+(x(i)==1)*sin(2*pi*f2*t)];
time=[time t];
t=t+1;
end;
%carrier
subplot(5,1,1);
plot(time,sin(2*pi*3*time));
xlabel('time');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 5

ylabel('amplitude');
title('carrier1');
axis([0 time(length(time)) -2 2]);
subplot(5,1,2);
plot(time,sin(2*pi*5*time));
xlabel('time');
ylabel('amplitude');
title('carrier 2');
axis([0 time(length(time)) -2 2]);
%input bit stream
subplot(5,1,3);
plot(time,dig_sig);
xlabel('time');
ylabel('amplitude');
axis([0 time(length(time)) -1 2]);
title('input bit stream');
%modulated carrier
subplot(5,1,4);
plot(time,fsk_sig);
xlabel('time');
ylabel('amplitude');
axis([0 time(length(time)) -2 2]);
title('bfsk modulated signal');
%bit error rate
Ebn=[0:.5:15];
BER= berawgn(Ebn,'fsk',2,'coherence');
subplot(5,1,5);
loglog(Ebn,BER,'r.-');
axis([0 20 0 5*10^(-1)]);
title('Eb/N0 vs BER(bfsk)');
xlabel('Eb/N0');
ylabel('BER');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 6

BPSK
x=input('enter the input stream ');
n=length(x);
f=3;
t=0:0.01:1;
time=[];
psk_sig=[];
dig_sig=[];
for i=1:n
dig_sig =[dig_sig (x(i)==0)*zeros(1,length(t))+(x(i)==1)*ones(1,length(t))];
psk_sig=[psk_sig (x(i)==0)*(-1)*sin(2*pi*f*t)+(x(i)==1)*sin(2*pi*f*t)];
time=[time t];
t=t+1;
end;
%carrier
subplot(4,1,1);
plot(time,sin(2*pi*3*time));
xlabel('time');
ylabel('amplitude');
title('carrier');
%input bit stream
subplot(4,1,2);
plot(time,dig_sig);
xlabel('time');
ylabel('amplitude');
axis([0 time(length(time)) -1 2]);
title('input bit stream');
%modulated carrier
subplot(4,1,3);
plot(time,psk_sig);
xlabel('time');
ylabel('amplitude');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 7

axis([0 time(length(time)) -2 2]);
title('bpsk modulated signal');

PERFORMANCE COMPARISON
%bit error rate
Ebn=[0:.5:15];
BER= berawgn(Ebn,'psk',2,'diff');
subplot(5,1,5);
loglog(Ebn,BER,'r.-');
axis([0 20 0 5*10^(-1)]);
title('Eb/N0 vsber(bask)');
xlabel('Eb/N0');
ylabel('BER');
Ebn=[0:.5:15];
BER= berawgn(Ebn,'pam',2);
loglog(Ebn,BER,'r.-');
grid on;
hold on;
BER= berawgn(Ebn,'fsk',2,'coherence');
loglog(Ebn,BER,'g*-');
hold on;
BER= berawgn(Ebn,'psk',2,'diff');
loglog(Ebn,BER,'b.-');
axis([0 20 0 5*10^(-1)]);
legend('BASK','BFSK','BPSK');
title('performance comparison of bask, bfsk and bpsk');
xlabel('Eb/N0');
ylabel('BER');



Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 8

OUTPUT WAVEFORMS
BASK
Enter the input stream [1 0 1 0]

Fig. 1
BPSK
Enter the input stream [1 0 1 0]

Fig. 2
0 0.5 1 1.5 2 2.5 3 3.5 4
-5
0
5
time
c
a
r
r
i
e
r

1
carrier1
0 0.5 1 1.5 2 2.5 3 3.5 4
-5
0
5
time
c
a
r
r
i
e
r

2
carrier 2
0 0.5 1 1.5 2 2.5 3 3.5 4
-1
0
1
2
time
i
/
p
input bit stream
0 0.5 1 1.5 2 2.5 3 3.5 4
-5
0
5
time
a
s
k

s
i
g
n
a
l
ask with two amplitudes
10
0
10
1
10
-10
Eb/N0 vs ber(bask)
Eb/N0
B
E
R
0 0.5 1 1.5 2 2.5 3 3.5 4
-1
0
1
time
a
m
p
l
i
t
u
d
e
carrier
0 0.5 1 1.5 2 2.5 3 3.5 4
-1
0
1
2
time
a
m
p
l
i
t
u
d
e
input bit stream
0 0.5 1 1.5 2 2.5 3 3.5 4
-2
0
2
time
a
m
p
l
i
t
u
d
e
bpsk modulated signal
10
0
10
1
10
-10
Eb/N0 vs ber(bask)
Eb/N0
B
E
R
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 9

BFSK
Enter the input stream [1 0 1 0]

Fig. 3
PERFORMANCE COMPARISON

RESULT
BASK, BFSK, BPSK digital modulation schemes were implemented in MATLAB
and compared the bit error rate of these modulation schemes.
0 0.5 1 1.5 2 2.5 3 3.5 4
-2
0
2
time
a
m
p
l
i
t
u
d
e
carrier1
0 0.5 1 1.5 2 2.5 3 3.5 4
-2
0
2
time
a
m
p
l
i
t
u
d
e
carrier 2
0 0.5 1 1.5 2 2.5 3 3.5 4
-1
0
1
2
time
a
m
p
l
i
t
u
d
e
input bit stream
0 0.5 1 1.5 2 2.5 3 3.5 4
-2
0
2
time
a
m
p
l
i
t
u
d
e
bfsk modulated signal
10
0
10
1
10
-5
Eb/N0 vs BER(bfsk)
Eb/N0
B
E
R
10
0
10
1
10
-14
10
-12
10
-10
10
-8
10
-6
10
-4
10
-2
Eb/N0
B
E
R
performance comparison of bask, bfsk and bpsk


BASK
BFSK
BPSK
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 10

Exp No: 2
31/10/2013
SCATTERPLOT OF ASK, PSK & FSK
AIM
To generate scatterplot of ASK, PSK, FSK modulated and demodulated signals with
and without effect of noise.
SOFTWARE USED
MATLAB 7.1
THEORY
A scatterplot or constellation diagram is a representation of a signal modulated by a
digital modulation scheme such as amplitude-shift keying (ASK), phase-shift keying (PSK)
and frequency-shift keying(FSK). Measured constellation diagrams can be used to recognize
the type of interference and distortion in a signal. The points on a constellation diagram are
called constellation points.
A constellation diagram can help us define the amplitude and phase of a signal
element, particularly when we are using two carriers. In a constellation diagram, a signal
element type is represented as a dot. The bit or combination of bits it can carry is often
written next to it. The diagram has two axes. The horizontal X axis is related to the in-phase
carrier; the vertical Y axis is related to the quadrature carrier.
ASK
A binary amplitude-shift keying (BASK) signal can be defined by
s(t) = A m(t) cos(2fct) ; 0 <t<T
Where A is a constant, m (t) = 1 or 0, fc is the carrier frequency, and T is the bit duration. It
displays the signal as a two-dimensional scatter diagram in the complex plane at symbol
sampling instants.

1
() =

2

cos 2


Fig. constellation diagram

Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 11

PSK
The M-signal waveforms are represented as
S
m
(t )= g(t )cos
2
M
(m 1)cos(2f
c
t ) g(t )sin(
2
M
)(m 1)sin(2f
c
t )

It displays the signal as a two-dimensional scatter diagram in the complex planeat symbol
sampling instants. In a more abstract sense, it represents the possible symbols that may be
selected by a given modulation scheme as points in the complex plane. By representing a
transmitted symbol as a complex number and modulating a cosine and sine carrier signal with
the real and imaginary parts (respectively), the symbol can be sent with two carriers on the
same frequency. They are often referred to as quadrature carriers. The real and imaginary
axes are often called the in phase, or I-axis, and the quadrature, or Q-axis, respectively

Fig. 1 A constellation diagram for Gray encoded 8-PSK.
FSK
FSK modulation cannot be represented on a phasor diagram, as the information is in
the frequency transition rather than a phase transition. However, the discrete states must be
represented and the constellation diagram is used to graphically represent them and the
transitions. Here, the states are on a circle on the constellation diagram .The constellation
diagram indicates that the amplitude of the phasor is constant, as FSK is a form of FM. In
four-state FSK modulation transitions between states take twice as long for states that are on
opposite sides of the constellation diagram compared to states that are only separated by 90 .
Let S
1
(t) and S
2
(t) be two sinus waveforms with different frequencies f
1
and f
2
but known
phase.

1
() = 2 cos (2
1
+
1
)

2
() = 2 cos (2
2
+
2
)


Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 12

The signal constellation diagram for BFSK with coherent demodulation can be given as



Fig. 2 Constellation diagram for two states and four states FSK
PROCEDURE
1. Create a random digital message
2. Generate phase noise
3. Modulate the message using PSK, PAM and FSK
4. Create a scatter plot and show constellation
5. Perturb the phase of modulated signals
6. Create scatter plot of phase perturbed signal and noisy signal
7. Pass through AWGN channel
8. Plot noisy and phase perturbed scatterplot
9. Perform demodulation
10. Scatterplot the demodulated signal



Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 13

PROGRAM
clc;
len=10000;
M=8
msg=randint(len,1,M);
snr=20;
scatterplot(msg);
title('Message scatter plot');
txpsk=pskmod(msg,M);
txpam=pammod(msg,M);
txfsk=fskmod(msg,M,1,2,16);
scatterplot(txpsk);
title('Modulated PSK scatter plot');
scatterplot(txpam);
title('Modulated PAM scatter plot');
scatterplot(txfsk);
title('Modulated FSK scatter plot');
phasenoise=randn(len,1)*0.015
rxpsk1=txpsk.*exp(j*2*pi*phasenoise);
rxpam1=txpam.*exp(j*2*pi*phasenoise);
scatterplot(rxpsk1,1,0,'ro');
title('Phase perturbed PSK scatter plot');
scatterplot(rxpam1,1,0,'ro');
title('Phase perturbed PAM scatter plot');
rxpsk=awgn(rxpsk1,snr);
scatterplot(rxpsk,1,0,'ro');
title('Noisy and Phase perturbed PSK scatter plot');
rxpam=awgn(rxpam1,snr);
scatterplot(rxpam,1,0,'ro');
title('Noisy and Phase perturbed PAM scatter plot');
scatterplot(awgn(txpsk,snr),1,0,'ro');
title('Noisy PSK scatter plot');
scatterplot(awgn(txpam,snr),1,0,'ro');
title('Noisy PAM scatter plot');
rxfsk=awgn(txfsk,snr);
scatterplot(rxfsk,1,0,'ro');
title('Noisy FSK scatter plot');
recovpsk=pskdemod(rxpsk,M);
recovpam=pamdemod(rxpam,M);
recovfsk=fskdemod(rxfsk,M,1,2,16);
hold on;
q1=scatterplot(recovpsk,1,0,'b*');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 14

hold on;
q2=scatterplot(recovpam,1,0,'y.',q1);
hold on;
scatterplot(recovfsk,1,0,'ro',q2);
title('Demodulated signal scatter plot');
legend('PSK demod','PAM demod','FSK demod');
OUTPUT WAVEFORMS

Fig. 1

Fig. 2
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Q
u
a
d
r
a
t
u
r
e
In-Phase
msg scatter plot
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Q
u
a
d
r
a
t
u
r
e
In-Phase
Mod PSK Scatterplot
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 15


Fig. 3

Fig. 4
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Q
u
a
d
r
a
t
u
r
e
In-Phase
Mod PAM Scatterplot
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Q
u
a
d
r
a
t
u
r
e
In-Phase
Mod FSK Scatterplot
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 16


Fig. 5


Fig. 6
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Q
u
a
d
r
a
t
u
r
e
In-Phase
Phase perturbed PSK Scatter Plot
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Q
u
a
d
r
a
t
u
r
e
In-Phase
Phase perturbed PAM Scatter Plot
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 17


Fig. 7



Fig. 8
-1 -0.5 0 0.5 1
-1
-0.5
0
0.5
1
Q
u
a
d
r
a
t
u
r
e
In-Phase
Niosy PSK Scatter Plot
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Q
u
a
d
r
a
t
u
r
e
In-Phase
Niosy PAM Scatter Plot
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 18


Fig. 9

Fig. 10

-1 -0.5 0 0.5 1
-1
-0.5
0
0.5
1
Q
u
a
d
r
a
t
u
r
e
In-Phase
Noisy and phase perturbed PSK Scatter plot
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Q
u
a
d
r
a
t
u
r
e
In-Phase
Noisy and phase perturbed PAM Scatter plot
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 19


Fig. 11

Fig. 12
RESULT
Scatterplot for of ASK, PSK, FSK modulated and demodulated signals with and
without effect of noise was plotted and verified.

-1 -0.5 0 0.5 1
-1
-0.5
0
0.5
1
Q
u
a
d
r
a
t
u
r
e
In-Phase
Noisy FSK Scatter plot
-6 -4 -2 0 2 4 6
-6
-4
-2
0
2
4
6
Q
u
a
d
r
a
t
u
r
e
In-Phase
Dmod signal scatter plot


PSK Dmod
PAM Dmod
FSK Dmod
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 20

Exp No: 3
21/11/2013
BER COMPARISON OF RAYLEIGH AND RICIAN FADING
CHANNELS
AIM
To obtain the BER comparison of Rayleigh and Rician fading channels.
SOFTWARE USED
MATLAB 7.1
THEORY
Rayleigh distribution is frequently used to model the statistics of signals transmitted
through radio channels such as cellular radio. This distribution is closely related to the chi-
square distribution. Depending on density of the scatters the signal will display different
fading characteristics. Rayleigh is used to model dense scatters.

R=

X
1
2
+ X
2
2
= Y

Rayleigh fading is most applicable when there is no dominant propagation along a
line of sight between the transmitter and receiver. If there is a dominant line of sight, Rician
fading may be more applicable.
PDF of Rayleigh distribution is given by

() =
2

2

2

, x 0

where s
2
/2=
2
is the variance of the each of the original Guassian random variables.
CDF of Rayleigh distribution is given by

() = 1

,x 0

Rician distribution is closely related to the nonchi-square distribution. Depending on
density of the scatters the signal will display different fading characteristics. Rician is used to
model fading with strong line of sight. Rician fading is a stochastic model for radio
propagation anomaly caused by partial cancellation of a radio signal by itself- the signal
arrives at the receiver by several different path (hence exhibiting multipath interference), and
at least one of the path is changing, (lengthening or shortening). Rician fading occurs when
one of the paths, typically a line of sight signal, is much stronger than the others. In rician
fading, the amplitude of gain is characterized by a rician distribution.

R=

X
1
2
+ X
2
2
= Y

Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 21


PDF is given by
(

|) =

2
exp(

2
+
2
2
2
)
0
(

2
)
Channel Characterization:
A Rician fading channel can be described by two parameters: K and . K is the ratio
between the power in the directed path and the power in the other, scattered paths. is the
total power from both paths (=v2 + 22 ), and acts as a scaling factor to the distribution.
The received signal amplitude (not the received signal power) R is then rician
distribution with parameters, v2=(K/1+K) and
2
= (/2(1+K)).
The resulting PDF then is:
() =
2(+1)

exp(- -
(+1)
2

)
0
(2
(+1)

)
Where I
0
(.) is the 0th order modified Bessel function of the first kind.
PROCEDURE
1. Generate the input stream.
2. Create Rayleigh and Rician channel objects.
3. The generated symbol is passed through the respective channels.
4. The signal that has been faded after passing through the channel is modulated by
performing any digital modulation scheme.
5. Additive white Gaussian noise is added.
6. Now the noisy signal is demodulated by performing digital demodulation scheme.
7. BER is calculated.
8. Theoretical and analytical comparison of BER is done.
PROGRAM
clc;
clear all;
close all;
subplot(6,1,1);
x=randint(1,5);
stem(x);
c1=rayleighchan(1/10000,130);
subplot(6,1,2);
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 22

y1=filter(c1,x);
stem(y1);
bpsk=dpskmod(x,2);
SNR = 0:2:20; % Range of SNR values, in dB.
for n = 1:length(SNR)
rxSig1 = awgn(y1,SNR(n)); % Add Gaussian noise.
rx1 = dpskdemod(rxSig1,2); % Demodulate.
% Compute error rate.
% Ignore first sample because of DPSK initial condition.
[nErrors, BER(n)] = biterr(x,rx1);
end
% Compute theoretical performance results, for comparison.
BERtheory = berfading(SNR,'dpsk',2,1);
% Plot BER results.
subplot(6,1,3);
semilogy(SNR,BERtheory,'b*',SNR,BER,'r*');
legend('Theoretical BER','Empirical BER');
xlabel('SNR (dB)'); ylabel('BER');
title('Binary DPSK over Rayleigh Fading Channel');
c2=ricianchan(1/10000,130,2);
subplot(6,1,4);
y2=filter(c2,x);
stem(y2);
bpsk=dpskmod(x,2);
SNR = 0:2:20; % Range of SNR values, in dB.
for n = 1:length(SNR)
rxSig2 = awgn(y2,SNR(n)); % Add Gaussian noise.
rx2 = dpskdemod(rxSig2,2); % Demodulate.
% Compute error rate.
% Ignore first sample because of DPSK initial condition.
[nErrors, BER(n)] = biterr(x,rx2);
end
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 23

% Compute theoretical performance results, for comparison.
BERtheory = berfading(SNR,'dpsk',2,1);
% Plot BER results.
subplot(6,1,5);
semilogy(SNR,BERtheory,'b*',SNR,BER,'r*');
legend('Theoretical BER','Empirical BER');
xlabel('SNR (dB)'); ylabel('BER');
title('Binary DPSK over Rician Fading Channel');
OUTPUT WAVEFORMS

Fig. 1
RESULT
In this experiment BER comparison of two fading channels were done. For that first the input
signal was passed through the two channels. Then modulation was performed and noise was
added. After demodulation BER was calculated and plotted .The output was verified.
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 24

Exp No: 4
10/01/2014
CENTRAL LIMIT THEOREM
AIM
To implement the central limit theorem using MATLAB.
SOFTWARE USED
MATLAB 7.1
THEORY
In probability theory, thecentral limit theorem(CLT) states that, given certain
conditions, the arithmetic meanof a sufficiently large number of iterates of
independentrandom variables, each with a well-defined expected value and well-defined
variance, will be approximately normally distributed.That is, suppose that a sampleis
obtained containing a large number of observations, each observation being randomly
generated in a way that does not depend on the values of the other observations, and that the
arithmetic average of the observed values is computed. If this procedure is performed many
times, the central limit theorem says that the computed values of the average will be
distributedaccording to the normal distribution(commonly known as a "bell curve"). The
central limit theorem has a number of variants. In its common form, the random variables
must be identically distributed. In variants, convergence of the mean to the normal
distribution also occurs for non-identical distributions, given that they comply with certain
conditions.
A real stationary discrete time stochastic process (X
j
) with E(X
j
) =0 and Var(X
j
) < is
said to satisfy the central limit theorem if

(0,1) for n

=1
,

2
= (

)

Central Limit Theorem (CLT) states thatirrespective of the underlying distribution of
a population (with mean and standard deviation of ), if there is a number of samples of
size N from the population, then the sample mean follow a normal distribution with a mean
of and a standard deviation of / sqrt(N).The normality gets better as sample size n
increases. It signifies that irrespective of the base distribution (it can be binomial, Poisson,
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 25

exponential, Chi-Square etc..,), the probability distribution curve will approach Gaussian or
Normal distribution as the number of sample increases. CLT states that the sum of
independent and identically distributed random variables (with finite mean and variance)
approaches Normal distribution as (sample size) N->.
The sum of independent, identically distributedlarge number of random variables with finite
variance is approximately normally distributed under certain conditions
Binomial distribution B(n,p) approaches normal for large n and p.
The Poisson() distribution is approximately normal N(,) for large values of .
The chi-squared distribution approaches normal for large k.
The Students t-distribution t() approaches normal N(0,1) when is large.
If a population has a mean of , a variance of (sigma) and takes samples of
size n, the means of these samples are approximately the distribution

=


N (,

)
CLT is being applied in vast range of applications including (but not limited to) Signal
processing, channel modeling, random process, population statistics, engineering research,
predicting the confidence intervals, hypothesis testing etc. One such application is deriving
the response of a cascaded series of Low pass filters by applying Central limit theorem. CLT
shows how the response of a cascaded series of low pass filters approaches Gaussian shape as
the number of filters in the series increases .In digital communication, channel noise is often
modeled as Normally distributed. Modeling a channel as Normally distributed when the noise
components in that channel are sufficiently large is justified by Central limit theorem.
PROCEDURE
1. Read the input as the array of inputs.
2. Declare an empty set to store the random variables
3. Apply exponential distribution to the input samples.
4. Take the mean of exponentially distributed random variables
5. Find the histogram using hist function and plot it.
PROGRAM
max=1000;
N=100;
for j=1:N
a=ones(1,j);
means=zeros(1,max);
for i=1:max
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 26

t=random('exp',a);
means(i)=sum(t)/j;
end
z=hist(means)
grid on;
plot(z)
xlabel('time');
ylabel('CDF');
end

OUTPUT WAVEFORM

Fig. 1
RESULT
The central limit theorem is implemented using matlab and the corresponding output
is obtained.




Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 27

Exp No: 5
17/01/2014
MATCHED FILTER
AIM
To implement the matched filter using MATLAB.
SOFTWARE USED
MATLAB 7.1
THEORY
The matched filter is the optimal linear filter for maximizing the signal to noise ratio
(SNR) in the presence of additive stochastic noise. Matched filters are commonly used in
radar,in which a signal is sent out, and we measure the reflected signals, looking for
somethingsimilar to what was sent out.Two-dimensional matched filters are commonly used
in image processing, e.g., to improve SNR for X-ray pictures. A general representation for a
matched filter is illustrated in Figure1.
Figure1: Matched Filter

The filter input x(t) consists of a pulse signal g(t) corrupted by additive channel noise
w(t), as shown by

x(t)= g(t)+ w(t) ; 0tT

where T is an arbitrary observation interval. The pulse signal g(t) may represent a binary
symbol I or 0 in a digital communication system. The w(t) is the sample function of a white
noise process of zero mean and power spectral density No/2. The source of uncertainty lies in
the noise w(t). The function of the receiver is to detect the pulse signal g(t) in an optimum
manner, given the received signal x(t). To satisfy this requirement, we have to optimize the
design of the filter so as to minimize the effects of noise at the filter output in some statistical
sense, and thereby enhance the detection of the pulse signal g(t). Since the filter is linear, the
resulting output y(t) may be
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 28


y(t )= g
0
(t )+ n(t )

where go(t) and n(t) are produced by the signal and noise components of the input x(t),
respectively. A simple way of describing the requirement that the output signal component
go(t) be considerably greater than the output noise component n(t) is to have the filter make
the instantaneous power in the output signal go(t), measured at time t = T, as large as possible
compared with the average power of the output noise n(t). This is equivalent to maximizing
the peak pulse signal-to-noise ratio, defined as
=
|
0
()|
2
[
2
()]


For the case of white noise, the description of the matched filter is simplified as follows
H( f )=
2K
N
0
S

( f ) e
jwt
0

PROCEDURE
1. Generate input signal
2. Plot the input signal
3. Apply AWGN function to get noisy signal.
4. Plot the impulse response of matched filter & which is matched with the input.
5. Take the convolution of matched filter output.
6. Take the convolution of filter output when its impulse response doesnt match
with input.
7. Plot the matched filter output & unmatched filter output.
8. Take the sampling of both & plot the sampled output of matched filter output &
unmatched filter output.
PROGRAM
clc
clear all
close all
t=0:0.01:6;
x=sin(t)
subplot(5,1,1)
plot(x)
title('input signal')
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 29

xlabel('time')
ylabel('amplitude')
y=awgn(x,3)
subplot(5,1,2)
plot(y)
title('noisy signal')
xlabel('time')
ylabel('amplitude')
m=fliplr(y)
subplot(5,1,3)
plot(m)
title('impulse response of matched filter')
xlabel('time')
ylabel('amplitude')
m1=sin(2*t)
z=conv(y,m)
z1=conv(y,m1)
subplot(5,1,4)
plot(z)
grid on;
title('matched filter o/p')
xlabel('time')
ylabel('amplitude')
subplot(5,1,5)
plot(z1)
grid on;
title('filter output with impulse response which is unmatched to input');
xlabel('time')
ylabel('amplitude')
sample_matched_filter=z(6/0.01)
sample_not_matched_filter=z1(6/0.01)
figure(2)
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 30

subplot(1,2,1)
stem(sample_matched_filter)
axis([0 2 0 400])
title('matched filter output sampled at input signal period')
subplot(1,2,2)
stem(sample_not_matched_filter)
axis([0 2 0 400])
title('other filter (does not match with input ) output sampled at input signal period');
OUTPUT WAVEFORMS

0 100 200 300 400 500 600 700
-1
0
1
input signal
time
a
m
p
l
i
t
u
d
e
0 100 200 300 400 500 600 700
-5
0
5
noisy signal
time
a
m
p
l
i
t
u
d
e
0 100 200 300 400 500 600 700
-5
0
5
impulse response of matched filter
time
a
m
p
l
i
t
u
d
e
0 200 400 600 800 1000 1200 1400
-1000
0
1000
matched filter o/p
time
a
m
p
l
i
t
u
d
e
0 200 400 600 800 1000 1200 1400
-100
0
100
filter output with impulse response which is unmatched to input
time
a
m
p
l
i
t
u
d
e
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 31

Fig. 1

Fig. 2
RESULT
The matched filter is implemented and corresponding output is obtained.











0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
50
100
150
200
250
300
350
400
matched filter output sampled at input signal period
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
50
100
150
200
250
300
350
400
other filter (does not match with input ) output sampled at input signal period
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 32

Exp No: 6
17/01/2014
CORRELATION RECEIVER
AIM
To implement the Correlation receiver using MATLAB.
SOFTWARE USED
MATLAB 7.1
THEORY
In correlation receiver we are measuring the correlation between the transmitted
signal and the received vector. The signal with the highest correlation will be the output
signal. A correlation receiver results in minimum error probability. An optimal receiver for
AWGN channel implements the MAP decision rule. For the case when the transmitted signals
s1(t),s2(t).sm(t) are equally likely, the optimum receiver consists of two subsystems, which
are described below.
(1) The detector part of the receiver is shown in figure 1. It consists of a bank of M
correlators, supplied with a corresponding set of coherent reference signals or
orthonormal basis functions
1
(),
2
() . . . ,

() that are generated locally.


This bank of correlators operates on the received signal x(t),0 t T, to produce
the observation vector x.
(2) The second part of the receiver ,namely, the signal transmission decoder is shown
in figure 2. It is implemented in the form of a maximum likelihood decoder that
operates on the observation vector x to produce an estimate the transmitted
symbol mi, i=1,2,M in a way that would minimize the average probability of
symbol error. N elements of the observation vector x are first multiplied by the
corresponding N elements of each of the M signal vectors s
1
,s
2
.s
M
and the
resulting products are successively summed in accumulators to form the
corresponding set of inner products Next ,the inner products are corrected for the
fact that the transmitted signal energies may be unequal. Finally the largest in the
resulting set of numbers is selected; and an appropriate decision on the transmitted
message is made.
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 33


Fig.1. Detector or demodulator

Fig.2 Signal transmission decoder
Probability of error
Suppose that observation space of a signal Z is partitioned ,in accordance with
the maximum likelihood decision rule,into set if M regions {Z
i
}, i=1,2M. let
symbol mi transmitted, and an observation vector x is received.Then an error occurs
whenever the received signal x doesnot fall on the region Zi associated with the message
point represented by s
i
, then average probability of symbol error P
e
is
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 34

P
e
=

i= 1
M
p
i
P( x does not lie withinZ
i
/ m
i
sent ) =
1
M

i= 1
M
P( x doesnot lie within Z
i
/ m
i
sent )
= 1
1
M

i= 1
M
P( x lies within Z
i
/ m
i
sent )
ie ; P
e
= 1
1
M

i =1
M

f
X
( x/ m
i
) dx

PROCEDURE
1. Generate the transmitting binary sequence randomly.
2. Plot the signal.
3. Generate square pulse corresponding to this binary sequence.
4. Plot the pulse signal.
5. Generate carrier signal.
6. Plot the signal.
7. Modulate the transmitting message signal with carrier signal.
8. Apply AWGN function to get noisy signal.(ie signal at the receiver input.)
9. Plot the channel output.
10. Demodulate the received signal.
11. Compare the signal amplitude with threshold. If amplitude is greater than threshold
approximate to 1 else to 0.
12. Plot the decoded signal.
PROGRAM
a=randint(1,10,2);
subplot(5,1,1)
stem(a)
title('transmiited bits');
xlabel('time')
ylabel('amplitude');
b=rectpulse(a,100);
subplot(5,1,2);
plot(b);
title('message signal');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 35

xlabel('time');
ylabel('amplitude');
axis([0 1000 -.2 1.2]);
t=0:.0001:.0999;
z=sin(2*pi*800*t);
subplot(5,1,3);
plot(t,z);
title('carrier signal');
xlabel('time');
ylabel('amplitude');
h=z.*b;
y=awgn(h,3);
subplot(5,1,4);
plot(y);
title('noisy signal');
xlabel('time');
ylabel('amplitude');

t1=0:.0001:.0099;
z1=sin(2*pi*800*t1);
for l=1:10
for k=1:100
n(k)=y(k+(l-1)*100);
end
h1=z1.*n;
h2=0;
for m=1:100
h2=h2+h1(m);
end
h2=h2/100;
if h2>0.25
h3(l)=1;
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 36

else
h3(l)=0;
end
end
subplot(5,1,5);
stem(h3);
title('decoded signal');
xlabel('time');
ylabel('amplitude');
OUTPUT WAVEFORMS
RESULT
The correlation receiver is implemented and corresponding output is obtained.
1 2 3 4 5 6 7 8 9 10
0
0.5
1
transmiited bits
time
a
m
p
l
i
t
u
d
e
0 100 200 300 400 500 600 700 800 900 1000
0
0.5
1
message signal
time
a
m
p
l
i
t
u
d
e
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
-1
0
1
carrier signal
time
a
m
p
l
i
t
u
d
e
0 100 200 300 400 500 600 700 800 900 1000
-5
0
5
noisy signal
time
a
m
p
l
i
t
u
d
e
1 2 3 4 5 6 7 8 9 10
0
0.5
1
decoded signal
time
a
m
p
l
i
t
u
d
e
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 37

Exp No: 7
17/01/2014
EQUALIZER
AIM
To implement an equalizer using MATLAB.
SOFTWARE REQUIRED
MATLAB 7.1
THEORY
A linear filter channel distorts the transmitted signal. The channel distortion results in
intersymbol interference at the output of the demodulator and leads to an increase in the
probability of error at the detector. Devices or methods used for correcting or undoing the
channel distortion, called channel equalizers.Signal dependence among signals transmitted in
different signal intervals can also result from intersymbol interference introduced by channel
distortion. Signal detectors that function in this manner are generally called equalizers.
Linear Equalizers
To compensate for the channel distortion, we may employ a linear filter with
adjustable parameters. The filter parameters are adjusted on the basis of measurements of the
channel characteristics. These adjustable filters are called channel equalizers or, simply,
equalizers. On channels whose frequency-response characteristics are unknown, but time
invariant, we may measure the channel characteristics, adjust the parameters of the equalizer,
and once adjusted, the parameters remain fixed during the transmission of data. Such
equalizers are called preset equalizers. On the other hand, adaptive equalizers update their
parameters on a periodic basis during the transmission of data. Figure 1 shows a block
diagram of a system that employs a linear filter as a channel equalizer.


Fig.1.Block diagram of a system with an equalizer
The demodulator consists of a receiving filter with frequency response G
R
( f ) in
cascade with a channel equalizing filter that has a frequency response GE ( f ). Since G
R
( f ) is
matched to G
T
( f ) and they are designed so that their product satisfies

Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 38

|

()||

()| =

()

and |G
E
( f )| must compensate for the channel distortion. Hence, the equalizer frequency
response must equal the inverse of the channel response; i.e.,

() =
1
()
=
1
|()|

()
, ||

where |G
E
(f)|=1/|C(f)| and the equalizer phase characteristic

(f)=-

()

In this case, the equalizer is said to be the inverse channel filter to the channel
response. The inverse channel filter completely eliminates ISI caused by the channel. Since it
forces the ISI to be zero at the sampling times the equalizer is called a zero-forcing equalizer.
In real channels, the ISI is limited to a finite number of samples, say L samples. As a
consequence, in practice the channel equalizer is approximated by a finite duration impulse
response (FIR) filter, or transversal filter, with adjustable tap coefficients {cn}, as illustrated
in Figure 2.


Fig.2. Linear transversal filter
One drawback to the zero-forcing equalizer is that it ignores the presence of additive
noise. As a consequence, its use may result in significant noise enhancement. An alternative
is to relax the zero ISI condition and select the channel equalizer characteristic such that the
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 39

combined power in the residual ISI and the additive noise at the output of the equalizer is
minimized. A channel equalizer that is optimized based on the minimum mean-square-error
(MMSE) criterion accomplishes the desired goal.
Adaptive Equalizer
Adaptive channel equalization is required for channels whose characteristics change
with time. In such a case, the ISI varies with time. The channel equalizer must track such
time variations in the channel response and adapt its coefficients to reduce the ISI.

Fig.3.Linear adaptive equalizer based on MSE criterion
A block diagram of an adaptive equalizer that adapts its tap coefficients is illustrated
in Figure3. The difference between the desired output a
k
and the actual output z
k
from the
equalizer is used to form the error signal e
k
. This error is scaled by the step-size parameter,
and the scaled error signal

multiplies the received signal values {y(kTn)} at the 2N +1
taps. The products at the (2N + 1) taps are then added to the previous values of the tap
coefficients to obtain the updated tap coefficients. This computation is repeated for each
received symbol. Thus, the equalizer coefficients are updated at the symbol rate.
Decision feedback equalizer
A decision-feedback equalizer (DFE) is a nonlinear equalizer that employs previous
decisions to eliminate the ISI caused by previously detected symbols on the current symbol to
be detected. A simple block diagram for a DFE is shown in Fig. 4.
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 40


Fig.4. Decision-feedback equalizer
PROCEDURE
1. Generate the message sequence randomly.
2. Modulate message sequence using QPSK.
3. Introduce channel distortion.
4. Create an equalizer object & Set signal constellation.
5. Equalize the received signal
6. Plot signals.
7. Compute error rates with and without equalization.
PROGRAM
% Set up parameters and signals.

M = 4; % Alphabet size for modulation
msg = randint(1500,1,M); % Random message
modmsg = pskmod(msg,M); % Modulate using QPSK.
trainlen = 500; % Length of training sequence
chan = [.986; .845; .237; .123+.31i]; % Channel coefficients
filtmsg = filter(chan,1,modmsg); % Introduce channel distortion.
% Equalize the received signal.
eq1 = lineareq(8, lms(0.01)); % Create an equalizer object.
eq1.SigConst = pskmod([0:M-1],M); % Set signal constellation.
[symbolest,yd] = equalize(eq1,filtmsg,modmsg(1:trainlen)); % Equalize.
% Plot signals.
h = scatterplot(filtmsg,1,trainlen,'bx'); hold on;
scatterplot(symbolest,1,trainlen,'g.',h);
scatterplot(eq1.SigConst,1,0,'k*',h);
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 41

legend('Filtered signal','Equalizedsignal','Ideal signal constellation');
hold off;

% Compute error rates with and without equalization.
demodmsg_noeq = pskdemod(filtmsg,M); % Demodulate unequalized signal.
demodmsg = pskdemod(yd,M); % Demodulate detected signal from equalizer.
[nnoeq,rnoeq] = symerr(demodmsg_noeq(trainlen+1:end),...
msg(trainlen+1:end));
[neq,req] = symerr(demodmsg(trainlen+1:end),...
msg(trainlen+1:end));
disp('Symbol error rates with and without equalizer:')
disp([reqrnoeq])
OUTPUT WAVEFORMS
RESULT
Equalizer was implemented using MATLAB and the output was verified.



Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 42

Exp No: 8
22/1/2014
PDF AND CDF OF POISSON, BINOMIAL AND GAUSSIAN
DISTRIBUTIONS
AIM
To plot the PDF & CDF of following distributions
1. Poisson
2. Binomial
3. Gaussian using MATLAB.
SOFTWARE REQUIRED
MATLAB 7.1
THEORY
POISSON DISTRIBUTION
In probability theory and statistics, the Poisson distribution is a discrete probability
distribution that expresses the probability of a given number of events occurring in a fixed
interval of time and/or space if these events occur with a known average rate and
independently of the time since the last event. It predicts the degree of spread around a
known average rate of occurrence. It can be applied to systems with a large number of
possible events, each of which is rare.
A discrete random variable X is said to have a Poisson distribution with parameter >
0, if for k =0, 1, 2, ... the probability distribution function(pdf) of X is given by:

p(k ; ) = P( X k)

k
e

k !

Where is equal to the expected value or mean of X and also to its variance,

= E( X) = Var( X)


The cumulative distribution function (cdf) is given as,

!
[]
=0


Figure 1 shows the pdf & cdf of poisson distributions.
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 43


Fig.1. PDF & CDF of poisson distributions
The poisson distribution arises in some problems involving counting, for example,
monitoring the number of telephone calls arriving at a switching center during various
intervals of time. In digital communication, poisson distribution is pertinent to the problem of
transmission of many data bits when the error rates are low.
BINOMIAL DISTRIBUTION
In probability theory and statistics, the binomial distribution is the discrete probability
distribution of the number of successes in a sequence of n independent yes/no experiments,
each of which yields success with probability p. The binomial distribution is the basis for the
popular binomial test of statistical significance. The binomial probability density function for
a given value x and given pair of parameters n and p is
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 44


y= f (x/ n, p) = (
n
x
) p
x
q
n x
I
(0,1,. ... , n)
( x)

where, q=1-p
The result, y, is the probability of observing x successes in n independent trials, where
the probability of success in any given trial is p. the indicator function i
(0,1,...,n)
(x) ensures
that x only adopts values of 0, 1, ..., n..
The cumulative distribution function can be expressed as:
(; , ) = Pr( ) = (

[]
=0
(1 )


GAUSSIAN / NORMAL DISTRIBUTION
The gaussian(or normal) distribution is a very commonly occurring continuous
probability distributiona function that tells the probability that an observation in some
context will fall between any two real numbers. The normal distribution is immensely useful
because of the central limit theorem, which states that, under mild conditions, the mean of
many random variables independently drawn from the same distribution is distributed
approximately normally, irrespective of the form of the original distribution: physical
quantities that are expected to be the sum of many independent processes often have a
distribution very close to the normal. Moreover, many results and methods can be derived
analytically in explicit form when the relevant variables are normally distributed. The
Gaussian distribution is sometimes informally called the bell curve.
PDF of normal distribution is
(, , ) =
1
2

()
2
2
2



The parameter in this definition is the mean or expectation of the distribution & its
variance is
2
. A random variable with a Gaussian distribution is said to be normally
distributed and is called a normal deviate. If = 0 and = 1, the distribution is called the
standard normal distribution or the unit normal distribution, and a random variable with that
distribution is a standard normal deviate.
Figure 2 shows the pdf&cdf of gaussian distributions,

() =
1
2
[1 +erf (

2
2
)]

Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 45


Fig.2. PDF & CDF of gaussian distributions
PROCEDURE
1. Create a random variable that varies between some ranges
2. Using MATLAB functions ,compute the CDF and PDF for various distributions
a) For Poisson PDF use MATLAB function poisspdf and for CDF use poisscdf.
b) For Gaussian PDF use normpdf and for CDF normcdf.
c) For binomial PDF use binopdf and for CDF binocdf.
3. Plot the graphs.
PROGRAM
clc;
clear all;
%pdf of normal distribution
r=random('normal',0,1,1000,1)
y=normpdf(r,0,1);
subplot(6,1,1);
plot(r,y,'*');
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 46

title('pdf of normal distribution');
xlabel('time'); ylabel('PDF');
% generate binomial pdf
x=0:10;
z=binopdf(x,10,0.5);
subplot(6,1,2);
plot(x,z,'-');
title('pdf of binomial distribution');
xlabel('time'); ylabel('PDF');

%generate the poissonpdf
x = 0:15;
y = poisspdf(x,5);
subplot(6,1,3);
plot(x,y,'+');
title('pdf of poisson distribution');
xlabel('time'); ylabel('PDF');

%cdf of normal distribution
r=random('normal',0,1,1000,1)
t=normcdf(r,0,1);
subplot(6,1,4);
plot(r,t,'*');
title('cdf of normal distribution');
xlabel('time'); ylabel('CDF');

%cdf of binomial distribution
w=binocdf(x,10,0.5);
subplot(6,1,5);
plot(x,w,'-');
title('cdf of binomial distribution');
xlabel('time'); ylabel('CDF');

%cdf of poisson
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 47

x=0:10;
z=poisscdf(x,5);
subplot(6,1,6);
plot(x,z,'+');
title('cdf of poisson distribution');
xlabel('time'); ylabel('CDF');
OUTPUT WAVEFORMS

RESULT
The PDF & CDF of Poisson distribution, Binomial distribution& Gaussian
distribution were plotted.
-4 -3 -2 -1 0 1 2 3 4
0
0.2
0.4
pdf of normal distribution
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
pdf of binomial distribution
0 5 10 15
0
0.1
0.2
pdf of poisson distribution
-3 -2 -1 0 1 2 3
0
0.5
1
cdf of normal distribution
0 5 10 15
0
0.5
1
cdf of binomial distribution
0 1 2 3 4 5 6 7 8 9 10
0
0.5
1
cdf of poisson distribution
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 48

Exp No: 9
29/1/2014
INTRODUCTION TO NS
2

AIM
To get familiarised with Network simulator-2
SOFTWARE USED
Linux
THEORY
Network Simulator (Version 2), widely known as NS2, is simply an event driven
simulation tool that has proved useful in studying the dynamic nature of communication
networks. Simulation of wired as well as wireless network functions and protocols (e.g.,
routing algorithms, TCP, UDP) can be done using NS2. In general, NS2 provides users with
a way of specifying such network protocols and simulating their corresponding behaviours.
NS2 provides users with executable command ns which take on input argument, the name of
a Tcl simulation scripting file. Users are feeding the name of a Tcl simulation script (which
sets up a simulation) as an input argument of an NS2 executable command ns. In most cases,
a simulation trace file is created, and is used to plot graph and/or to create animation. NS2
consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl).
While the C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the
OTcl sets up simulation by assembling and configuring the objects as well as scheduling
discrete events (i.e., a frontend). The C++ and the OTcl are linked together using TclCL.
There are three steps in defining a simulation scenario in a NS2.
PROCEDURE
Step 1 - simulation design
The first step in simulating a network is to design the simulation. In this step, the
users should determine the simulation purposes, network configuration and assumptions, the
performance measures, and the type of expected results.
Step 2 - configuring and running simulation
This step implements the design in the first step. It consists of two phases:
1. Network configuration phase: In this phase network components (e.g.,node, TCP
and UDP) are created and configured according to the simulation design. Also, the
events such as data transfer are scheduled to start at a certain time.
2. Simulation Phase: This phase starts the simulation which was configured in the
Network Configuration Phase. It maintains the simulation clock and executes
event chronologically. This phase usually runs until the simulation clock reached a
threshold value specified in the Network Configuration Phase.
Federal Institute of Science And Technology (FISAT)

COMMUNICATION SYSTEM ENGINEERING LAB Page 49

Step 3 - post simulating processing
The main tasks in this steps include verifying the integrity of the program and
evaluating the performance of the simulated network.
PROGRAM
set ns [new Simulator]

settr [open second.tr w]

$ns trace-all $tr

setnf [open out.nam w]

$ns namtrace-all $nf

proc finish {} {puts "Complete";exit 0}

set n0 [$ns node]

set n1 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n1 $sink0
$ns connect $tcp0 $sink0
$ns at 0.5 "$ftp0 start"
$ns at 4.5 "$ftp0 stop"
$ns at 5.0 "finish"
$ns run
RESULT
Thus familiarized with network simulator 2 and verified the output.

Anda mungkin juga menyukai