Digital Communication Lab File
Digital Communication Lab File
(ii)
EXPERIMENT 1
(UNIPOLAR RZ & NRZ)
AIM: To study generation of Unipolar RZ & NRZ line coding using MATLAB.
Theory
Unipolar encoding is a line coding in which positive voltage represents a binary ‘1’,
and zero volts indicates a binary ‘0’. It is the simplest line code, directly encoding the
bit sequence.
NRZ (Non-Return-to-Zero)
In NRZ scheme the signal does not return to zero at the middle of the bit.
RZ (Return-to-Zero)
In RZ Polar line coding, signal return to zero at the middle of the bit.
For Unipolar RZ
If symbol 1 is transmitted:
𝑻𝒃
𝑿(𝒕) = 𝑨 𝒇𝒐𝒓 𝟎 ≤ 𝐭 ≤ (𝒉𝒂𝒍𝒇 𝒊𝒏𝒕𝒆𝒓𝒗𝒂𝒍)
𝟐
𝑻𝒃
𝟎 𝒇𝒐𝒓 ≤ 𝒕 ≤ 𝑻𝒃
𝟐
If symbol 0 is transmitted:
𝑿(𝒕) = 𝟎 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
If symbol 1 is transmitted:
𝑿(𝒕) = 𝑨 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
If symbol 0 is transmitted:
𝑿(𝒕) = 𝟎 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
1. UNIPOLAR RZ
i) Take input bit sequence and amplitude.
ii) Initialize Arrays: It initializes an array d of zeros with the same length as
the input bit sequence n. This array will store the amplitude values
corresponding to each bit.
ASHUTOSH
1
iii) Assign Amplitude Values: It iterates over each bit in the input sequence
n. If the bit is 1, it assigns the amplitude to the corresponding position in
the d array; otherwise, it assigns 0.
iv) Adjust Time Vector: It creates a time vector t with a step size of 0.01 and
a length equal to the length of the input sequence n.
v) Initialize Output Array: It initializes an array y of zeros with the same
length as the time vector t. This array will store the amplitude values
corresponding to each time point.
vi) Generate Output Signal: It iterates over each time point in the time
vector t. For each time point, it checks if the time is less than or equal to
the current index i. If so, it assigns the corresponding amplitude value
from the d array to the output array y. If not, it increments i and assigns the
next amplitude value from the d array to the output array y.
2. UNIPOLAR NRZ
i) The code prompts the user to enter a bit sequence (b) and an amplitude.
ii) Iteration & Time Vector: It iterates through each bit in the input sequence
b. For each bit, it generates a time vector t ranging from (n-1) to n with a
step size of 0.001.
iii) Signal Generation
• If the current bit is 1, it checks the next bit.
i) If the next bit is also 1, it generates an amplitude
amp for the duration (n-0.5, n].
ii) If the next bit is different or it's the last bit, it
generates an amplitude amp for the duration (n-0.5,
n] and (n, n+0.5].
• If the current bit is 0, it checks the next bit.
i) If the next bit is 1, it generates an amplitude amp for
the duration (n, n+0.5].
ii) If the next bit is 0 or it's the last bit, it generates a
zero signal for the duration (n-0.5, n].
• Plot the graph.
MATLAB CODE
UNIPOLAR RZ
clc;
clear all;
close all;
b = input('Enter bit sequence: ');
amp = input('Enter amplitude (e.g., 1): ');
l = length(b);
b(l + 1) = 0;
n = 1;
while n <= l
t = (n - 1):0.001:n;
ASHUTOSH
2
if b(n) == 1
if b(n + 1) == b(n)
y = amp * ((t < (n - 0.5)) + (t == n));
else
y = amp * (t < (n - 0.5));
end
else
if b(n + 1) == 1
y = 0 * (t < (n - 0.5)) + amp * (t == n);
else
y = 0 * (t < (n - 0.5));
end
end
n = n + 1;
plot(t, y)
hold on;
axis([0 l -1.5 * amp 1.5 * amp]);
end
title('UNIPOLAR RZ for given bit sequence');
xlabel('Time');
ylabel('Amplitude');
%CODE WRITTEN BY ASHUTOSH
UNIPOLAR NRZ
clc;
n = input('Enter the bit sequence: ');
ip = input('Enter the amplitude: ');
d = zeros(1, length(n)); % Initialize d array
for i = 1:length(n)
if n(i)==1
d(i)=ip;
else
d(i)=0;
end
end
i=1;
t=0:0.01:(length(n)); % Adjust the time vector length
y = zeros(1, length(t)); % Initialize y array
for j=1:length(t)
if t(j)<=i
y(j)=d(i);
else
i=i+1;
y(j)=d(i);
end
end
plot(t,y,'r');
axis([0 length(n) -(ip+2) (ip+2)]); % Adjust the x-axis limit
xlabel('Time axis');
ylabel('Amplitude');
title('Unipolar NRZ for n = %d', n);
%CODE WRITTEN BY ASHUTOSH
ASHUTOSH
3
FIG-1.1: OUTPUT FOR UNIPOLAR NRZ [1 0 1 1 1 0 1 1 0 1]
ASHUTOSH
4
CASE: 2
ASHUTOSH
5
EXPERIMENT 2
(POLAR RZ & NRZ)
AIM: To Study the generation of Polar RZ and NRZ line codes using MATLAB.
THEORY
Polar coding scheme uses multiple voltage level to represent binary values.
NRZ (Non-Return-to-Zero)
In NRZ scheme the signal does not return to zero at the middle of the bit.
RZ (Return-to-Zero)
In RZ Polar line coding, signal return to zero at the middle of the bit.
For Polar RZ
If symbol 1 is transmitted:
𝑨 𝑻𝒃
𝑿(𝒕) = 𝒇𝒐𝒓 𝟎 ≤ 𝐭 ≤ (𝒉𝒂𝒍𝒇 𝒊𝒏𝒕𝒆𝒓𝒗𝒂𝒍)
𝟐 𝟐
𝑻𝒃
𝟎 𝒇𝒐𝒓 ≤ 𝒕 ≤ 𝑻𝒃
𝟐
If symbol 0 is transmitted:
𝑨 𝑻𝒃
𝑿(𝒕) = − 𝒇𝒐𝒓 𝟎 ≤ 𝐭 ≤ (𝒉𝒂𝒍𝒇 𝒊𝒏𝒕𝒆𝒓𝒗𝒂𝒍)
𝟐 𝟐
𝑻𝒃
𝟎 𝒇𝒐𝒓 ≤ 𝒕 ≤ 𝑻𝒃
𝟐
If symbol 1 is transmitted:
𝑨
𝑿(𝒕) = 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
𝟐
If symbol 0 is transmitted:
𝑨
𝑿(𝒕) = − 𝟐 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
1. POLAR RZ
i) Input Prompt: The user is prompted to input a bit sequence (bits) and an
amplitude (amp).
ii) Time Calculation: It calculates the total time (T) of the bit sequence
based on its length.
ASHUTOSH
6
iii) Parameters Setup: Parameters such as the number of samples per bit
(n), total number of samples (N), and time step (dt) are defined based on
the calculated time T.
iv) Signal Initialization: It initializes an array x of zeros to store the output
signal.
v) Encoding: It iterates through each bit in the input sequence. For each bit:
• If the bit is 1, it assigns the amplitude amp for the first half of the
bit duration and sets the second half to zero.
• If the bit is 0, it assigns the amplitude -amp for the first half of the
bit duration and sets the second half to zero.
vi) Plotting: It plots the Polar RZ encoded signal using the plot function,
setting the line width to 2. It also adds a grid to the plot.
2. POLAR NRZ
i) Input Prompt: The user is prompted to input a bit sequence (h) and an
amplitude (amp).
ii) Initialization: It initializes variables including n (loop counter), l (length of
the input sequence), and appends an extra bit (1) at the end of the
sequence to handle the last bit case.
iii) Main Loop: It iterates through each bit in the input sequence, excluding
the extra bit added in the initialization.
iv) Time Vector Generation: For each bit, it generates a time vector t ranging
from (n-1) to n with a step size of 0.001.
v) Signal Generation:
• If the current bit is 0, it checks the next bit.
i) If the next bit is also 0, it generates a signal with
amplitude -amp for the duration (n-1, n) and -(t == n).
ii) If the next bit is different, it generates a signal with
amplitude -amp for the duration (n-1, n) and +(t == n).
• If the current bit is 1, it checks the next bit.
i) If the next bit is 0, it generates a signal with
amplitude amp for the duration (n-1, n) and -(t == n).
ii) If the next bit is 1, it generates a signal with
amplitude amp for the duration (n-1, n) and +(t == n).
vi) Plotting: It plots the generated signal y against the time vector t for each
bit, scaling the signal by the amplitude amp.
MATLAB CODE
POLAR RZ
function prz()
% Prompting the user to input the bit sequence and amplitude
bits = input('Enter the bit sequence: ');
amp = input('Enter the amplitude: ');
ASHUTOSH
7
% Calculate full time of bit sequence
T = length(bits);
xlabel('Time');
ylabel('Amplitude');
title('LINE CODE POLAR RZ ');
end
%CODED BY ASHUTOSH
POLAR NRZ
function PNRZ()
h = input('Enter the bit sequence: ');
amp = input('Enter the amplitude: ');
clf;
n = 1;
l = length(h);
h(l+1) = 1;
if h(n) == 0
if h(n+1) == 0
y = -(t < n) - (t == n);
else
y = -(t < n) + (t == n);
end
d = plot(t, amp*y); grid on; % Scale the signal by the amplitude
title('Line code POLAR NRZ');
set(d, 'LineWidth', 2.5);
hold on;
ASHUTOSH
8
axis([0 length(h)-1 -1.5*amp 1.5*amp]);
disp('zero');
else
if h(n+1) == 0
y = (t < n) - 1*(t == n);
else
y = (t < n) + 1*(t == n);
end
d = plot(t, amp*y); grid on; % Scale the signal by the amplitude
title('POLAR NRZ for given bit sequence');
set(d, 'LineWidth', 2.5);
hold on;
axis([0 length(h)-1 -1.5*amp 1.5*amp]);
disp('one');
end
n = n + 1;
end
end
%CODED WRITTEN BY ASHUTOSH
ASHUTOSH
9
FIG-2.2: OUTPUT FOR POLAR NRZ [1 0 1 1 1 0 1 1 0 1]
ASHUTOSH
10
FIG-2.4: OUTPUT FOR POLAR NRZ [1 0 1 1 0 0 1 0 1 0]
ASHUTOSH
11
EXPERIMENT 3
(BIPOLAR RZ & NRZ)
THEORY
Bipolar encoding is a line coding scheme in which two non-zero value are used, so that
the three values are +, -, and zero are presented.
NRZ (Non-Return-to-Zero)
In NRZ scheme the signal does not return to zero at the middle of the bit.
RZ (Return-to-Zero)
In RZ Polar line coding, signal return to zero at the middle of the bit.
For Polar RZ
If symbol 1 is transmitted:
𝑻𝒃
𝑿(𝒕) = 𝑨 𝒇𝒐𝒓 𝟎 ≤ 𝐭 ≤ (𝒉𝒂𝒍𝒇 𝒊𝒏𝒕𝒆𝒓𝒗𝒂𝒍)
𝟐 For odd occurrence
𝑻𝒃
𝟎 𝒇𝒐𝒓 ≤ 𝒕 ≤ 𝑻𝒃 (For 1st, 3rd, 5th… ‘1’ bit)
𝟐
𝑻𝒃
𝑿(𝒕) = −𝑨 𝒇𝒐𝒓 𝟎 ≤ 𝐭 ≤ (𝒉𝒂𝒍𝒇 𝒊𝒏𝒕𝒆𝒓𝒗𝒂𝒍)
𝟐 For even occurrence
𝑻𝒃
𝟎 𝒇𝒐𝒓 ≤ 𝒕 ≤ 𝑻𝒃 (For 2nd, 4th, 6th… ‘1’ bit)
𝟐
If symbol 0 is transmitted:
𝑨
𝑿(𝒕) = − 𝒇𝒐𝒓 𝟎 ≤ 𝐭 ≤ 𝑻𝒃 (𝒉𝒂𝒍𝒇 𝒊𝒏𝒕𝒆𝒓𝒗𝒂𝒍)
𝟐
For Polar NRZ
If symbol 1 is transmitted:
𝑿(𝒕) = 𝑨 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃 For odd occurrence (For 1st, 3rd, 5th… ‘1’ bit)
𝑿(𝒕) = −𝑨 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃 For even occurrence (For 2nd, 4th, 6th… ‘1’ bit)
If symbol 0 is transmitted:
𝑿(𝒕) = 𝟎 𝒇𝒐𝒓 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
ASHUTOSH
12
Algorithm Of Code
1. BIPOLAR RZ
i) Input Prompt: The user is prompted to input a bit sequence (h) and an
amplitude (amp).
ii) Initialization: It initializes variables including l (length of the input
sequence) and appends an extra bit (1) at the end of the sequence to
handle the last bit case. Also, it initializes ami (Alternate Mark Inversion)
to -1.
iii) Main Loop: It iterates through each bit in the input sequence, excluding
the extra bit added in the initialization.
iv) Time Vector Generation: For each bit, it generates a time vector t ranging
from (n-1) to n with a step size of 0.001.
v) Signal Generation:
• If the current bit is 0, it checks the next bit.
i) If the next bit is also 0, it generates a signal with
amplitude amp for the duration (n-1, n].
ii) If the next bit is different, it generates a signal based
on the AMI coding scheme:
▪ If the previous signal was positive, it
generates a negative pulse at the current bit
time.
▪ If the previous signal was negative, it
generates a positive pulse at the current bit
time.
• If the current bit is 1, it toggles the AMI value and generates a
signal accordingly:
i) If the next bit is 0, it generates a signal based on the
AMI coding scheme:
▪ If the current AMI value is positive, it
generates a positive pulse for the first half of
the bit duration.
▪ If the current AMI value is negative, it
generates a negative pulse for the first half of
the bit duration.
ii) If the next bit is 1, it generates a signal with
amplitude amp for the duration (n-1, n] and a
negative pulse at the current bit time.
vi) Plotting: It plots the generated signal y against the time vector t for each
bit, setting the line width to 2.5. Each plot is added to the previous plot
(hold on).
2. BIPOLAR NRZ
ASHUTOSH
13
i) Input Prompt: The user is prompted to input a bit sequence (h) and an
amplitude (amp).
ii) Initialization: It initializes variables including l (length of the input
sequence) and appends an extra bit (1) at the end of the sequence to
handle the last bit case. Also, it initializes ami (Alternate Mark Inversion)
to -1.
iii) Main Loop: It iterates through each bit in the input sequence, excluding
the extra bit added in the initialization.
iv) Time Vector Generation: For each bit, it generates a time vector t ranging
from (n-1) to n with a step size of 0.001.
v) Signal Generation:
• If the current bit is 0, it checks the next bit.
i) If the next bit is also 0, it generates a signal with
amplitude amp for the duration (n-1, n].
ii) If the next bit is different, it generates a signal based
on the AMI coding scheme:
▪ If the previous signal was positive, it
generates a negative pulse at the current bit
time.
▪ If the previous signal was negative, it
generates a positive pulse at the current bit
time.
• If the current bit is 1, it toggles the AMI value and generates a
signal accordingly:
i) If the next bit is 0, it generates a signal based on the
AMI coding scheme:
▪ If the current AMI value is positive, it
generates a positive pulse for the duration (n-
1, n).
▪ If the current AMI value is negative, it
generates a negative pulse for the duration (n-
1, n).
ii) If the next bit is 1, it generates a signal with
amplitude amp for the duration (n-1, n] and a
negative pulse at the current bit time.
vi) Plotting: It plots the generated signal y against the time vector t for each
bit, setting the line width to 2.5. Each plot is added to the previous plot
(hold on).
ASHUTOSH
14
FIG-3.1: OUTPUT FOR BIPOLAR RZ [1 0 1 1 1 0 1 1 0 1]
ASHUTOSH
15
CASE 2: Input bit Sequence: [1 0 1 1 0 0 1 0 1 0]; Amplitude: 2
ASHUTOSH
16
EXPERIMENT 4
(ASK)
AIM: To generate and demodulate Binary amplitude shift keyed (BASK) signal using
MATLAB.
Theory:
Generation of ASK
Amplitude shift keying - ASK - is a modulation process, which imparts to a sinusoid two
or more discrete amplitude levels. These are related to the number of levels adopted by
the digital message. For a binary message sequence there are two levels, one of which
is typically zero. The data rate is a sub-multiple of the carrier frequency. Thus, the
modulated waveform consists of bursts of a sinusoid.
Demodulation
Algorithm
1. ASK MODULATION
i) Generate carrier signal.
ii) Start FOR loop.
iii) Generate binary data, message signal (on-off form).
iv) Generate ASK modulated signal.
v) Plot message signal and ASK modulated signal.
vi) End FOR loop.
vii) Plot the binary data and carrier.
2. ASK DEMODULATION
i) Start FOR loop.
ii) Perform correlation of ASK signal with carrier to get decision variable.
iii) Make decision to get demodulated binary data. If x>0, choose ‘1’ else
choose ‘0’.
iv) Plot the demodulated binary data.
MATLAB CODE
%ASK Modulation
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1; fc=10;
ASHUTOSH
17
t=0:Tb/100:1;
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));
else
m(i)=0;
m_s=zeros(1,length(t));
end
message(i,:)=m_s;
%product of carrier and message
ask_sig(i,:)=c.*m_s;
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
%plot the message and ASK signal
subplot(5,1,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal');xlabel('t--->');ylabel('m(t)');grid on
hold on
subplot(5,1,4);plot(t,ask_sig(i,:));
title('ASK signal');xlabel('t--->');ylabel('s(t)');grid on
hold on
end
hold off
%Plot the carrier signal and input binary data
subplot(5,1,3);plot(t,c);
title('carrier signal');xlabel('t--->');ylabel('c(t)');grid on
subplot(5,1,1);stem(m);
title('binary data bits');xlabel('n--->');ylabel('b(n)');grid on
% ASK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:Tb/100:t2]
%correlator
x=sum(c.*ask_sig(i,:));
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
%plot demodulated binary data bits
subplot(5,1,5);stem(demod);
title('ASK demodulated signal'); xlabel('n--->');ylabel('b(n)');grid on
ASHUTOSH
18
Modal Graphs
Result:
The program for ASK modulation and demodulation has been simulated in MATLAB and
necessary graphs are plotted.
ASHUTOSH
19
EXPERIMENT 5
(PHASE SHIFT KEY)
AIM: To generate and demodulate binary phase shift keyed (BPSK) signal using MATLAB.
Theory:
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
𝟐𝑬
𝑺𝟏 (𝒕) = √ 𝑻 𝒃 𝑪𝒐𝒔𝟐𝝅𝒇𝒄 𝒕
𝒃
𝟐𝑬 𝟐𝑬
𝑺𝟐 (𝒕) = √ 𝑻 𝒃 (𝑪𝒐𝒔𝟐𝝅𝒇𝒄 𝒕 + 𝝅) = 𝑺𝟏 (𝒕) = −√ 𝑻 𝒃 𝑪𝒐𝒔𝟐𝝅𝒇𝒄 𝒕
𝒃 𝒃
where 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
𝑬𝒃 = Transmitted signal energy for bit
𝒏
The carrier frequency 𝒇𝒄 = 𝑻 for some fixed integer n
𝒃
BPSK Transmitter
𝟐
𝒄𝟏 (𝒕) = √ 𝒄𝒐𝒔𝟐𝝅𝒇𝒄 𝒕
𝑻𝒃
The input binary symbols are represented in polar form with symbols 1 & 0 represented
by constant amplitude levels √𝐸𝑏 & − √𝐸𝑏 This binary wave is multiplied by a
sinusoidal carrier in a product modulator. The result in a BSPK signal.
ASHUTOSH
20
BPSK Receiver:
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
1. PSK MODULATION
i) Generate carrier signal.
ii) Start FOR loop.
iii) Generate binary data, message signal in polar form.
iv) Generate PSK modulated signal.
v) Plot message signal and PSK modulated signal.
vi) End FOR loop.
vii) Plot the binary data and carrier.
2. PSK DEMODULATION
i) Start FOR loop.
ii) Perform correlation of PSK signal with carrier to get decision variable.
iii) Make decision to get demodulated binary data. If x>0, choose ‘1’ else
choose ‘0’.
iv) Plot the demodulated binary data.
MATLAB CODE
% 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));
ASHUTOSH
21
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
ASHUTOSH
22
Modal Graph
Result:
The program for PSK modulation and demodulation has been simulated in MATLAB and
necessary graphs are plotted.
ASHUTOSH
23
EXPERIMENT 6
(QUADRATURE PHASE SHIFT KEY)
AIM: To generate and demodulate quadrature phase shifted (QPSK) signal using
MATLAB.
Theory:
QPSK is also known as quaternary PSK, quadriphase PSK, 4-PSK, or 4-QAM. It is a phase
modulation technique that transmits two bits in four modulation states.
𝛑 𝟑𝛑 𝟓𝛑 𝟕𝛑
Phase of the carrier takes on one of four equally spaced values such as , , and .
𝟒 𝟒 𝟒 𝟒
𝟐𝑬 (𝟐𝒊−𝟏)𝝅
𝑺𝒊 (𝒕) = √ 𝑻 𝑪𝒐𝒔 [𝟐𝝅𝒇𝒄 𝒕 + ]; 𝟎≤𝒕≤𝑻
𝟒
0; Elsewhere
T = symbol duration
Each of the possible value of phase corresponds to a pair of bits called dibits.
𝟐𝑬 (𝟐𝒊−𝟏)𝝅 𝟐𝑬 (𝟐𝒊−𝟏)𝝅
𝑺𝒊 (𝒕) = √ 𝑻 𝑪𝒐𝒔 [ ] 𝑪𝒐𝒔(𝟐𝝅𝒇𝒄 𝒕) − √ 𝑻 𝑺𝒊𝒏 [ ] 𝑺𝒊𝒏(𝟐𝝅𝒇𝒄 𝒕); 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
𝟒 𝟒
0; Elsewhere
𝟐
𝒄𝟏 (𝒕) = √𝑻 𝑪𝒐𝒔(𝟐𝝅𝒇𝒄 𝒕), 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
𝟐
𝒄𝟐 (𝒕) = √𝑻 𝑺𝒊𝒏(𝟐𝝅𝒇𝒄 𝒕), 𝟎 ≤ 𝒕 ≤ 𝑻𝒃
3𝜋 𝐸 𝐸
00 −√ −√
4 2 2
ASHUTOSH
24
5𝜋 𝐸 𝐸
01 −√ √
4 2 2
7𝜋 𝐸 𝐸
11 √ √
4 2 2
The I/p binary sequence b(t) is represented in polar from with symbols 1 & 0
𝐸 𝐸
represented as +√ 2 𝑎𝑛𝑑 − √ 2 . This binary wave is demultiplexed into two separate
binary waves consisting of odd & even numbered i/p bits denoted by 𝑏1 (𝑡) & 𝑏2 (𝑡).
𝑏1 (𝑡) & 𝑏2 (𝑡) are used to modulate a pair of quadrature carrier. The result is two PSK
waves. These two binary PSK waves are added to produce the desired QPSK signal.
QPSK Receiver
QPSK receiver consists of a pair of correlators with common I/P & supplied with locally
generated signal 𝑐1 (𝑡) & 𝑐2 (𝑡). The correlator output, x1, & x2 are each compared with a
threshold of zero volts. If x1 > 0, decision is made in favour of symbol ‘1’ for upper
ASHUTOSH
25
channel and if x1 < 0, decision is made in favour of symbol 0. Parallely if x2 >0, decision
is made in favour of symbol 1 for lower channel & if x2 <0, decision is made in favour of
symbol 0. These two channels are combined in a multiplexer to get the original binary
output.
Algorithm
1. QPSK Modulation
i) Generate quadrature carriers.
ii) Start FOR loop.
iii) Generate binary data, message signal (bipolar form).
iv) Multiply carrier 1 with odd bits of message signal and carrier 2 with even
bits of message signal.
v) Perform addition of odd and even modulated signals to get the QPSK
modulated signal.
vi) Plot QPSK modulated signal.
vii) End FOR loop.
viii) Plot the binary data and carriers.
2. QPSK Demodulation
i) Start FOR loop.
ii) Perform correlation of QPSK modulated signal with quadrature carriers to
get two decision variables x1 and x2.
iii) Make decision on x1 and x2 and multiplex to get demodulated binary data.
If x1>0and x2>0, choose ‘11’. If x1>0 and x2<0, choose ‘10’. If x1<0 and x2>0,
choose ‘01. If x1<0 and x2<0, choose ‘00’.
iv) End FOR loop.
v) Plot demodulated data.
MATLAB CODE
% QPSK Modulation
clc;
clear all;
close all;
%GENERATE QUADRATURE CARRIER SIGNAL
Tb=1;t=0:(Tb/100):Tb;fc=1;
c1=sqrt(2/Tb)*cos(2*pi*fc*t);
c2=sqrt(2/Tb)*sin(2*pi*fc*t);
%generate message signal
N=8;m=rand(1,N);
t1=0;t2=Tb
for i=1:2:(N-1)
t=[t1:(Tb/100):t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=-1*ones(1,length(t));
end
ASHUTOSH
26
%odd bits modulated signal
odd_sig(i,:)=c1.*m_s;
if m(i+1)>0.5
m(i+1)=1;
m_s=ones(1,length(t));
else
m(i+1)=0;
m_s=-1*ones(1,length(t));
end
%even bits modulated signal
even_sig(i,:)=c2.*m_s;
%qpsk signal
qpsk=odd_sig+even_sig;
%Plot the QPSK modulated signal
subplot(3,2,4);plot(t,qpsk(i,:));
title('QPSK signal');xlabel('t---->');ylabel('s(t)');grid on; hold on;
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
hold off
%Plot the binary data bits and carrier signal
subplot(3,2,1);stem(m);
title('binary data bits');xlabel('n---->');ylabel('b(n)');grid on;
subplot(3,2,2);plot(t,c1);
title('carrier signal-1');xlabel('t---->');ylabel('c1(t)');grid on;
subplot(3,2,3);plot(t,c2);
title('carrier signal-2');xlabel('t---->');ylabel('c2(t)');grid on;
% QPSK Demodulation
t1=0;t2=Tb
for i=1:N-1
t=[t1:(Tb/100):t2]
%correlator
x1=sum(c1.*qpsk(i,:));
x2=sum(c2.*qpsk(i,:));
%decision device
if (x1>0&&x2>0)
demod(i)=1;
demod(i+1)=1;
elseif (x1>0&&x2<0)
demod(i)=1;
demod(i+1)=0;
elseif (x1<0&&x2<0)
demod(i)=0;
demod(i+1)=0;
elseif (x1<0&&x2>0)
demod(i)=0;
demod(i+1)=1;
end
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
subplot(3,2,5);stem(demod);
title('qpsk demodulated bits');xlabel('n---->');ylabel('b(n)');grid on;
ASHUTOSH
27
Modal Graph
Result: The program for QPSK modulation and demodulation has been simulated in
MATLAB and necessary graphs are plotted.
ASHUTOSH
28
EXPERIMENT 7
(DIFFERENTIAL PHASE SHIFT KEY)
AIM: To study modulation and Demodulation of DPSK signal using MATLAB.
Theory
DPSK Transmitter
A DPSK system may be viewed as the non-coherent version of the PSK. It eliminates the
need for coherent reference signal at the receiver by combining two basic operations at
the transmitter:
Hence the name differential phase shift keying [DPSK]. To send symbol ‘0’ we phase
advance the current signal waveform by 1800 and to send symbol ‘1’ we leave the phase
of the current signal waveform unchanged.
The differential encoding process at the transmitter input starts with an arbitrary first
but, securing as reference and thereafter the differentially encoded sequence {dk} is
generated by using the logical equation:
𝒅𝒌 = 𝒅𝒌−𝟏 𝒃𝒌 ̅̅̅̅̅̅
𝒅𝒌−𝟏 ̅𝒅̅̅𝒌̅
Where bk is the input binary digit at time kTb and dk-1 is the previous value of the
differentially encoded digit.
DPSK Receiver
The received signal is first passed through a BPF centred at carrier frequency fc to limit
noise power. The filter output and its delay version are applied to correlator the resulting
output of correlator is proportional to the cosine of the difference between the carrier
phase angles in the two correlator inputs. The correlator output is finally compared with
threshold of ‘0’ volts.
ASHUTOSH
29
ALGORITHM
MATLAB CODE
DPSK Modulation
clear all;
close all;
clc;
fc=1; % carrier frequency;
samp=1000;
t=linspace(0,2*pi,samp);
ph1=cos(fc*t);
ph2=-cos(fc*t);
b=[ 1 0 0 0 0 0 0 1 1 1 1 1 0 1 0 1];
x=0;
nb(1)=not(xor(b(1),0));
for i=2:length(b)+1
nb(i)=not(xor(b(i-1),x));
x=nb(i);
end;
dpsk=[];bin1=[];bin2=[];
for j=1:length(nb)
if nb(j)==0
dpsk=[dpsk,ph1];
bin1=[bin1,zeros(1,samp)];
elseif nb(j)==1
dpsk=[dpsk,ph2];
bin1=[bin1,ones(1,samp)];
end;%% end of if..
end;%% end of for
for k=1:length(b)
if b(k)==0
bin2=[bin2,zeros(1,samp)];
ASHUTOSH
30
elseif b(k)==1
bin2=[bin2,ones(1,samp)];
end;
end;
subplot(313),plot(bin2,'k','LineWidth',3');
axis([0 samp*length(b) -0.2 1.2]);
xlabel('Time index'); ylabel('Amplitude');
title('The Binary Output','FontSize',12);
subplot(312),plot(bin1,'k','LineWidth',3');
axis([0 samp*length(b) -0.2 1.2]);
xlabel('Time index'); ylabel('Amplitude');
title('The Binary (differential) Output','FontSize',12);
subplot(311),plot(dpsk,'k','LineWidth',3');
axis([0 samp*length(b) -1.2 1.2]);
xlabel('Time index'); ylabel('Amplitude');
title('The DPSK Input','FontSize',12);
DPSK Demodulation
%DPSK modulation
%With input information of 1 0 0 0 0 0 0 1 1 1 1 1 0 1 0 1
clear all;
close all;
clc;
fc=1; % carrier frequency;
samp=1000;
t=linspace(0,2*pi,samp);
ph1=cos(fc*t);
ph2=-cos(fc*t);
b=[ 1 0 0 0 0 0 0 1 1 1 1 1 0 1 0 1];
x=0;
nb(1)=not(xor(b(1),0));
for i=2:length(b)+1
nb(i)=not(xor(b(i-1),x));
x=nb(i);
end;
dpsk=[];bin1=[];bin2=[];
for j=1:length(nb)
if nb(j)==0
dpsk=[dpsk,ph1];
bin1=[bin1,zeros(1,samp)];
elseif nb(j)==1
dpsk=[dpsk,ph2];
bin1=[bin1,ones(1,samp)];
end;%% end of if..
end;%% end of for
for k=1:length(b)
if b(k)==0
bin2=[bin2,zeros(1,samp)];
elseif b(k)==1
bin2=[bin2,ones(1,samp)];
end;
end;
subplot(311),plot(bin2,'k','LineWidth',3');
axis([0 samp*length(b) -0.2 1.2]);
xlabel('Time index'); ylabel('Amplitude');
title('The Binary Input','FontSize',12);
bn=num2str(b);
bx=['The Binary string is ',bn];
gtext(bx,'FontSize',12);
ASHUTOSH
31
subplot(312),plot(bin1,'k','LineWidth',3');
axis([0 samp*length(b) -0.2 1.2]);
xlabel('Time index'); ylabel('Amplitude');
title('The Binary (differential) Input','FontSize',12);
bn=num2str(nb);
bx=['The Differential Binary string is ',bn];
gtext(bx,'FontSize',12);
subplot(313),plot(dpsk,'k','LineWidth',3');
axis([0 samp*length(b) -1.2 1.2]);
xlabel('Time index'); ylabel('Amplitude');
title('The Simulated DPSK output','FontSize',12);
MODAL GRAPH
ASHUTOSH
32
Fig (2): OUTPUT OF DPSK DEMODULATION
Result: The program for DPSK modulation and demodulation has been simulated in
MATLAB and necessary graphs are plotted.
ASHUTOSH
33