Mathworks COMMUNICATIONS TOOLBOX 4 Reference

Communications To
Reference
olbox™ 4
How to Contact The MathWorks
www.mathworks. comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html T echnical Support
suggest@mathworks.com Product enhancement suggestions bugs@mathwo doc@mathworks.com Documentation error reports service@mathworks.com Order status, license renewals, passcodes info@mathwo
com
rks.com
rks.com
Web
Bug reports
Sales, prici
ng, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
Communications Toolbox™ Reference
© COPYRIGHT 1996–20 10 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
April 1996 First printing Version 1.0 May 1997 Second printing Revised for Version 1.1 (MATLAB 5.0) September 2000 Third printing Revised for Version 2.0 (Release 12) May 2001 Online only Revised for Version 2.0.1 (Release 12.1) July 2002 Fourth printing Revised for Version 2.1 (Release 13) June 2004 Fifth printing Revised for Version 3.0 (Release 14) October 2004 Online only Revised for Version 3.0.1 (Release 14SP1) March 2005 Online only Revised for Version 3.1 (Release 14SP2) September 2005 Online only Revised for Version 3.2 (Release 14SP3) October 2005 Reprint Version 3.0 (Notice updated) March 2006 Online only Revised for Version 3.3 (Release 2006a) September 2006 Sixth printing Revised for Version 3.4 (Release 2006b) March 2007 Online only Revised for Version 3.5 (Release 2007a) September 2007 Online only Revised for Version 4.0 (Release 2007b) March 2008 Online only Revised for Version 4.1 (Release 2008a) October 2008 Online only Revised for Version 4.2 (Release 2008b) March 2009 Online only Revised for Version 4.3 (Release 2009a) September 2009 Online only Revised for Version 4.4 (Release 2009b) March 2010 Online only Revised for Version 4.5 (Release 2010a)
Function Reference
1
Signal Sources .................................... 1-2
Contents
Performance Evaluation
Source Coding
Error-Control Coding
Interleaving/Deinterleaving
Analog Modulation/Demodulation
Digital Modulation/Demodulation
Pulse Shaping
Filters
Lower-Level Filters
Channels
Equalizers
............................................ 1-9
..................................... 1-3
..................................... 1-9
.......................................... 1-9
........................................ 1-11
........................... 1-2
.............................. 1-4
........................ 1-6
................................ 1-9
................... 1-7
................... 1-7
Galois Field
MATLAB F unctions and Operators
Galois Fields of Odd Characteristic
Utilities
MATLAB U tilities
....................................... 1-11
........................................... 1-14
................................. 1-16
................... 1-12
................. 1-13
v
GUI .............................................. 1-16
Functions — Alphabetical List
2
Index
vi Contents

Function Reference

Signal Sources (p. 1-2) Sources of random signals
Performance Evaluation (p. 1-2) Analyzing and visualizing
performance of a communication system
Source Coding (p. 1-3) Quantization, companders, and
other kinds of source coding
1
Error-Control Coding (p. 1-4)
Interleaving/Deinterleaving (p. 1-6)
Analog Modulation/Demodulation (p. 1-7)
Digital Modulation/Demodulation (p. 1-7)
Pulse Shaping (p. 1-9) Oversampling and shaping a signal
Filters (p. 1-9) Raised cosine and Hilbert filters
Channels (p. 1-9) Channel models for real, complex,
Equalizers (p. 1-11) Adaptive and MLSE equalizers
Galois Field (p. 1-11) Manipulating elements of finite
Galois Fields of Odd Characteristic (p. 1-13)
Utilities (p. 1-14) Miscellaneous relevant functions
GUI (p. 1-16)
Block and convolutional coding
Block and convolutional interleaving
Passband amplitude, frequency, and phase modulation
Baseband digital modulation
and binary signals
fields of even order
Manipulating elements of finite fields of odd order
Bit error rate analysis tool
1 Function Reference

Signal Sources

Performan
commsrc.pattern
randerr
randint
randsrc
wgn
ce Evaluation
berawgn
bercoding
berconfint
berfading
berfit
sync
ber
terr
bi
ommmeasure.ACPR
c
commmeasure.EVM
commmeasure.MER
Construct pattern generator object
Generate bit error patterns
Generate matrix of uniformly distributed random integers
Generate random matrix using prescribed alphabet
Generate white Gaussian noise
Bit error rate (BER) for uncoded AWGN channels
Bit error rate (BER) for coded AWGN channels
Bit error rate (BER) and confidence interval of Monte Carlo simulation
Bit error rate (BER) for Rayleigh and Rician fa ding channels
urve to nonsmooth empirical bit
Fit c
r rate (BER) data
erro
error rate (BER) for imperfect
Bit
chronization
syn
mpute number of bit errors and
Co
t error rate (BER)
bi
eate adjacent channel power
Cr
easurement object
m
reate EVM measurement object
C
Create MER measurement object
1-2

Source Coding

commscope
commscope.eyediagram
commscope.ScatterPlot
commtest.ErrorRate
distspec
eyediagram
EyeScope
noisebw
scatterplot
semianalytic
symerr
Package of communications scope classes
Eye diagram analysis
Create Scatter Plot scope
Create error rate test console
Compute distance spectrum of convolutional code
Generate eye diagram
Launch eye diagram scope for eye diagram object H
Equivalent noise bandwidth of filter
Generate scatter plot
Calculate bit error rate (BER) using semianalytic technique
Compute number of symbol errors and symbol error rate
Source Coding
arithdeco
arithenco
compand
dpcmdeco
dpcmenco
Decode binary code using arithmetic decoding
Encode sequence of symbols using arithmetic coding
Source code mu-law or A-law compressor or expander
Decode using differential pulse code modulation
Encode using differential pulse code modulation
1-3
1 Function Reference
dpcmopt
huffmandeco
huffmandict
huffmanenco
lloyds
quantiz

Error-Control Coding

bchdec
bchenc
bchgenpoly
bchnumerr
convenc
cyclgen
cyclpoly
decode
dvbs2ldpc
encode
fec.bchdec
Optimize differential pulse code modulation parameters
Huffman decoder
Generate Huffman code dictionary for source with known probability model
Huffman encoder
Optimize quantization parameters using Lloyd algorithm
Produce quantization index and quantized output value
BCH decoder
BCH encoder
Generator polynomial of BCH code
Number of correctable errors for BCH code
Convolutionally encode binary data
Produce parity-check and generator matrices for cyclic code
Produce generator po lyno mials for cyclic code
Block decoder
Low-density parity-check codes from DVB-S.2 standard
Block encoder
Construct B CH decoder object
1-4
Error-Control Coding
fec.bchenc
fec.ldpcdec
fec.ldpcenc
fec.rsdec
fec.rsenc
gen2par
gfweight
hammgen
rsdec
rsdecof
rsenc
rsencof
rsgenpoly
syndtable
vitdec
Construct BCH encoder object
Construct LD PC decoder object
Construct LDPC encoder object
Construct Reed-Solomon decoder object
Construct Reed-Solomon encoder object
Convert between parity-check and generator matrices
Calculate minimum distance of linear block code
Produce parity-check and generator matrices for Hamming code
Reed-Solomon decoder
Decode ASCII file encoded using Reed-Solomon code
Reed-Solomon encoder
Encode ASCII file using Reed-Solomon code
Generator polynomial of Reed-Solomon code
Produce syndrome decoding table
Convolutionally decode binary data using Viterbi al gorithm
1-5
1 Function Reference

Interleaving/Deinterleaving

algdeintrlv
algintrlv
convdeintrlv
convintrlv
deintrlv
heldeintrlv
helintrlv
helsca
helsc
intrlv
matdeintrlv
matintrlv
muxdeintrlv
muxintrlv
randdeintrlv
randintrlv
ndeintrlv
anintrlv
Restore ordering of symbols using algebraically derived permutation table
Reorder symbols using algebraically derived permutation table
Restore ordering of symbols using shift registers
Permute symbols using shift registers
Restore ordering of symbols
Restore ordering of symbols permuted using
Permute
Restor helica
symbols using helical array
e ordering of symbols in
l pattern
helintrlv
Reorder symbols in helical pattern
Reorder sequence of symbols
Restore ordering of symbols by filling matrix by columns and emptying it by rows
Reorder symbols by filling matrix by rowsandemptyingitbycolumns
Restore ordering of symbols using specified shift registers
Permute symbols using shift registers with specified delays
Restore ordering of symbols using random permutation
Reorder symbols using random permutation
1-6

Analog Modulation/Demodulation

Analog Modulation/Demodulation
amdemod
ammod
fmdemod
fmmod
pmdemod
pmmod
ssbdemod
ssbmod

Digital Modulation/Demodulation

emod
dpskd
mod
dpsk
demod
fsk
mod
fsk
nqamdemod
ge
enqammod
g
modem
modem.dpskdemod
modem.dpskmod
Amplitude demodulation
Amplitude m odulation
Frequency demodulation
Frequency mo
dulation
Phase demodulation
Phase modulation
Single sideband am plitude demodulation
Single sideband am plitude modulation
rential phase shift keying
Diffe demod
Diff modu
Fre
Fre
Ge de
G m
ulation
erential phase shift keying
lation
quency shift keying demodulation
quency shift keying modulation
neral quadrature amplitude
modulation
eneral quadrature amplitude
odulation
Package of modem classes
Construct DPSK demodulator object
Construct DPSK modulator object
1-7
1 Function Reference
modem.genqamdemod
modem.genqammod
modem.mskdemod
modem.mskmod
modem.oqpskdemod
modem.oqpskmod
modem.pamdemod
modem.pammod
modem.pskdemod
modem.pskmod
modem.qamdemod
modem.qammod
modnorm
mskdemod
mskmod
oqpskdemod
oqpskmod
pamdemod
pammod
pskdemod
pskmod
qamdemod
qammod
Construct General QAM demodulator object
Construct General QAM modulator object
Construct MSK demodulator object
Construct MSK modulator object
Construct OQPSK demodulator object
Construct OQPSK modulator object
Construct PAM demodulator object
Construct PAM modulator object
Construct PSK demodulator object
Construct PSK modulator object
Construct QAM demodulator object
Construct QAM modulator object
Scaling factor for normalizing modulation output
Minimum shift keying demodulation
Minimum shift keying modulation
Offset quadrature phase shift keying demodulation
Offset quadrature phase shift keying modulation
Pulse amplitude demodulation
Pulse amplitude modulation
Phase shift keying demodulation
Phase shift keying modulation
Quadrature amplitude demodulation
Quadrature amplitude modulation
1-8

Pulse Shaping

Pulse Shaping

Filters

intdump
rcosflt
rectpulse
hank2sys
hilbiir
rcosine
Lower-L
rcosfir
rcosiir
evel Filters
Integrate and dump
Filter input si cosine filter
Rectangular pulse shaping
Convert Hankel matrix to linear system model
Design Hilbert transform IIR filter
Design raised cosine filter
Design raised cosine finite impulse response (FIR) filter
Design raised cosine infinite impulse response (IIR) filter
gnal using raised

Channels

n
awg
bsc
doppler
doppler.ajakes
white Gaussian noise to signal
Add
Model binary symmetric channel
Package of Doppler classes
Construct asymmetrical Doppler spectrum object
1-9
1 Function Reference
doppler.bell
doppler.bigaussian
doppler.flat
doppler.gaussian
doppler.jakes
doppler.rjakes
doppler.rounded
filter (channel)
legacychannelsim
mimochan
plot (channel)
rayleighchan
reset (channel)
ricianchan
stdchan
Construct bell-shaped Doppler spectrum object
Construct bi-Gaussian Doppler spectrum object
Construct flat Doppler spectrum object
Construct Gaussian Doppler spectrum object
Construct Jakes Doppler spectrum object
Construct restricted Jakes Doppler spectrum object
Construct rounded Doppler spectrum object
Filter sig nal w i th channel object
Toggles random number generation mode for channel objects
Create MIMO fading channel object
Plot channel characteristics with channel v isualization tool
Construct Rayleigh fading channel object
Reset channel object
Construct Rician fading channel object
Construct channel object from set of standardized channel models
1-10

Equalizers

Equalizers
cma
dfe
equalize
lineareq
lms
mlseeq
normlms
reset (
rls
signlms
varlms
equalizer)
Construct constant modulus algorithm (CMA) object
Construct decision-feedback equalizer object
Equalize signal using equalizer object
Construct linear equalizer object
Construct least mean square (LMS) adaptive algorithm object
Equalize using Vit
Constru square ( object
Reset equalizer object
Construct recursive least squares (RLS) adaptive algorithm object
Construct signed least m ean square (LMS) a daptive algorithm object
Construct variable-step-size least mean square (LMS) adaptive algorithm object
linearly modulated signal
erbi algorithm
ct normalized least mean LMS) adaptive algorithm
alois Field
G
convmtx
cosets
Convolution matrix of Galois field vector
Produce cyclo tomic cosets for Galois field
1-11
1 Function Reference
dftmtx
Discrete Fourier transform matrix in Galois field
fft
filter (gf)
gf
gftable
Discrete Fourier transform
1-D digital filter over Galois field
Create Galois field array
Generate file to accelerate Galois field computations
ifft
isprimitive
Inverse discrete Fourier transform
True for primitive polynomial for Galois field
log
minpol
Logarithm in Galois field
Find minimal polynomial of Galois field element
mldivide
primpoly
Matrix left division \ of Galois arrays
Find primitive polynomials for Galois field

MATLAB Functions and Operators

1-12
+-
*/\
.* ./ .\
^
.^
'.'
==, ~=
all
any
conv
Addition and subtraction of Galois arrays
Matrix multiplication and d iv isi o n of Galois arrays
Elementwise m ultiplicat ion and division of Galois arrays
Matrix exponentiation of Galois array
Elementwise e xponentiation of Galois array
Transpose of Galois array
Relational o perators for Galois arrays
True if all elements o f a Galois vector are n onzero
True if any element of a Galois vector is nonzero
Convolution of Galois vectors

Galois Fields of Odd Characteristic

deconv Deconvolution and polynomial division
det
diag
inv
isempty
length
lu
polyval
rank
reshape
roots
size
tril
triu
Determinant of square G alois matrix
Diagonal Galois matrices and diagonals of a Galois matrix
Inverse of Galois matrix
True for empty Galois arrays
Length of Galois vector
Lower-upper triangular factorization of Galois array
Evaluate polynomial in Galois field
Rank of a Galois array
Reshape Galois array
Find poly nomial roots across a Galois field
Size of Galois array
Extract low er triangular part of Galois array
Extract upper triangular part of Galois array
Galois Fields of Odd Characteristic
gfadd
gfconv
gfcosets
gfdeconv
gfdiv
gffilter
Add polyn omials over Galois field
Multiply polynomials over Galois field
Produce cyclo tomic cosets for Galois field
Divide polynomials over Galois field
Divide eleme nts of Galois field
Filter data using polynomials over prime Galois field
1-13
1 Function Reference
gflineq
gfminpol
gfmul
gfpretty
gfprimck
gfprimdf
gfprimfd
gfrank
gfrepcov
gfroots
gfsub
gftrunc
gftuple
Find particular solution of Ax = b over prime Galois field
Find minimal polynomial of Galois field element
Multiply elements of G a lois field
Polynomial in traditional format
Check whether polynomial over Galois field is primitive
Provide defau lt primitive polynomials for Galois field
Find primitive polynomials for Galois field
Compute rank of m atrix over Galois field
Convert one binary polynomial representation to another
Find roots of polynomial over prime Galois field
Subtract polynomials over Galois field
Minimize length of polynomial representation
Simplify or convert Galois field element formatting

Utilities

1-14
alignsignals
bi2de
Align two signals b y delaying earliest signal
Convert binary vectors to decimal numbers
Utilities
bin2gray
commsrc.pn
de2bi
finddelay
gray2bin
iscatastrophic
istrellis
marcumq
mask2shift
oct2dec
poly2trellis
qfunc
qfuncinv
seqgen
seqgen.pn
shift2mask
vec2mat
Convert positive integers into corresponding Gray-encoded integers
Create PN sequence g enerator package
Convert decimal numbers to binary vectors
Estimate delay(s) between signals
Convert Gray-encoded positive integers to corresponding Gray-decoded integers
True for trellis corresponding to catastrophic convolutional code
True for valid trellis structure
Generalized M arcum Q function
Convert mask vector to shift for shift register configuration
Convert octal to decimal numbers
Convert convolutional code polynomials to trellis description
Qfunction
Inverse Q function
Sequence generator package
Construct default PN sequence generator object
Convert shift to mask vector for shift register configuration
Convert vector into matrix
1-15
1 Function Reference
GUI
MATLAB Utilitie
erf Error function
erfc Complementary error function
bertool
s
Open bit error rate analysis GUI (BERTool)
1-16

Functions — Alphabetical List

2
algdeintrlv
Purpose Restore ordering of symbols using algebraically derived permutation
table
Syntax deintrlvd = algdeintrlv(data,num,'takeshita-costello',k,h)
deintrlvd = algdeintrlv(data,num,
Description deintrlvd = algdeintrlv(data,num,'takeshita-costello',k,h)
restores the original ordering of the elements in data using a permutation table that is algebraically derived using the Takeshita-Costello method.
data is a vector, or the number of rows of data if data is a matrix with
multiple columns. In the Takeshita-C ostello method, power of 2. The multiplicative factor, than
num,andthecyclicshift,h, must be a nonnegative integer less than
num.Ifdata is a matrix with multiple rows and columns, the function
processes the columns independently.
deintrlvd = algdeintrlv(data,num,'welch-costas',alph) uses the
Welch-Costas method. In the Welch-Costas method, prime number.
alph is an integer between 1 an d num that represents a
primitive element of the finite field GF(
num is the number of elements in data if
'welch-costas',alph)
num must be a
k,mustbeanoddintegerless
num+1 must be a
num+1).
To use this function as an inverse of the same inputs in both functions, except for the
algintrlv function, use the
data input. In that case,
the two functions are inverses in the sense that applying followed by algdeintrlv leaves data unchanged.
Examples The code below uses the Takeshita-Costello method of algintrlv and
algdeintrlv.
num = 16; % Power of 2 ncols = 3; % Number of columns of data to interleave data = rand(num,ncols); % Random data to interleave k=3; h=4; intdata = algintrlv(data,num,'takeshita-costello',k,h); deintdata = algdeintrlv(intdata,num,'takeshita-costello',k,h);
2-2
algintrlv
algdeintrlv
See Also algintrlv,“Interleaving”
References [1] Heegard, Chris, and Stephen B. Wicker, Turbo Coding,Boston,
Kluwer Academic Publishers, 1999.
[2] Takeshita,O.Y.,andD.J.Costello,Jr.,“NewClassesOfAlgebraic Interleavers for Turbo-Codes,” Proc. 1998 IEEE International Symposium on Information Theory, Boston, Aug. 16–21, 1998. p. 419.
2-3
algintrlv
Purpose Reorder symbols using algebraically derived permutation table
Syntax intrlvd = algintrlv(data,num,'takeshita-costello',k,h)
intrlvd = algintrlv(data,num,
Description intrlvd = algintrlv(data,num,'takeshita-costello',k,h)
rearranges the elem ents in data using a permutation table that is algebraically derived using the Takeshita-Costello method. the number of elements in of rows of
data if data is a matrix with multiple columns. In the
Takeshita-Costello method, factor,
h, must b e a nonnegative integer less than num.Ifdata is a matrix
k,mustbeanoddintegerlessthannum, and the cyclic shift,
with multiple rows and columns, the function processes the columns independently.
intrlvd = algintrlv(data,num,'welch-costas',alph) uses the
Welch-Costas method. In the Welch-Costas method, prime number.
alph is an integer between 1 an d num that represents a
primitive element of the finite field GF( nonzero element of GF( integer power.
data if data is a vector, or the number
num must be a power of 2. The multiplicative
num+1) can be expressed as alph raised to some
'welch-costas',alph)
num+1). This means that every
num is
num+1 must be a
Examples This example illustrates how to use the Welch-Costas method of
algebraic interleaving.
1 Define num and the data to interleave.
num = 10; % Integer such that num+1 is prime ncols = 3; % Number of columns of data to interleave data = randint(num,ncols,num); % Random data to interleave
2 Find primitive polynomials of the finite field GF(num+1). The
gfprimfd function re presents each primitive polynomial as a row
containing the coefficients in order of ascending powers.
pr = gfprimfd(1,'all',num+1) % Primitive polynomials of GF(num+1) pr =
2-4
algintrlv
31 41 51 91
3 Notice from the output that pr hastwocolumnsandthatthe
second column consists solely of 1s. In other words, each primitive polynomial is a monic degree-one polynomial. This is because
num+1 is prime. As a result, to find the primitive element that is a
root of each primitive polynomial, find a root of the polynomial by subtracting the first column of
primel = (num+1)-pr(:,1) % Primitive elements of GF(num+1) primel =
8 7 6 2
pr from num+1.
4 Now define alph as one of the elements of primel and use algintrlv.
alph = primel(1); % Choose one primitive element. intrlvd = algintrlv(data,num,'Welch-Costas',alph); % Interleave.
Algorithm A Takeshita-Costello interleaver uses a length-num cycle vector whose
nth elemen t is mod(k*(n-1)*n/2, num) for integers n between 1 and num. The function creates a permutation vector by listing, for each
element of the cycle vector in ascending order, one plus the element’s successor. The interleaver’s actual permutation table is the result of shifting the elements of the permutation vector left by function performs all computations on numbers and indices modulo
num.)
A Welch-Costas interleav er uses a permutation that maps an integer
K to mod(AK,num+1)-1.
h.(The
2-5
algintrlv
See Also algdeintrlv,“Interleaving”
References [1] Heegard, Chris, and Stephen B. Wicker, Turbo Coding,Boston,
Kluwer Academic Publishers, 1999.
[2] Takeshita,O.Y.,andD.J.Costello,Jr.,“NewClassesOfAlgebraic Interleavers for Turbo-Codes,” Proc. 1998 IEEE International Symposium on Information Theory, Boston, Aug. 16–21, 1998. p. 419.
2-6
alignsignals
Purpose Align two signals by delaying earliest signal
Syntax [Xa Ya] = alignsignals(X,Y)
[Xa Ya] = alignsignals(X,Y,MAXLAG) [Xa Ya] = alignsignals(X,Y,MAXLAG,'truncate') [Xa Ya D] = alignsignals(...)
Description [Xa Ya] = alignsignals(X,Y),whereX and Y are row or column
vectors of length LX and LY, respectively, aligns the two vectors by estimating the delay D between the two. If
X, D is positive, and X is delayed by D samples. If Y is advanced with
respect to signals
X, D is negative, and Y is delayed by -D samples. The aligned
Xa and Ya are returned. Delays in X and Y can be introduced by
pre-pending zeros.
[Xa Ya] = alignsignals(X,Y,MAXLAG) uses MAXLAG as the maximum
window size used to find the estimated delay D betw een is an integer-valued scalar. By default, MAXLAG is equal to MAX(LX, LY)-1. If
MAXLAG is negative, it is replaced by its absolute value. If MAXLAG is not
integer-valued, or is complex,
MAXLAG is input as [], it is replaced by the default value. If
Inf,orNaN,thenalignsignals returns
an error.
Y i s delayed with respect to
X and Y. MAXLAG
[Xa Ya] = alignsignals(X,Y,MAXLAG,'truncate') keeps the lengths
of Xa and Ya the same as those of D zeros are pre-pended to
X,andthelastD samples of X are truncated.
If D is negative, -D zeros are pre-pended to
Y are truncated. Note: If
of all samples of
zeros, and all samples of to
MAXLAG when using the 'truncate' option, set MAXLAG to [].
[Xa Ya D] = alignsignals(...) returns the estimated delay D.
X are lost. Similarly, if
Y are l ost. To avoid assigning a specific value
X and Y,respectively. IfD is positive,
Y,andthelast-D samples
DLX
, Xa will consist of LX zeros, and
−≥DLY
, Ya will consist of LY
2-7
alignsignals
Theory and Algorithm
The theory on delay estimation can be found in the specification of the
finddelay function (see Theory and Algorithm).
alignsignals function simply uses the estimated delay to delay the
The earliest signal such that the two signals have the same starting point.
As specified for the be exact d elayed copies of each other. However, the signals can be successfully aligned only if there is sufficient correlation between them.
finddelay function, the pair of signals need not
Examples The following illustrates how X is aligned when Y is delayed with respect
to
X by two samples.
X=[123]; Y=[00123]; MAXLAG = 2; [Xa Ya D] = alignsignals(X, Y, MAXLAG)
The resulting values are:
Xa=[00123] Ya=[00123] D=2
The following is a case where Y is advanced with respect to X by three samples.
2-8
X=[00012300]'; Y = [1 2 3 0]'; [Xa Ya] = alignsignals(X, Y)
The resulting values are:
Xa=[00012300]' Ya=[0001230]'
The following illustrates a signal Y that is aligned with respect to X but is noisy.
alignsignals
X=[001230]; Y = [0.02 0.12 1.08 2.21 2.95 -0.09]; [Xa Ya D] = alignsignals(X, Y)
The resulting values are:
Xa=[001230] Ya = [0.02 0.12 1.08 2.21 2.95 -0.09]; D=0
The following shows that when Y is a periodic repetition of X,the smallest possible delay is retu r ned.
X=[0123]; Y=[123000012300]; [Xa Ya D] = alignsignals(X, Y)
The resulting values are:
Xa=[0123]; Ya=[0123000012300]; D=-1
Here is an example of alignsignals using the 'truncate' option.
X=[123]; Y=[00123]; [Xa Ya D] = alignsignals(X, Y, [], 'truncate');
The resulting values are:
Xa = [0 0 1]; Ya = [0 0 1 2 3]; D=2
Inthecasewhereusingthe'truncate' option ends up truncating all the original data of
X, a warning will be issued. The following example
makes MATLAB issue such a warning.
2-9
alignsignals
See Also finddelay
X=[123]; Y=[0000123]; [Xa Ya D] = alignsignals(X, Y, [], 'truncate')
2-10
amdemod
Purpose Amplitude demodulation
Syntax z = amdemod(y,Fc,Fs)
z = amdemod(y,Fc,Fs,ini_phase) z = amdemod(y,Fc,Fs,ini_phase,carramp) z = amdemod(y,Fc,Fs,ini_phase,carramp,num,den)
Description z = amdemod(y,Fc,Fs) demodulates the amplitude modulated signal y
from a carrier signal with frequency Fc (Hz). The carrier signal and y have sample frequency Fs (Hz). The m odulated signal y has zero initial phase and zero carrier amplitude, so it represents suppressed carrier modulation. The demodulation processusesthelowpassfilterspecified by
[num,den] = butter(5,Fc*2/Fs).
Note The Fc and Fs arguments must satisfy Fs >2(Fc + BW), where BW is the bandwidth of the originalsignalthatwasmodulated.
z = amdemod(y,Fc,Fs,ini_phase) specifies the initial phase of the
modulated signal in radians.
z = amdemod(y,Fc,Fs,ini_phase,carramp) demodulates a signal that
was created via transmitted carrier modulation instead of suppressed carrier modulation. signal.
z = amdemod(y,Fc,Fs,ini_phase,carramp,num,den) specifies
the numerator and denominator of the lowpass filter used in the demodulation.
carramp is the carrier am plitude of the modulated
Examples The code below illustrates the use of a nondefault filter.
t = .01; Fc = 10000; Fs = 80000; t = [0:1/Fs:0.01]'; s = sin(2*pi*300*t)+2*sin(2*pi*600*t); % Original signal
2-11
amdemod
[num,den] = butter(10,Fc*2/Fs); % Lowpass filter
y1 = ammod(s,Fc,Fs); % Modulate. s1 = amdemod(y1,Fc,Fs,0,0,num,den); % Demodulate.
See Also ammod, ssbdemod, fmdemod, pmdemod,“Modulation”
2-12
ammod
Purpose Amplitude modulation
Syntax y = ammod(x,Fc,Fs)
y = ammod(x,Fc,Fs,ini_phase) y = ammod(x,Fc,Fs,ini_phase,carramp)
Description y = ammod(x,Fc,Fs) uses the message signal x to modulate a carrier
signal with frequency signal and has zero initial phase and zero carrier amplitude, so the result is suppressed-carrier modulation.
Note The x, Fc,andFs input arguments must satisfy Fs >2(Fc + BW), where
y = ammod(x,Fc,Fs,ini_phase) specifies the initial phase in the
modulated signal
x have sample frequency Fs (Hz). The modulated signal
BW is the bandwidth of the modulating signal x.
Fc (Hz) using amplitude modulation. The carrier
y in radians.
y = ammod(x,Fc,Fs,ini_phase,carramp) performs
transmitted-carrier modulation instead of suppressed-carrier modulation. The carrier amplitude is
carramp.
Examples The example below co m p are s double-sideband and single-sideband
amplitude modulation.
% Sample the signal 100 times per second, for 2 seconds. Fs = 100; t = [0:2*Fs+1]'/Fs; Fc = 10; % Carrier frequency x = sin(2*pi*t); % Sinusoidal signal
% Modulate x using single- and double-sideband AM. ydouble = ammod(x,Fc,Fs); ysingle = ssbmod(x,Fc,Fs);
2-13
ammod
% Compute spectra of both modulated signals. zdouble = fft(ydouble); zdouble = abs(zdouble(1:length(zdouble)/2+1)); frqdouble = [0:length(zdouble)-1]*Fs/length(zdouble)/2; zsingle = fft(ysingle); zsingle = abs(zsingle(1:length(zsingle)/2+1)); frqsingle = [0:length(zsingle)-1]*Fs/length(zsingle)/2;
% Plot spectra of both modulated signals. figure; subplot(2,1,1); plot(frqdouble,zdouble); title('Spectrum of double-sideband signal'); subplot(2,1,2); plot(frqsingle,zsingle); title('Spectrum of single-sideband signal');
See Also amdemod, ssbmod, fmmod, pmmod,“Modulation”
2-14
arithdeco
Purpose Decode binary code using arithmetic decoding
Syntax dseq = arithdeco(code,counts,len)
Description dseq = arithdeco(code,counts,len) decodes the binary arithmetic
code in the vector symbols. The vector counts represents the source’s statistics by listing the number of times each symbol of the source’s alphabet occurs in a test data set. This function assumes that the data in by the
arithenco function.
Examples This example is similar to the example on the arithenco reference
page,exceptthatituses
counts = [99 1]; % A one occurs 99% of the time. len = 1000; seq = randsrc(1,len,[1 2; .99 .01]); % Random sequence code = arithenco(seq,counts); dseq = arithdeco(code,counts,length(seq)); % Decode. isequal(seq,dseq) % Check that dseq matches the original seq.
code to recover the corresponding sequence of len
code was produced
arithdeco to recover the original sequence.
The output is
ans =
1
Algorithm This function uses the algorithm described in [1].
See Also arithenco,“ArithmeticCoding”
References [1] Sayood, Khalid, Introduction to Data Compression, San Francisco,
Morgan Kaufmann, 2000.
2-15
arithenco
Purpose Encode sequence of symbols using arithmetic coding
Syntax code = arithenco(seq,counts)
Description code = arithenco(seq,counts) generates the binary arithmetic
code corresponding to the sequence of symbols specified in the vector
seq.Thevectorcounts represents the source’s statistics by listing t he
number of times each symbol of the source’s alphabet occurs in a test data set.
Examples This example illustrates the compression that arithmetic coding can
accomplish in some situations. A source has a two-symbol alphabet and produces a test data set in which 99% of the sy mbols are 1s. Encoding 1000 symbols from this source produces a code vector having many fewer than 1000 elements. The actual number of elements in varies, depending on the particular random sequence contained in seq.
counts = [99 1]; % A one occurs 99% of the time. len = 1000; seq = randsrc(1,len,[1 2; .99 .01]); % Random sequence code = arithenco(seq,counts); s = size(code) % length of code is only 8.3% of length of seq.
code
The output is
s=
183
Algorithm This function uses the algorithm described in [1].
See Also arithdeco,“ArithmeticCoding”
References [1] Sayood, Khalid, Introduction to Data Compression, San Francisco,
Morgan Kaufmann, 2000.
2-16
Purpose Add white Gaussian noise to signal
Syntax y = awgn(x,snr)
y = awgn(x,snr,sigpower) y = awgn(x,snr,' y = awgn(x,snr,sigpower,s) y = awgn(x,snr,' y = awgn(...,powertype)
measured')
measured',state)
Description y = awgn(x,snr) adds white Gaussian noise to the vector signal x.
The scalar
x is complex, awgn adds complex noise. This syntax assumes that the
power of
y = awgn(x,snr,sigpower) is the same as the syntax above, except
that
y = awgn(x,snr,'measured') isthesameasy = awgn(x,snr),except
that
y = awgn(x,snr,sigpower,s) uses s, which is a random stream
handle, to generate random noise samples with randn. If s is an integer, then resets the state of randn to s. The latter usage is obsolete and may be removed in a future release. If you want to generate repeateable noise samples, then provide the handle of a random stream or use reset method on the default random stream.
snr specifies the signal-to-noise ratio per sample, in dB. If
x is 0 dBW.
sigpower is the power of x in dBW .
awgn measures the power of x before adding noise.
awgn
y = awgn(x,snr,'measured',state) is the same as y= awgn(x,snr,'
normal random number generator
measured'),exceptthatawgn first resets the state of
randn to the integer state.
Note This usage is deprecated and may be removed in a future release. Instead of
y = awgn(...,powertype) isthesameastheprevioussyntaxes,
except that the string
sigpower.Choicesforpowertype are 'db' and 'linear'.Ifpowertype
state,uses, as in the previous example.
powertype specifies the units of snr and
2-17
awgn
is 'db',thensnr is measured in dB and sigpower is meas ured in dBW. If
powertype is 'linear', snr is measured as a ratio and sigpower is
measured in watts.
Relationship Among SNR, Es/N0,andEb/N
For the relationships between SNR and other measures of the relative power of the noise, see “Describing the Noise Level of an AWGN Channel”.
0
Examples The commands below add white Gaussian noise to a sawtooth signal. It
then plots the original and noisy signals.
t = 0:.1:10; x = sawtooth(t); % Create sawtooth signal. y = awgn(x,10,'measured'); % Add white Gaussian noise. plot(t,x,t,y) % Plot both signals. legend('Original signal','Signal with AWGN');
2-18
Several other examples that illustrate the use of awgn are in “Getting Started”. The following demos also use
vitsimdemo,andscattereyedemo.
awgn: basicsimdemo,
See Also wgn, randn, bsc, “AWGN Channel”
awgn
2-19
bchdec
Purpose BCH decoder
Note bchdec will be removed in a future release. Use fec.bchdec
instead.
Syntax decoded = bchdec(code,n,k)
decoded = bchdec(...,paritypos) [decoded,cnumerr] = bchdec(...) [decoded,cnumerr,ccode] = bchdec(...)
Description decoded = bchdec(code,n,k) attempts to decode thereceivedsignal
in
code using an [n,k] BC H decoder with the narrow-sense generator
polynomial.
n-element row of code represents a corrupted systematic codeword,
where the parity symbols are at the end and the leftmost symbol is the most significant symbol.
code is a Galois array of symbols over GF(2). Each
2-20
In the Galois array decoding the corresponding row in if
bchdec detects more than t errors in a row of code,wheretisthe
number of correctable errors as reported by a decoding failure, merely removing
decoded = bchdec(...,paritypos) specifies whether the parity
symbols in
code were appended or prepended to the message in
the coding operation. The string
'beginning'. The default is 'end'.Ifparitypos is 'beginning',
then a decoding failure causes
decoded, each row represents the attempt at
code.Adecoding failure occurs
bchgenpoly.Inthecaseof
bchdec forms the corresponding row of decoded by
n-k symbols from the end of the row of code.
paritypos can be either 'end' or
bchdec to remove n-k symbols from the
beginning rather than the end of the row.
[decoded,cnumerr] = bchdec(...) returns a column vector cnumerr,
each element of which is the number of corrected errors in the corresponding row of decoding failure in that row in
code.Avalueof-1 in cnumerr indicates a
code.
[decoded,cnumerr,ccode] = bchdec(...) returns ccode,the
corrected version of as
code. If a decoding failure occurs in a certain row of code,the
corresponding row in
code. The Galois array ccode has the same format
ccode contains that row unchanged.
bchdec
Results of Error Correction
BCH decoders correct up to a certain number of errors, specified by the user. If the input contains more errors than the decoder is meant to correct, the decoder will most likely not output the correct codeword.
The chance of a BCH decoder decoding a corrupted input to the correct codeword depends on the number of errors in the input and the number of errors the decoder is meant to correct.
For example, when a single-error-correcting BCH decoder is given input with two errors, it actually decodes it to a different codeword. When a double-error-correcting BCH decoder is given input with three errors, then it only sometimes decodes it to a valid codeword.
The following code illustrates this phenomenon for a single-error-correcting BCH decoder given input with two errors.
n=63;k=57; msg = gf(randint(1, k, 2, 9973)); code = bchenc(msg, n, k);
% Add 2 errors cnumerr2 = zeros(nchoosek(n,2),1); nErrs = zeros(nchoosek(n,2),1); cnumerrIdx = 1; for idx1 = 1 : n-1
sprintf('idx1 for 2 errors = %d', idx1) for idx2 = idx1+1 : n
errors = zeros(1,n); errors(idx1) = 1; errors(idx2) = 1; erroredCode = code + gf(errors); [decoded2, cnumerr2(cnumerrIdx)]...
= bchdec(erroredCode, n, k);
2-21
bchdec
% If bchdec thinks it corrected only one error, % then encode the decoded message. Check that % the re-encoded message differs from the errored % message in only one coordinate. if cnumerr2(cnumerrIdx) == 1
code2 = bchenc(decoded2, n, k); nErrs(cnumerrIdx) = biterr(double(erroredCode.x),...
double(code2.x));
end
cnumerrIdx = cnumerrIdx + 1;
end
end
% Plot the computed number of errors, based on the difference % between the double-errored codeword and the codeword that was % re-encoded from the initial decoding. plot(nErrs) title(['Number of Actual Errors between Errored Codeword and' ...
'Re-encoded Codeword'])
2-22
The resulting plot shows that all inputs with two errors are decoded to a codeword that differs in exactly one position.
bchdec
Examples The script below encodes a (random) message, simulates the addition of
noise to the code, and then decodes the message.
m=4;n=2 k=5;%M nwords msg = gf % Find t
oly,t] = bchgenpoly(n,k);
[genp % Defi t2 = t;
%Enc code %Cor noi
ne t2, the number of errors to add in this example.
ode the message. = bchenc(msg,n,k); rupt up to t2 bits in each codeword.
sycode = code + randerr(nwords,n,1:t2);
^m-1; % Codeword length
essage length
= 10; % Number of words to encode
(randint(nwords,k)); , the error-correction capability.
2-23
bchdec
% Decode the noisy code. [newmsg,err,ccode] = bchdec(noisycode,n,k); if ccode==code
disp('All errors were corrected.') end if newmsg==msg
disp('The message was recovered perfectly.') end
In this case, all errors are corrected and the message is recovered perfectly. However, if you change the definition of
t2 = t+1;
then some codewords w ill contain more than t errors. This is too many errors, and some are not corrected.
Algorithm bchdec uses the Berlekamp-Massey decoding algorithm. For
information about this algorithm, see the works listed in “References” on page 2-24.
t2 to
Limitations The maximum allowable value of n is 65535.
See Also bchenc, bchgenpoly,“BlockCoding”
References [1] Wicker, Stephen B., Error Control Systems for Digital
Communication and Storage,UpperSaddleRiver,NJ,PrenticeHall,
1995.
[2] Berlekamp, Elwyn R., Algebraic Coding Theory,NewYork, McGraw-Hill, 1968.
2-24
bchenc
Purpose BCH encoder
Note bchenc will be removed in a future release. Use fec.bchenc
instead.
Syntax code = bchenc(msg,n,k)
code = bchenc(...,paritypos)
Description code = bchenc(msg,n,k) encodes the mess ag e in msg using an [n,k]
BCH encoder with the narrow-sense generator polynomial. a Galois array o f symbols over GF(2). Each represents a mes sage word, where the leftmost symbol is the most significant symbol. Parity symbols are at the end of each word in the output Galois array
code = bchenc(...,paritypos) specifies whether bchenc appends or
prepends the parity symbols to the input message to form string
'end'.
paritypos can be either 'end' or 'beginning'. The default is
code.
k-element row of msg
msg is
code.The
The tables below list valid [ the corresponding values of the error-correction capability,
n
7
n
15
15 7 2
15 5 3
n,k] pairs for small values of n,aswellas
k
41
k
11 1
t.
t
t
2-25
bchenc
n
31 26
31 21 2
31 16 3
31
31 6 7
n
63 57
63 51 2
63 45 3
63 39
63 36 5
63 30 6
63 24 7
63 18 10
63 16
63 10 13
63715
k
11
k
t
1
5
t
1
4
11
2-26
bchenc
n
127 120
127 113 2
127 106 3
127 99
127 92 5
127 85 6
127 78 7
127 71 9
127 64 10
127 57
127 50 13
127 43
127 36 15
127 29 21
127 22 23
127 15 27
127 8 31
k
t
1
4
11
14
n
255 247
255 239 2
255 231 3
255 223
k
t
1
4
2-27
bchenc
n
255 215 5
255 207 6
255 199 7
255 191 8
255 187 9
255 179 10
255 171
255 163 12
255 155 13
255 147
255 139 15
255 131 18
255 123 19
255 115 21
255 107 22
255 99 23
255 91 25
255 87 26
255 79 27
255 71 29
255 63 30
255 55 31
255 47 42
255 45 43
255 37 45
k
11
14
t
2-28
bchenc
n
255 29 47
255 21 55
255 13 59
255 9 63
n
511 502
511 493 2
511 484 3
511 475
511 466 5
511 457 6
511 448 7
511 439 8
511 430 9
511 421 10
511 412
511 403 12
511 394 13
511 385
511 376 15
511 367 16
511 358 18
k
k
t
t
1
4
11
14
2-29
bchenc
n
511 349 19
511 340 20
511 331 21
511 322 22
511 313 23
511 304 25
511 295 26
511 286 27
511 277 28
511 268 29
511 259 30
511 250 31
511 241 36
511 238 37
511 229 38
511 220 39
511 211
511 202 42
511 193 43
511 184 45
511 175 46
511 166 47
511 157 51
511 148 53
511 139 54
k
41
t
2-30
bchenc
n
511 130 55
511 121 58
511 112 59
511 103 61
511 94 62
511 85 63
511 76 85
511 67 87
511 58 91
511 49 93
511 40 95
51131109
511 28
51119119
51110121
k
t
111
Examples Seetheexampleonthereferencepageforthefunctionbchdec.
Limitations The maximum allowable value of n is 65535.
See Also bchdec, bchgenpoly, bchnumerr,“BlockCoding”
2-31
bchgenpoly
Purpose Generator polynomial of BCH code
Syntax genpoly = bchgenpoly(n,k)
genpoly = bchgenpoly(n,k,prim_poly) [genpoly,t] = bchgenpoly(...)
Description genpoly = bchgenpoly(n,k) returns the narrow-sense generator
polynomial of a BCH code with codeword length
k. The codeword length n must have the form 2
The output
genpoly is a Galois row vector in GF(2) that represents the
coefficients o f the generator polynomial in order of descending powers. The narrow-sense generator polynomial is LCM[m_1(x), m_2(x), ..., m_2t(x)], where LCM is the least common multiple, m_i(x) is the minimum polynomial corresponding to α primitive polynomial for the field GF(
i
, α is a root of the default
n+1), and t is the error-correcting
capability of the code.
Note Although the bchgenpoly function performs intermediate computations in GF( The output from in GF(
n+1).
n+1), the final polynomial has binary coefficients.
bchgenpoly is a Galois vector in GF(2) rather than
n and message length
m
-1 for some integer m.
genpoly = bchgenpoly(n,k,prim_poly) is the same as the syntax
above, except that GF(
n+1) that has A as a root. prim_poly is an integer whose binary
prim_poly specifies the pr imitive polynomial for
representation indicates the co efficients of the primitive polynomial. To use the default primitive polynomial for GF(
[genpoly,t] = bchgenpoly(...) returns t, the error-correction
n+1), set prim_poly to [].
capability of the code.
Examples The results below show that a [15,11] BCH code can correct one error
and has a generator polynomial X
m=4;
2-32
4
+X+1.
n = 2^m-1; % Codeword length k = 11; % Message length % Get generator polynomial and error-correction capability. [genpoly,t] = bchgenpoly(n,k)
The output is
genpoly = GF(2) array.
Array elements =
10011
t=
1
Limitations The maximum allowable value of n is 511.
bchgenpoly
See Also bchenc, bchdec, bchnumerr,“BlockCoding”
References [1] Peterson, W. Wesley, and E. J. Weldon, Jr., Error-Correcting Codes,
2nd ed., Cambridge, MA, MIT Press, 1972.
2-33
bchnumerr
Purpose Number of correctable errors for BCH code
Syntax T = bchnumerr(N)
T = bchnumerr(N, K)
Description T = bchnumerr(N) returns all the possible combinations of message
length, codeword length, between 3 and 16. lists
T = bchnumerr(N, K) returns the number of correctable errors, t,
for an
See Also bchenc, bchdec, bchgenpoly
K, and number of correctable errors, t, for a BCH code of
N. N must have the form 2
T is a matrix with three columns. The first column
N, the second column lists K, and the third column lists t.
(N, K) BCH code.
m
-1 for some integer, m ,
2-34
Purpose Bit error rate (BER) for uncoded AWGN channels
Syntax ber = berawgn(EbNo,'pam',M)
ber = berawgn(EbNo,' ber = berawgn(EbNo,' ber = berawgn(EbNo,' ber = berawgn(EbNo,' ber = berawgn(EbNo,' ber = berawgn(EbNo,' ber = berawgn(EbNo,' ber = berawgn(EbNo,' berlb = berawgn(EbNo,' [BER,SER] = berawgn(EbNo, ...)
qam',M) psk',M,dataenc) oqpsk',dataenc) dpsk',M) fsk',M,coherence) fsk',2,coherence,rho) msk',precoding) msk',precoding,coherence)
cpfsk',M,modindex,kmin)
berawgn
Graphical Interface
As an alternative to the berawgn function, invoke the BERTool GUI (
bertool), and u se the Theoretical tab.
Description For All Syntaxes
The berawgn function returns the BER of various modulation schemes over an additive white Gaussian noise (AWGN) channel. The first input argument, density, in dB. If size, whose elements corres po nd to the different E supported modulation schemes, which corre spond to the second input argument to the function, are in the following table.
Modula
Phase
Offs keyi
Dif (DP
tion Scheme
shift keying (PSK)
et quaternary phase shift
ng (OQPSK)
ferential phase shift keying
SK)
EbNo, is the ratio of bit energy to noise power spectral
EbNo is a vector, the output ber is a vector of the same
Second
'psk'
sk
'oqp
'
sk
'dp
levels. The
b/N0
Input Argument
'
2-35
berawgn
Modulation Scheme Second Input Argument
Pulse amplitude modulation
'pam'
(PAM)
Quadrature amplitude
'qam'
modulation (QAM)
Frequency shift keying (FSK)
Minimum shift keying (MSK)
Continuous phase frequency shift
'fsk'
'msk'
'cpfsk'
keying (CPFSK)
Most syntaxes also have an M inputthatspecifiesthealphabetsize for the modulation.
k. For all cases, the function assumes the use of a Gray-coded signal
M must have the form 2
k
for some positive integer
constellation.
For Specific Syntaxes
ber = berawgn(EbNo,'pam',M) returns the BER of uncoded PAM over
an AWGN channel with coherent demodulation.
ber = berawgn(EbNo,'qam',M) returns the BER of uncoded QAM over
an AWGN channel with coherent demodulation. The alphabet size,
must be at least 4. When
of size
ber = berawgn(EbNo,'psk',M,dataenc) returns the BER of coherently
MIJ
is used, where
kM= log
detected uncoded PSK over an AWGN channel.
'diff' for differential data encoding or 'nondiff' for nondifferential
data encoding. If
ber = berawgn(EbNo,'oqpsk',dataenc) returns the B ER of coherently
dataenc is 'diff', M must be no greater than 4.
is odd, a rectangular constellation
2
Ik=−2
1
2
and
Jk=+2
1
2
.
dataenc is either
M,
detected offset-QPSK over an uncoded AWGN channel.
ber = berawgn(EbNo,'dpsk',M) returns the BER of uncoded DPSK
modulation over an AWGN channel.
2-36
berawgn
ber = berawgn(EbNo,'fsk',M,coherence) returns the BER of
orthogonal uncoded FSK modulation over an AWGN channel.
coherence is either 'coherent' for coherent demodulation or 'noncoherent' for noncoherent demodulation. M must be no greater
than 64 for
ber = berawgn(EbNo,'fsk',2,coherence,rho) returns the BER for
binary nonorthogonal FSK over an uncoded AWGN channel, where
rho is the complex correlation coefficient. See “Nonorthogonal 2-FSK
with Coherent Detection” for the definition of the complex correlation coefficient and how to compute it for nonorthogonal BFSK .
ber = berawgn(EbNo,'msk',precoding) returns the BER of coherently
detected MSK modulation over an uncoded AWGN channel. Setting
precoding to 'off' returns results for conventional MSK while setting precoding to 'on' returns results for precoded MSK.
ber = berawgn(EbNo,'msk',precoding,coherence) specifies whether
the detection is coherent or noncoherent.
berlb = berawgn(EbNo,'cpfsk',M,modindex,kmin) returns a low er
bound on the BER of uncoded CPFSK modulation over an AWGN channel.
kmin is the number of paths having the minimum distance; if this
number is unknown, you can assume a value of 1.
'noncoherent'.
modindex is the modulation index, a positive real number.
[BER,SER] = berawgn(EbNo, ...) returns both the BER and SER.
Examples An example using this function is in “Comparing Theoretical and
Empirical Error Rates”.
Limitations The numerical accuracy of this function’s output is limited by
approximations related to the numerical implementation of the expressions.
You can generally rely on the first couple of significant digits of the function’s output.
2-37
berawgn
See Also bercoding, berfading, bersync, “Theoretical Performance Results”,
Analytical Expressions U sed in berawgn, bercoding, berfading, and BERTool
References [1] Anderson, John B., Tor Aulin, and Carl-Erik Sundberg, Digital
Phase Modulation,NewYork,PlenumPress,1986.
[2] Cho, K., and Yoon, D., “On the general BER expression of one- and two-dimensional amplitude modulations”, IEEE Trans. Commun.,Vol. 50, Number 7, pp. 1074-1080, 2002.
[3] Lee, P. J., “Computation of the bit error rate of coherent M-ary PSK with Gray code bit mapping”, IEEE Trans. Commun., Vol. COM-34, Number 5, pp. 488-491, 1986.
[4] Proakis,J.G.,Digital Communications, 4th ed., McGraw-Hill, 2001.
[5] Simon, M. K, Hinedi, S. M ., and Lindsey, W . C., Digital Communication Techniques – Signal Design and Detection, Prentice-Hall, 1995.
2-38
[6] Simon, M. K, “On the bit-error probability of differentially encoded QPSK and offset QPSK in the presence of carrier synchronization”, IEEE Trans. Commun., Vol. 54, pp. 806-812, 2006.
[7] Lindsey, W. C., and Simon, M. K, Telecommunication Systems Engineering, Englewood Cliffs, N.J., Prentice-Hall, 1973.
bercoding
Purpose Bit error rate (BER) for coded AWGN channels
Syntax berub = bercoding(EbNo,'conv',decision,coderate,dspec)
berub = bercoding(EbNo,' berub = bercoding(EbNo,' berapprox = bercoding(EbNo,' berub = bercoding(EbNo,' berapprox = bercoding(EbNo,'
block','hard',n,k,dmin) block','soft',n,k,dmin)
Hamming','hard',n)
Golay','hard',24)
RS','hard',n,k)
Graphical Interface
As an alternative to the bercoding function, invoke the BERTool GUI (
bertool) and use the Theoretical tab.
Description berub = bercoding(EbNo,'conv',decision,coderate,dspec)
returnsanupperboundorapproximationontheBERofabinary convolutional code with coherent phase shift keying (PSK ) modulation over an additive white Gaussian noise (AWGN) channel. ratio of bit energy to noise power spectral density, in dB. If vector, to the different E
decision to 'hard'; to specify soft-decision decoding, set decision to 'soft'. The convolutional code has code rate equal to coderate.The dspec input is a structure that contains information about the code’s
berub is a vector of the same size, whose elem ents correspond
levels. To specify hard-decision decoding, set
b/N0
distance spectrum:
dspec.dfree is the minimum free distance of the code.
dspec.weight is the weight spectrum of the code.
To find distance spectra for some sample codes, use the function or see [5] and [3].
Note The results for binary PSK and quaternary PSK modula tion are the same. This function does not support M-ary PSK when M is other than 2 or 4.
EbNo is the
EbNo is a
distspec
2-39
bercoding
berub = bercoding(EbNo,'block','hard',n,k,dmin) returns an
upper bound on the BER of an [ decoding and coherent BPSK or Q PSK modulation.
n,k] binary block code with hard-decision
dmin is the
minimum distance of the code.
berub = bercoding(EbNo,'block','soft',n,k,dmin) returns an
upper bound on the BER of an [ decoding and coherent BPSK or Q PSK modulation.
n,k] binary block code with soft-decision
dmin is the
minimum distance of the code.
berapprox = bercoding(EbNo,'Hamming','hard',n) returns an
approximation of the BER of a Hamming code using hard-decision decoding and coherent BPSK modulation. (For a Hamming code, if n is known, then k can be computed directly from n.)
berub = bercoding(EbNo,'Golay','hard',24) returns an upper
bound of the BER of a Golay code using hard-decision decoding and coherent BPSK modulation. Support for Golay currently is only for n=24. In accordance with [3], the Golay coding upper bound assumes only the correction of 3-error patterns. Even though it is theoretically possible to correct approximately 19% of 4-error patterns, most decoders in practice do not have this capability.
berapprox = bercoding(EbNo,'RS','hard',n,k) returns an
approximation of the BER of (n,k) Reed-Solomon code using hard-decision decoding and coherent BPSK modulation.
Examples An example using this function for a convolutional code is in “Plotting
Theoretical Error Rates”.
The following example finds an upper bound on the theoretical BER of a block code. It also uses the
n = 23; k = 12; % Lengths of codewords and messages dmin = 7; % Minimum distance EbNo = 1:10; ber_block = bercoding(EbNo,'block','hard',n,k,dmin); berfit(EbNo,ber_block) % Plot BER points and fitted curve. ylabel('Bit Error Probability');
2-40
berfit function to perform curve fitting.
bercoding
title('BER Upper Bound vs. Eb/No, with Best Curve Fit');
Limitations The numerical accuracy of this function’s output is limited by
Approximati on s in the analysis l ea ding to the closed-form expressions
that the function uses
Approximations related to the numerical implementation of the
expressions
You can generally rely on the first couple of significant digits of the function’s output.
See Also berawgn, berfading, bersync, distspec, “Theoretical Performance
Results” Analytical Expressions Usedinberawgn,bercoding,berfading, and BERTool
2-41
bercoding
References [1] Proakis, J. G., Digital Communications,4thed.,NewYork,
McGraw-Hill, 2001.
[2] Frenger, P., P. Orten, and T. Ottosson, “Convolutional Codes with Optimum Distance Spectrum,” IEEE Communications Letters,Vol. 3, No. 11, Nov. 1999, pp. 317–319.
[3] Odenwalder, J. P., Error Control Coding Handbook,FinalReport, LINKABIT Corporation, San Diego, CA, 1976.
[4] Sklar, B., Digital Communications, 2nd ed., Prentice Hall, 2001.
[5] Ziemer, R. E., and R. L., Peterson, Introduction to Digital Communication, 2nd ed., Prentice Hall, 2001.
2-42
berconfint
Purpose Bit error rate (BER) and confidence interval of Monte Carlo simulation
Syntax [ber,interval] = berconfint(nerrs,ntrials)
[ber,interval] = berconfint(nerrs,ntrials,level)
Description [ber,interval] = berconfint(nerrs,ntrials) returns the error
probability estimate Monte Carlo simulation of is a two-element vector that lists the endpoints of the interval. If the errors and trials are measured in bits, the error probability is the bit error rate (BER); if the errors and trials are measured in symbols, the error probability is the symbol error rate (SER).
[ber,interval] = berconfint(nerrs,ntrials,level) specifies the
confidence level as a real number between 0 and 1.
ber and the 95% confidence interval interval for a
ntrials trials with nerrs errors. interval
Examples If a simulation of a communication system results in 100 bit errors in
6
10
trials, the BER (bit error rate) for that simulation is the quotient
-4
10
. The command below finds the 95% confidence interval for the
BER of the system.
nerrs = 100; % Number of bit errors in simulation ntrials = 10^6; % Number of trials in simulation level = 0.95; % Confidence level [ber,interval] = berconfint(nerrs,ntrials,level)
The output below shows that, with 95% confidence, the BER for the system is between 0.0000814 and 0.0001216.
ber =
1.0000e-004
interval =
1.0e-003 *
2-43
berconfint
0.0814 0.1216
For an example that uses the output of berconfint to plot error bars on a BER plot, see “Example: Curve Fitting for an Error Rate Plot”
See Also binofit (Statistics Toolbox), mle (Statistics Toolbox), “Performance
Evaluation”
References [1] Jeruchim, Michel C., Philip Balaban, and K. Sam Shanmugan,
Simulation of Communication Systems, Second Edition, New York, Kluwer Academic/Plenum, 2000.
2-44
Purpose Bit error rate (BER) for Rayleigh and Rician fading channels
Syntax ber = berfading(EbNo,'pam',M,divorder)
ber = berfading(EbNo,'qam',M,divorder) ber = berfading(EbNo,'psk',M,divorder) ber = berfading(EbNo,'depsk',M,divorder) ber = berfading(EbNo,'oqpsk',divorder) ber = berfading(EbNo,'dpsk',M,divorder) ber = berfading(EbNo,'fsk',M,divorder,coherence) ber = berfading(EbNo,'fsk',2,divorder,coherence,rho) ber = berfading(EbNo,...,K) ber = berfading(EbNo,'psk',2,1,K,phaserr) [BER,SER] = berfading(EbNo, ...)
berfading
Graphical Interface
As an alternative to the berfading function, invoke the BERTool GUI (
bertool), and u se the Theoretical tab.
Description For All Syntaxes
The first input argument, EbNo, is the ratio of bit energy to noise power spectral density, in dB. If thesamesize,whoseelementscorrespondtothedifferentE
Most syntaxes also have a n the modulation.
berfading uses expressions that assume Gray coding. If you use binary
coding, the results may differ.
For cases where diversity is used, the SNR on each diversity branch is
EbNo/divorder,wheredivorder is the diversity order (the number of
diversity branches) and is a positive integer.
For Specific Syntaxes
ber = berfading(EbNo,'pam',M,divorder) returns the BER for PAM
over an uncoded Rayleigh fading channel with coherent demodulation.
ber = berfading(EbNo,'qam',M,divorder) returns the BER for QAM
over an uncoded Rayleigh fading channel with coherent dem odulation.
M must have the form 2
EbNo is a vector, the output ber is a vector of
levels.
b/N0
M inputthatspecifiesthealphabetsizefor
k
for some positive integer k.
2-45
berfading
The alphabet size, M,mustbeatleast4. When
rectangular constellation of size
1
2
Jk=+2
and
ber = berfading(EbNo,'psk',M,divorder) returns the BER for
.
MIJ
kM= log
2
is used, where
is odd, a
2
Ik=−2
1
coherently detected PSK over an uncoded Rayleigh fading channel.
ber = berfading(EbNo,'depsk',M,divorder) returns the BER
for coherently detected PSK with differential data encoding over an uncoded Rayleigh fading channel. Only M = 2 is currently supported.
ber = berfading(EbNo,'oqpsk',divorder) returns the BER of
coherently detected offset-QPSK over an uncoded Rayleigh fading channel.
ber = berfading(EbNo,'dpsk',M,divorder) returns the BER for
DPSK over an uncoded Rayleigh fading channel. For DPSK, it is assumed that the fading is slow enough that two consecutive symbols are affected by the same fading coefficient.
ber = berfading(EbNo,'fsk',M,divorder,coherence) returns
the BER for orthogonal FSK over an uncoded Rayleigh fading channel.
'noncoherent' for noncoherent detection.
coherence should be 'coherent' for coherent detection, o r
2-46
ber = berfading(EbNo,'fsk',2,divorder,coherence,rho) returns
the BER for binary nonorthogonal FSK over an uncoded Rayleigh fading channel.
rho is the complex correlation coefficient. See “Nonorthogonal
2-FSK with Coherent Detection” for the definition of the complex correlation coefficient and how to compute it for nonorthogonal BFSK.
ber = berfading(EbNo,...,K) returns the BER over an uncoded
Rician fading channel, where in linear scale. For the case of
ber = berfading(EbNo,'psk',2,1,K,phaserr) returns the BER of
K is the ratio of specular to diffuse energy
'fsk', rho must be specified before K.
BPSK over an uncoded Rician fading channel with imperfect phase
berfading
synchronization. phaserr is the standard deviation of the reference carrier phase error in radians.
[BER,SER] = berfading(EbNo, ...) returns both the BER and SER.
Examples The following example computes and plots the BER for uncoded DQPS K
(differential quaternary phase shift keying) modulation over an flat Rayleigh fading channel.
EbNo = 8:2:20; M = 16; % Use 16 QAM L = 1; % Start without diversity ber = berfading(EbNo,'qam',M,L); semilogy(EbNo,ber); text(18.5, 0.02, sprintf('L=%d', L)) hold on % Loop over diversity order, L, 2 to 20 for L=2:20
ber = berfading(EbNo,'qam',M,L);
semilogy(EbNo,ber); end text(18.5, 1e-11, sprintf('L=%d', L)) title('QAM over fading channel with diversity order 1 to 20') xlabel('E_b/N_o (dB)') ylabel('BER') grid on
2-47
berfading
Limitations The numerical accuracy of this function’s output is limited by
approximations related to the numerical implementation of the expressions
You can generally rely on the first couple of significant digits of the function’s output.
See Also berawgn, bercoding, bersync, “Theoretical Performance Results”
Analytical Expressions U sed in berawgn, bercoding, berfading, and BERTool
roakis, John G., Digital Communications, 4th ed., New York,
[1] P
aw-Hill, 2001.
McGr
odestino, James W., and Mui, Shou Y., Convolutional code
[2] M
formance in the Rician fading channel, IEEE Trans. Commun., 1976.
per
2-48
Refe
rences
berfading
[3] Cho, K., and Yoon, D., “On the general BER expression of one- and two-dimensional amplitude modulations”, IEEE Trans. Commun.,Vol. 50, Number 7, pp. 1074-1080, 2002.
[4] Lee, P. J., “Computation of the bit error rate of coherent M-ary PSK with Gray code bit mapping”, IEEE Trans. Commun., Vol. COM-34, Number 5, pp. 488-491, 1986.
[5] Lindsey, W. C., “Error probabilities for Rician fading multichannel reception of binary and N-ary signals”, IEEE Trans. Inform. Theory, Vol. IT-10, pp. 339-350, 1964.
[6]Simon,M.K,Hinedi,S.M.,andLindsey,W.C.,Digital Communication Techniques – Signal Design and Detection, Prentice-Hall, 1995.
[7] Simon, M. K., and Alouini, M. S., Digital Communication over Fading Channels – A Unified Approach to Performance Analysis,1st ed., Wiley, 2000.
[8] Simon,M.K,“Onthebit-errorprobability of differentially encoded QPSK and offset QPSK in the presence of carrier synchronization”, IEEE Trans. Commun., Vol. 54, pp. 806-812, 2006.
2-49
berfit
Purpose Fit curve to nonsmooth empirical bit error rate (BER) data
Syntax fitber = berfit(empEbNo,empber)
fitber = berfit(empEbNo,empber,fitEbNo) fitber = berfit(empEbNo,empber,fitEbNo,options) fitber = berfit(empEbNo,empber,fitEbNo,options,fittype) [fitber,fitprops] = berfit(...) berfit(...) berfit(empEbNo,empber,fitEbNo,options,
Description fitber = berfit(empEbNo,empber) fits a curve to the empirical BER
data in the vector (BER) points. The values in E
values, in dB, given by empEbNo.ThevectorempEbNo must be in
b/N0
ascending order and must have at least four elements.
Note The berfit function is intended for curve fitting or interpolation, not extrapolation. Extrapolating BER data beyond an order of magnitude below the smallest empirical BER value is inherently unreliable.
empber and returns a vector of fitted bit error rate
empber and fitber correspond to the
'all')
2-50
fitber = berfit(empEbNo,empber,fitEbNo) fits a curve to the
empirical BER data in the vector
empber corresponding to the E
b/N0
values, in dB, given by empEbNo. The function then evaluates the curve at the E points. The length of
fitber = berfit(empEbNo,empber,fitEbNo,options) uses the
structure These options are the ones used by the create the
values, in dB, given by fitEbNo and returns the fitted BER
b/N0
options to override the default options used for optimization.
options structure using the optimset function. Particularly
fitEbNo must equal or exceed that of empEbNo.
fminsearch function. You can
relevant fields are described in the table below.
berfit
Field
options.Display
options.MaxFunEvals
options.MaxIter
options.TolFun
options.TolX
Description
Level of display: 'off' (default) displays no output;
'iter'
displays output at each iteration;
'final' displays only the final
output;
'notify' displays output
only if the function does not converge.
Maximum number of function evaluations before optimization ceases. The default is 10
4
.
Maximum number of iterations before optimization ceases. The default is 10
4
.
Termination tolerance on the closed-form function used to generate the fit. The default is
-4
10
.
Termination tolerance on the coefficient values of the closed-form function used to generate the fit. The default is
-4
10
.
fitber = berfit(empEbNo,empber,fitEbNo,options,fittype)
specifies which closed-form function berfit uses to fit the empirical data, from the possible fits listed in “Algorithm” on page 2-53 below.
'doubleExp+const'. To avoid overriding default optimization options,
use
[fitber,fitprops] = berfit(...) returns the MATLAB structure fitprops, which describes the results of the curve fit. Its fields are
fittype can be 'exp', 'exp+const', 'polyRatio',or
options = [].
described in the table below.
2-51
berfit
Field
fitprops.fitType
fitprops.coeffs
fitprops.sumSqErr
fitprops.exitState
fitprops.funcCount
fitprops.iterations
Description
The closed-form function type used to generate the fit:
'exp+const', 'polyRatio',or 'doubleExp+const'.
'exp',
Thecoefficientsusedtogenerate the fit. If the function cannot find a valid fit,
fitprops.coeffs
is an empty vector.
The sum squared error between the log of the fitted BER points and the log of the empirical BER points.
The exit condition of berfit:
'The curve fit converged to a solution.' maximum number of function evaluations was exceeded.'
or
'No desirable fit was
found'
.
, 'The
,
The number of function evaluations used in minimizing the sum squared error function.
The number of iterations taken in minimizing the sum squared error function. This is not necessarily equal to the numb er of function evaluations.
2-52
berfit(...) plots the empirical and fitted BER data.
berfit(empEbNo,empber,fitEbNo,options,'all') plots the empirical
and fitted BER data from all the possible fits, listed in the “Algorithm”
berfit
on page 2-53 below, that return a valid fit. To avoid overriding default options, use
Note Avalidfitmustbe
real-valued
monotonically decreasing
greater than or equal to 0 and less than or equal to 0.5
If a fit does not confirm to this criteria, it is rejected.
Algorithm The berfit function fits the BER data using unconstrained nonlinear
optimization via the that
berfit considers are listed in the table below, where x is the
E
b/N0
functions were empirically found to provide close fits in a wide variety of situations, including exponentiallydecayingBERs,linearlyvarying BERs, and BER curves with error rate floors.
options = [].
fminsearch function. The closed-form functions
in linear terms (not dB) and f is the estimated BER. These
Value of f ittype
'exp'
'exp+const'
Functional Expression
a
4
a
fx
()
fx
()
axa
exp{ [( ) ]}
−−
12
=
axa
12
=
a
exp[ ( ) ]
−−
a
4
3
3
a
+
5
2-53
berfit
Value of f ittype
'polyRatio'
'doubleExp+const'
Functional Expression
2
ax ax a
++
1
fx
()=
3
xaxaxa
axa
exp
−−
12
()
a
4
axa
exp
56
+
23
2
+++
4
56
a
3
⎤ ⎥
−−
()
a
8
a
7
⎤ ⎥
+
a
9
The sum squared error function that fminsearch attempts to minimize is
F =−
[log( ) log( )]empirical BER fitted BER
2
where the fitted BER points are the values in fitber and the sum is over the E
points given in empEbNo. It is important to use the
b/N0
log of the BER values rather than the BER values themselves so that the high-BER regions do not dominate the objective function inappropriately.
Examples The examples below illustrate the syntax of the function, but they use
hard-coded or theo retical BER data for simplicity. For an example that uses empirical BER data from a simulation, see “Example: Curve Fitting for an Error Rate Plot”.
The code below plots the best fit for a sample set of data.
EbNo = 0:13;
berdata = [.2 .15 .13 .12 .08 .09 .08 .07 .06 .04 .03 .02 .01 .004];
berfit(EbNo,berdata); % Plot the best fit.
2-54
berfit
The curve at the va like uses mor fit exp
The nex floor. with a MMSE e optio
'exp 'pol
EbNo = -10:3:15;
empBER = [0.3361 0.3076 0.2470 0.1878 0.1212 0.0845 0.0650 0.0540 0.0474];
connects the points created by evaluating the fit expression
lues in
fit(EbNo,berdata,[0:0.2:13])
ber
EbNo. To make the curve look smoother, use a syntax
. This alternative syntax
e points when plotting the curve, but it does not change the
ression.
t example demonstrates a fit for a BER curve with an error
We generate the empirical BER array by simulating a channel
null (
ch = [0.5 0.47]) with BPSK modulation and linear
qualizer at the receiver. We run the berfit with the
n. The
' yRatio'
'doubleExp+const' fit does not provide a valid fit, and the
fit type does not work well for this data. The 'exp+const' and
fits closely match the simulated data.
'all'
2-55
berfit
figure; berfit(EbNo, empBER, [], [], 'all');
2-56
The following code illustrates the use of the options input structure as well as the
fitprops output structure. The 'notify' value for the
display level causes the function to produce output when one of the attempted fits does not converge. The
exitState field of the output
structure also indicates which fit converges and which fit does not.
M = 4; EbNo = 3:10; berdata = berfading(EbNo,'psk',M,2); % Compute theoretical BER. noisydata = berdata.*[.93 .92 1 .59 .08 .15 .01 .01]; % Say when fit fails to converge. options = optimset('display','notify');
disp('*** Trying exponential fit.') % Poor fit [fitber1,fitprops1] = berfit(EbNo,noisydata,EbNo,...
berfit
options,'exp')
disp('*** Trying polynomial ratio fit.') % Good fit [fitber2,fitprops2] = berfit(EbNo,noisydata,EbNo,...
options,'polyRatio')
Theoutputisasfollows:
*** Trying exponential fit.
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option. Current function value: 2.729948
fitber1 =
0.0766 0.0423 0.0205 0.0086 0.0030 0.0009 0.0002 0.00
fitprops1 =
fitType: 'exp'
coeffs: [4x1 double]
sumSqErr: 2.7299
exitState: 'The maximum number of function evaluations...
has been exceeded'
funcCount: 10000
iterations: 6177
*** Trying polynomial ratio fit.
fitber2 =
0.0931 0.0476 0.0220 0.0090 0.0031 0.0008 0.0001 0.00
2-57
berfit
fitprops2 =
fitType: 'polyRatio'
coeffs: [6x1 double]
sumSqErr: 2.0578 exitState: 'The curve fit converged to a solution' funcCount: 580
iterations: 344
See Also fminsearch, optimset, “Performance Evaluation”
References For a general description of unconstrained nonlinear optimization, see
the following work.
[1] Chapra, Steven C., and Raymond P. Canale, Numerical Methods for Engineers, Fourth Edition, New York, McGraw-Hill, 2002.
2-58
Purpose Bit error rate (BER) for imperfect synchronization
Syntax ber = bersync(EbNo,timerr,'timing')
ber = bersync(EbNo,phaserr,
'carrier')
bersync
Graphical Interface
As an alternative to the bersync function, invoke the BERTool GUI (
bertool) and use the Theoretical tab.
Description ber = bersync(EbNo,timerr,'timing') returns the BER of uncoded
coherent binary phase shift keying (BPSK) m odulation over an additive white Gaussian noise (AWGN) channel with imperfect timing. The normalized timing error is assumed to have a Gaussian distribution.
EbNo is the ratio of bit energy to noise power spectral density, in
dB. If
EbNo is a vector, the output ber is a vector of the same size,
whose elements correspond to the different E the standard deviation of the timing error, normalized to the symbol interval.
ber = bersync(EbNo,phaserr,'carrier') returns the BER of uncoded
BPSK modulation over an AWGN channel with a noisy phase re fere nce. The phase error is assumed to have a Gaussian distribution. is the standard deviation of the error in the reference carrier phase, in radians.
timerr must be between 0 and 0.5.
levels. timerr is
b/N0
phaserr
Examples The code below computes the BER of coherent BPSK modulation over an
AWGN channel with imperfect timing. The example varies both and timerr.(Whentimerr assumes the final value of zero, the bersync command produces the same result as berawgn(EbNo,'psk',2).)
EbNo = [4 8 12]; timerr = [0.2 0.07 0]; ber = zeros(length(timerr), length(EbNo)); for ii = 1:length(timerr)
ber(ii,:) = bersync(EbNo, timerr(ii),'timerr'); end % Display result using scientific notation. format short e; ber
EbNo
2-59
bersync
format; % Switch back to default notation format.
The output is below, where each row c orresponds to a different value of
timerr and each column corresponds to a different value of EbNo.
ber =
5.2073e-002 2.0536e-002 1.1160e-002
1.8948e-002 7.9757e-004 4.9008e-006
1.2501e-002 1.9091e-004 9.0060e-009
Limitations The numerical accuracy of this function’s output is limited by
Approximati on s in the analysis l ea ding to the closed-form expressions
that the function uses
Approximations related to the numerical implementation of the
expressions
You can generally rely on the first couple of significant digits of the function’s output.
Limitations Related to Extreme Values of Input Arguments
Inherent limitations in numerical precision force the function to assume perfect synchronization if the value of small. The table below indicates how the function behaves under these conditions.
Condition
timerr < eps bersync(EbNo,timerr,'timing')
phaserr < eps bersync(EbNo,phaserr,'carrier')
Algorithm This function uses formulas from [3].
When the last input is
2-60
'timing', the function computes
timerr or phaserr is very
Behavior of Function
defined as berawgn(EbNo,'psk',2)
defined as berawgn(EbNo,'psk',2)
bersync
1
exp( ) exp( ) exp( )
∫∫
−∞
4
πσ
2
ξ
−−+
2
R 22R
σ
212
2
ξ
()
2
x
dxd
2
ξ
22
1
π
2
x
2
where σ is the timerr input and R is the value of EbNo converted from dB to a linear scale.
When the last input is
∞∞
1
exp( ) exp( )
∫∫
0
πσ
φ
−−
2
σ
'carrier', the function computes
2
2
φ
cos
R
2
2
y
dyd
φ
2
where σ is the phaserr input and R is the value of EbNo converted from dB to a linear scale.
See Also berawgn, bercoding, berfading, “Theoretical Performance Results”
References [1] Jeruchim, Michel C., Philip Balaban, and K. Sam Shanmugan,
Simulation of Communication Systems, Second Edition, New York, Kluwer Academic/Plenum, 2000.
[2] Sklar, Bernard, Digital Communications: Fundamentals and Applications, Second Edition, Upper Saddle River, NJ, Prentice-Hall,
2001.
dx
[3] Stiffler, J. J., Theory of Synchronous Communications,Englewood Cliffs, NJ, Prentice-Hall, 1971.
2-61
bertool
Purpose Open bit error rate analysis GUI (BERTool)
Syntax bertool
Description bertool launches the Bit Error Rate Analysis Tool (BERTool). BERTool
is a graphical user interface (GUI) that enables you to analyze BER performance of communications systems. Performance analysis is done via simulation-based, semianalytic, or theoretical approach. To learn more abo ut BERTool, s ee “BERTool: A Bit Error Rate Analysis GUI”.
2-62
bi2de
Purpose Convert binary vectors to decimal numbers
Syntax d = bi2de(b)
d = bi2de(b,flg) d = bi2de(b,p) d = bi2de(b,p,flg)
Description d = bi2de(b) converts a binary row vector b to a nonnegative decimal
integer. If number. In this case, the output which is the decimal representation of the corresponding row of
Note By default, bi2de interprets the first column of b as the lowest-order digit.
d = bi2de(b,flg) is the same as the syntax above, except that flg
is a string that determines whether the first column of b contains the lowest-order or highest-order digits. Possible values for
'right-msb' and 'left-msb'.Thevalue'right-msb' produces the
default behavior.
b is a matrix, each row is interpreted separately as a binary
d is a column vector, each element of
b.
flg are
d = bi2de(b,p) converts a base-p ro w vector b to a nonnegative
decimal integer , where first column of
d is a nonnegative decimal vector, each row of which is the decimal
b is the lowest base-p digit. If b is a matrix, the output
form of the corresponding row of
d = bi2de(b,p,flg) is the same as the syntax above, except that flg is a string that determines whether the first column of b contains
the lowest-order or highest-order digits. Possible values for
'right-msb' and 'left-msb'.Thevalue'right-msb' produces the
p is an integer greater than or equal to 2. The
b.
flg are
default behavior.
2-63
bi2de
Examples The code below generates a matrix that contains binary representations
of five random numbers between 0 and 15. It then converts all five numbers to decimal integers.
b = randint(5,4); % Generate a 5-by-4 random binary matrix. de = bi2de(b); disp(' Dec Binary') disp(' ----- -------------------') disp([de, b])
Sample output is below. Your results might vary because the numbers are random.
Dec Binary
----- ------------------­131011
71110
151111
40010 91001
See Also de2bi
2-64
The command below converts a base-five number into its decimal counterpart, using the leftmost base-fiv e digit (4 in this case) as the most significant digit. The example reflects the fact that
3
4(5
)+2(52)+50=551.
d = bi2de([4 2 0 1],5,'left-msb')
The output is
d=
551
bin2gray
Purpose Convert positive integers into corresponding Gray-encoded integers
Syntax y = bin2gray(x,modulation,M)
[y,map] = bin2gray(x,modulation,M)
Description y = bin2gray(x,modulation,M) generates a Gray-encoded vector or
matrix output can be a scalar, vector, or matrix. modulation is the modulation type and must be a string equal to isthemodulationorderthatcanbeanintegerpowerof2.
[y,map] = bin2gray(x,modulation,M) generates a Gray-encoded
output
You can use map output to label a Gray-encoded constellation. The map output gives the G ra y encoded labels for the corresponding modulation. See the example below.
Note If you are converting binary coded data to Gray-coded data and modulating the result immediately afterwards, you should use the a ppropriate modulation object or function wi th the instead of BIN2GRAY.
y wi th its re s pe ctiv e Gray-encoded constellation map, map.
y with the same dimensions as its input parameter x. x
'qam', 'pam', 'fsk', 'dpsk',or'psk'. M
'Gray' option,
Example % To Gray encode a vector x with a 16-QAM Gray encoded
% constellation and return its map, use: x=randint(1,100,16); [y,map] = bin2gray(x,'qam',16); % Obtain the symbols for 16-QAM hMod = modem.qammod('M', 16); symbols = hMod.Constellation; % Plot the constellation scatterplot(symbols); set(get(gca,'Children'),'Marker','d','MarkerFaceColor',... 'auto'); hold on; % Label the constellation points according
2-65
bin2gray
% to the Gray mapping for jj=1:16 text(real(symbols(jj))-0.15,imag(symbols(jj))+0.15,... dec2base(map(jj),2,4)); end set(gca,'yTick',(-4:2:4),'xTick',(-4:2:4),... 'XLim',[-4 4],'YLim',... [-4 4],'Box','on','YGrid','on', 'XGrid','on');
The example code generates the following plot, which shows the 16 QAM constellation with Gray-encoded labeling.
See Also gray2bin
2-66
Purpose Compute number of bit errors and b it error rate (BER)
Syntax [number,ratio] = biterr(x,y)
[number,ratio] = biterr(x,y,k)
[number,ratio] = biterr(x,y,k,flg) [number,ratio,individual] = biterr(...)
Description For All Syntaxes
The biterr function compares unsigned binary representations of elements in shapes of
x with those in y. The schematics below illustrat e how the
x and y determine which elements biterr compares.
biterr
x1 x4
x2 x5
x3 x6
(a) Compares x1 with y1, x2 with y2, and so on.
y1 y4
y2 y5
y3 y6
xy
(b) Compares column vector y with each column of matrix x
x
(c) Compares row vector y with each row of matrix x
y
Each element of x and y must be a nonnegative decimal integer; biterr converts each element into its natural unsigned binary representation.
number is a scalar or vector that indicates the number of bits that differ. ratio is number divided by the total number of bits. The total number
of bits, the size of are determined by the dimensions of
number, and the elements that biterr compares
x and y and by the optional
parameters.
For Specific Syntaxes
[number,ratio] = biterr(x,y) compares the elements in x and y.
If the largest among all elements of
x and y has exactly k bits in its
simplest binary representation, the total number of bits is k times the number of entries in the smaller input. The sizes of
x and y determine
which elements are compared:
2-67
biterr
If x and y are matrices of the same dimensions, then biterr compares
x and y element by element. number is a scalar. See schematic (a) in
the preceding figure.
If one is a row (respectively, column) vector and the other is a
two-dimensional m atrix, then
biterr compares the vector element
by element with each row (resp., column) of the matrix. The length of the vector must equal the number of columns (resp., rows) in the matrix.
number is a column (resp., row) vector whose mth entry
indicates the number of bits that differ when comparing the vector with the mth row (resp., column) of the matrix. See schematics (b) and (c) in the figure.
[number,ratio] = biterr(x,y,k) is the same as the first syntax, except
that it considers each entry in of bits is
k times the number of entries of the smaller of x and y.An
error occurs if the binary representation of an element of requiremorethan
[number,ratio] = biterr(x,y,k,flg) is similar to the previous
syntaxes, except that elements
biterr compares and how biterr com putes the outputs. The
possible values of
k digits.
flg can override the defaults that govern which
flg are 'row-wise', 'column-wise',and'overall'.
x and y to have k bits. The total number
x or y would
The table below describes the differences that result from various combinations of inputs. As always, total number of bits. If you do not provide
ratio is number divided by the
k as an input argument,
the function defines it internally as the number of bits in the simplest binary representation of the largest among all elements of
x and y.
2-68

Comparing a Two-Dimensional Matrix x with Another Input y

biterr
Shape of y flg Type of
Comparison
2-D m a trix
'overall'
(default)
'row-wise'
Element by element
mth row of x vs. mth row of
y
'column-wise'
mth column of
x vs. mth
column of
number Total
Total number of bit errors
Column vector whose entries count bit errors in each row
Row vector whose
y
entries count bit errors in each column
Number of Bits
k times
number of entries of
k times
number of entries of
k times
number of entries of
y
y
y
2-69
biterr
Comparing a Two-Dimensional Matrix x with Another Input y(Continued)
Shape of y flg Type of
Comparison
Row vector
Column vector
'overall'
'row-wise'
(default)
'overall'
'column-wise'
(default)
y
vs. each
row of
y vs. each
row of
y
x
x
vs. each
column of
y vs. each
column of
number Total
Total number of bit errors
Column vector whose entries count bit errors in each row of
x
Total number
x
of bit errors
Row vector
x
whose entries count bit errors in each column of
x
Number of Bits
k times
number of entries of
k
times size
of
y
k times
number of entries of
k
times size
of
y
x
x
2-70
[number,ratio,individual] = biterr(...) returns a matrix individual whose dimensions are those of the larger of x and y.Each
entry of individual corresponds to a comparison between a pair of elements of elements in the pair differ.
Examples Example 1
The commands below compare the column vector [0; 0; 0] to each column of a random binary matrix. The output is the number, proportion, and locationsof1sinthematrix. Inthiscase, the random matrix.
format rat; [number,ratio,individual] = biterr([0;0;0],randi([0 1],3,5))
The output is
number =
20031
biterr
x and y, and specifies the number of bits by w hich the
individual isthesameas
ratio =
2/3 0 0 1 1/3
individual =
10010 10010 00011
Example 2
The commands below illustrate the use of flg to override the default row-by-row comparison.
number and ratio are scalars, and individual
has the same dimensions as the larger of the first two arguments of
biterr.
2-71
biterr
format rat; [number2,ratio2,individual2] = biterr([1 2; 3 4],[1 3],3,'overall')
The output is
number2 =
5
ratio2 =
5/12
individual2 =
01 13
2-72
Example 3
The script below adds errors to 10% of the elements in a matrix. Each entry in the matrix is a two-bit nu mber in de c imal form. The script computes the bit error rate using using
symerr.
x = randi([0 3],100); % Original signal % Create errors to add to ten percent of the elements of x. % Errors can be either 1, 2, or 3 (not zero). errorplace = (rand(100,100) > .9); % Where to put errors errorvalue = randi(3,100); % Value of the errors errors = errorplace.*errorvalue; y = rem(x+errors,4); % Signal with errors added, mod 4 format short [num_bit,ratio_bit] = biterr(x,y,2) [num_sym,ratio_sym] = symerr(x,y)
biterr and the symbol error rate
biterr
Sample output is below. ratio_sym is close to the target value of 0.10. Your results might vary because the example uses random numbers.
num_bit =
1304
ratio_bit =
0.0652
num_sym =
981
ratio_sym =
0.0981
Example 4
Thefollowingexampleuseslogicalinputarguments.
SNR = 3; frameLen = 100; x = randi([0 1], frameLen, 1); y = awgn(2*x-1, SNR); z=y>0; biterr(x, z)
Example 5
Thefollowingexampleuseslogicalinputarguments.
SNR = 5; frameLen = 100; x = rand(100, 1) > 0.5; y = awgn(2*x-1, SNR);
2-73
biterr
z=y>0; biterr(x, z)
See Also symerr, “Performance Results via S imulation”
2-74
Purpose Model binary symmetric channel
Syntax ndata = bsc(data,p)
ndata = bsc(data,p,s) ndata = bsc(data,p,state) [ndata,err] = bsc(...)
Description ndata = bsc(data,p) passes the binary input signal data through
a binary symmetric channel with error probability introduces a bit error with probability
data independently. data must be an array of binary numbers or a
Galois array in GF(2).
bsc(data,p,s)
random stream. See RandStream for more details.
ndata = bsc(data,p,state) resets the state of the uniform random
number generator
Note This usage is deprecated and may be removed in a future release. Instead of
causes rand to use the random stream s. s is any valid
p must be a scalar between 0 and 1.ndata =
rand to the integer state.
state,uses, as in the previous example.
p, processing each element of
p. The channel
bsc
[ndata,err] = bsc(...) returns an array, err,containingthe
channel errors.
This function uses, by default, the Mersenne Twister algorithm by Nishimura and Matsumoto.
Note Using the state parametercausesthisfunctiontoswitch random generators to use the
See
rand for details on the generator algorithm.
'state' algorithm of the rand function.
2-75
bsc
Examples To introduce bit errors in the bits in a random matrix with probability
0.15, use the
z = randint(100,100); % Random matrix
nz = bsc(z,.15); % Binary symmetric channel
[numerrs, pcterrs] = biterr(z,nz) % Number and percentage of errors
The output below is typical. The percentage of bit errors is not exactly 15% in most trials, but it is close to 15% if the size of the matrix large.
numerrs =
pcterrs =
bsc function:
1509
0.1509
z is
Another example using this function is in “Binary Symmetric Channel”.
See Also rand, awgn, “Binary Symmetric Channel”
2-76
Purpose Construct constant modulus algorithm (CMA) object
Syntax alg = cma(stepsize)
alg = cma(stepsize,leakagefactor)
Description The cma function creates an adaptive algorithm object that you can use
with the You can then use the equalizer object with the equalize a signal. To learn more about the process for equalizing a signal, see “Using Adaptive Equalizer Functions and Objects”.
Note After you use either lineareq or dfe to create a CMA equalizer object, you should initialize the equalizer object’s a nonzero vector. Typically, CMA is used with differential modulation; otherwise, the initial weights a re very important. A typical vector of initial weights has a 1 corresponding to the center tap and 0s elsewhere.
lineareq function or dfe function to create an equalizer object.
equalize function to
Weights property with
cma
alg = cma(stepsize) constructs an adaptive algorithm object based
on the constant modulus algorithm (CMA) with a step size of
alg = cma(stepsize,leakagefactor) sets the leakage factor of
the CMA. corresponds to a conventional w eight update algorithm, while a value of 0 corresponds to a memoryless update algorithm.
leakagefactor must be between 0 and 1. A value of 1
stepsize.
Properties
The table below describes the properties of the CMA adaptive algorithm object. Tolearnhowtovieworchangethevaluesofanadaptive algorithm object, see “Accessing Properties of an Adaptive Algorithm”.
2-77
cma
Property
AlgType
StepSize
Description
Fixed value, 'Constant
Modulus'
CMA step size parameter, a nonnegative real number
LeakageFactor
CMA leakage factor, a real number between 0 and 1
Algorithm Referring to the schematics p resented in “Overview of Adaptive
Equalizer Classes”, def in e w as the vector of all weights w u as the vector of all inputs u
. B ased on the current set of weights, w,
i
this adaptive algorithm creates the new set of weights given by
(
LeakageFactor)w+(StepSize)u
*
e
where the * operator denotes the complex conjugate.
and define
i
See Also lms, signlms, normlms, varlms, rls, lineareq, dfe, equalize,
“Equalizers”
References [1] Haykin, Simon, Adaptive Filter Theory, Third Ed., Upper Saddle
River, NJ, Prentice-Hall, 1996.
2-78
[2] Johnson, Richard C., Jr., Philip Schniter, Thomas. J. Endres, et al., “Blind Equalization Using the Constan t Modulus Criterion: A Review,” Proceedings of the IEEE, Vol. 86, October 1998, pp. 1927–1950.
Loading...