2.7 M-PAM: A Concrete Example of Digital Modulation
Pulse amplitude modulation (PAM) is the generic term adopted for a set of techniques that allow to transport information via the amplitude of a waveform. For example, in analog PAM systems, an analog waveform carrying information in its amplitude is multiplied by a periodic pulse train. In this text, the emphasis is on digital -ary PAM systems, which for simplicity are called PAM systems hereafter.
Figure 2.4 shows an example of an -PAM signal with symbols composing the set . For each symbol interval , which in this case is s, the amplitude of the PAM waveform is obtained from and is held constant for the corresponding . The PAM signal in Figure 2.4 is assumed to be arriving at the receiver, which corresponds to the ideal situation of receiving a noiseless signal without any distortion. The set of symbols , known by both transmitter and receiver, allows the receiver to use the sensible strategy of guessing which symbol of was transmitted by comparing the amplitude of the received signal to the decision thresholds . For example, if the amplitude lies between and 0, the receiver assumes the transmitted symbol was . These decisions must be done periodically at a rate , which is called the symbol rate.
The advantage of departing from binary systems and using symbols is the capability of transporting bits per symbol. In the signal of Figure 2.4, bits can be mapped such that the amplitudes can be related to the bits , respectively. A constellation is fully specified by the set and the assignment of bits (or codewords) to the symbols in . Figure 2.5 is a version of Figure 2.4 that shows the binary codes used for each amplitude. It can be observed that the demodulated bitstream is 10 11 10 00 10 00 10 00 11 01 and, given the received and transmitted signals are the same in this ideal situation, the bit error rate (BER) is zero. In this case, the bit rate in number of bits per second (bps) can be found by noting that symbols are received per second and each symbol carries bits, which leads to bps.
Note from Figure 2.5 that due to the assumed ideal situation, it is easy to observe where each symbol starts and ends. However, the practical transmission systems have some degree of channel dispersion, which loosely speaking means that the channel will delay and distort the signal such that a symbol can interfere with subsequent symbols. Note that channel dispersion can be observed when the channel impulse response differs from an impulse and can be interpreted in frequency-domain as a non-flat frequency response. Hence, a frequency-selective channel corresponds to a dispersive channel. Figure 2.6 shows an example where the signal of Figure 2.4 was transmitted over a system (a Chebyshev filter obtained with cheby1). This is a situation where there is no noise, only channel dispersion, but it is clearly harder to demodulate the signal. The first point is that there is a delay imposed by the channel. For example, the first symbol is not limited to the interval from 0 to 25 s, as in Figure 2.5.
The delay imposed by a channel is discussed in Applications E.6 and E.10. For the channel used to generate Figure 2.6, the group delay (estimated with grpdelay) is approximately 12 s around DC, increases up to 25 s at 0.06 Hz and is approximately zero for frequencies higher than 0.3 Hz. The overall effect of these influences in the frequency components of the input signal generates the situation of Figure 2.6, where the amplitude of the intended symbol is better visualized almost at the end of the corresponding original time interval. For example, a maximum amplitude of 1.13 corresponding to the first symbol is observed around 20.8 s while the second received symbol has a peak of amplitude 3.23 at 45.4 s.
A pertinent question is how to estimate the channel delay in practice, especially in situations such as wireless communications where this delay varies over time. One approach is based on cross-correlation. As done in Application C.13, using the function xcorr for the transmitted and received signals of Figure 2.6 indicates that the correlation has a peak at a lag corresponding to 12.6 s. This kind of information can be used by the receiver to determine an instant of reference for demodulating the symbols.
The next paragraphs correspond to a hands-on discussion of PAM-based systems, where the reader is invited to execute short codes in Matlab/Octave to get familiar with important concepts.
2.7.1 Generation of symbols from a PAM constellation
Any set of distinct real numbers can be used to constitute a PAM constellation. An example could be , with . But in practice, a PAM constellation obeys the following guidelines:
- the constellation order is a power of 2, where is the number of bits per symbol;
- the distance between neighboring symbols is the same;
- the symbols average is zero, i. e., ;
- when relating the symbols to their binary representation, Gray coding is used to aim at a smaller number of bit errors (BER) when a symbol error occurs.
Using is convenient and adopted in many situations. In case , the PAM symbols can be generated in Matlab/Octave with the command -(M-1):2:M-1 and later normalized to have a specified distance or constellation energy
| (2.9) |
Considering that all symbols are equiprobable leads to Eq. (C.69).
While PAM symbols are real numbers, this definition of uses the modulus to take into account that other modulations use complex symbols.
For example, Listing 2.2 illustrates how to obtain two sets of constellation symbols from symbols spaced by : the first set cx with and another set cy with J.
1M=4 %modulation order 2canonicalPAMSymbols = -(M-1):2:M-1 %original, Delta = 2 3cx = canonicalPAMSymbols/2; %intermediate result, Delta=1 4cx = 8 * cx %convert to the specified Delta=8 5originalEnergy = mean(abs(canonicalPAMSymbols).^2); 6cy = canonicalPAMSymbols / sqrt(originalEnergy); %Ec = 1 7cy = sqrt(20) * cy %convert to the specified Ec=20 J
Note that after transmission over a channel, the received signal can be significantly attenuated and, before the detection stage, it may be necessary to use an AGC or normalize the received symbols to have the energy (or power) assumed by the detection stage.
Up to now, the discussion was restricted to the set of symbols of a constellation. To completely specify the constellation, its symbols must be associated to bits. Figure 2.7 shows an example for 8-PAM with . The assignment of bits to each symbol uses the natural order. The first (left-most) symbol corresponds to 0 in decimal, corresponds to 1, etc. Hence, is 000, is 001 and so on. One can observe that identifying individual symbols using the decimal or binary representation depends only on convenience. The Matlab/Octave functions dec2bin and bin2dec help converting between these two representations.
In the GNU Radio (GR) platform, as discussed in Application 2.3, the bits are typically packed into integers that are called chunks.
Note that if the symbol (representing the bits 011) gets confused at the receiver by its neighbor symbol 1 (bits 100), there are three bit errors. When one considers the presence of noise, it is interesting to use Gray coding and aim at achieving the performance predicted by Eq. (2.4).
Table 2.1 contrasts the natural and Gray representations. In Matlab/Octave, the Gray code can be conveniently generated with the command M=8; alphabet = pammod(0:M-1,M,0,’gray’) that results in [-7,-5,-1,-3,7,5,1,3]. For this constellation, a chunk in Gnu Radio of integer value 2 (or 010 in binary) represents the symbol . Figure 2.8 illustrates a Gray-coded constellation.
Symbol m | -7 | -5 | -3 | -1 | 1 | 3 | 5 | 7 |
Natural decimal representation | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Natural binary representation | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
Gray decimal representation | 0 | 1 | 3 | 2 | 6 | 7 | 5 | 4 |
Gray binary representation | 000 | 001 | 011 | 010 | 110 | 111 | 101 | 100 |
|
The random generation of a large number of PAM symbols in Matlab/Octave is relatively simple and can be done with a code such as Listing 2.3.
1M=8; %modulation order 2N=10000; %number of symbols to be generated 3indices=floor(M*rand(1,N))+1; %random indices from [1, M] 4alphabet=[-(M-1):2:(M-1)]; %symbols ...,-3,-1,1,3,5,7,... 5m=alphabet(indices); %obtain N random symbols
Listing 2.3 uses the function rand to generate uniformly distributed random indices and the syntax m=alphabet(indices) to obtain their corresponding symbols.
2.7.2 Average energy of PAM constellations
Assuming that practical PAM constellations have uniformly-spaced symbols with distance between neighbors, the average constellation energy depends only on and and Eq. (2.9) can be specialized to this case.
To calculate for the uniformly-spaced PAM constellation where is an even number, one should note that there are pairs of symbols with energy , where is an odd number: . Therefore,
About the three parcels in the above summation, the second one (corresponding to ) can be calculated from the arithmetic series . The first one (corresponding to ) can use Eq. (A.17), which indicates that the sum of squares is . With these two results and after some algebra one gets
| (2.10) |
2.7.3 PAM detection
When using the traditional PAM constellations, in which every symbol has the same distance from its neighbors, the detection is relatively simple, as shown in Listing 2.4 for .
1function [symbolIndex, x_hat]=ak_pamdemod(x,M) 2% function [symbolIndex, x_hat]=ak_pamdemod(x,M) 3%Inputs: x has the PAM values and M the number of symbols 4%Outputs: symbolIndex has the indices from 0 to M-1 5% x_hat contains the nearest symbol(s) 6delta = 2; %assume symbols are separated by 2 7symbolIndex = (x+M-1) / delta; %quantizer levels 8symbolIndex=round(symbolIndex); %nearest integer 9symbolIndex(symbolIndex > M-1) = M-1; %impose maximum 10symbolIndex(symbolIndex < 0) = 0; %impose minimum 11if nargout > 1 %calculate only if necessary 12 x_hat = (symbolIndex * delta)-(M-1);%quantized output 13end
In this case, the PAM detection is equivalent to a uniform quantization. The only distinction between PAM detection and Listing C.18 is that the quantization stairs is shifted because “zero” is not a PAM symbol.9
If the constellation does not have the same distance among neighboring symbols, the computational cost of detection increases. Listing 2.5 illustrates how to choose the decoded symbol for a generic constellation, by picking the symbol with the smallest Euclidean distance to the input value.
1function [symbolIndex, x_hat]=ak_genericDemod(x,constel) 2% function [symbolIndex, x_hat]=ak_genericDemod(x,constel) 3%Finds the nearest-neighbor symbol for any constellation. 4%Inputs: x the symbols (PAM, QAM or 3d-vectors, etc) to be 5% "demodulated", one per column (PAM and QAM can be vectors 6% with real and complex numbers, respectively). 7% constel - constellation with a symbol per column 8%Outputs: symbolIndex has the indices from 0 to M-1, where 9% x_hat has the nearest symbol(s) and same dimension as x 10%Usage: 11%x=[2,2+4j,-1,-1,-j], c=[1,j,-1,-j], [s,x_hat]=ak_genericDemod(x,c) 12%x=rand(3,5); c=[1 0;0 1;1 1]; [s,x_hat]=ak_genericDemod(x,c) 13if isvector(x) 14 S=length(x); %number of symbols (PAM or QAM) in x 15 if ~isvector(constel) 16 error('Constellation must be a vector if input is a vector'); 17 end 18 x=transpose(x(:)); %make sure x is a row vector 19 constel=transpose(constel(:)); %make sure constel is a row vector 20 M=length(constel); %number M of symbols in constellation 21 D=1; %assume dimension is 1 22else 23 [D,S]=size(x); %S symbols of dimension D are organized in columns 24 [D2,M]=size(constel); %get number M of symbols in constellation 25 if D ~= D2 26 error('Dimension (number of rows) must be same for inputs'); 27 end 28end 29symbolIndex=zeros(1,S); %pre-allocate space for S indices 30x_hat=zeros(D,S); %pre-allocate space for S symbols of dimension D 31for i=1:S %loop over all S input vectors in x 32 bestSymbolIndex = 1; %temporarily assume first symbol as closest 33 minDistance=norm(x(:,i)-constel(:,bestSymbolIndex),2);%initialize 34 for j=2:M %search all other symbols in constellation 35 distance = norm(x(:,i)-constel(:,j),2); %Euclidean distance 36 if distance < minDistance %update best symbol if true 37 minDistance = distance; %update minimum distance 38 bestSymbolIndex = j; %store best symbol index 39 end 40 end 41 symbolIndex(i)=bestSymbolIndex-1; %store best symbol index 42 x_hat(:,i)=constel(:,bestSymbolIndex); %and corresponding symbol 43end
Note that, for example, the two functions invoked in the following code give the same result, but ak_pamdemod is faster because it can take into account the symbols are uniformly spaced.
1x=[1.1, -4, 7]; %some arbitrary vector to test the two functions 2[a,b]=ak_pamdemod(x,4) %function assumes symbols are uniformly spaced 3[a,b]=ak_genericDemod(x,[-3 -1 1 3])%supports arbitrary constellation
2.7.4 Symbol-based PAM simulation
As discussed, samples and symbols are distinct elements of a digital communication system. Samples compose waveforms while symbols carry information and are restricted to be elements of a given constellation. Hence, one must distinguish two distinct rates: the sampling frequency and the symbol rate or, equivalently, the sampling and symbol intervals, respectively.
Based on symbols and samples, two important simulation strategies will be discussed: symbol-based and sample-based (or oversampled) simulations. For a symbol-based simulation, the vector representing the transmit signal is composed not by samples, but by the symbols themselves, and the time interval between consecutive elements is not , but . The symbol-based often demands less computation than the sample-based simulations, as discussed in the sequel.
The symbol-based simulation model is based on sending the symbols directly to a channel that accepts symbols at its input and outputs symbols. In this case, the sampling interval is not defined or, if convenient, it can be thought as equal to the symbol rate, i. e., .
As a “sanity check”, Listing 2.6 provides a transmission example without noise nor distortion. It illustrates a situation where the received symbols are made equal to the transmitted symbols. The variable numberOfErrors is zero, as expected in this case.
1M=16; %modulation order 2numberOfSymbols = 40000; % number of symbols 3alphabet = [-(M-1):2:M-1]; %M-PAM constellation 4symbolIndicesTx = floor(M*rand (1, numberOfSymbols )); 5s = alphabet(symbolIndicesTx +1); %transmit signal 6r = s; %no channel: received = transmit signal 7symbolIndicesRx = ak_pamdemod(r, M);% demodulate 8numberOfErrors = sum(symbolIndicesTx ~= symbolIndicesRx)
The AWGN channel can easily operate at the symbol-level. As exemplified in Listing 2.7, random noise n can be directly added to the transmitted symbols s such that the received symbols are r=s+n. Note that, in this case, each symbol can be considered a waveform sample, but it is important to keep distinguishing the concepts of symbol and sample.
1randn('state',0); rand('state',0);%reset random generators 2M=16; %modulation order 3numSymbols = 40000; % number of symbols 4alphabet = [-(M-1):2:M-1]; %M-PAM constellation 5symbolIndicesTx = floor(M*rand(1, numSymbols)); %random indices 0:M-1 6s = alphabet(symbolIndicesTx + 1); %transmit symbols (indices 1 to M) 7Pn = 2 %noise power (assumed to be in Watts) 8n = sqrt(Pn)*randn(size(s)); %white Gaussian noise 9r = s+n; %channel with additive white Gaussian noise 10symbolIndicesRx = ak_pamdemod (r, M);% demodulate 11SER = sum(symbolIndicesTx~=symbolIndicesRx)/numSymbols %symbol errors 12Ps = mean(alphabet.^2) %transmit signal power (Watts) 13Pr = mean(r.^2) %received signal power (Watts) 14SNR = Ps/Pn %SNR in linear scale 15N0_s = 10*log10(Ps/pi) %unilateral Tx PSD level in log scale 16N0_r = 10*log10(Pr/pi) %unilateral Rx PSD level in log scale 17N0_n = 10*log10(Pn/pi)%unilateral PSD noise level in log scale
Executing Listing 2.7 leads to SER=0.45, which is rather high. Observing the received constellation with plot(real(r),imag(r),’x’) would illustrate the noise is too intense.
Note that for improved efficiency the signal power was obtained with mean(alphabet.2), which is the constellation energy as dictated by Eq. (C.69).10 The power could also be obtained with mean(s.2) but given that in this case, the former method is faster. Note that, asymptotically, when numSymbols goes to infinity, in symbol-based PAM simulations. The more general case of finding the power of sample-based PAM signals is discussed in Section 2.7.8.
2.7.5 Flat PSD of symbol-based PAM signals
They are faster than sample-based simulations, but one important limitation of symbol-based simulations is that there is no control of the transmit signal spectrum. The implicit assumption that and of statistical independence of the symbols leads to a flat (white) PSD because the signal autocorrelation is, theoretically, non-zero only at lag . Hence, a sequence of PAM symbols has the same PSD as white noise and the concepts in Section F.7.3 apply here.11
For Listing 2.7, the transmit, noise and received signals had power , and W, respectively. Figure 2.9 shows the one-sided PSDs obtained by commands pwelch. Because the noise and transmitted signals are uncorrelated, one can apply Eq. (C.76) and observe that . The transmit PSD has an average value (recall that, by default, pwelch returns unilateral PSDs) of dB/normalized frequency. Similarly, the values of for the noise and received signals are 4.4 and 14.7 dB/normalized frequency, respectively, which are indicated by horizontal lines in Figure 2.9. Note that is applied with powers in linear scale (Watts), not in dB, and a similar reasoning applies when adding PSDs.
It can be proved that in some cases the performance of a PAM system can be evaluated by an equivalent symbol-based representation.12 However, to assess aspects such as channel equalization, it would be a limiting factor to simulate a communication system only with flat PSDs. Oversampling is used to circumvent this restriction. The next section discusses sample-based simulations, which allow using signals with non-flat PSDs. PAM is assumed for simplicity.
2.7.6 Sample-based (oversampled) PAM simulation
This section deals with the generation and demodulation of PAM signals with a spectrum imposed by a shaping pulse (or in continuous-time). Oversampling is a required condition for having control of the transmit signal spectrum.
In the oversampled case, and the ratio
| (2.11) |
is called the oversampling factor. Its choice depends on several aspects, such as the bandwidth of the signals used to represent information. In many communication device firmwares, such as the modem of a handset, for example, the oversampling is an integer in the range . Higher values of may be used during simulation-based studies though.
Assuming discrete-time, samples are used to describe the waveform segment that represents a single symbol. While a symbol-based simulation has and a transmit signal that has a flat spectrum, the extra degree of freedom provided by allows to shape this spectrum, as desired.
The majority of the PAM systems generates the -th waveform segment or via the simple expressions
| (2.12) |
respectively, where is the -th symbol (e. g., two values, representing bits 0 and 1 in case of a binary system) and or is a formatting pulse.
Figure 2.10 illustrates an example of PAM with s ( bauds) and a pulse with support from 0 to 12.5 s and amplitude 1. Observe that a new symbol is transmitted at every , but the transmitted waveform exists for all and depends on both the symbols and shaping pulse . The pulse in Figure 2.10 has support such that is called a RZ (return-to-zero) signal. If the spectrum of needs to obey constraints, they can imposed by controlling and also the statistical properties of the symbols . This leads to several distinct families of transmitted signals, which are called line codes, as will be seen in Section 2.10.
2.7.7 Interpreting the shaping pulse as the impulse response of a LIT
For continuous-time processing and assuming an infinite sequence of symbols , the PAM signal is given by:
| (2.13) |
Similarly, for discrete-time processing:
| (2.14) |
where is the oversampling factor defined in Eq. (2.11).
The generation of an oversampled PAM signal is a little more involved than a symbol-based PAM. It can be interpreted as an interpolation process and, consequently, it may be tempting to use a function such as interp, which implements upsampling and filtering. However, it is recommended to explicitly deal with the shaping pulse (that typically represents ) and do not use interp or similar functions.
In continuous-time, the PAM generation uses a D/C conversion to obtain a sampled signal with sampling interval from a discrete-time sequence of symbols , as indicated in
| (2.15) |
The signal can be interpreted as the impulse response of a LTI system, and this interpretation will be often used hereafter. The convolution of with provides the PAM signal . The observation of the signals described in Figure 2.10, which depicts , helps to interpret the process.
A similar approach can be used to generate a discrete-time PAM signal . In this case, the D/C conversion is substituted by an upsampling operation that inserts zeros between samples of (do not confuse upsampling with frequency upconversion). Hence, one can obtain the signal by convolving an upsampled symbols sequence with , as illustrated in:
| (2.16) |
The notation indicates that the first signal has an associated sampling interval that is distinct from the interval adopted for the other two signals.
The generation of a discrete-time oversampled PAM signal is illustrated in Listing 2.8. Note that both and must be associated to the same sampling frequency . In other words, when converted to continuous-time, the interval between the original samples of discrete-time signals is the sampling period .
1M=8; %modulation order (cardinality of the set of symbols) 2N=10000; %number of symbols to be generated 3L=3; %oversampling factor 4indices=floor(M*rand(1,N))+1; %random indices from [1, M] 5alphabet=[-(M-1):2:M-1]; %symbols ...,-3,-1,1,3,5,7,... 6m=alphabet(indices); %obtain N random symbols 7m_upsampled=zeros(1,N*L); %pre-allocate space with zeros 8m_upsampled(1:L:end)=m; %symbols with L-1 zeros in-between 9p=ones(1,L); %shaping pulse with square waveform 10s=conv(m_upsampled,p); %convolve symbols with pulse
The samples of the sequence m in Listing 2.8 are separated by an interval equivalent to . The upsampling operation creates a new sequence m_upsampled in which the samples are separated by an interval of . The command s=conv(m_upsampled,p) obtains the desired PAM signal. Note that, as in the continuous-time case, can be interpreted as the impulse response of a LTI system.
Recall that the convolution of sequences of lengths and generates a sequence of samples. When using s=conv(m_upsampled,p) in Listing 2.8, the vector s has more samples than m_upsampled. If their lengths should be the same (see Section E.15.3), the convolution tail can be eliminated manually (after conv) or by using filter (instead of conv):
In the previous command, the filter command used the fact that the impulse response p of a FIR filter coincides with its coefficients, such that p and 1 are, respectively, the numerator and denominator of the system function of this filter.
Figure 2.11 shows an example obtained by modifying Listing 2.8. In this case, the oversampling factor was made longer than the support of (3 samples), such that has two zero-valued samples per symbol.
It should be noticed that Figure 2.11 and Figure 2.10 correspond to distinct representations of signals (discrete and continuous-time, respectively). However, the actual representation when simulating in Matlab/Octave is the discrete-time version of Figure 2.11 given that the simulations represent signals as arrays. For example, Figure 2.10 was obtained in Matlab/Octave using a relatively high oversampling factor for getting plots that better represent continuous-time signals (with sharp transitions). Continuous-time signals are more naturally represented by tools such as Simulink.
2.7.8 Advanced: Power of PAM signals
Eq. (E.102) can be used to obtain the power of a PAM signal, even if the duration of (or ) is longer than (or ), i. e., there is overlap between symbols.
Assuming discrete-time and the PAM of Block (2.16), if the symbols are independent, Eq. (E.102) indicates that the power of the PAM signal is , where is the power of the upsampled signal and is the energy of the shaping pulse .
The upsampling modifies the power of the sequence of symbols and this must be taken in account. For discrete-time PAM, the power of the upsampled signal is given by
| (2.17) |
where is the oversampling factor and the constellation energy (recall Eq. (C.69)). Therefore, the power of the PAM signal is
| (2.18) |
as exemplified in Listing 2.9.
If a normalized pulse with is adopted and , then and the units (power and Joules, respectively) must be interpreted with care.
1M=4; %PAM order 2constellation = -(M-1):2:M-1; %PAM constellation 3N=10000000; %number of PAM symbols 4m=constellation(floor(rand(1,N)*M)+1); %random PAM symbols 5Ec=mean(m.^2); %average constellation energy 6L=4; %oversampling factor 7p=[1:8]; %arbitrary shaping pulse with duration longer than L 8mu=zeros(1,L*N); mu(1:L:end)=m; %upsampled signal 9s=filter(p,1,mu); %generate PAM signal 10Ep=sum(p.^2); Pu=mean(mu.^2); Ps=mean(s.^2); 11disp(['Ec=' num2str(Ec) ' and Pu=Ec/L=' num2str(Pu)]) 12disp(['Pu*Ep=' num2str(Pu*Ep) ' should be equal to Py=' num2str(Ps)])
As discussed in Section E.5.2, for continuous-time PAM, the power of the upsampled signal is given by
| (2.19) |
and the PAM signal has power
| (2.20) |