# QPSK modulation and Demodulation

(15 votes, average: 3.67 out of 5)

This post is a part of the ebook : Simulation of digital communication systems using Matlab – available in both PDF and EPUB format.

### QPSK Modulation:

In digital modulation techniques a set of basis functions are chosen for a particular modulation scheme.Generally the basis functions are orthogonal to each other. Basis functions can be derived using ‘Gram Schmidt orthogonalization’ procedure.Once the basis function are chosen, any vector in the signal space can be represented as a linear combination of the basis functions.

In Quadrature Phase Shift Keying (QPSK) two sinusoids (sin and cos) are taken as basis functions for modulation. Modulation is achieved by varying the phase of the basis functions depending on the message symbols. In QPSK, modulation is symbol based,where one symbol contains 2 bits. The following equation outlines QPSK modulation technique.

$$s_i(t)=\sqrt{\frac{2E_s}{T}}cos(2 \pi f_c t + (2n-1) \frac{\pi}{4})\;\; \mbox{,n=1,2,3,4}$$

When $$n=1$$, the phase shift is 45 degrees. This is called pi/4 QPSK.The constellation diagram of QPSK will show the constellation points lying on both x and y axes.This means that the QPSK modulated signal will have an in-phase component (I) and also a quadrature component (Q). This is because it has only two basis functions.

A QPSK modulator can be implemented as follows. A demultiplexer (or serial to parallel converter) is used to separate odd and even bits from the generated information bits. Each of the odd bits (quadrature arm) and even bits (in-phase arm) are converted to NRZ format in a parallel manner. The signal on the in-phase arm is multiplied by cosine component and the signal on the quadrature arm is multiplied by sine component. QPSK modulated signal is obtained by adding the signal from both in-phase and quadrature arm.

### QPSK Demodulation:

For QPSK demodulator , a coherent demodulator is taken as an example. In coherent detection technique the knowledge of the carrier frequency and phase must be known to the receiver. This can be achieved by using a PLL (phase lock loop) at the receiver. A PLL essentially locks to the incoming carrier frequency and tracks the variations in frequency and phase. For the following simulation , a PLL is not used but instead we simple use the output of the PLL. For demonstration purposes we simply assume that the carrier phase recovery is done and simply use the generated reference frequencies at the receiver (cos(ωt)) and (sin(ωt)).

In the demodulator the received signal is multiplied by a reference frequency generators (cos(ωt)) and (sin(ωt)) on separate arms (in-phase and quadrature arms). The multiplied output on each arm is integrated over one bit period using an integrator. A threshold detector makes a decision on each integrated bit based on a threshold. Finally the bits on the in-phase arm (even bits) and on the quadrature arm (odd bits) are remapped to form detected information stream. Detector for in-phase arm is shown below. For quadrature arm the below architecture remains same but sin(ωt) basis function must be used instead.

### File1: QPSK.m

Check this book for full Matlab code.
Simulation of Digital Communication Systems Using Matlab – by Mathuranathan Viswanathan

### File2: NRZ_Encoder.m

Check this book for full Matlab code.
Simulation of Digital Communication Systems Using Matlab – by Mathuranathan Viswanathan

The output of the Matlab code provides more insight into the QPSK modulation technique. Apart from plotting the modulated and demodulated signal it also shows the constellation at transmitter/receiver. This Matlab code is written without using any of the inbuilt functions from communication toolbox.

### Recommended Books

• http://www.blogger.com/profile/09715503862664753239 u’ll never know till u’ve tried

i found in other reference, the equation for qpsk :
s(t)=Acos(wt+(n-1)(phi/2)
it means, the diagram constellation placed syombol on 0, 90, 180, 270..
not 45,135,225,315

is there an effect for qpsk modulation with that differennce place of symbol?

• http://www.blogger.com/profile/14472055926898539663 mathuranathan

That is equation is for non-offset QPSK. PSK modulation has lot of variations like OQPSK (offset QPSK), pi/4-QPSK, DQPSK (differential QPSK),etc..,

In reality pi/4-QPSK modulation uses two constellations (dual constellations) which are shifted by 45* with respect to each other. Only either the odd or even symbol are allowed to select a point from one of the constellations while the other chooses the point from the other constellation.

This reduces the maximum phase shift from 180* to 135*. Reduction of maximum phase shift implies reduction of bandwidth and reduction of overshoot (minimized side lobes)

• http://www.blogger.com/profile/13821039279415178607 bahpullo

Hi Mathuranathan,

I am new to MATLAB and i need some help in generating MATLAB code for QPSK. I have tried to modify your code to produce the required result but no success. I need to generate/plot a polarised version of the bit stream “00 01 01 01 01 10 11 10” for input into a QPSK modulator (odd bits = 00 00 01 11; even bits =01 11 10 10). I also need a polarised version of the odd and even bits plotted. The odd and even bits are then multiplied by +/-(sqrt2) and then modulated by carriers cos(wt) and -sin(wt). The two modulated signals are then combined to produce QPSK. plots of the modulated odd bits, modulated even bits and the QPSK signals included. The carrier frequency is 1600Hz with two cycles of carrier during each symbol (baud rate =800 symbols per sec, symbol duration =1.25mS).

At the other end, a plot of the two demodulated signals and the instantaneous waveforms of the integrators.

• http://www.blogger.com/profile/02512606512802936366 Naveed

Hello sir,

I am trying to understand this program.I unable to understand what is the need for NRZ encoder.Can you explain me please….

• http://www.blogger.com/profile/14472055926898539663 mathuranathan

Hi Naveed,
Understand that the NRZ encoder converts 0’s and 1’s into -1 and +1 respectively. In any digital modulation technique, the user input interms of 0’s and 1’s has to be converted to -1’s and +1s, each bits with a definite bit duration. For this purpose, a NRZ encoder is used.

• http://www.blogger.com/profile/02595436239843936183 Unknown

hi
i think there is a small error in the line:
‘Modulation is achieved by varying the phase of the basis functions depending on the message symbols.’

instead of the word ‘phase’ in the above line, it should be amplitude of the basis functions depends on the message symbol. the linear combination of the basis functions in turn results in the output function whose phase depends on the message symbol.

• itsluser

I tried this code using unipolar and polar line coding. With polar coding, the reconstructed bit sequence was okay. but with unipolar coding, the reconstructed bit sequence always appeared same (all 1s) in almost all cases. Can anyone tell me the reason for this behaviour ?

• Mathuranathan

Hi can you paste your modified main program.. I will try it out and let you know …

• itsluser

I mean, in the program provided by you, I changed one of the input parameter in NRZEncoder function from polar to unipolar.

• Mathuranathan

Hi,
QPSK modulation is achieved using NRZ (polar) encoding method. If you use unipolar encoding the constellations in trasmitter and receiver will be different.
QPSK modulation has to be simulated with polar encoding. Simulating using unipolar, zeros out the sine/cos components. Because of that your bits are detected wrongly

In QPSK, the inphase component is multiplied by cos and quadrature component by sine. For polar encoding, inphase and quadrature phase components are either +1 and -1 . So there is no problem here.
But when you use unipolar encoding, the inphase or quadrature phase components take value 0 or 1. The value ‘0’ will nullify the corresponding cos or sine component and there is no way to recover from this error.

It is not recommended to use unipolar encoding for QPSK modulation as it defeats the basic architecture of the modulation itself.

Hope this helps.

• QPSK_passband

Hello Mathuranathan
I tried to get BER Vs Eb/N0 graph of passband QPSK modultion.
I chosed N = 1e6 samples of bits and used your code in a loop.
The result was that the BER was zero every time even if I had increased the noise varianc (I actually deceased the SNR).
How can I get the BER Vs Eb/N0 graph for passband ?

Hi I tried the program for QPSK modulation and demodulation …. but am getting an error consistently…

Error in ==> QPSK at 10

[evenTime,evenNrzData,Fs]=NRZ_Encoder(evenBits,Rb,amplitude,’Polar’);

What do I do for this… Is there something I need to do to prevent this error….

• http://www.gaussianwaves.com/ Mathuranathan

The ebook contains the function “NRZ_Encoder.m”. Please check page 191 in the PDF version. Just copy the code and save it as NRZ_Encoder.m in the same location as your current working directory.

• AMM

I just bought the ebook and copied the same code for the two m files. I got the same error message.

Undefined function or variable “output”.
Error in NRZ_Encoder (line 31)
output=[output amplitude*(-1)^(1+input(count))];
Error in QPSK_modulation_demodulation (line 10)
[evenTime,evenNrzData,Fs]=NRZ_Encoder(evenBits,Rb,amplitude,’Polar’);

• http://www.gaussianwaves.com/ Mathuranathan

Can you check whether the code in your file declares the following on line 11, just before the switch statement on line 12 as shown below?
line 11: output=[];

line 12: switch lower(style)

Hello Sir:

thank you for all this infromations.

i want to use the Square Root Raised Cosine encoder in place of NRZ Encoder for QPSK modulation.
my idea is used the ideal pulse and after that we using the the Square Root Raised Cosine filter.is this correct and i want to know what is the transfer function of this filter. if you can help me with this program.

• http://www.gaussianwaves.com/ Mathuranathan
• Shahab Shariat Bagheri

Actually, Just for checking a Theoretical important problem, Square Root Raised Cosine filter does not have a relation with your NRZ Stream, it’s just a pulse shaping of your NRZ Stream it means that you wanna send for example 1 -1 1 -1 -1 1 , … then the signal analogue that specifies to 1 will be 1 * Cosine filter and for -1 will be (-1)* Cosine wave, … which effectively depends on your sampling frquency of filter that you have choosen and the rol of factor of pulse,

So my solution for you is at first upsample of your NRZ data arbiary (4,8 or 16 , …) and then taking convolution of upsampled data and root raised cosine filter will have give simply the output that you need. and now it’s your ready signal to modulation.

Matlab code :
N = 10^4 ; % number of data
up = 4; % upsampling data
d = randsrc(1,N);

du = upsample (d,up);