Experiment No.1 Phase Shift Keying (PSK/BPSK) Aim: To Generate and Demodulate Phase Shift Keyed (PSK) Signal Using MATLAB
Experiment No.1 Phase Shift Keying (PSK/BPSK) Aim: To Generate and Demodulate Phase Shift Keyed (PSK) Signal Using MATLAB
Experiment No.1
Aim: To generate and demodulate phase shift keyed (PSK) signal using MATLAB
PSK is a digital modulation scheme that conveys data by changing, or modulating, the phase of a
reference signal (the carrier wave). PSK uses a finite number of phases, each assigned a unique
pattern of binary digits. Usually, each phase encodes an equal number of bits. Each pattern of bits
forms the symbol that is represented by the particular phase. The demodulator, which is designed
specifically for the symbol-set used by the modulator, determines the phase of the received signal
and maps it back to the symbol it represents, thus recovering the original data.
In a coherent binary PSK system, the pair of signal S1(t) and S2 (t) used to represent binary
symbols 1 & 0 are defined by
Antipodal Signal:
The pair of sinusoidal waves that differ only in a relative phase shift of 180° are called antipodal
signals.
BPSK Transmitter
Product
Binary Wave BPSK signal
Modulator
(Polar form)
1
JKKNCET/Digital Communication laboratory-MATLAB Programs
The input binary symbols are represented in polar form with symbols 1 & 0 represented by
constant amplitude levels √Eb & -√Eb. This binary wave is multiplied by a sinusoidal carrier in a
product modulator. The result in a BSPK signal.
BSPK Receiver:
Decision
PSK signal X ∫ dt x device Choose ‘1’ if x > 0
Choose ‘0’ if x < 0
c1 (t).
2
JKKNCET/Digital Communication laboratory-MATLAB Programs
The received BPSK signal is applied to a correlator which is also supplied with a locally generated
reference signal c1 (t). The correlated o/p is compared with a threshold of zero volts. If x> 0, the
receiver decides in favour of symbol 1. If x< 0, it decides in favour of symbol 0.
Algorithm
Initialization commands
PSK modulation
PSK demodulation
Program
% PSK modulation
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1;
t=0:Tb/100:Tb;
fc=2;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
%generate message signal
N=8;
m=rand(1,N);
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
3
JKKNCET/Digital Communication laboratory-MATLAB Programs
else
m(i)=0;
m_s=-1*ones(1,length(t));
end
message(i,:)=m_s;
%product of carrier and message signal
bpsk_sig(i,:)=c.*m_s;
%Plot the message and BPSK modulated signal
subplot(5,1,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal(POLAR form)');xlabel('t--->');ylabel('m(t)');
grid on; hold on;
subplot(5,1,4);plot(t,bpsk_sig(i,:));
title('BPSK signal');xlabel('t--->');ylabel('s(t)');
grid on; hold on;
t1=t1+1.01; t2=t2+1.01;
end
hold off
%plot the input binary data and carrier signal
subplot(5,1,1);stem(m);
title('binary data bits');xlabel('n--->');ylabel('b(n)');
grid on;
subplot(5,1,3);plot(t,c);
title('carrier signal');xlabel('t--->');ylabel('c(t)');
grid on;
% PSK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
%correlator
x=sum(c.*bpsk_sig(i,:));
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+1.01;
t2=t2+1.01;
end
%plot the demodulated data bits
subplot(5,1,5);stem(demod);
title('demodulated data');xlabel('n--->');ylabel('b(n)');
grid on
4
JKKNCET/Digital Communication laboratory-MATLAB Programs
Modal Graphs
Result
The program for PSK modulation and demodulation has been simulated in MATLAB and
necessary graphs are plotted.
5
JKKNCET/Digital Communication laboratory-MATLAB Programs
Experiment No.2
Aim: To generate and demodulate frequency shift keyed (FSK) signal using MATLAB
Theory
Generation of FSK
In binary FSK system, symbol 1 & 0 are distinguished from each other by transmitting one of the
two sinusoidal waves that differ in frequency by a fixed amount.
0 elsewhere
Where i=1, 2 & Eb=Transmitted energy/bit
Transmitted freq= ƒi = (nc+i)/Tb, and n = constant (integer), Tb = bit interval
Symbol 1 is represented by S1 (t)
Symbol 0 is represented by S0 (t)
BFSK Transmitter
X
Binary wave c1 (t) = √2/Tb cos 2πƒ1t +
(On-Off signaling
Form) Σ
The input binary sequence is represented in its ON-OFF form, with symbol 1
represented by constant amplitude of √Eb with & symbol 0 represented by zero volts.
By using inverter in the lower channel, we in effect make sure that when symbol 1is
at the input, The two frequency f1& f2 are chosen to be equal integer multiples of the
6
JKKNCET/Digital Communication laboratory-MATLAB Programs
bit rate 1/Tb.By summing the upper & lower channel outputs, we get BFSK signal.
10
7
JKKNCET/Digital Communication laboratory-MATLAB Programs
BFSK Receiver x1
X Tbƒdt
0 + x = x1-x2
c1 (t) Decision
E
Device
L
FSK signal - choose ‘1’ if x >0
The receiver consists of two correlates with common inputs which are supplied with
locally generated coherent reference signals c1(t) and c2 (t).
The correlator outputs are then subtracted one from the other, and the resulting difference
x is compared with a threshold of zero volts. If x >0, the receiver decides in favour of
symbol 1 and if x <0, the receiver decides in favour of symbol 0.
Algorithm
Initialization commands
FSK modulation
FSK demodulation
8
JKKNCET/Digital Communication laboratory-MATLAB Programs
9
JKKNCET/Digital Communication laboratory-MATLAB Programs
Program
% FSK Modulation
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1; fc1=2;fc2=5;
t=0:(Tb/100):Tb;
c1=sqrt(2/Tb)*sin(2*pi*fc1*t);
c2=sqrt(2/Tb)*sin(2*pi*fc2*t);
%generate message signal
N=8;
m=rand(1,N);
t1=0;t2=Tb
for i=1:N
t=[t1:(Tb/100):t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
invm_s=zeros(1,length(t));
else
m(i)=0;
m_s=zeros(1,length(t));
invm_s=ones(1,length(t));
end
message(i,:)=m_s;
%Multiplier
fsk_sig1(i,:)=c1.*m_s;
fsk_sig2(i,:)=c2.*invm_s;
fsk=fsk_sig1+fsk_sig2;
%plotting the message signal and the modulated signal
subplot(3,2,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal');xlabel('t---->');ylabel('m(t)');grid on;hold on;
subplot(3,2,5);plot(t,fsk(i,:));
title('FSK signal');xlabel('t---->');ylabel('s(t)');grid on;hold on;
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
hold off
%Plotting binary data bits and carrier signal
subplot(3,2,1);stem(m);
title('binary data');xlabel('n---->'); ylabel('b(n)');grid on;
subplot(3,2,3);plot(t,c1);
title('carrier signal-1');xlabel('t---->');ylabel('c1(t)');grid on;
subplot(3,2,4);plot(t,c2);
10
JKKNCET/Digital Communication laboratory-MATLAB Programs
% FSK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:(Tb/100):t2]
%correlator
x1=sum(c1.*fsk_sig1(i,:));
x2=sum(c2.*fsk_sig2(i,:));
x=x1-x2;
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
%Plotting the demodulated data bits
subplot(3,2,6);stem(demod);
title(' demodulated data');xlabel('n---->');ylabel('b(n)'); grid on;
11
JKKNCET/Digital Communication laboratory-MATLAB Programs
Modal Graphs
Result
The program for FSK modulation and demodulation has been simulated in
MATLAB and necessary graphs are plotted.
12
JKKNCET/Digital Communication laboratory-MATLAB Programs
Experiment No.3
Theory:
Spread spectrum is a digital modulation technology and a technique based on principals
of spreading a signal among many frequencies to prevent interference and signal detection. It is a
technique to spread the transmitted spectrum over a wide range of frequencies.
Direct sequence spread spectrum (DSSS):
In Direct sequence spread spectrum (DSSS) each bit in the original signal is represented
by multiple bits after signal is transmitted into channel. In this technique when the signal is
transmitted spreading code spreads the signal in wider frequency band. When PN bits are
generated the number of bits used to represent each original is directly proportional to Number of
PN sequence generated and used. In the next section you will see how this process works.
13
JKKNCET/Digital Communication laboratory-MATLAB Programs
14
JKKNCET/Digital Communication laboratory-MATLAB Programs
PROGRAMS:
15
JKKNCET/Digital Communication laboratory-MATLAB Programs
x1= 0;
x2 =0;
x3 =0;
N = input('Enter the period of the signal')
for i =1:N
x3 =x2;
x2 =x1;
x1 = x0;
x0 =xor(x1,x3);
disp(i,'The PN sequence at step')
x = [x1 x2 x3];
disp(x,'x=')
end
m = [7,8,9,10,11,12,13,17,19];
N = 2^m-1;
disp('Table Range of PN Sequence lengths')
disp('_________________________________________________________')
disp('Length of shift register (m)')
disp(m)
disp('PN sequence Length (N)')
disp(N)
disp('_________________________________________________________')
Alternate Method:
GENERATION OF PN-SEQUENCE:
clear
clc
G=63; % Code length
%Generation of first m-sequence using generator polynomial [45]
sd1 =[0 0 0 0 1]; % Initial state of Shift register
PN1=[]; % First m-sequence
for j=1:G
PN1=[PN1 sd1(5)];
if sd1(1)==sd1(4)
temp1=0;
else temp1=1;
end
sd1(1)=sd1(2);
sd1(2)=sd1(3);
sd1(3)=sd1(4);
sd1(4)=sd1(5);
sd1(5)=temp1;
16
JKKNCET/Digital Communication laboratory-MATLAB Programs
end
subplot(3,1,1)
stem(PN1)
title('M-sequence generated by generator polynomial [45]')
function DSSS
clc
PNbit_stream = round(rand(1,32));
input_signal=[0 1 0 0 1 0 1 1];
PNbit_stream
for i=1:1:8
for j=1:4:32
for k=1:1:4
a(j)=xor(PNbit_stream(k+j-1),input_signal(i));
a(j);
end
end
end
figure(1)
stem(PNbit_stream)
title('PNbit_stream');
figure(2)
stem(input_signal)
title('input_signal');
figure(3)
stem(a)
title('DSSS');
17
JKKNCET/Digital Communication laboratory-MATLAB Programs
Model graph:
18
JKKNCET/Digital Communication laboratory-MATLAB Programs
19
JKKNCET/Digital Communication laboratory-MATLAB Programs
Result,
Experiment No.3
ERROR CONTROL CODING USNG MATLAB
AIM
To write a mat lab program for the simulation of error detection implementation of
linear block code.
APPARATUS REQUIRED
PROCEDURE
THEORY
20
JKKNCET/Digital Communication laboratory-MATLAB Programs
21
JKKNCET/Digital Communication laboratory-MATLAB Programs
d_min = min(sum((c(2:2^k,:))'))
% Code Word
r = input('Enter the Received Code Word:')
p = [g(:,n-k+2:n)];
h = [transpose(p),eye(n-k)];
disp('Hammimg Code')
ht = transpose(h)
disp('Syndrome of a Given Codeword is :')
s = rem(r*ht,2)
for i = 1:1:size(ht)
if(ht(i,1:3)==s)
r(i) = 1-r(i);
break;
end
end
disp('The Error is in bit:')
i
disp('The Corrected Codeword is :')
r
OUTPUT
G=
The Order of Linear block Code for given Generator Matrix is:
n=
7
k=
4
c=
0000000
0001011
0010110
0011101
22
JKKNCET/Digital Communication laboratory-MATLAB Programs
0100111
0101100
0110001
0111010
1000101
1001110
1010011
1011000
1100010
1101001
1110100
1111111
The Minimum Hamming Distance dmin for given Block Code is=
d_min =
r=
1000100
Hammimg Code
ht =
101
111
110
011
100
010
001
23
JKKNCET/Digital Communication laboratory-MATLAB Programs
RESULT
Thus the simulation of MATLAB program for error detection implementation of linear block
code was done and verified.
24