Digital Carrier Modulation with MATLAB and SIMULINK A) OBJECTIVES . To understand digital carrier modulation such as ASK, FSK and PSK and QAM. . To use MATLAB to: - Create ASK, PSK, FSK and 16 QAM signals by modulating a binary bit stream on a carrier. - Examine the modulated signals in the time domain. . To illustrate M−ary modulation blocks using SIMULINK.

B) SOFTWARE REQUIRED . MATLAB version 5.3 or higher . MATLAB Simulink version 5.0 or higher with Communications Blockset library

C) THEORY OF DIGITAL CARRIER MODULATION Baseband digital signals are suitable for transmission over a pair of wires or coaxial cables due to its sizable power at low frequencies. These signals cannot be transmitted over a radio link because this would require impractically large antennas to efficiently radiate the low-frequency spectrum of the signal. Hence, for such purposes, we use analog modulation techniques in which the digital signal messages are used to modulate a high-frequency continuous-wave (CW) carrier.

In binary modulation schemes, the modulation process corresponds to switching (or keying) the amplitude, frequency or phase of the CW carrier between either of two values corresponding to binary symbols “0” or “1”. The three types of digital modulation are amplitude-shift keying (ASK), frequency-shift keying (FSK) and phase-shift keying (PSK).

Amplitude-Shift Keying (ASK)

In ASK, the amplitude of the carrier assumes one of the two amplitudes dependent on the logic states of the input bit stream. This modulated signal can be expressed as: 0 symbol "0" (1) xc (t)   Acosct symbol "1"

Note that the modulated signal is still an on-off signal.

Frequency-Shift Keying (FSK)

In FSK, the frequency of the carrier is changed to two different frequencies depending on the logic state of the input bit stream. Usually, a logic high causes the centre frequency to increase to a maximum and a logic low causes the centre frequency to decrease to minimum. The modulated signal can be expressed as:

Acos1t symbol "0" (2) xc (t)   Acos 2t symbol "1"

Page 1 of 12 Phase-Shift Keying (PSK)

In PSK, the phase of the carrier changes between different phases determined by the logic states of the input bit stream. In two-phase shift keying, the carrier assumes one of the two phases. A logic “1” produces no phase change and a logic “0” produces a 1800 phase changes This modulated signal can be expressed as:

A cos(c t  ) symbol "0" (3) xc (t)   A cosc t symbol "1" Figure 1 illustrates the above digital modulation schemes for the case in which the data bits are represented by the polar NRZ waveform.

Figure 1− Digital Carrier Modulation

Four Phase-Shift Keying (PSK) In 4PSK or QPSK, 2 bits are processed to produce a single-phase change. In this case, each symbol consists of 2 bits. The actual phases that are produced by a 4PSK modulated signal are shown in Table 1: Bits Phase 00 450 01 1350 10 3150 11 2250

Table 1 − Bits and Phases for 4PSK or QPSK modulation From Table 1, a signal space diagram or signal constellation can be drawn as shown in Figure 2. Note that from any two closest bits sequences, there is only one bit change. This is called Gray Coded scheme. For example, bit sequence “00” has one bit change for its closest bit sequences “01” and “10”.

Page 2 of 12 /2

01 00

 0

11 10

3/2

Figure 2 − 4PSK or QPSK Constellation

Eight Phase-Shift Keying (PSK)

In this modulation, 3 bits are processed to produce a single-phase change. This means that each symbol consists of 3 bits. Figure 3 shows the constellation and mapping of the 3-bit sequences onto appropriate phase angles. /2

010 000

011 001

 0 111 101

110 100

3/2 Figure 3 − 8PSK Constellation

High Order Phase Shift Keying modulation

Modulation schemes like 16 PSK, 32 PSK and higher orders can be also be designed and represented on a signal space diagram.

Quadrature Amplitude Modulation (QAM)

QAM is a method for sending two separate (and uniquely different) channels of information. The carrier is shifted to create two carriers namely the sine and cosine versions. The outputs of both modulators are algebraically summed, the results of which is a single signal to be transmitted, containing the In-phase (I) and Quadrature-phase (Q) information. The set of possible combinations of amplitudes, as shown on an x-y plot, is a pattern of dots known as a QAM constellation as shown in Figure 4.

Page 3 of 12 Quadrature-phase I value

A Q value  In-phase

Figure 4 − IQ Constellation (Diagram)

Consider the 16 QAM modulation schemes, in which 4 bits are processed to produce a single vector. The resultant constellation consists of four different amplitude distributed in 12 different phases as shown in Figure 5. CD Quadrant 2 Quadrant 1

0111 3V 1011 0011 1111

2V 0110 1010 0010 1110 1V AB AB

−3V −2V −1V 1V 2V 3V 1101 0001 0101 1001 −2V 0000 1100 0100 −3V 1000

Quadrant 3 Quadrant 4 CD

Figure 5 − 16 QAM Constellation

D) MATLAB and SIMULINK

MATLAB is an interactive matrix based system for scientific and engineering numeric computation and visualization. Its strength lies in the fact that complex numerical problem can be solved easily and in a fraction of the time required with a programming language such as Fortran or C. It is also powerful in the sense that by using its relatively simple programming capabilities, MATLAB can be easily extended to create new commands and functions.

SIMULINK is a software package in MATLAB used for modelling, simulating, and analyzing dynamical systems. It supports linear and nonlinear systems, modelled in continuous time, sampled time, or a hybrid of the

Page 4 of 12 two. Systems can also be multirate that has different parts that are sampled or updated at different rates. For modeling, SIMULINK provides a graphical user interface (GUI) for building models as block diagrams, using click-and-drag mouse operations. With this interface, you can draw the models just as you would with pencil and paper (or as most textbooks depict them). It also includes a comprehensive block library of sinks, sources, linear and nonlinear components, and connectors.

Models are hierarchical, so you can build models using both top-down and bottom-up approaches. You can view the system at a high level, then double-click on blocks to go down through the levels to see increasing levels of model detail. This approach provides insight into how a model is organized and how its parts interact. After you define a model, you can simulate it, using a choice of integration methods, either from the SIMULINK menus or by entering commands in MATLAB's command window. The menus are particularly convenient for interactive work, while the command-line approach is very useful for running a batch of simulations. Using scopes and other display blocks, you can see the simulation results while the simulation is running. In addition, you can change parameters and immediately see what happens, for "what if" exploration. The simulation results can be put in the MATLAB workspace for post-processing and visualization. Model analysis tools include linearization and trimming tools, which can be accessed from the MATLAB command line, plus the many tools in MATLAB and its application toolboxes.

All digital modulation blocks process only discrete-time signals. The data types of inputs and outputs are depicted in the figure below:

Figure 6 − Representing Signals for Digital Modulation in Simulink

E) EXPERIMENT PROCEDURES – MATLAB

1. Open and start the MATLAB program by double-clicking the MATLAB icon.

2. Type the command in the MATLAB COMMAND WINDOW or create a script file in the MATLAB EDITOR.

3. Analyze the following function for creating the ASK modulated signal: function bask(b,f) % b is the input binary bit stream % f is the frequency of the carrier n = length(b); % determine the length of bit stream t = 0:.01:n; % time axis x = 1:1:(n+1)*100; for i = 1:n for j = i:.1:i+1 bw(x(i*100:(i+1)*100)) = b(i); % loop end end bw = bw(100:end); % binary bit stream

Page 5 of 12 carrier = cos(2*pi*f*t); % carrier signal modulated = bw.*carrier; % modulated signal subplot(3,1,1) plot(t,bw) grid on ; axis([0 n -2 +2]) subplot(3,1,2) plot(t,carrier) grid on ; axis([0 n -2 +2]) subplot(3,1,3) plot(t,modulated) grid on ; axis([0 n -2 +2])

Next, plot the time domain for an ASK modulated signal with a carrier signal of s1(t) = cos (10t) and an unipolar NRZ binary bit stream m1(t) as shown below,

m (t) 1 Binary code 1 0 1 0 1

1V

0V 1 2 3 4 5 t/s

4. Create a new function by modifying the function bask in order to plot the time domain for a FSK modulated

signal with the following polar NRZ bit stream m2(t) as shown below,

m (t) 2 Binary code 1 0 1 0 1

+1V

−1V 1 2 3 4 5 t/s

Assume the following for the FSK modulated signal: cos(10t  5t) symbol "0" xc (t)   cos(10t  5t) symbol "1"

where the carrier frequency, c = 10t and frequency deviation, = 5t.

5. Repeat procedure (4) with the same polar NRZ bit stream in order to create a new function for plotting the PSK time domain with the following expression:

Page 6 of 12 Acos(10t   ) symbol "0" xc (t)   Acos(10t) symbol "1"

6. Consider the following 16 QAM transmission through an Additive White Gaussian Noise (AWGN) channel.

Random Bit Symbol 16 QAM 16 QAM Generator Mapping Modulator AWGN Demodulator

The randint function is use to generate the random binary data stream by creating a column vector that lists the successive values of a binary data stream. Set the length of the binary data stream to 1,000. The code below creates a stem plot of a portion of the data stream, showing the binary values.

%% Definition % Random binary bit stream generation. Fd=1; Fs=1; % Input and output message sampling frequency. nsamp=1; % Oversampling rate. M = 16; % Size of signal constellation. k = log2(M); % Number of bits per symbol. n = 8e4; % Number of bits to process. x = randint(n,1); % Random binary data stream

% Plot the first 20 bits in a stem plot. stem(x(1:20),'filled'); title('Random Bits'); xlabel('Bit Index'); ylabel('Binary Value');

Next, use the following script to convert the random generated bit stream into symbol. In this script, each 4- tuple of values from x is arranged across a row of a matrix, using the reshape function in MATLAB, and then the bi2de function is applied to convert each 4-tuple to a corresponding integer. (The .' characters after the reshape command form the unconjugated array transpose operator in MATLAB.)

%% Bit-to-Symbol Mapping % Convert the bits in x into k-bit symbols. xsym = bi2de(reshape(x,k,length(x)/k).'); % Plot the first 10 symbols in a stem plot. figure; % Create new figure window. stem(xsym(1:10)); title('Random Symbols'); xlabel('Symbol Index'); ylabel('Integer Value');

The dmodce function implements a 16 QAM modulator. xsym from above is a column vector containing integers between 0 and 15. The dmodce function can now be used to modulate xsym using the baseband representation. Note that M is 16, the alphabet size. The result is a complex column vector whose values are in the 16-point QAM signal constellation.

%% Modulation % Modulate using 16-QAM. y = dmodce(xsym,Fd,Fs, 'qask',M);

Page 7 of 12 Next, we add white Gaussian noise to the modulated signal. The ratio of bit energy to noise power spectral density, Eb/N0, is arbitrarily set at 10 dB. The expression to convert this value to the corresponding signal- to-noise ratio (SNR) involves k, the number of bits per symbol (which is 4 for 16-QAM), and nsamp, the oversampling factor (which is 1 in this example). The factor k is used to convert Eb/N0 to an equivalent Es/N0, which is the ratio of symbol energy to noise power spectral density. The factor nsamp is used to convert Es/N0 in the symbol rate bandwidth to an SNR in the sampling bandwidth.

%% Transmitted Signal ytx = y; %% Channel % Send signal over an AWGN channel. EbNo = 10; % In dB snr = EbNo + 10*log10(k) - 10*log10(nsamp); Pinput = std(ytx); noise = (randn(1,n/k)+sqrt(-1)*randn(1,n/k))*(1/sqrt(2)); Noisestd = (pinput*10^(-snr/20)); Ynoisy = ytx + (NoiseStd*noise).’; %% Received Signal yrx = ynoisy;

Then, generate the scatter plot of the transmitted and received signals. This shows how the signal constellation looks like and how the noise distorts the signal. In the plot, the horizontal axis is the In-phase (I) component of the signal and the vertical axis is the Quadrature (Q) component. The code below also uses the title, legend, and axis functions in MATLAB to customize the plot.

%% Scatter Plot % Create scatter plot of noisy signal and transmitted signal on % the same axes. figure; plot(real(yrx(1:5e3)),imag(yrx(1:5e3)),’b*’); hold on; plot(real(ytx(1:5e3)),imag(yrx(1:5e3)),’g.’); title(‘Received Signal’); legend(‘Received Signal’,’Signal Constellation’); axis([-5 5 -5 5]); % Set axis ranges. hold off;

Demodulation of the received 16-QAM signal is done by using the ddemodce function. The result is a column vector containing integers between 0 and 15.

%% Demodulation % Demodulate signal using 16-QAM. zsym = ddemodce(yrx,Fd,Fs, 'qask', M);

The previous step produced zsym, a vector of integers. To obtain an equivalent binary signal, use the de2bi function to convert each integer to a corresponding binary 4-tuple along a row of a matrix. Then use the reshape function to arrange all the bits in a single column vector rather than a four-column matrix.

%% Symbol-to-Bit Mapping % Undo the bit-to-symbol mapping performed earlier. z = de2bi(zsym); % Convert integers to bits. % Convert z from a matrix to a vector. z = reshape(z.',prod(size(z)),1); The biterr function is now applied to the original binary vector and to the binary vector from the demodulation step above. This yields the number of bit errors and the bit error rate. Page 8 of 12 %% BER Computation % Compare x and z to obtain the number of errors and % the bit error rate. [number_of_errors,bit_error_rate] = biterr(x,z)

7. Modify the following parameters Fd, Fs and Eb/No in the simulation:  Fd = Fs = 2; Eb/No = 20  Fd = Fs = 5; Eb/No = 40  Fd = Fs = 10; Eb/No = 60

Compute the Bit Error Rates (BER) and comments on all the BER results obtained. Explain why there are differences in the BER.

F) REFERENCES [1] Hwei P. Hsu, “Schaum's Series of Analog & Digital Communications”, 2nd Edition, McGraw Hill International Series, 2001 [2] S. Haykin, “Digital Communications”, John Wiley & Sons, 2001 [3] The MathWorks, Inc.: www.mathworks.com

APPENDIX: SIMULINK for MATLAB 7 (for reference only)

EXPERIMENT PROCEDURES

1. Type simulink at the MATLAB COMMAND prompt. * The Simulink Library Browser window is opened.

2. Create a new model window by clicking the Create a new model button on the Library Browser toolbar or click File >> New >> Model. * A new empty workspace window is opened.

3. Double-click to expand the Simulink folder at the Library Browser window.

4. Go to Communications Blockset -> Comm Sources -> Random Data Sources sub-folder. Drag and drop Random Integer Generator module into the workspace window. Double-click this module and make the following settings:  M−ary number to 16  Initial seed to 37  Sample time to 0.1  Ouput Data Type to double

5. Go to Communications Blockset -> Modulation -> Digital Baseband Modulation -> AM sub-folder. Drag and drop Rectangular QAM Modulator Baseband module into the workspace window. Double- click this module and make the following settings:  M−ary number to 16  Input type to Integer  Constellation ordering to Binary  Normalization method to Peak Power  Peak power (watts): to 1  Phase offset (rad) to 0  Output Data Type to double

Page 9 of 12 6. Go to Communications Blockset -> Channels sub-folder. Drag and drop AWGN Channel Baseband module into the workspace window. Double-click this module and make the following settings:  Initial seed to 37  Mode to Signal-to-noise ratio (Eb/No)  Eb/No (dB) to 10  Number of bits per symbol to 4  Input signal power (watts): to 1  Symbol period to 0.1

7. Go to Communications Blockset -> Modulation -> Digital Baseband Modulation -> AM sub-folder. Drag and drop Rectangular QAM Demodulator Baseband module into the workspace window. Double- click this module and make the following settings:  M−ary number to 16  Output type to Integer  Constellation ordering to Binary  Normalization method to Peak Power  Peak power (watts): to 1  Phase offset (rad) to 0  Output Data Type to double

8. Go to Communications Blockset -> Comm Sinks sub-folder. Drag and drop Error Rate Calculation module into the workspace window. Double-click this module and make the following settings:  Receive delay to 0  Computation delay to 1  Computation mode to Entire frame  Output data to Port

9. Go to Simulink -> Sinks sub-folder. Drag and drop the Display module into the workspace window. Drag the bottom edge of this inserted (Display module) icon to make the display big enough for three entries.

10. Go to Communications Blockset -> Comm Sinks sub-folder. Drag and drop TWO Discrete-Time Eye and Scatter Diagram modules into the workspace window. Double-click these TWO module and make the following settings:  Trace period to 0.1  Decision point to 0.07  Sample per symbol to 1

11. Go to Simulink -> Math Operations sub-folder. Drag and drop TWO Complex to Real−Imag modules into the workspace window.

12. Go to Simulink -> Sinks sub-folder. Drag and drop TWO XY Graph modules into the workspace window.

13. Go to Simulink -> Sinks sub-folder. Drag and drop TWO Scope modules into the workspace window.

14. Go to Simulink Extra -> Additional Sinks sub-folder. Drag and drop TWO Power Spectral Density modules into the workspace window.

15. Connect all the inserted modules as shown in Figure 7.

Page 10 of 12 Figure 7 – Simulink model for 16 QAM transmission

Page 11 of 12 16. Set the simulation parameters (Simulation >> Parameters) as follows:

17. Save your file as recqam.mdl by clicking File >> Save As.

18. Run (Simulation >> Start) the simulation and observe all plots and BER display.

Page 12 of 12