# dpskdemod

Differential phase shift keying demodulation

## Syntax

`z = dpskdemod(y,M)z = dpskdemod(y,M,phaserot)z = dpskdemod(y,M,phaserot,symbol_order)`

## Description

`z = dpskdemod(y,M)` demodulates the complex envelope `y` of a DPSK modulated signal. `M` is the alphabet size and must be an integer. If `y` is a matrix with multiple rows and columns, the function processes the columns independently.

 Note:   An initial phase rotation of 0 is used in determining the first element of the output `z`, or the first row of `z`, if `z` is a matrix with multiple rows, because the differential algorithm compares two successive elements of the modulated signal.

`z = dpskdemod(y,M,phaserot)` specifies the phase rotation of the modulation in radians. In this case, the total phase shift per symbol is the sum of `phaserot` and the phase generated by the differential modulation.

`z = dpskdemod(y,M,phaserot,symbol_order)` specifies how the function assigns binary words to corresponding integers. If `symbol_order` is set to `'bin'` (default), the function uses a natural binary-coded ordering. If `symbol_order` is set to `'gray'`, it uses a Gray-coded ordering.

## Examples

collapse all

### DPSK Demodulation

This example shows how to demodulate DPSK data in a communication channel in which a phase shift is introduced.

Set the random number generator to the default state for repeatability.

```rng default ```

Generate a 4-ary data vector and modulate using DPSK.

```M = 4; % Alphabet size dataIn = randi([0 M-1],1000,1); % Random message txSig = dpskmod(dataIn,M); % Modulate ```

Apply the random phase shift resulting from the transmission process.

```rxSig = txSig*exp(2i*pi*rand()); ```

```dataOut = dpskdemod(rxSig,M); ```

As the modulator and demodulator have the same initial condition while only the received signal experiences a phase shift, the first demodulated symbol is likely to be in error. Because of this, you should always discard the first symbol when using DPSK.

Find the number of symbol errors.

```errs = symerr(dataIn,dataOut) ```
```errs = 1 ```

Observe that there is one symbol in error. Repeat the error calculation after discarding the first symbol.

```errs = symerr(dataIn(2:end),dataIn(2:end)) ```
```errs = 0 ```

Get trial now