This section describes a Simulink^{®} model of a communications system and is intended to
familiarize you with the basic functionality of Simulink models.. The model displays a scatter plot of a signal
with added noise and performs error rate computations.

To open the model, first start MATLAB^{®}. In the MATLAB Command Window, enter `doc_commphasenoise`

at the
prompt. This opens the model shown here in a new window.

The `doc_commphasenoise`

model,
simulates the effect of phase noise on quadrature amplitude
modulation (QAM) of a signal. The Simulink model is a graphical representation of a mathematical
model of a communication system that generates a random signal,
modulates it using QAM, and adds noise to simulate a channel. The
model also contains components for displaying the symbol error rate
and a scatter plot of the modulated signal.

The blocks and lines in the Simulink model describe mathematical relationships among signals and states.

The Bernoulli Binary Generator block, labeled

*Bernoulli Binary*, generates a signal consisting of a sequence of 8-bit binary values between zero and 255The Rectangular QAM Modulator Baseband block, to the right of the Bernoulli Binary Generator block, modulates the signal using baseband 256-ary QAM.

The AWGN Channel block models a noisy channel by adding white Gaussian noise to the modulated signal.

The Phase Noise block introduces noise in the angle of its complex input signal.

The Rectangular QAM Demodulator Baseband block, to the right of the Phase Noise block, demodulates the signal.

Additional blocks in the model help you interpret the simulation.

The Constellation Diagram block, labeled AWGN plus Phase Noise, displays a scatter plot of the signal with added noise.

The Error Rate Calculation block counts symbols that differ between the received signal and the transmitted signal.

The To Workspace block, labeled

*outputBER*outputs the results to the workspace to use when plotting results.The Display Figure block, at the far right of the model window, displays the bit error rate (BER), the total number of errors, and the total number of symbols processed during the simulation.

All these blocks are included in Communications
Toolbox™. You can find more detailed information about these
blocks by right-clicking the block and selecting
**Help** from the context
menu.

This model simulates quadrature amplitude modulation (QAM), which is a
method for converting a digital signal to a complex signal. The
model modulates the signal onto a sequence of complex numbers that
lie on a lattice of points in the complex plane, called the
*constellation* of the signal. The
constellation for baseband 256-ary QAM with is shown in the
following figure.

**Constellation for 256-ary QAM**

To run a simulation, click on the **Run**
button at the top of the model window. The run duration is set to
`inf`

, which is specified by **Stop
time** in the **Configuration
Parameters** dialog box. The simulation is
configured in the Error Rate Calculation block to run
until 100 bit errors occur. You can stop the simulation at any time
by selecting **Stop** from the
**Simulation** menu at the top of the
model window or by clicking the **Stop** button on
the toolstrip.

When you run the model, a new window appears, displaying a scatter plot of the modulated signal with added noise. For a high EbN0 setting, the phase noise impairment is apparent as shown in this figure.

**Scatter Plot of Signal Plus Noise**

The points in the scatter plot do not lie exactly on the constellation shown in the figure because of the added noise. The radial displacement of points is due to the addition of phase noise, which alters the angle of the complex modulated signal.

The Display block displays the number of errors introduced by the channel noise. When you run the simulation, three small boxes appear in the block, as shown in the following figure, displaying the vector output from the Error Rate Calculation block.

The image below is a representative example and may not exactly match results you see when running in Simulink.

The block displays the output as follows:

The first entry is the bit error rate (BER).

The second entry is the total number of errors.

The third entry is the total number of comparisons made. The notation

`8.92e+005`

is shorthand for 8.92×10^{5}.

You can control the way a Simulink block functions by setting its
parameters. To view or change a block's parameters, double-click the
block. This opens a dialog box, sometimes called the block's
*mask*. For example, the dialog box for
the Phase Noise block is shown in the following figure.

**Dialog for the Phase Noise Block**

To change the amount of phase noise, click in the **Phase
noise level (dBc/Hz)** field and enter a new value.
Then click **OK**.

Alternatively, you can enter a variable name, such as
`phasenoise`

, in the field. You can then
set a value for that variable in the MATLAB Command Window, for
example by entering `phasenoise = -60`

. Setting
parameters in the Command Window is convenient if you need to run
multiple simulations with different parameter values.

You can also change the amount of noise in the AWGN Channel block.
Double-click the block to open its dialog box, and change the value
in the **Eb/No** parameter field. This changes the
signal to noise ratio, in dB. Decreasing the value of
**Eb/No** increases the noise level.

You can also use callback functions to configure your simulation. The
default setting for several parameters in this model are set using
the *PreLoadFcn* callback function. To access the
callback functions under **File**, open
**Model Properties**, then select the
**Callbacks** tab.

For more information on **Model Properties** and
callback functions, see Model Callbacks (Simulink).

You can experiment with the model by changing these or other parameters and then running a simulation. For example,

Change

**Phase noise level (dBc/Hz)**to`-150`

in the dialog box for the Phase Noise block.Change

**Eb/No**to`100`

in the dialog for the AWGN Channel block.

The default setting for simulation duration is `inf`

with the Error Rate
Calculation is set to stop when 100 errors have
occurred. By reducing the phase noise and increasing the
**Eb/No**, nearly all noise is removed from
the model. This will mean the simulation may need to run for a long
time before 100 errors occur. So, before running the model with
nearly no noise, you may want to change the run duration from
*inf* to a smaller value, such as
`10`

. When you now run a simulation, the
scatter plot appears as in the figure Constellation for 256-ary QAM.

To display a figure that plots simulation results of BER vs EbNo curves for a range of phase noise settings, double-click the Display Figureblock at the bottom left of the model window.

**BER Plot at Different Noise Levels**

Each curve is a plot of bit error rate as a function of signal to noise ratio for a fixed amount of phase noise.

You can create plots like this by running multiple simulations with
different values for the **Phase noise level
(dBc/Hz)** and **Eb/No**
parameters. To generate the plot shown in this example, run this
code. Since random numbers are generated when running the
simulation, your results may not exactly match the results shown
here.

%% Plot 256QAM BER vs EbN0dB % Helper script to generate EbN0 vs. BER curves plotting phase % noise performance of 256 QAM for a frequency offset of 1000 Hz. % This script generates the 'Display Figure' for the doc_commphasenoise model. clear; open_system('doc_commphasenoise'); %% % Set the frequency offset to 1000 Hz in the Phase Noise block and % number of bits per symbol to 8 thoughout the model. freqOffset = 1000; Nbps = 8; % Define EbNo and phase noise ranges for simulation and plotting. EbNoRng=(20:0.5:23); PhNoiseRng=-88:3:-76; % Specify the target number of bit errors. tgtMaxErr = 200; %% % Sweep phase noise and EbNo ranges to generate results, then plot. ber = zeros(length(PhNoiseRng),length(EbNoRng)); for ip=1:length(PhNoiseRng) phaseNoise = PhNoiseRng(ip); for ies=1:length(EbNoRng) EbN0 = EbNoRng(ies); sim('doc_commphasenoise') ber(ip,ies) = outputBER(1); end end semilogy(EbNoRng,ber,'*-'); axis([EbNoRng(1) EbNoRng(end) 1e-6 1e-2]) xlabel('EbNo in dB') ylabel('BER') legend([num2str(PhNoiseRng(:)) repmat(' dBc/Hz',[length(PhNoiseRng),1])],'Location','southwest') title(['Performance of 256-QAM for Frequency Offset of ' num2str(freqOffset) ' Hz']) hold off grid on