0% found this document useful (0 votes)
85 views24 pages

Experiment No.1 Phase Shift Keying (PSK/BPSK) Aim: To Generate and Demodulate Phase Shift Keyed (PSK) Signal Using MATLAB

The document describes experiments on generating and demodulating phase shift keying (PSK) and frequency shift keying (FSK) signals using MATLAB. For PSK, it explains generating a PSK signal by modulating binary data with a carrier signal, and demodulating by correlating the received PSK signal with a reference carrier. For FSK, it describes generating an FSK signal by frequency modulating two carrier signals with binary data, and demodulating by correlating with each carrier and comparing the results. MATLAB programs are provided to simulate PSK and FSK modulation and demodulation, generating necessary signals and graphs.

Uploaded by

AmnaSajjad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views24 pages

Experiment No.1 Phase Shift Keying (PSK/BPSK) Aim: To Generate and Demodulate Phase Shift Keyed (PSK) Signal Using MATLAB

The document describes experiments on generating and demodulating phase shift keying (PSK) and frequency shift keying (FSK) signals using MATLAB. For PSK, it explains generating a PSK signal by modulating binary data with a carrier signal, and demodulating by correlating the received PSK signal with a reference carrier. For FSK, it describes generating an FSK signal by frequency modulating two carrier signals with binary data, and demodulating by correlating with each carrier and comparing the results. MATLAB programs are provided to simulate PSK and FSK modulation and demodulation, generating necessary signals and graphs.

Uploaded by

AmnaSajjad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

JKKNCET/Digital Communication laboratory-MATLAB Programs

Experiment No.1

PHASE SHIFT KEYING (PSK/BPSK)

Aim: To generate and demodulate phase shift keyed (PSK) signal using MATLAB

Generation of PSK signal

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

S1 (t) = √2Eb/ Tb Cos 2πfct


S2 (t) =√2Eb/Tb (2πfct+π) = - √ 2Eb/Tb Cos 2πfct where 0 ≤ t< Tb and
Eb = Transmitted signed energy for bit
The carrier frequency fc =n/Tb for some fixed integer n.

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)

c1 (t) = √2/Tb cos 2πfct

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

1. Generate carrier signal.


2. Start FOR loop
3. Generate binary data, message signal in polar form
4. Generate PSK modulated signal.
5. Plot message signal and PSK modulated signal.
6. End FOR loop.
7. Plot the binary data and carrier.

PSK demodulation

1. Start FOR loop


Perform correlation of PSK signal with carrier to get decision variable
2. Make decision to get demodulated binary data. If x>0, choose ‘1’ else choose ‘0’
3. Plot the demodulated binary data.

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

FREQUENCY SHIFT KEYING (FSK/BFSK)

Aim: To generate and demodulate frequency shift keyed (FSK) signal using MATLAB

Theory

Generation of FSK

Frequency-shift keying (FSK) is a frequency modulation scheme in which digital information is


transmitted through discrete frequency changes of a carrier wave. The simplest FSK is binary FSK
(BFSK). BFSK uses a pair of discrete frequencies to transmit binary (0s and 1s) information. With
this scheme, the "1" is called the mark frequency and the "0" is called the space frequency.

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.

Si (t) = √2E/Tb cos 2πf1t 0≤ t ≤Tb

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) Σ

Inverter X + FSK signal

c2 (t) = √2/Tb cos 2πƒ2t

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

X choose ‘0’ if x < 0


c2 (t) x2

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

1. Generate two carriers signal.


2. Start FOR loop
3. Generate binary data, message signal and inverted message signal
4. Multiply carrier 1 with message signal and carrier 2 with inverted message signal
5. Perform addition to get the FSK modulated signal
6. Plot message signal and FSK modulated signal.
7. End FOR loop.
8. Plot the binary data and carriers.

FSK demodulation

1. Start FOR loop


2. Perform correlation of FSK modulated signal with carrier 1 and carrier 2 to get two decision
variables x1 and x2.
3. Make decisionon x = x1-x2 to get demodulated binary data. If x>0, choose ‘1’ else choose ‘0’.
4. Plot the demodulated binary data.

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

title('carrier signal-2');xlabel('t---->');ylabel('c2(t)');grid on;

% 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

SPREAD SPECTRUM COMMUNICATION

Aim: To study the spread spectrum communication using MATLAB

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

DSSS Transmitter Example:


 Data Input A shown the input original message which is ready to encode or spread by
using a PN sequence as illustrated in the above section.
 2nd diagram shows the locally generated PN sequence. In this diagram each bit of
original message is represented by 4-bits of PN sequence.
 Now by Exclusive-Or first and 2nd diagram 3rd signal is obtained simply by Xor
between 1 bit of original data with 4 bits of PN sequence.

DSSS Receiver Example:

 On receiver side we received signal which was transmitted from transmitter side. Assume


that there is no error or no bit corrupted in the received signals.
 When signal is received same PN sequence is generated on receiver side, the signal
which was generated on transmitted side.
 Received signal and PN sequence is Xor. By this original Signal is received.

14
JKKNCET/Digital Communication laboratory-MATLAB Programs

Frequency Hopping spread spectrum:


Frequency hopping spread spectrum is a transmission technology used in wireless
networks and a technique to generate spread spectrum by hopping the carrier frequency. FHSS
uses narrow band signal which is less than 1 MHz, In this method data signal is modulated with a
narrowband carrier signal that "hops" in random and hopping happens in pseudo-random
"predictable" sequence in a regular time from frequency to frequency which is synchronized at
both ends. Using FHSS technology improves privacy, it is a powerful solution to avoid
interference and multi path fading (distortion), it decreases narrowband interference, increases
signal capacity, improve the signal to  noise ratio, efficiency of bandwidth is high and difficult to
intercept also this transmission can share a frequency band with many types of conventional
transmissions with minimal interference. For frequency hopping a mechanism must be defined to
transmit data in a clear channel and to avoid the congested channels. Frequency hopping is the
periodic change of transmission frequency and hopping happens over a frequency bandwidth
which consists of numbers of channels. Channel which is used as a hopped channel is
instantaneous bandwidth while the hopping spectrum is called total hopping bandwidth.
Frequency hopping categorized into slow hopping and fast hopping which by slow hopping more
than one data symbol is transmitted in same channel and by fast hopping frequency changes
several times during one symbol. Hopping sequence means which next channel to hop; there are
two types of hopping sequence: random hopping sequence and deterministic hopping sequence.
The focus of this work is on slow and deterministic frequency hopping sequence. In a frequency
hopping network, there can be different number of receivers which one sender is designed as
Base that is responsible to transmit the synchronization data to the receivers.

PROGRAMS:

%PN sequence generation


%Maximum-length sequence generator
%Program to generate Maximum Length Pseudo Noise Sequence
clc;
%Assign Initial value for PN generator
x0= 1;

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]')

Direct Sequence Spread Spectrum:

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,

The program for spread spectrum communication has been simulated in


MATLAB and necessary graphs are plotted.

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

MATLAB 7.0.1 Software

PROCEDURE

1. Select MATLAB 7.0.1 from Programs menu.


2. Select File-New-M File.
3. Type the program in the new file.
4. Save the file using .m extension.
5. Select debug-run.
6. Any errors if present can be viewed by selecting windows-0 command window.
7. If no error, the signal appears in the screen.
8. The output signal thus viewed.

THEORY

20
JKKNCET/Digital Communication laboratory-MATLAB Programs

ERROR DETECTION IMPLEMENTATION OF LINEAR BLOCK CODE


INFORMATION ON CYCLIC CODE
Cyclic codes are an important sub-class of linear block codes for error detection, where a new
codeword in the code can be formed by shifting the elements along one place and taking one off
the end and putting it on to the beginning. Instead of being generated by a matrix, a cyclic code
is generated by a polynomial so that the codes are sometimes called polynomial codes.
Importantly, cyclic codes have a structure that makes it possible for the encoding and decoding
to be performed by simple feedback circuitry. Satellite communications systems commonly use
cyclic codes.
INFORMATION ON CONVOLUTIONAL CODE
A convolutional code extends the concept of a block code to allow memory from block to block.
Each encoded symbol is therefore a linear combination of information symbols in the current
block and a selected number of preceding blocks.
Therefore, for example, if the final output is a ‘1’ followed by a ‘0’, then these two digits
could only have been arrived at by via a certain sequence of 0s and 1s preceding them. The
longer the sequence, the easier it becomes for the receiver to detect where the received sequence
deviates from a possible sequence and so correct one or more errors. Decoding of convolutional
codes is based on the principle of the Viterbi decoding algorithm or sequential decoding.
Satellite communications systems commonly use a convolutional code to protect all data carried
on the link.
PROGRAM
clf;
clc;
clear all;
close all;
% Input Generator Matrix
g=input('Enter The Generator Matrix: ')
disp ('G = ')
disp ('The Order of Linear block Code for given Generator Matrix is:')
[n,k] = size(transpose(g))
for i = 1:2^k
for j = k:-1:1
if rem(i-1,2^(-j+k+1))>=2^(-j+k)
u(i,j)=1;
else
u(i,j)=0;
end
end
end
u;
disp('The Possible Codewords are :')
c = rem(u*g,2)
disp('The Minimum Hamming Distance dmin for given Block Code is= ')

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

Enter The Generator Matrix: [1 0 0 0 1 0 1;0 1 0 0 1 1 1;0 0 1 0 1 1 0;0 0 0 1 0 1 1]


g=
1000101
0100111
0010110
0001011

G=
The Order of Linear block Code for given Generator Matrix is:
n=
7
k=
4

The Possible Codewords are :

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 =

Enter the Received Code Word:[1 0 0 0 1 0 0]

r=
1000100

Hammimg Code
ht =
101
111
110
011
100
010
001

Syndrome of a Given Codeword is :


s=
001

The Error is in bit:


i=
7

The Corrected Codeword is :


r=
1000101

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

You might also like