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 1996First printingVersion 1.0
May 1997Second printingRevised for Version 1.1 (MATLAB 5.0)
September 2000 Third printingRevised for Version 2.0 (Release 12)
May 2001Online onlyRevised for Version 2.0.1 (Release 12.1)
July 2002Fourth printingRevised for Version 2.1 (Release 13)
June 2004Fifth printingRevised for Version 3.0 (Release 14)
October 2004Online onlyRevised for Version 3.0.1 (Release 14SP1)
March 2005Online onlyRevised for Version 3.1 (Release 14SP2)
September 2005 Online onlyRevised for Version 3.2 (Release 14SP3)
October 2005ReprintVersion 3.0 (Notice updated)
March 2006Online onlyRevised for Version 3.3 (Release 2006a)
September 2006 Sixth printingRevised for Version 3.4 (Release 2006b)
March 2007Online onlyRevised for Version 3.5 (Release 2007a)
September 2007 Online onlyRevised for Version 4.0 (Release 2007b)
March 2008Online onlyRevised for Version 4.1 (Release 2008a)
October 2008Online onlyRevised for Version 4.2 (Release 2008b)
March 2009Online onlyRevised for Version 4.3 (Release 2009a)
September 2009 Online onlyRevised for Version 4.4 (Release 2009b)
March 2010Online onlyRevised for Version 4.5 (Release 2010a)
Function Reference
1
Signal Sources....................................1-2
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.
ExamplesThe 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 Alsoalgintrlv,“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 InternationalSymposium on Information Theory, Boston, Aug. 16–21, 1998. p. 419.
2-3
algintrlv
PurposeReorder symbols using algebraically derived permutation table
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
ExamplesThis 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.
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 Alsoalgdeintrlv,“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 InternationalSymposium on Information Theory, Boston, Aug. 16–21, 1998. p. 419.
2-6
alignsignals
PurposeAlign two signals by delaying earliest signal
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
ExamplesThe 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.
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 Alsofinddelay
X=[123];
Y=[0000123];
[Xa Ya D] = alignsignals(X, Y, [], 'truncate')
2-10
amdemod
PurposeAmplitude demodulation
Syntaxz = 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)
Descriptionz = 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
ExamplesThe 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
See Alsoammod, ssbdemod, fmdemod, pmdemod,“Modulation”
2-12
ammod
PurposeAmplitude modulation
Syntaxy = ammod(x,Fc,Fs)
y = ammod(x,Fc,Fs,ini_phase)
y = ammod(x,Fc,Fs,ini_phase,carramp)
Descriptiony = 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.
ExamplesThe 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);
% 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 Alsoamdemod, ssbmod, fmmod, pmmod,“Modulation”
2-14
arithdeco
PurposeDecode binary code using arithmetic decoding
Syntaxdseq = arithdeco(code,counts,len)
Descriptiondseq = 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.
ExamplesThis 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
AlgorithmThis function uses the algorithm described in [1].
See Alsoarithenco,“ArithmeticCoding”
References[1] Sayood, Khalid, Introduction to Data Compression, San Francisco,
Morgan Kaufmann, 2000.
2-15
arithenco
PurposeEncode sequence of symbols using arithmetic coding
Syntaxcode = arithenco(seq,counts)
Descriptioncode = 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.
ExamplesThis 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
AlgorithmThis function uses the algorithm described in [1].
See Alsoarithdeco,“ArithmeticCoding”
References[1] Sayood, Khalid, Introduction to Data Compression, San Francisco,
Morgan Kaufmann, 2000.
2-16
PurposeAdd white Gaussian noise to signal
Syntaxy = 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)
Descriptiony = 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
ExamplesThe 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 Alsowgn, randn, bsc, “AWGN Channel”
awgn
2-19
bchdec
PurposeBCH decoder
Note bchdec will be removed in a future release. Use fec.bchdec
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.
% 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
ExamplesThe 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.
Algorithmbchdec uses the Berlekamp-Massey decoding algorithm. For
information about this algorithm, see the works listed in “References”
on page 2-24.
t2 to
LimitationsThe maximum allowable value of n is 65535.
See Alsobchenc, 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
PurposeBCH encoder
Note bchenc will be removed in a future release. Use fec.bchenc
instead.
Syntaxcode = bchenc(msg,n,k)
code = bchenc(...,paritypos)
Descriptioncode = 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,
Descriptiongenpoly = 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.
ExamplesThe 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
LimitationsThe maximum allowable value of n is 511.
bchgenpoly
See Alsobchenc, 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
PurposeNumber of correctable errors for BCH code
SyntaxT = bchnumerr(N)
T = bchnumerr(N, K)
DescriptionT = 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 Alsobchenc, 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
PurposeBit error rate (BER) for uncoded AWGN channels
Syntaxber = 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, ...)
As an alternative to the berawgn function, invoke the BERTool GUI
(
bertool), and u se the Theoretical tab.
DescriptionFor 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 SchemeSecond 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.
ExamplesAn example using this function is in “Comparing Theoretical and
Empirical Error Rates”.
LimitationsThe 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 Alsobercoding, 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.
[5] Simon, M. K, Hinedi, S. M ., and Lindsey, W . C., DigitalCommunication 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 SystemsEngineering, Englewood Cliffs, N.J., Prentice-Hall, 1973.
bercoding
PurposeBit error rate (BER) for coded AWGN channels
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.
ExamplesAn 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');
LimitationsThe 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 Alsoberawgn, 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 DigitalCommunication, 2nd ed., Prentice Hall, 2001.
2-42
berconfint
PurposeBit 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
ExamplesIf 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.08140.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 Alsobinofit (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
PurposeBit error rate (BER) for Rayleigh and Rician fading channels
Syntaxber = 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.
DescriptionFor 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.
ExamplesThe 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
LimitationsThe 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 Alsoberawgn, 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.,DigitalCommunication Techniques – Signal Design and Detection,
Prentice-Hall, 1995.
[7] Simon, M. K., and Alouini, M. S., Digital Communication overFading 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
PurposeFit curve to nonsmooth empirical bit error rate (BER) data
Descriptionfitber = 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
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.
AlgorithmThe 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 BERfitted 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.
ExamplesThe 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.
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.07660.04230.02050.00860.00300.00090.00020.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.09310.04760.02200.00900.00310.00080.00010.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 Alsofminsearch, optimset, “Performance Evaluation”
ReferencesFor a general description of unconstrained nonlinear optimization, see
the following work.
[1] Chapra, Steven C., and Raymond P. Canale, Numerical Methods forEngineers, Fourth Edition, New York, McGraw-Hill, 2002.
2-58
PurposeBit error rate (BER) for imperfect synchronization
Syntaxber = 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.
Descriptionber = 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
ExamplesThe 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-0022.0536e-0021.1160e-002
1.8948e-0027.9757e-0044.9008e-006
1.2501e-0021.9091e-0049.0060e-009
LimitationsThe 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 < epsbersync(EbNo,timerr,'timing')
phaserr < epsbersync(EbNo,phaserr,'carrier')
AlgorithmThis 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
R22R
σ
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 Alsoberawgn, 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 andApplications, 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
PurposeOpen bit error rate analysis GUI (BERTool)
Syntaxbertool
Descriptionbertool 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
PurposeConvert binary vectors to decimal numbers
Syntaxd = bi2de(b)
d = bi2de(b,flg)
d = bi2de(b,p)
d = bi2de(b,p,flg)
Descriptiond = 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 thelowest-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
ExamplesThe 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('DecBinary')
disp('------------------------')
disp([de, b])
Sample output is below. Your results might vary because the numbers
are random.
DecBinary
-----------------------131011
71110
151111
40010
91001
See Alsode2bi
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
PurposeConvert positive integers into corresponding Gray-encoded integers
Syntaxy = bin2gray(x,modulation,M)
[y,map] = bin2gray(x,modulation,M)
Descriptiony = 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 Alsogray2bin
2-66
PurposeCompute number of bit errors and b it error rate (BER)
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 flgType 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
numberTotal
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 flgType 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
numberTotal
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.
ExamplesExample 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/30011/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 Alsosymerr, “Performance Results via S imulation”
DescriptionThe 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
AlgorithmReferring 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 Alsolms, 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...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.