Lab Manual - 801
Lab Manual - 801
BY
SHASHANK DUEBY
LECTURER
EC DEPTT.
EXPERIMENT 1
OBJECTIVE:
To encode and decode data using a [15,13] Reed-Solomon code for the simulation of
block codes.
INTRODUCTION:
Block codes: Block coding is a special case of error-control coding. Block coding
techniques map a fixed number of message symbols to a fixed number of code symbols.
A block coder treats each block of data independently and is a memoryless device.
The block coder input is a stream of information bits. The coder segments this bit
stream into blocks of k information bits and for each block it calculates a number of r
check bits, or it picks the r check bits from a tabulated set of values. It then transmits the
entire block, or codeword of n = k + r channel bits. This is called an (n,k) block code.
If errors occur in sufficiently few of these transmitted channel bits, the r check
bits may provide the receiver with sufficient information to enable it to detect
and/or correct the channel errors.
The code efficiency (or code rate) is k/n.
If the k information bits are transmitted unaltered first followed by the
transmission of the r check bits it is called a systematic code.
A non-systematic block code is one which has the check bits interspersed
between the information bits.
Communications Toolbox supports general linear block codes. It also includes functions
to process cyclic, LDPC, BCH, Hamming, and Reed-Solomon codes (which are all
special kinds of linear block codes). Functions in the toolbox can accomplish these
tasks:
Encode or decode a message using one of the techniques mentioned above
Determine characteristics of a technique, such as error-correction capability or
valid message length
Perform lower level computations associated with a technique, such as
o Compute a decoding table
o Compute a generator or parity-check matrix
o Convert between generator and parity-check matrices
o Compute a generator polynomial
LAB WORK:
Representing Words for Reed-Solomon Codes
This toolbox supports Reed-Solomon codes that use m-bit symbols instead of
bits. A message for an [n,k] Reed-Solomon code must be a k-column Galois
array in the field GF(2m). Each array entry must be an integer between 0 and
2m-1. The code corresponding to that message is an n-column Galois array in
GF(2m). The codeword length n must be between 3 and 2m-1.
To represent words for a [7,3] Reed-Solomon code:
n = 7; k = 3; % Codeword length and message length
m = 3; % Number of bits in each symbol
msg = gf([1 6 4; 0 4 3],m); % Message is a Galois array.
c = rsenc(msg,n,k) % Code will be a Galois array.
Reed-Solomon Coding Syntaxes
This experiment illustrate how to encode and decode data using a [15,13]
Reed-Solomon code. It shows that you can
Vary the generator polynomial for the code, using rsgenpoly to produce
a different generator polynomial.
Vary the primitive polynomial for the Galois field that contains the
symbols, using an input argument in gf.
Vary the position of the parity symbols within the codewords, choosing
either the end (default) or beginning.
m = 4; % Number of bits in each symbol
n = 2^m-1; k = 13; % Codeword length and message length
data = randint(4,k,2^m); % Four random integer messages
msg = gf(data,m); % Represent data using a Galois array.
% Simplest syntax for encoding
c1 = rsenc(msg,n,k);
d1 = rsdec(c1,n,k);
% Vary the generator polynomial for the code.
c2 = rsenc(msg,n,k,rsgenpoly(n,k,19,2));
d2 = rsdec(c2,n,k,rsgenpoly(n,k,19,2));
% Vary the primitive polynomial for GF(16).
msg2 = gf(data,m,25);
c3 = rsenc(msg2,n,k);
d3 = rsdec(c3,n,k);
% Prepend the parity symbols instead of appending them.
c4 = rsenc(msg,n,k,'beginning');
d4 = rsdec(c4,n,k,'beginning');
% Check that the decoding worked correctly.
chk = isequal(d1,msg) & isequal(d2,msg) & isequal(d3,msg2)
&...
isequal(d4,msg)
The output is
chk =1
Detecting and Correcting Errors in a Reed-Solomon Code
The example below illustrates the decoding results for a corrupted code. The
example encodes some data, introduces errors in each codeword, and invokes
rsdec to attempt to decode the noisy code. It uses additional output
arguments in rsdec to gain information about the success of the decoding
process.
m = 3; % Number of bits per symbol
n = 2^m-1; k = 3; % Codeword length and message length
t = (n-k)/2; % Error-correction capability of the code
nw = 4; % Number of words to process
msgw = gf(randint(nw,k,2^m),m); % Random k-symbol messages
c = rsenc(msgw,n,k); % Encode the data.
noise = (1+randint(nw,n,2^m-1)).*randerr(nw,n,t); % t
errors/row
cnoisy = c + noise; % Add noise to the code.
[dc,nerrs,corrcode] = rsdec(cnoisy,n,k); % Decode the noisy
code.
% Check that the decoding worked correctly.
isequal(dc,msgw) & isequal(corrcode,c)
nerrs % Find out how many errors rsdec corrected.
The array of noise values contains integers between 1 and 2^m, and the
addition operation c + noise takes place in the Galois field GF(2^m) because
c is a Galois array in GF(2^m).
The output from the example is below. The nonzero value of ans. indicates
that the decoder was able to correct the corrupted code words and recover the
original message. The values in the vector nerrs indicate that the decoder
corrected t errors in each codeword.
ans =
1
nerrs =
2
2
2
2
EXPERIMENT: 2
OBJECT:
To simulate Hamming code using the binary format, and a Reed-Solomon
code using the integer format.
INTRODUCTION:
Binary Format (All Coding Methods)
You can structure messages and codewords as binary vector signals, where each vector represents a
message word or a codeword. At a given time, the encoder receives an entire message word, encodes
it, and outputs the entire codeword. The message and code signals share the same sample time.
Unbuffer Scope
Random -K-
RS Encoder RS DecoderErr
Integer
Gain
Random-Integer Integer-Input Integer-Output
Generator RS Encoder RS Decoder
Unbuffer1 Scope1
Info
To build the model, gather and configure these blocks:
Random Integer Generator, in the Comm Sources library
o Set M-ary number to 15.
o Set Initial seed to a positive number, randseed(0) is chosen here.
o Check the Frame-based outputs check box.
o Set Samples per frame to 5.
Integer-Input RS Encoder
o Set Codeword length N to 15.
o Set Message length K to 5.
Gain, in the Simulink Math Operations library
o Set Gain to [0; 0; 0; 0; 0; ones(10,1)].
Integer-Output RS Decoder
o Set Codeword length N to 15.
o Set Message length K to 5.
Scope, in the Simulink Sinks library. Get two copies of this block.
Sum, in the Simulink Math Operations library
o Set List of signs to |-+
Connect the blocks as in the preceding figure. From the model window's Simulation menu, select
Configuration parameters. In the Configuration Parameters dialog box, set Stop time to 500.
The vector length numbers appear on the connecting lines only if you select Signal dimensions from
the Port/signal displays submenu of the model's Format menu. The encoder accepts a vector of
length 5 (which is K in this case) and produces a vector of length 15 (which is N in this case). The
decoder does the opposite.
Running the model produces the following scope images. Your plot of the error counts might differ
somewhat, depending on your Initial seed value in the Random Integer Generator block. (To make the
axis range exactly match that of the first scope, right-click the plot area in the scope and select Axes
properties.)
EXPERIMENT 3
OBJECT:
To design and simulate a rate 2/3 feed forward convolutional Encoder .
INTODUCTION:
Convolutional coding is a special case of error-control coding. Unlike a block coder, a convolutional
coder is not a memoryless device. Even though a convolutional coder accepts a fixed number of
message symbols and produces a fixed number of code symbols, its computations depend not only on
the current set of input symbols but on some of the previous input symbols.
Tx
Error Rate
Convolutional Calculation
Bernoulli BS C Rx
Encoder Viterbi Decoder
Binary
Error Rate Calculation
Bernoulli Random Bina ry S ymme tric
Convolutional Viterbi Decoder Display
Binary Generator Cha nne l
Encoder
Info
EXPERIMENT 4
OBJECT:
Simulation of Low-Density Parity-Check (LDPC) codes with LDPC encoder and decoder.
INTRODUCTION :
Low-Density Parity-Check (LDPC) codes are linear error control codes with:
Sparse parity-check matrices
Long block lengths that can attain performance near the Shannon limit (see fec.ldpcenc and
fec.ldpcdec)
The decoding process is done iteratively. If the number of iterations is too small, the algorithm may not
converge. You may need to experiment with the number of iterations to find an appropriate value for
your model. For details on the decoding algorithm, see Decoding Algorithm.
Unlike some other codecs, you cannot connect an LDPC
decoder directly to the output of an LDPC encoder, because the decoder requires log-likelihood ratios
(LLR). Thus, you may use a demodulator to compute the LLRs.
LAB WORK:
Decoding Method
Decoding Algorithm
OBJECT:
Simulation of end-to-end baseband model of the physical layer of an OFDM based wireless
metropolitan area network (WMAN) according to the IEEE® 802.16-2004 standard.
This demo represents an end-to-end baseband model of the
physical layer of a wireless metropolitan area network (WMAN) according to the IEEE® 802.16-2004
standard. More specifically, it models the OFDM-based physical layer called WirelessMAN-OFDM,
supporting all of the mandatory coding and modulation options. It also illustrates Space-Time Block
Coding (STBC), an optional transmit diversity scheme specified for use on the downlink.
Contents
Structure of the Demo
Exploring the Demo
Results and Displays
Available Demo Models
Selected References
MISO
Double-click to set Channel
channel parameters 2x1
BER
Bit Error Rate
[rateID] #Errors
Calculation
#Bits
Bit Error Rate AWGN
Double-click to set
Display Channel
AWGN variance
Rx Constellation
Adaptive
SNR
Rate [rateID]
Estimation
Control
u-1
Double-click to open
Info RateID link model w ithout
Copyright 2007-2008 The MathWorks, Inc. Space-Time Block Coding
Est. SNR (dB)
INTRODUCTION:
Rayleigh and Rician fading channels are useful models of real-world phenomena in wireless
communication. These phenomena include multipath scattering effects, time dispersion, and Doppler
shifts that arise from relative motion between the transmitter and receiver.
This demo shows how to use the following in order to model a fading channel:
1. Rayleigh and Rician multipath fading channel objects
2. Channel visualization tool
Processing a signal using a fading channel involves the following steps:
1. Create a channel object that describes the channel that you want to use. A channel object is a
type of MATLAB® variable that contains information about the channel, such as the maximum
Doppler shift.
2. Adjust properties of the channel object, if necessary, to tailor it to your needs. For example, you
can change the path delays or average path gains.
3. Apply the channel object to your signal using the filter function, which has been overloaded to
work with channel objects.
The characteristics of a channel can be plotted using the channel visualization tool.
LAB WORK:
Contents
Initialization
Creating Channel Objects
Modulation and Channel Filtering
Visualization
Narrowband or Frequency-Flat Fading
Rician Fading
Wideband or Frequency Selective Channel
Initialization
The following variables control both the Rayleigh and Rician channel objects. By default, the channel
is modeled as four fading paths, each representing a cluster of multipath components received at
around the same delay.
sampleTime = 1/500000; % Sample time (s)
maxDopplerShift = 200; % Maximum Doppler shift of diffuse components (Hz)
delayVector = 1.0e-004 * [0 0.0400 0.0800 0.1200]; % Discrete delays of
% four-path channel (s)
gainVector = [0 -3 -6 -9]; % Average path gains (dB)
The maximum Doppler shift is computed as v*f/c, where v is the mobile speed, f is the carrier
frequency, and c is the speed of light. For example, a maximum Doppler shift of 200 Hz (as above)
corresponds to a mobile speed of 65 mph (30 m/s) and a carrier frequency of 2 GHz.
By convention, the delay of the first path is typically set to zero. For subsequent paths, a 1
microsecond delay corresponds to a 300 m difference in path length. In some outdoor multipath
environments, reflected paths can be up to several kilometers longer than the shortest path. With the
path delays specified above, the last path is 3.6 km longer than the shortest path, and thus arrives 12
microseconds later.
Together, the path delays and path gains specify the channel's average delay
profile. Typically, the average path gains decay exponentially with delay (i.e., the dB values decay
linearly), but the specific delay profile depends on the propagation environment. In the delay profile
specified above, we assume a 3 dB decrease in average power for every 4 microseconds of path delay.
The following variables control the Rician channel object. The Doppler shift of the specular
component is typically smaller than the maximum Doppler shift (above) and depends on the mobile's
direction of travel relative to the direction of the specular component. The K-factor specifies the linear
ratio of average received power from the specular component relative to that of the associated diffuse
components.
specDopplerShift = 100; % Doppler shift of specular component (Hz)
KFactor = 10; % Linear ratio of specular power to diffuse power
% Apply channel object on the modulated data using the FILTER function
filter(rayChanObj,modSignal);
filter(ricChanObj, modSignal);
Visualization
The Communications Toolbox™ provides a plotting function that helps you visualize the
characteristics of a fading channel using a GUI. The channel visualization tool can be invoked using
the PLOT or the CHANNEL_VIS function.
Using option 'IR' opens the visualization for the bandlimited impulse response (green curve). The
visualization also shows the delays and magnitudes of the underlying fading path gains
(red/magenta/blue stembars) clustered around the peak of the impulse response. Since the channel's
delay span (12 microseconds) is much smaller than our QPSK symbol period (100 microseconds),
these components cause minimal time dispersion. The resultant bandlimited impulse response closely
approximates a sinc pulse and thus has very small intersymbol interference (ISI) components (green
circles).
Note: For path gains, red corresponds to the smallest path delay while blue corresponds to the largest.
Components with intermediate delay values are shades between red and blue, becoming more blue for
larger delays.
channel_vis(rayChanObj, 'Visualization', 'ir'); % View Impulse Response
channel_vis(rayChanObj, 'Animation', 'medium'); % Set animation speed
channel_vis(rayChanObj, 'SampleIndex', 1); % Set animation start point
% Note: In this plot, the gains do not equal the average path gains because
% the Doppler effect causes the gains to fluctuate around their average
% values over time
EXPERIMENT : 7
OBJECT:
Simulation of Multiple-Input-Multiple-Output (MIMO) systems, which use multiple antennas at the
transmitter and receiver ends of a wireless communication system.
INTRODUCTION:
This demo introduces Multiple-Input-Multiple-Output (MIMO) systems, which use multiple antennas
at the transmitter and receiver ends of a wireless communication system. MIMO systems are
increasingly being adopted in communication systems for the potential gains in capacity they realize
when using multiple antennas. Multiple antennas use the spatial dimension in addition to the time and
frequency ones, without changing the bandwidth requirements of the system.
For a generic communications link, this demo focuses on transmit diversity in lieu of traditional
receive diversity. Using the flat-fading Rayleigh channel, it illustrates the concept of Orthogonal
Space-Time Block Coding, which is employable when multiple transmitter antennas are used. It is
assumed here that the channel undergoes independent fading between the multiple transmit-receive
antenna pairs.
For a chosen system, it also provides a measure of the performance degradation when the channel is
imperfectly estimated at the receiver, compared to the case of perfect channel knowledge at the
receiver.
Contents
PART 1: Transmit Diversity vs. Receive Diversity
PART 2: Space-Time Block Coding with Channel Estimation
PART 3: Orthogonal Space-Time Block Coding and Further Explorations
PART 1: Transmit Diversity vs. Receive Diversity
Using diversity reception is a well-known technique to mitigate the effects of fading over a
communications link. However, it has mostly been relegated to the receiver end. In [1], Alamouti
proposes a transmit diversity scheme that offers similar diversity gains, using multiple antennas at the
transmitter. This was conceived to be more practical as, for example, it would only require multiple
antennas at the base station in comparison to multiple antennas for every mobile in a cellular
communications system.
This section highlights this comparison of transmit vs. receive diversity by simulating coherent binary
phase-shift keying (BPSK) modulation over flat-fading Rayleigh channels. For transmit diversity, we
use two transmit antennas and one receive antenna (2x1 notationally), while for receive diversity we
employ one transmit antenna and two receive antennas (1x2 notationally).
The simulation covers an end-to-end system showing the encoded and/or transmitted signal, channel
model, and reception and demodulation of the received signal. It also provides the no-diversity link
(single transmit- receive antenna case) and theoretical performance of second-order diversity link for
comparison. It is assumed here that the channel is known perfectly at the receiver for all systems. We
run the simulation over a range of Eb/No points to generate BER results that allow us to compare the
different systems.
We start by defining some common simulation parameters
frmLen = 100; % frame length
numPackets = 1000; % number of packets
EbNo = 0:2:20; % Eb/No varying to 20 dB
N = 2; % maximum number of Tx antennas
M = 2; % maximum number of Rx antennas
and set up the simulation.
% Seed states for repeatability
seed = [98765 12345]; randn('state', seed(1)); rand('state', seed(2));
% Received signals
% for uncoded 1x1 system
r11 = awgn(H(:, 1, 1).*tx, EbNo(idx));
% Determine errors
error11(packetIdx) = biterr(demod11, data);
error21(packetIdx) = biterr(demod21, data);
error12(packetIdx) = biterr(demod12, data);
end % end of FOR loop for numPackets
% Calculate BER for current idx
% for uncoded 1x1 system
BER11(idx) = sum(error11)/(numPackets*frmLen);
% Plot results
semilogy(EbNo(1:idx), BER11(1:idx), 'r*', ...
EbNo(1:idx), BER21(1:idx), 'go', ...
EbNo(1:idx), BER12(1:idx), 'bs', ...
EbNo(1:idx), BERthy2(1:idx), 'm');
legend('No Diversity (1Tx, 1Rx)', 'Alamouti (2Tx, 1Rx)',...
'Maximal-Ratio Combining (1Tx, 2Rx)', ...
'Theoretical 2nd-Order Diversity');
drawnow;
end % end of for loop for EbNo
% Channel Estimation
% For each link => N*M estimates
for n = 1:N
H_e(1, n, :) = (r(1:pLen, :).' * pilots(:, n))./pLen;
end
% assume held constant for the whole frame
H_e = H_e(ones(frmLen, 1), :, :);
% Determine errors
numPackets = numPackets + 1;
totNumErr22_e = totNumErr22_e + biterr(demod22_e, data);
totNumErr22 = totNumErr22 + biterr(demod22, data);
end % end of FOR loop for numPackets
% Plot results
semilogy(EbNo(1:idx), BER22_e(1:idx), 'ro');
semilogy(EbNo(1:idx), BER22(1:idx), 'g*');
legend(['Channel estimated with ' num2str(pLen) ' pilot symbols/frame'],...
'Known channel');
drawnow;
end % end of for loop for EbNo
% Plot results
semilogy(EbNo, ber11, 'r*', EbNo, ber41, 'ms', EbNo, ber22, 'c^', ...
EbNo, ber14, 'ko', EbNo, BERthy4, 'g');
legend('No Diversity (1Tx, 1Rx), BPSK', 'OSTBC (4Tx, 1Rx), QPSK', ...
'Alamouti (2Tx, 2Rx), BPSK', 'Maximal-Ratio Combining (1Tx, 4Rx), BPSK', ...
'Theoretical 4th-Order Diversity, QPSK');