Documentation Center

  • Trial Software
  • Product Updates

QPSK Transmitter and Receiver



This example describes the MATLAB implementation of the QPSK transceiver.

MATLAB script using System objects: commQPSKTransmitterReceiver.mcommQPSKTransmitterReceiver.m.

For a Simulink® implementation using blocks, check: commqpsktxrx.mdlcommqpsktxrx.mdl.


The transmitted QPSK data undergoes impairments that simulate the effects of wireless transmission such as addition of Additive White Gaussian Noise (AWGN), introduction of carrier frequency and phase offset, and timing delay. To cope with these impairments, this example provides a reference design of a practical digital receiver. The receiver includes FFT-based coarse frequency compensation, PLL-based fine frequency compensation, timing recovery with fixed-rate resampling and bit stuffing/skipping, frame synchronization, and phase ambiguity resolution.

This example serves three main purposes:





The commqpsktxrx_init.mcommqpsktxrx_init.m script initializes simulation parameters and generates the structure prmQPSKTxRx.

prmQPSKTxRx = commqpsktxrx_init % QPSK system parameters

useScopes = true; % true if scopes are to be used
compileIt = false; % true if code is to be compiled
useCodegen = false; % true to run the generated mex file
prmQPSKTxRx = 

                                M: 4
                       Upsampling: 4
                     Downsampling: 2
                               Fs: 200000
                               Ts: 5.0000e-06
                        FrameSize: 100
                     BarkerLength: 13
                       DataLength: 174
                    ScramblerBase: 2
              ScramblerPolynomial: [1 1 1 0 1]
       ScramblerInitialConditions: [0 0 0 0]
                             sBit: [17400x1 double]
                 RxBufferedFrames: 10
           PhaseErrorDetectorGain: 2.0000
                PhaseRecoveryGain: 1
          TimingErrorDetectorGain: 5.4000
               TimingRecoveryGain: -1
           RaisedCosineFilterSpan: 10
                    MessageLength: 105
                       FrameCount: 100
                      PhaseOffset: 47
                             EbNo: 13
                  FrequencyOffset: 5000
                        DelayType: 'Triangle'
       CoarseFrequencyCompFFTSize: 2048
       PhaseRecoveryLoopBandwidth: 0.0100
       PhaseRecoveryDampingFactor: 1
      TimingRecoveryLoopBandwidth: 0.0100
      TimingRecoveryDampingFactor: 1
                          Rolloff: 0.5000
    TransmitterFilterCoefficients: [1x41 double]
       ReceiverFilterCoefficients: [1x41 double]

Code Architecture for the System Under Test







Description of the Individual Components






This component regenerates the original transmitted message. It is divided into five subcomponents, modeled using System objects. Each subcomponent is modeled by other subcomponents using System objects.

1) Automatic Gain Control: Ensures that the amplitude of the input of the Coarse Frequency Compensation subsystem is 1/Upsampling Factor , so that the equivalent gains of the phase and timing error detectors keep constant over time. The AGC is placed before the Raised Cosine Receive Filter so that the signal amplitude can be measured with an oversampling factor of four. This process improves the accuracy of the estimate.

2) Coarse frequency compensation: Uses nonlinearity and a Fast Fourier Transform (FFT) to roughly estimate the frequency offset and then compensate for it. The subsystem raises the input signal to the power of four to obtain a signal that is not a function of the QPSK modulation. Then it performs an FFT on the modulation-independent signal to estimate the tone at four times the frequency offset. After dividing the estimate by four, the Phase/Frequency Offset System object corrects the frequency offset.

3) Fine frequency compensation: Performs closed-loop scalar processing and compensates for the frequency offset accurately. The Fine Frequency Compensation subsystem implements a phase-locked loop (PLL) to track the residual frequency offset and the phase offset in the input signal. For more information, see Chapter 7 of [ 1 ]. The PLL uses a Direct Digital Synthesizer (DDS) to generate the compensating phase that offsets the residual frequency and phase offsets. The phase offset estimate from DDS is the integral of the phase error output of the Loop Filter. To obtain details of PLL design, refer to Appendix C.2 of [ 1 ].

4) Timing recovery: Performs timing recovery with closed-loop scalar processing to overcome the effects of delay introduced by the channel. The Timing Recovery subsystem implements a PLL, described in Chapter 8 of [ 1 ], to correct the timing error in the received signal. The NCO Control subsystem implements a decrementing modulo-1 counter described in Chapter 8.4.3 of [ 1 ] to generate the control signal for the Modified Buffer to select the interpolants of the Interpolation Filter. This control signal also enables the Timing Error Detector (TED), so that it calculates the timing errors at the correct timing instants. The NCO Control subsystem updates the timing difference for the Interpolation Filter , generating interpolants at optimum sampling instants. The Interpolation Filter is a Farrow parabolic filter with alpha set o 0.5 as described in Chapter 8.4.2 of [ 1 ]. Based on the interpolants, timing errors are generated by a zero-crossing Timing Error Detector as described in Chapter 8.4.1 of [ 1 ], filtered by a tunable proportional-plus-integral Loop Filter as described in Appendix C.2 of [ 1 ], and fed into the NCO Control for a timing difference update. The Loop Bandwidth (normalized by the sample rate) and Loop Damping Factor are tunable for the Loop Filter. The default normalized loop bandwidth is set to 0.01 and the default damping factor is set to 1 for critical damping. These settings ensure that the PLL quickly locks to the correct timing while introducing little phase noise.

5) Data decoder: Uses a Barker code to perform frame synchronization, phase ambiguity resolution, and demodulation. Also, the data decoder compares the regenerated message with the transmitted one and calculates the BER.


This component provides optional visualization by plotting the following diagrams:

  • a time scope showing the normalized time delay,


  • constellation diagrams showing the received signal after receiver filtering, and then after carrier phase and symbol timing recovery.


System Under Test



for count = 1:prmQPSKTxRx.FrameCount
    transmittedSignal = step(hTx);
    corruptSignal = step(hChan, transmittedSignal, count);
    if useScopes
        stepQPSKScopes(hScopes,RCRxSignal,coarseCompBuffer, timingRecBuffer);

Execution and Results


1) Scatter plot of the Raised Cosine Receive Filter output.

2) Power spectrum of the Raised Cosine Receive Filter output.

3) Scatter plot at the output of the Fine Frequency Compensation subcomponent.

4) Estimated (fractional) timing difference at the output of the Timing Recovery subcomponent.

if compileIt
if useCodegen
   BER = runQPSKSystemUnderTest_mex(prmQPSKTxRx, useScopes, printReceivedData);
   BER = runQPSKSystemUnderTest(prmQPSKTxRx, useScopes, printReceivedData);
Error rate = 0.006025.
Number of detected errors = 62.
Total number of compared samples = 10290.

Alternate Execution Options






This example utilizes several System objects to simulate digital communication over an AWGN channel. It shows how to model several parts of the QPSK system such as modulation, frequency and phase recovery, timing recovery, and frame synchronization. It measures the system performance by obtaining BER with the error rate measurement System object. It also shows that the generated C code runs several times faster than the original MATLAB code.


This example uses the following script and helper functions:



Was this topic helpful?