Digi comm Report

DIGITAL
COMMUNICATION
SYSTEM
DESIGN
EE 5362
DIGITAL COMMUNICATION PROJECT
FALL 2010
INSTRUCTOR:
Dr. Tracy Jing Liang
Chirag Pandya:
Safwan Ahmed Muneer:
Saurabh Ghorpade:
1
1000722427
1000718848
1000718850
ACKNOWLEDGEMENT
It is a great pleasure to have completed the project under Dr. Tracy Jing Liang. We
take this opportunity in thanking her and her teaching assistants Davis Kirachaiwanich and Junjie
Chen who have taken their precious time and effort in helping us finishing the different stages of
the project successfully.
Your’s Faithfully,
Chirag Pandya
Safwan Ahmed Muneer
Saurabh Ghorpade
2
CONTENTS
1) About the Project
03
2) Abstract
04
3) System Description
06
i) Transmitter
ii) Receiver
4) Channel Equalizer
11
i) Minimum Distance Decision
ii) Maximum Likelihood Sequence Estimation
5) Channel Coding
17
6) Channel Decoding
18
7) Performance Analysis
19
8) Acknowledgement
22
9) Conclusion
23
10) Program Code (Matlab®)
24
11) References
47
3
ABSTRACT
Digital communications is the physical transfer of data (a digital bit stream) over a point-to-point or
point-to-multipoint communication channel. Examples of such channels are copper wires, optical fibres,
wireless communication channels, and storage media. The data is represented as an electromagnetic
signal, such as an electrical voltage, radio-wave, microwave or infrared signal.
While analog communications is the transfer of continuously varying information signal, digital
communications is the transfer of discrete messages. The messages are either represented by a sequence
of pulses i.e. by means of a line code, or by a limited set of continuously varying wave forms, using a
digital modulation method. The pass-band modulation and corresponding demodulation (also known as
detection) is carried out by modem equipment. Transmitting data in discrete messages allows for greater
signal processing capability.
According to the most common definition of digital signal, both baseband and pass-band signals
representing bit-streams are considered as digital transmission, while an alternative definition only
considers the baseband signal as digital, and pass-band transmission of digital data as a form of digital-toanalog conversion.
Data transmitted may be digital messages originating from a data source, for example a computer or a
keyboard. It may also be an analog signal such as a phone call or a video signal, digitized into a bit-stream
for example using pulse-code modulation (PCM) or more advanced source coding (analog-to-digital
conversion and data compression) schemes. This source coding and decoding is carried out by codec
equipment.
We have designed such a digital communication system in our project with a fixed wireless
local area network using MATLAB. In the design of the physical layer of the digital system, we
have assumed initially that the noise is zero and then ascertained whether the BER is zero or not.
This is done in order to insure the correct design of the digital system. Then we design and make
use of 2 types of equalizers:


Maximum Likelihood Sequence Equalizer.
Minimum Distance Detection Equalizer.
In a practical digital system, Inter symbol interference is studied and a equalizer is designed
in order to overcome it. In order to realize Inter symbol interference, a channel is designed as a
finite impulse response filter, so that the output of the channel not only depends on the present
value, but also on the past values. In this way Inter symbol interference is introduced in the
channel.
4
PROJECT SPECIFICATION
In this project we had to design a physical layer simulation reference system for a digital
communication system, a fixed wireless local area network (WLAN). The specifications are
listed as follows:
• Modulation: BPSK with bits to symbol mapping:
0 → -1, 1 → +1.
• Burst structure:
and transmitting such a burst needs 2 ms.
• A multipath channel containing three paths, which was modeled as a FIR filter,
with filter coefficients H(z) = 1+2z-1-1.5z-2
• Based on hardware requirements, 32 samples/symbol was used.
• We used a roll-off factor of 0.25 for the square root raised cosine filter.
We designed a simulation system using MATLAB®, a channel equalizer using MLSE
(Viterbi algorithm) and a Minimum Distance Decision (MDD) channel equalizer that we had
learnt in this course. We introduced Inter symbol interference for this multipath channel with
BPSK modulation and assumed that the channel can be perfectly estimated at the receiver. We
have included the following elements in this report about the channel equalizer design :






MLSE and MDD channel equalization scheme that we designed in this project.
A plot of the raw bit error rate (BER) obtained via MLSE, i.e., without channel
coding, at (Eb/No) = 10, 12, 14, 16, 18, 20 dB obtained in our simulation.
A plot of the raw bit error rate (BER) obtained via MDD channel equalization,
i.e., without channel coding, at (Eb/No) = 10, 12, 14, 16, 18, 20 dB obtained in our
simulation. Also we have compared the results with the BER curves obtained via
MLSE.
We have also plotted the theoretical BER curve using MDD and compared it with
the BER curves obtained in the simulation.
We have made use of linear block codes [6,3,3] with parity check matrix
101100
H=[ 1 1 1 0 1 0 ] and plotted the coded BER at (Eb/No) = 10, 12, 14, 16, 18, 20 dB
011001
obtained in our simulation and made analysis of the theoretical BER based on
MLSE and MDD performance.
We have compare the plots obtained in (2), (3), (4) and (5) and calculated the dB
gain achieved at BER = 2%.
5
SYSTEM DESCRIPTION
Fig.1: Block diagram of Digital Communication System
TRANSMITTER:
Following are the main components of transmitter design.
 Information bits
 Burst Builder
 Modulation
 Up sampling
 Pulse Shaping filter
 Channel
INFORMATION BITS:
In this project, we have made use of 800 information bits which later undergo size enhancement
in terms of the number of bits, when the payload is sent through a burst builder. The burst
builder adds redundancy to these bits, so that the information bits can be easily recovered at the
receive end.
6
BURST BUILDER:
Fig.2: A sample message with individual size
GUARD BITS:
Guard bits are necessary to avoid data losses at the time of recovering the signal from the
received message. Guard bits can be any bits which do not contain any information. As the name
suggests they are only used for guarding the message and the information contained in it. For our
project we have taken guard bits of length 5 - [0 0 0 0 0].
UNIQUE WORD:
We have made use of a 64 bit unique word in this project. Bits - 00101110 are repeated 8 times
to obtain the unique word. In a practical digital system, the channel is unknown so we make use
of a unique word to retrieve data. The process of adding a unique work helps us in the received
signal decision making process.
TAIL BITS:
Two tail bits are attached to the message to denote the end of message. These bits do not carry
any useful information and are used to decode the information in the received message. Tail bits
are followed by another set of guard bits.
So thus at the end of the burst builder arrangement, the total number of bits increases to 876 = 5
guard bits + 64 unique word bits + 800 information bits + 2 tail bits + 5 guard bits.
BPSK MODULATION:
BPSK modulation is performed to render the message less prone to error. This action will also
enable the easy recovery of the information at the receiver end. The modulation is achieved by
mapping bit 0 to -1 and bit 1 to +1. In practical systems error is introduced during transmission,
hence in order to recover the information easily we introduce a difference in these information
bits by doing it to symbol mapping. So thus 876 bits get mapped to 876 samples after the
modulation.
UP SAMPLING
Up sampling is performed in order to reduce the effect of noise in the transmitted message. In
our project we have implemented a 32sample/ bit up sampling. So thus the total number of
samples increases to 876 * 32 = 28,032 samples.
7
Fig.3a: Part of burst in symbol domain
Fig.3b: Up sampling
PULSE SHAPING FILTER:
We have used this block in our project to generate a waveform, improve system performance and
provide signal synchronization. This block acts like a low pass filter to remove noise and other
periodic signals. As we add zeros in between two symbols we have to the assign values to these
newly appended bits. We have used the RCOSINE filter feature, available in MATLAB, to
achieve the desired result. The shape of RCOSINE filter is shown below. The result that we
obtain after implementing RCOSINE filter is convolved with newly appended samples to
achieve pulse shaping. We can also call this process as interpolation.
0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05
0
10
20
30
40
50
60
70
Fig.4: RCOSINE plot
8
80
90
100
Now,
Length of burst= M
Length of filter= L
Length of convolved signal= L+M-1
We should make the length of convolved signal same as input signal. So we will cut L-1 extra
samples. Thus we remove (L-1)/2 samples at the start of the burst and (L-1)/2 samples at the end
of the burst. As we are adding guard symbols, cutting symbols at the start and end would not
affect the information in anyway.
In time domain we have infinite long sinc function, but we cannot implementing an infinite
length function is impractical. Hence we roll it off or use approximation. We have used a roll off
factor of 0.25 in our project.
CHANNEL:
In the beginning of our project implementation we try to achieve a BER of 0 by implementing a
single path channel. Then we model the channel as a FIR filter described by the following
equation – H(z) = 1 + 2z-1 – 1.5 z-2.
RECEIVER:
Following are the main components of our receiver design.





Matched Filter
Down sampling
Equalizer/Demodulator
Burst Extractor
BER calculator
MATCHED FILTER:
Matched filter does the same function as did our pulse shaping at the transmitter. Thus we
perform convolution using the RCOSINE filter with the received signal. This operation acts like
de-convolution, that is, it will nullify the effect of convolution done at the transmitter end.
DOWN SAMPLING:
The output of matched filter is in sample domain so we will convert it in into symbol domain
again. Thus our output after the down sampling has 876 symbols.
9
EQUALIZER:
We make use of an equalizer to demodulate the original information. By making use of this
block we can map the 876 symbols back to 876 bits.
Since, we make use of an FIR filter, we need to make use of an equalizer. As discussed above,
we have designed and implemented 2 types of equalization:


Maximum Likely Hood Sequence Detector
Minimum Distance Decision Rule
BURST EXTRACTOR:
It removes the guard bits, unique word and tail bits to give us only the information bits. Thus at
the end of this block we obtain the original 800 information bits.
CHANNEL DECODER:
We know that, S=H * r
where S- Syndrome, H- Parity check matrix, r- Received signal.
From these parameters we know H and r, therefore we can get S from above
equation. And since each S map to each e (error), we finally obtain the corrected codeword from
the equation - C = r + e.
Finally, we calculate the BER for both types of equalizations and compare the value with those
obtained theoretically.
CHANNEL EQUALIZER:
There are five types of channel equalizers:





Bayes Decision rule
Minimum Distance Desicision(MDD)
Maximum Likely Hood sequence detection(MLSE)
Zero Forcing channel equalizer
Least mean square error channel equalizer
Among the above equalizers, MLSE equalizer gives us the best performance. However, this
equalizer is also difficult to implement.
10
MINIMUM DISTANCE DECISION EQUALIZER:
In this equalizer we define decision boundary. Then according to nearest node
(+1 or -1) we will make decision of the received signal. Minimum distance decoding is also
known as nearest neighbor decoding. It can be assisted or automated by using a standard array.
Minimum distance decoding is a reasonable decoding method when the following conditions are
met:
1. The probability p that an error occurs is independent of the position of the symbol
2. Errors are independent events – an error at one position in the message does not affect
other positions
These assumptions may be reasonable for transmission over a binary symmetric channel. They
may be unreasonable for other media, such as a DVD, where a single scratch on the disk can
cause an error in many neighbor symbols or codewords.
S(k)
1
1
1
1
-1
-1
-1
-1
The channel given is 1 +2z-1 - 1.5 z-2
So r(k) = S(k) +2 S(k-1) – 1.5 S(k-2)
S(k-1)
1
1
-1
-1
1
1
-1
-1
S(k-2)
1
-1
1
-1
1
-1
1
-1
So according to this we will make decision boundary and detect the received signal.
11
r(k)
1.5
4.5
-2.5
0.5
-0.5
2.5
-4.5
-1.5
Fig.5: Decision Boundary for MDD
Where Hypothesis Ho corresponding to -1 and H1 corresponding to +1
In MDD equalizer we assume that channel is unknown. So we will use UNIQUE
WORD to determine the channel.
Unique word: 0 0 1 0 1 1 1 0
Modulated unique word: -1 -1 1 -1 1 1 1 -1
We have total 64 bit unique word. Pattern of 8 bit is repeated 8 times.
We should get same received signal for r(8) , r(16), r(24) .. … ….
But because of noise we wouldn’t get the same value. So we would take average of these
eight values. From these received signals we will take decision as explain above.
MAXIMUM LIKELIHOOD SEQUENCE ESTIMATION
In our project we have used Viterbi Algorithm to implement MLSE. The Viterbi algorithm is
a dynamic programming algorithm for finding the most likely sequence of hidden states –
called the Viterbi path – that results in a sequence of observed events, especially in the
context of Markov information sources, and more generally, hidden Markov models. The
forward algorithm is a closely related algorithm for computing the probability of a sequence
of observed events. These algorithms belong to the realm of information theory. To illustrate
how the Viterbi Algorithm works to obtain the shortest path, we need to represent the
Markov process in a simple way. A state diagram for a channel is often used for this purpose.
State diagrams are usually used in a system to describe its behavior. These diagrams can tell
the possible state of the system when events occur. Each diagram usually represents objects
of a single class and tracks the different states of its objects through the system.
At any time the system being modeled is in some state. There are a finite number of states.
While multiple sequences of states (paths) can lead to a given state, at least one of them is a
most likely path to that state, called the "survivor path". This is a fundamental assumption of
the algorithm because the algorithm will examine all possible paths leading to a state and
only keep the one most likely. This way the algorithm does not have to keep track of all
possible paths, only one per state.
12
A second key assumption is that a transition from a previous state to a new state is marked by
an incremental metric, usually a number. This transition is computed from the event. The
third key assumption is that the events are cumulative over a path in some sense, usually
additive. So the crux of the algorithm is to keep a number for each state. When an event
occurs, the algorithm examines moving forward to a new set of states by combining the
metric of a possible previous state with the incremental metric of the transition due to the
event and chooses the best. The incremental metric associated with an event depends on the
transition possibility from the old state to the new state.
Fig.6: State Diagram of a four state process
A sample of the state diagram and the trellis diagram are shown in this page for
reference. The state diagram has 4 states and the trellis diagram has been implemented for the
same number of states.
13
Fig.7: Trellis for the four-state process
In the starting part of our MLSE code, we have implemented the simultaneous construction
of the state diagram and the trellis diagram. This was realized by making use of several for
loops, matrices and variables. Once the trellis diagram was successfully constructed, the
shortest path from the final state to the initial state of the trellis diagram was obtained. This
was obtained by first calculating the distance between the final state and the immediate 2
states backwards the final state and also by ascertaining the value of the present state. Based
on the value of the present state and the immediate 2 states backwards the final state, the next
present value was evaluated. Based on these values of the present state and the previous state,
all 876 bits were evaluated.
CHANNEL CODING
This component converts bit stream into stream of messages, or source symbols. As we
already saw, the channel may cause the receiver to interpret wrong the transmitted source
symbols. This component offers more protection for our information, which represented by
the bit stream, by adding redundancy to the bit stream and defining source symbols. This
additional redundancy would serve the receiver for correct interpretations when the channel
garbles some of our bits. The idea to protect our data in a digital manner was quite
revolutionary and enabled the development of many advance communication systems such as
cellular modems.
We are using LINER BLOCK CODES. Examples of linear block codes are



Repetition code
Parity check code
Hamming code
14
In this project we are using [6 3 3] linear code.
We are getting drastic decrease in BER for MLSE and MDD.
We use m G = C Where m= message bits
G=generator matrix
C=code word
011001
H = [1 1 1 0 1 0]
101100
Where H is called as parity check matrix.
If G=[Ik , P] form then H = [Pt , In-k ] form. We are using [6 3 3] code. If we have 3
information bits then we have codeword of 6 bits. So we are taking 249 information bits so
we have 498 bits of burst. We will add 2 extra bits so final our burst has 500 bits.
CHANNEL DECODING
We know S = H * r
Where,
S: Syndrome
H: Parity check matrix
r: Received signal
H and r are known, therefore we then can get S from above equation. Depending on the
syndrome we then use the lookup table to obtain 𝑒̂ .
000000
000001
000010
000100
001000
010000
100000
000101
100110
100111
100100
100010
101110
110110
000110
100011
010011
010010
010001
010111
011011
000011
110011
010110
001111 110101 101001 011100
001110 110100 101000 011101
001101 110111 101011 011110
001011 110001 101101 011000
000111 111101 100001 010100
011111
10010
111001 001100
101111 010101 001001 111100
001010 110000 101100 011001
Table 3: Standard Array for the [6 3 3] code
15
111010
111011
111000
111110
110010
101010
011010
111111
(000)t
(001)t
(010)t
(100)t
(111)t
(011)t
(110)t
(101)t
and since each S map to each e (error), we finally obtain the received codeword from the
equation 𝐶̂ = 𝑟 + 𝑒̂ . Now we compare the received code word from the transmitted codeword
by doing binary addition. If the result is [0 0 0 0 0], then the received codeword has no errors in
it.
RESULT:
1) RAW BIT ERROR RATE obtained via MLSE without channel coding
plot of raw BER vs SNR for MLSE channel equlization
-1
10
-2
raw bit error ->
10
-3
10
-4
10
6
7
8
9
10
Signal to noise ratio(SNR) in dB ->
11
12
2) RAW BIT ERROR RATE obtained via MDD channel equalization without channel
plot of raw BER vs SNR for MDD channel equlization
coding
0
10
16
3) Comparison between practical MDD and theoretical MDD
0
10
raw BER MDD
raw BER theoretical MDD
-1
10
-2
10
6
8
10
12
17
14
16
18
20
4)
Coded BER via MLSE
plot of coded BER vs SNR for MLSE channel equlization
-4
raw bit error ->
10
-5
10
-6
10
6
6.2
6.4
6.6
6.8
7
7.2
7.4
Signal to noise ratio(SNR) in dB ->
18
7.6
7.8
8
5) Coded BER via MDD
plot of coded BER vs SNR for MDD channel equlization
0
raw bit error ->
10
-1
10
-2
10
6
8
10
12
14
16
Signal to noise ratio(SNR) in dB ->
19
18
20
6) Comparison of various graphs generated by various methods
20
CONCLUSION
1) In this project, we found out that with the introduction of ISI to the channel, large number of
errors signal were generated in the received signal. Though, after adding the MLSE channel
equalizer which has 8 signal patterns, the BER reduced considerably when compared with
the results obtained by MDD. Meaning that MLSE equalizer helps in reducing the BER and
helps in retrieving signal almost noise free.
2) We also found out that implementing MDD is easier to implement as compared with MLSE.
3) A signal suffers from nonlinear, linear, and additive distortion when transmitted through a
channel. Linear equalizers are commonly used in receivers to compensate for linear channel
distortion. So when we add channel coding before burst builder and decode the information
bit after burst extractor, we can achieve even better BER comparing to the one without
channel coding, which is 1.3 dB more.
4) The Channel coding is a viable method to reduce information rate through the channel and
increase reliability. If the coding rate is higher the channel is called as an aggressive channel
but is not reliable. Whereas channel coding rate is less, the system is much more stable. This
goal is achieved by adding redundancy to the information symbol vector resulting in a longer
coded vector of symbols that are distinguishable at the output of the channel.
5) Lastly, increasing timing error will cause system performance degrading more after burst
extractor, we can achieve even better BER comparing to the one without channel.
PROGRAM CODE (MATLAB®)
Code for Q.2
clc;
clear all;
snr=0;
for SNR=1:6
snr=snr+1;
kn =[0.0994 0.0829 0.0710 0.0621 0.0552 0.0497];% This corresponds to SNR val
for count=1:4000
21
% Information symbols
no_of_infosymbol=800;
Infosymbol=randint (1,no_of_infosymbol);
% uniqueword
uw=[0 0 1 0 1 1 1 0];
uniqueword=cat(2,uw,uw,uw,uw,uw, uw, uw, uw);
% guard
guard (1:5) =0;
%tail
tail(1:2)=1;
%burst structure
burst=cat(2,guard,uniqueword,Infosymbol,tail,guard);
burst_length= length (burst);
% 876
% modulation
for i=1:burst_length
if(burst(i)==0)
burst_modulation(i)= -1;
else
burst_modulation(i)=1;
end
end
%
modulation 1->1 , 0->-1
% Upsampling
m=1;
for j=1:burst_length
up(m)= burst_modulation(j);
for k=1:32
m=m+1;
up(m)=0;
end
end
upsample_length = length( up)-1;% length is 28032 ( 876*32)
for i=1:upsample_length
upsample(i)= up(i);
end
filter=rcosine(1,32,'sqrt',0.25);% length is M=193
filter_len=length(filter);
pulse_op=conv(filter,upsample);
pulse_op_len= length (pulse_op);% length is (876*32 + 193 -1)= 28224
% Discarding M-1 samples
cut1=(filter_len-1)/2;
cut2= pulse_op_len-cut1;
j=1;
for i= cut1+1:cut2
pulseshape_output(j)=pulse_op(i);
22
j=j+1;
end
pulseshape_op_len=length(pulseshape_output);
% length is 876*32= 28032
%channel
for i=1:31
u(i)=0;
end
h1=1;
h2=2;
h3=-1.5;
filter_output=cat(2,h1,u,h2,u,h3);
len_filter_output=length(filter_output);
% length = 65
channel_conv=conv(pulseshape_output,filter_output);
len_channel_conv=length(channel_conv);
% length is (876*3)+65-1 = 28096
% discarding M-1 samples
c1= (len_filter_output-1)/2;
c2= (len_channel_conv)-c1;
j=1;
for i= c1+1 : c2
transmit_output(j) = channel_conv(i);
j=j+1;
end
transmit_output_len= length(transmit_output);
% AWGN NOISE
k=kn(snr);
Noise=k*randn(1,transmit_output_len);
tx_output=transmit_output + Noise;
% RECEIVER
% Matched Filter
Matched_filter= rcosine(1,32,'sqrt',0.25);
len_Matched_filter= length(Matched_filter); % length 193
Matched_conv=conv(Matched_filter,tx_output);
len_Matched_conv=length(Matched_conv);
% discard N-1;
23
% length 28224
m1= (len_Matched_filter-1)/2;
m2= (len_Matched_conv)-m1;
j=1;
for i= m1+1 : m2
Matched_output(j) = Matched_conv(i);
j=j+1;
end
Matched_output_length=length(Matched_output);
% DOWNSAMPLING
j=1;
for i= 1:32:Matched_output_length
r(j)=Matched_output(i);
j=j+1;
end
len=length(r) ;
%
% 876
MLSE DEMODULATOR
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
for i=1:len
if(i==1)
c_state=s11;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2;
min(i,1)=d(i,1);
elseif(input==1)
s1=1; s2=-1; s3=-1;
n_state=s12;
c(i,2)=state_value(s1,s2,s3);
d(i,2)=(r(i)-c(i,2))^2;
min(i,2)=d(i,2);
end
end
elseif(i==2)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
24
elseif(input==1)
s1=1; s2=-1; s3=-1;
n_state=s12;
c(i,2)=state_value(s1,s2,s3);
d(i,2)=(r(i)-c(i,2))^2 + min(i-1,1);
min(i,2)=d(i,2);
end
end
c_state=s12;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=-1;
n_state=s13;
c(i,3)=state_value(s1,s2,s3);
d(i,3)=(r(i)-c(i,3))^2 + min(i-1,2);
min(i,3)=d(i,3);
elseif(input==1)
s1=1; s2=1; s3=-1;
n_state=s14;
c(i,4)=state_value(s1,s2,s3);
d(i,4)=(r(i)-c(i,4))^2 + min(i-1,2);
min(i,4)=d(i,4);
end
end
elseif(i>2 && i<len-1)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
elseif(input==1)
s1=1; s2=-1; s3=-1;
n_state=s12;;
c(i,2)=state_value(s1,s2,s3);
d(i,2)=(r(i)-c(i,2))^2 + min(i-1,1);
min(i,2)=d(i,2);
end
end
c_state=s12;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=-1;
n_state=s13;
c(i,3)=state_value(s1,s2,s3);
d(i,3)=(r(i)-c(i,3))^2 + min(i-1,2);
min(i,3)=d(i,3);
elseif(input==1)
s1=1; s2=1; s3=-1;
n_state=s14;
c(i,4)=state_value(s1,s2,s3);
d(i,4)=(r(i)-c(i,4))^2 + min(i-1,2);
min(i,4)=d(i,4);
25
end
end
c_state=s13;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=1;
n_state=s11;
c(i,5)=state_value(s1,s2,s3);
d(i,5)=(r(i)-c(i,5))^2 + min(i-1,3);
if(d(i,5)<d(i,1))
min(i,1)=d(i,5);
end
elseif(input==1)
s1=1; s2=-1; s3=1;
n_state=s12;
c(i,6)=state_value(s1,s2,s3);
d(i,6)=(r(i)-c(i,6))^2 + min(i-1,3);
if(d(i,6)<d(i,2))
min(i,2)=d(i,6);
end
end
end
c_state=s14;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=1;
n_state=s13;
c(i,7)=state_value(s1,s2,s3);
d(i,7)=(r(i)-c(i,7))^2 + min(i-1,4);
if(d(i,7)<d(i,3))
min(i,3)=d(i,7);
end
elseif(input==1)
s1=1; s2=1; s3=1;
n_state=s14;
c(i,8)=state_value(s1,s2,s3);
d(i,8)=(r(i)-c(i,8))^2 + min(i-1,4);
if(d(i,8) < d(i,4))
min(i,4)=d(i,8);
end
end
end
elseif(i==len-1)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
end
end
c_state=s12;
26
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=-1;
n_state=s13;
c(i,3)=state_value(s1,s2,s3);
d(i,3)=(r(i)-c(i,3))^2 + min(i-1,2);
min(i,3)=d(i,3);
end
end
c_state=s13;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=1;
n_state=s11;
c(i,5)=state_value(s1,s2,s3);
d(i,5)=(r(i)-c(i,5))^2 + min(i-1,3);
if(d(i,5)<d(i,1))
min(i,1)=d(i,5);
end
end
end
c_state=s14;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=1;
n_state=s13;
c(i,7)=state_value(s1,s2,s3);
d(i,7)=(r(i)-c(i,7))^2 + min(i-1,4);
if(d(i,7)<d(i,3))
min(i,3)=d(i,7);
end
end
end
elseif(i==len)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
end
end
c_state=s13;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=1;
n_state=s11;
c(i,5)=state_value(s1,s2,s3);
d(i,5)=(r(i)-c(i,5))^2 + min(i-1,3);
if(d(i,5)<d(i,1))
min(i,1)=d(i,5);
end
end
end
27
end
end
for k=len:-1:1
if(k==len)
min_all=min(k,1);
index=1;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
%
switch p_state
% case s11
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
previous_state2=s13;
%case s12
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
previous_state2=s13;
% case s13
elseif(p_state==s13)
received(k)=s13(1);
previous_state1=s12;
previous_state2=s14;
%case s14
elseif(p_state==s14)
received(k)=s14(1);
previous_state1=s12;
previous_state2=s14;
end
elseif(k<len && k>2)
cal_index1=find_index(previous_state1);
cal_index2=find_index(previous_state2);
if(min(k,cal_index1)<min(k,cal_index2))
min_all=min(k,cal_index1);
index=cal_index1;
else
min_all=min(k,cal_index2);
index=cal_index2;
end
min_all;
index;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
previous_state2=s13;
elseif(p_state==s12)
28
received(k)=s12(1);
previous_state1=s11;
previous_state2=s13;
elseif(p_state==s13)
received(k)=s13(1);
previous_state1=s12;
previous_state2=s14;
elseif(p_state==s14)
received(k)=s14(1);
previous_state1=s12;
previous_state2=s14;
end
elseif (k==2)
cal_index1=find_index(previous_state1);
cal_index2=find_index(previous_state2);
if(min(k,cal_index1)<min(k,cal_index2))
min_all=min(k,cal_index1);
index=cal_index1;
else
min_all=min(k,cal_index2);
index=cal_index2;
end
min_all;
index;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
elseif(p_state==s13)
received(k)=s13(1);
previous_state1=s12;
elseif(p_state==s14)
received(k)=s14(1);
previous_state1=s12;
end
elseif(k==1)
cal_index1=find_index(previous_state1);
min_all=min(k,cal_index1);
index=cal_index1;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
29
end
end
end
for i=len:-1:1
if(i>1)
received(i)=received(i-1);
end
end
ber=0;
for i=1:876
if (received(i)~=burst_modulation(i))
ber=ber+1;
end
end
BER(count)=ber/876;
end
BER=sum(BER)/4000;
Bit_ERR(SNR)=BER;
End
snr1=[6 7 8 9 10 11 12] % since it gives zero value for snr >12
semilogy(snr1,Bit_ERR);
title('plot of raw BER vs SNR for MLSE channel equlization ');
xlabel('Signal to noise ratio(SNR) in dB ->');
ylabel('raw bit error ->');
FUNCTIONS USED FOR CODE 2
function r=state_value(s1,s2,s3)
r=s1 +2*s2 -1.5*s3;
end
function index=find_index(state)
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(state==s11)
index=1;
elseif(state==s12)
index=2;
elseif(state==s13)
index=3;
elseif(state==s14)
index=4;
end
function p_state=state(index)
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
30
if(index==1)
s1=-1; s2=-1;
p_state=s11;
elseif(index==2)
s1=1; s2=-1;
p_state=s12;
elseif(index==3)
s1=-1; s2=1;
p_state=s13;
elseif(index==4)
s1=1; s2=1;
p_state=s14;
end
end
Code for Q.3
clc;
clear all;
snr=0;
for SNR=1:6
kn =[0.0994 0.0829 0.0710 0.0621 0.0552 0.0497];% This corresponds to SNR val
for count=1:4000
% Information symbols
no_of_infosymbol=800;
Infosymbol=randint (1,no_of_infosymbol);
% uniqueword
uw=[0 0 1 0 1 1 1 0];
uniqueword=cat(2,uw,uw,uw,uw,uw, uw, uw, uw);
% guard
guard (1:5) =0;
%tail
tail(1:2)=1;
%burst structure
burst=cat(2,guard,uniqueword,Infosymbol,tail,guard);
burst_length= length (burst);
% 876
% modulation
31
for i=1:burst_length
if(burst(i)==0)
burst_modulation(i)= -1;
else
burst_modulation(i)=1;
end
end
%
modulation 1->1 , 0->-1
% Upsampling
m=1;
for j=1:burst_length
up(m)= burst_modulation(j);
for k=1:32
m=m+1;
up(m)=0;
end
end
upsample_length = length( up)-1;% length is 28032 ( 876*32)
for i=1:upsample_length
upsample(i)= up(i);
end
% Filter
filter=rcosine(1,32,'sqrt',0.25);% length is M=193
filter_len=length(filter);
pulse_op=conv(filter,upsample);
pulse_op_len= length (pulse_op);% length is (876*32 + 193 -1)= 28224
% Discarding M-1 samples
cut1=(filter_len-1)/2;
cut2= pulse_op_len-cut1;
j=1;
for i= cut1+1:cut2
pulseshape_output(j)=pulse_op(i);
j=j+1;
end
pulseshape_op_len=length(pulseshape_output);
% length is 876*32= 28032
%channel
for i=1:31
u(i)=0;
end
h1=1;
h2=2;
h3=-1.5;
filter_output=cat(2,h1,u,h2,u,h3);
len_filter_output=length(filter_output);
% length = 65
channel_conv=conv(pulseshape_output,filter_output);
len_channel_conv=length(channel_conv);
% length is (876*3)+65-1 = 28096
32
% discarding M-1 samples
c1= (len_filter_output-1)/2;
c2= (len_channel_conv)-c1;
j=1;
for i= c1+1 : c2
transmit_output(j) = channel_conv(i);
j=j+1;
end
transmit_output_len= length(transmit_output);
% AWGN NOISE
k=kn(snr);
Noise=k*randn(1,transmit_output_len);
tx_output=transmit_output + Noise;
% RECEIVER
% Matched Filter
Matched_filter= rcosine(1,32,'sqrt',0.25);
len_Matched_filter= length(Matched_filter); % length 193
Matched_conv=conv(Matched_filter,tx_output);
len_Matched_conv=length(Matched_conv);
% discard N-1;
m1= (len_Matched_filter-1)/2;
m2= (len_Matched_conv)-m1;
j=1;
for i= m1+1 : m2
Matched_output(j) = Matched_conv(i);
j=j+1;
end
Matched_output_length=length(Matched_output);
% DOWNSAMPLING
j=1;
for i= 1:32:Matched_output_length
downsample(j)= Matched_output(i);
j=j+1;
end
33
% length 28224
len_downsample=length(downsample);
% MDD demodulation
j=1;
for m=1:69
if(m>7)
mdd_input(j)=downsample(m);
j=j+1;
end
end
mdd_input(63)=0;
mdd_input(64)=0;
for i=64:-1:1
if(i>1)
mdd_input(i)=mdd_input(i-1);
end
end
mdd_input(1)=0;
length(mdd_input);
k=0;
out(1:8)=0;
for j=1:8
for i=9:8:56
out(j)=out(j) + mdd_input(k+i);
end
r(j)=out(j)/6;
k=k+1;
end
b1=(r(7)+r(3))/2;
b2=(r(3)+r(8))/2;
b3=(r(1)+r(6))/2;
b4=(r(5)+r(2))/2;
b5=(r(2)+r(4))/2;
for i=1:len_downsample
if(downsample(i) < b1)
output(i)=-1;
elseif(downsample(i) < b2 && downsample(i)> b1)
output(i)=1;
elseif(downsample(i) < b3 && downsample(i)> b2)
output(i)=-1;
elseif(downsample(i)< b4 && downsample(i)>b3)
output(i)=1;
elseif(downsample(i)< b5 && downsample(i)>b4)
output(i)=-1;
elseif( downsample(i)>b5)
output(i)=1;
end
end
for i=len_downsample:-1:1
if(i>1)
output(i)=output(i-1);
end
34
end
ber=0;
for i=1:len_downsample
if(output(i)~=burst_modulation(i))
ber=ber+1;
end
end
ber
ber/876*100
ber(count)=ber/len_downsample;
end
BER=0;
for i=1:4000
BER=BER+ber(i);
end
BER=BER/4000;
Bit_ERR(SNR)=BER;
end
figure;
snr2=[6 8 10 12 14 16 18 20] % to get good response
semilogy(snr2,final_ber);
title('plot of raw BER vs SNR for MDD channel equlization ');
xlabel('Signal to noise ratio(SNR) in dB ->');
ylabel('raw bit error ->');
Code for Q4.
clc;
clear all;
for b=1:100
% Inforamation symbols
no_of_infosymbol=800;
Infosymbol=randint (1,no_of_infosymbol);
% uniqueword
uw=[0 0 1 0 1 1 1 0];
uniqueword=cat(2,uw,uw,uw,uw,uw, uw, uw, uw);
% guard
guard (1:5) =0;
%tail
tail(1:2)=1;
%burst structure
burst=cat(2,guard,uniqueword,Infosymbol,tail,guard);
burst_length= length (burst);
% 876
% modulation
for i=1:burst_length
if(burst(i)==0)
%
35
modulation 1->1 , 0->-1
burst_modulation(i)= -1;
else
burst_modulation(i)=1;
end
end
% Upsampling
m=1;
for j=1:burst_length
up(m)= burst_modulation(j);
for k=1:32
m=m+1;
up(m)=0;
end
end
upsample_length = length( up)-1;% length is 28032 ( 876*32)
for i=1:upsample_length
upsample(i)= up(i);
end
% Filter
filter=rcosine(1,32,'sqrt',0.25);% length is M=193
filter_len=length(filter);
pulse_op=conv(filter,upsample);
pulse_op_len= length (pulse_op);% length is (876*32 + 193 -1)= 28224
% Discarding M-1 samples
cut1=(filter_len-1)/2;
cut2= pulse_op_len-cut1;
j=1;
for i= cut1+1:cut2
pulseshape_output(j)=pulse_op(i);
j=j+1;
end
pulseshape_op_len=length(pulseshape_output);
% length is 876*32= 28032
% RECEIVER
% Matched Filter
Matched_filter= rcosine(1,32,'sqrt',0.25);
len_Matched_filter= length(Matched_filter); % length 193
Matched_conv=conv(Matched_filter,pulseshape_output);
len_Matched_conv=length(Matched_conv);
% length 28224
% discard N-1;
m1= (len_Matched_filter-1)/2;
m2= (len_Matched_conv)-m1;
j=1;
for i= m1+1 : m2
36
Matched_output(j) = Matched_conv(i);
j=j+1;
end
Matched_output_length=length(Matched_output);
% DOWNSAMPLING
j=1;
for i= 1:32:Matched_output_length
downsample(j)= Matched_output(i);
j=j+1;
end
len_downsample=length(downsample);
%Signal Power
P_signal=0;
for i=1:len_downsample
P_signal=downsample(i)^2+ P_signal;
end
P_S(b)=(P_signal)/len_downsample;
end
Signal_Power=0;
for i=1:100
Signal_Power=P_S(i)+Signal_Power;
end
Signal_Power=Signal_Power/100
% it is 0.9935
snr=[10 12 14 16 18 20];
for i=1:length(snr)
x1=1/ sqrt(signal_power /snr(i)) ;
x2=0.5/ sqrt(signal_power /snr(i)) ;
x3=1.5/ sqrt(signal_power /snr(i)) ;
ber(i)= 0.5((2*(erfc(x1/sqrt(2)))) + 3*(erfc(x2/sqrt(2)))+
2*(erfc(x3/sqrt(2))));
end
figure;
snr3=[6 8 10 12 14 16 18 20] % to get good response
semilogy(snr3,ber);
title('plot of raw BER vs SNR for MDD theoretical channel equlization ');
xlabel('Signal to noise ratio(SNR) in dB ->');
ylabel('raw bit error ->');
Code for Q.5.1
clc;
clear all;
snr=0;
for SNR=1:6
kn =[0.0994 0.0829 0.0710 0.0621 0.0552 0.0497];% This corresponds to SNR val
37
for count=1:4000
% Encoder
Encoder_info_len=399;
info=randint(1,Encoder_info_len) ;
% generate information bits
G=[1 0 0 1 1 0;0 1 0 0 1 1;0 0 1 1 1 1]; % generator matrix
j=1;
for i=1:3:Encoder_info_len
mat(j,:)=info(i:i+2);
codeword(j,:)=mat(j,:)*G;
j=j+1;
end
a=[1 1];
final=[];
cat_val = (Encoder_info_len)/3;
for i=1:cat_val
p=cat(2,final,codeword(i,:));
end
p=cat(2,p,a);
p_len=length(p);
for i=1:fin_len
if(p(:,i) > 1)
if(mod(p(:,i),2) == 0)
p(:,i)=0;
end
end
if(p(:,i) > 1)
if(mod(p(:,i),2) ~= 0)
p(:,i)=1;
end
end
end
Infosymbol=p;
% uniqueword
uw=[0 0 1 0 1 1 1 0];
uniqueword=cat(2,uw,uw,uw,uw,uw, uw, uw, uw);
% guard
guard (1:5) =0;
%tail
tail(1:2)=1;
%burst structure
burst=cat(2,guard,uniqueword,Infosymbol,tail,guard);
burst_length= length (burst);
% 876
% modulation
for i=1:burst_length
if(burst(i)==0)
burst_modulation(i)= -1;
else
burst_modulation(i)=1;
end
end
38
%
modulation 1->1 , 0->-1
% Upsampling
m=1;
for j=1:burst_length
up(m)= burst_modulation(j);
for k=1:32
m=m+1;
up(m)=0;
end
end
upsample_length = length( up)-1;% length is 28032 ( 876*32)
for i=1:upsample_length
upsample(i)= up(i);
end
filter=rcosine(1,32,'sqrt',0.25);% length is M=193
filter_len=length(filter);
pulse_op=conv(filter,upsample);
pulse_op_len= length (pulse_op);% length is (876*32 + 193 -1)= 28224
% Discarding M-1 samples
cut1=(filter_len-1)/2;
cut2= pulse_op_len-cut1;
j=1;
for i= cut1+1:cut2
pulseshape_output(j)=pulse_op(i);
j=j+1;
end
pulseshape_op_len=length(pulseshape_output);
% length is 876*32= 28032
%channel
for i=1:31
u(i)=0;
end
h1=1;
h2=2;
h3=-1.5;
filter_output=cat(2,h1,u,h2,u,h3);
len_filter_output=length(filter_output);
% length = 65
channel_conv=conv(pulseshape_output,filter_output);
len_channel_conv=length(channel_conv);
% length is (876*3)+65-1 = 28096
% discarding M-1 samples
c1= (len_filter_output-1)/2;
c2= (len_channel_conv)-c1;
j=1;
for i= c1+1 : c2
transmit_output(j) = channel_conv(i);
j=j+1;
end
39
transmit_output_len= length(transmit_output);
% AWGN NOISE
k=kn(snr);
Noise=k*randn(1,transmit_output_len);
tx_output=transmit_output + Noise;
% RECEIVER
% Matched Filter
Matched_filter= rcosine(1,32,'sqrt',0.25);
len_Matched_filter= length(Matched_filter); % length 193
Matched_conv=conv(Matched_filter,tx_output);
len_Matched_conv=length(Matched_conv);
% discard N-1;
m1= (len_Matched_filter-1)/2;
m2= (len_Matched_conv)-m1;
j=1;
for i= m1+1 : m2
Matched_output(j) = Matched_conv(i);
j=j+1;
end
Matched_output_length=length(Matched_output);
% DOWNSAMPLING
j=1;
for i= 1:32:Matched_output_length
r(j)=Matched_output(i);
j=j+1;
end
len=length(r) ;
%
% 876
MLSE DEMODULATOR
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
40
% length 28224
for i=1:len
if(i==1)
c_state=s11;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2;
min(i,1)=d(i,1);
elseif(input==1)
s1=1; s2=-1; s3=-1;
n_state=s12;
c(i,2)=state_value(s1,s2,s3);
d(i,2)=(r(i)-c(i,2))^2;
min(i,2)=d(i,2);
end
end
elseif(i==2)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
elseif(input==1)
s1=1; s2=-1; s3=-1;
n_state=s12;
c(i,2)=state_value(s1,s2,s3);
d(i,2)=(r(i)-c(i,2))^2 + min(i-1,1);
min(i,2)=d(i,2);
end
end
c_state=s12;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=-1;
n_state=s13;
c(i,3)=state_value(s1,s2,s3);
d(i,3)=(r(i)-c(i,3))^2 + min(i-1,2);
min(i,3)=d(i,3);
elseif(input==1)
s1=1; s2=1; s3=-1;
n_state=s14;
c(i,4)=state_value(s1,s2,s3);
d(i,4)=(r(i)-c(i,4))^2 + min(i-1,2);
min(i,4)=d(i,4);
end
end
elseif(i>2 && i<len-1)
c_state=s11;
41
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
elseif(input==1)
s1=1; s2=-1; s3=-1;
n_state=s12;;
c(i,2)=state_value(s1,s2,s3);
d(i,2)=(r(i)-c(i,2))^2 + min(i-1,1);
min(i,2)=d(i,2);
end
end
c_state=s12;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=-1;
n_state=s13;
c(i,3)=state_value(s1,s2,s3);
d(i,3)=(r(i)-c(i,3))^2 + min(i-1,2);
min(i,3)=d(i,3);
elseif(input==1)
s1=1; s2=1; s3=-1;
n_state=s14;
c(i,4)=state_value(s1,s2,s3);
d(i,4)=(r(i)-c(i,4))^2 + min(i-1,2);
min(i,4)=d(i,4);
end
end
c_state=s13;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=1;
n_state=s11;
c(i,5)=state_value(s1,s2,s3);
d(i,5)=(r(i)-c(i,5))^2 + min(i-1,3);
if(d(i,5)<d(i,1))
min(i,1)=d(i,5);
end
elseif(input==1)
s1=1; s2=-1; s3=1;
n_state=s12;
c(i,6)=state_value(s1,s2,s3);
d(i,6)=(r(i)-c(i,6))^2 + min(i-1,3);
if(d(i,6)<d(i,2))
min(i,2)=d(i,6);
end
end
end
c_state=s14;
for input=-1:2:1
if(input==-1)
42
s1=-1; s2=1; s3=1;
n_state=s13;
c(i,7)=state_value(s1,s2,s3);
d(i,7)=(r(i)-c(i,7))^2 + min(i-1,4);
if(d(i,7)<d(i,3))
min(i,3)=d(i,7);
end
elseif(input==1)
s1=1; s2=1; s3=1;
n_state=s14;
c(i,8)=state_value(s1,s2,s3);
d(i,8)=(r(i)-c(i,8))^2 + min(i-1,4);
if(d(i,8) < d(i,4))
min(i,4)=d(i,8);
end
end
end
elseif(i==len-1)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
end
end
c_state=s12;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=-1;
n_state=s13;
c(i,3)=state_value(s1,s2,s3);
d(i,3)=(r(i)-c(i,3))^2 + min(i-1,2);
min(i,3)=d(i,3);
end
end
c_state=s13;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=1;
n_state=s11;
c(i,5)=state_value(s1,s2,s3);
d(i,5)=(r(i)-c(i,5))^2 + min(i-1,3);
if(d(i,5)<d(i,1))
min(i,1)=d(i,5);
end
end
end
c_state=s14;
for input=-1:2:1
if(input==-1)
s1=-1; s2=1; s3=1;
n_state=s13;
c(i,7)=state_value(s1,s2,s3);
43
d(i,7)=(r(i)-c(i,7))^2 + min(i-1,4);
if(d(i,7)<d(i,3))
min(i,3)=d(i,7);
end
end
end
elseif(i==len)
c_state=s11;
for input= -1:2:1
if(input==-1)
s1=-1; s2=-1; s3=-1;
n_state=s11;
c(i,1)=state_value(s1,s2,s3);
d(i,1)=(r(i)-c(i,1))^2 + min(i-1,1);
min(i,1)=d(i,1);
end
end
c_state=s13;
for input=-1:2:1
if(input==-1)
s1=-1; s2=-1; s3=1;
n_state=s11;
c(i,5)=state_value(s1,s2,s3);
d(i,5)=(r(i)-c(i,5))^2 + min(i-1,3);
if(d(i,5)<d(i,1))
min(i,1)=d(i,5);
end
end
end
end
end
for k=len:-1:1
if(k==len)
min_all=min(k,1);
index=1;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
%
switch p_state
% case s11
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
previous_state2=s13;
%case s12
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
previous_state2=s13;
% case s13
elseif(p_state==s13)
received(k)=s13(1);
44
previous_state1=s12;
previous_state2=s14;
%case s14
elseif(p_state==s14)
received(k)=s14(1);
previous_state1=s12;
previous_state2=s14;
end
elseif(k<len && k>2)
cal_index1=find_index(previous_state1);
cal_index2=find_index(previous_state2);
if(min(k,cal_index1)<min(k,cal_index2))
min_all=min(k,cal_index1);
index=cal_index1;
else
min_all=min(k,cal_index2);
index=cal_index2;
end
min_all;
index;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
previous_state2=s13;
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
previous_state2=s13;
elseif(p_state==s13)
received(k)=s13(1);
previous_state1=s12;
previous_state2=s14;
elseif(p_state==s14)
received(k)=s14(1);
previous_state1=s12;
previous_state2=s14;
end
elseif (k==2)
cal_index1=find_index(previous_state1);
cal_index2=find_index(previous_state2);
if(min(k,cal_index1)<min(k,cal_index2))
min_all=min(k,cal_index1);
index=cal_index1;
else
min_all=min(k,cal_index2);
index=cal_index2;
end
min_all;
index;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
45
s13=[-1 1];
s14=[1 1];
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
elseif(p_state==s13)
received(k)=s13(1);
previous_state1=s12;
elseif(p_state==s14)
received(k)=s14(1);
previous_state1=s12;
end
elseif(k==1)
cal_index1=find_index(previous_state1);
min_all=min(k,cal_index1);
index=cal_index1;
p_state=state(index);
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(p_state==s11)
received(k)=s11(1);
previous_state1=s11;
elseif(p_state==s12)
received(k)=s12(1);
previous_state1=s11;
end
end
end
for i=len:-1:1
if(i>1)
received(i)=received(i-1);
end
end
% Burst Extractor
j=1;
for i=1:len_downsample
if(i>69 && i<870)
burst_received(j)=output(i);
j=j+1;
end
end
len_burst=length(burst_received);
% Decoding
for i=1:len_burst
if(burst_received(i)==-1)
l(i)=0;
46
else
l(i)=1;
end
end
len_l=length(l);
received=l(1:len_l-2);
len_received=length(received);
H=[1 0 1 1 0 0; 1 1 1 0 1 0; 0 1 1 0 0 1];
j=1;
for i=1:6:len_received
r_mat(j,:)=received(i:i+5);
syn(j,:)=H*r_mat(j,:)';
j=j+1;
end
r_cat_val = (len_received)/6;
for i=1:r_cat_val
for k=1:3
if(syn(i,k)>1)
if(mod(syn(i,k),2)==0)
syndrom(i,k)=0;
else
syndrom(i,k)=1;
end
else
syndrom(i,k)=syn(i,k);
end
end
end
[row col]=size(syndrom);
for i=1:row
error(i,:)=error_calculate(syndrom(i,:));
estimated(i,:)=r_mat(i,:)+error(i,:);
end
received=[];
for p=1:len_estimated
received=cat(2,received,estimated(p,:));
end
ber=0;
for i=70:870
if (received(i)~=burst_modulation(i))
ber=ber+1;
end
end
BER(count)=ber/800;
end
BER=sum(BER)/4000;
Bit_ERR(SNR)=BER;
End
snr4=[6 6.2 6.6 6.8 7 7.2 7.4 7.6 7.8 8]% since it gives zero value for snr>8
semilogy(snr4,Bit_ERR);
title('plot of raw BER vs SNR for MLSE channel equlization ');
xlabel('Signal to noise ratio(SNR) in dB ->');
ylabel('raw bit error ->');
47
FUNCTIONS USED FOR CODE 5.1
function error=error_calculate(syndrom)
% syndrom=[1 0 0]';
if(syndrom==[0 0 0])
error=[0 0 0 0 0 0];
elseif (syndrom==[0 0 1])
error=[0 0 0 0 0 1];
elseif (syndrom==[0 1 0])
error=[0 0 0 0 1 0];
elseif (syndrom==[1 0 0])
error=[0 0 0 1 0 0];
elseif (syndrom==[1 1 1])
error=[0 0 1 0 0 0];
elseif (syndrom==[0 1 1])
error=[0 1 0 0 0 0];
elseif (syndrom==[1 1 0])
error=[1 0 0 0 0 0];
elseif (syndrom==[1 0 1])
error=[0 0 0 1 0 1];
end
function r=state_value(s1,s2,s3)
r=s1 +2*s2 -1.5*s3;
end
function index=find_index(state)
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
if(state==s11)
index=1;
elseif(state==s12)
index=2;
elseif(state==s13)
index=3;
elseif(state==s14)
index=4;
end
function p_state=state(index)
s11=[-1 -1];
s12=[1 -1];
s13=[-1 1];
s14=[1 1];
48
if(index==1)
s1=-1; s2=-1;
p_state=s11;
elseif(index==2)
s1=1; s2=-1;
p_state=s12;
elseif(index==3)
s1=-1; s2=1;
p_state=s13;
elseif(index==4)
s1=1; s2=1;
p_state=s14;
end
end
Code for Q.5.2
clc;
clear all;
snr=0;
for SNR=1:6
kn =[0.0994 0.0829 0.0710 0.0621 0.0552 0.0497];% This corresponds to SNR val
for count=1:4000
% Encoder
Encoder_info_len=399;
info=randint(1,Encoder_info_len) ;
% generate information bits
G=[1 0 0 1 1 0;0 1 0 0 1 1;0 0 1 1 1 1]; % generator matrix
j=1;
for i=1:3:Encoder_info_len
mat(j,:)=info(i:i+2);
codeword(j,:)=mat(j,:)*G;
j=j+1;
end
a=[1 1];
final=[];
cat_val = (Encoder_info_len)/3;
for i=1:cat_val
p=cat(2,final,codeword(i,:));
end
p=cat(2,p,a);
p_len=length(p);
for i=1:fin_len
if(p(:,i) > 1)
if(mod(p(:,i),2) == 0)
p(:,i)=0;
end
49
end
if(p(:,i) > 1)
if(mod(p(:,i),2) ~= 0)
p(:,i)=1;
end
end
end
Infosymbol=p;
% uniqueword
uw=[0 0 1 0 1 1 1 0];
uniqueword=cat(2,uw,uw,uw,uw,uw, uw, uw, uw);
% guard
guard (1:5) =0;
%tail
tail(1:2)=1;
%burst structure
burst=cat(2,guard,uniqueword,Infosymbol,tail,guard);
burst_length= length (burst);
% 876
% modulation
for i=1:burst_length
if(burst(i)==0)
burst_modulation(i)= -1;
else
burst_modulation(i)=1;
end
end
%
modulation 1->1 , 0->-1
% Upsampling
m=1;
for j=1:burst_length
up(m)= burst_modulation(j);
for k=1:32
m=m+1;
up(m)=0;
end
end
upsample_length = length( up)-1;% length is 28032 ( 876*32)
for i=1:upsample_length
upsample(i)= up(i);
end
filter=rcosine(1,32,'sqrt',0.25);% length is M=193
filter_len=length(filter);
pulse_op=conv(filter,upsample);
pulse_op_len= length (pulse_op);% length is (876*32 + 193 -1)= 28224
% Discarding M-1 samples
cut1=(filter_len-1)/2;
cut2= pulse_op_len-cut1;
50
j=1;
for i= cut1+1:cut2
pulseshape_output(j)=pulse_op(i);
j=j+1;
end
pulseshape_op_len=length(pulseshape_output);
% length is 876*32= 28032
%channel
for i=1:31
u(i)=0;
end
h1=1;
h2=2;
h3=-1.5;
filter_output=cat(2,h1,u,h2,u,h3);
len_filter_output=length(filter_output);
% length = 65
channel_conv=conv(pulseshape_output,filter_output);
len_channel_conv=length(channel_conv);
% length is (876*3)+65-1 = 28096
% discarding M-1 samples
c1= (len_filter_output-1)/2;
c2= (len_channel_conv)-c1;
j=1;
for i= c1+1 : c2
transmit_output(j) = channel_conv(i);
j=j+1;
end
transmit_output_len= length(transmit_output);
% AWGN NOISE
k=kn(snr);
Noise=k*randn(1,transmit_output_len);
tx_output=transmit_output + Noise;
% RECEIVER
% Matched Filter
Matched_filter= rcosine(1,32,'sqrt',0.25);
len_Matched_filter= length(Matched_filter); % length 193
Matched_conv=conv(Matched_filter,tx_output);
51
len_Matched_conv=length(Matched_conv);
% length 28224
% discard N-1;
m1= (len_Matched_filter-1)/2;
m2= (len_Matched_conv)-m1;
j=1;
for i= m1+1 : m2
Matched_output(j) = Matched_conv(i);
j=j+1;
end
Matched_output_length=length(Matched_output);
% DOWNSAMPLING
j=1;
for i= 1:32:Matched_output_length
r(j)=Matched_output(i);
j=j+1;
end
len=length(r) ;
% 876
% MDD DEMODULATION
j=1;
for m=1:69
if(m>7)
mdd_input(j)=downsample(m);
j=j+1;
end
end
mdd_input(63)=0;
mdd_input(64)=0;
for i=64:-1:1
if(i>1)
mdd_input(i)=mdd_input(i-1);
end
end
mdd_input(1)=0;
length(mdd_input);
k=0;
out(1:8)=0;
for j=1:8
for i=9:8:56
out(j)=out(j) + mdd_input(k+i);
end
r(j)=out(j)/6;
k=k+1;
end
b1=(r(7)+r(3))/2;
b2=(r(3)+r(8))/2;
b3=(r(1)+r(6))/2;
b4=(r(5)+r(2))/2;
b5=(r(2)+r(4))/2;
52
for i=1:len_downsample
if(downsample(i) < b1)
output(i)=-1;
elseif(downsample(i) < b2 && downsample(i)> b1)
output(i)=1;
elseif(downsample(i) < b3 && downsample(i)> b2)
output(i)=-1;
elseif(downsample(i)< b4 && downsample(i)>b3)
output(i)=1;
elseif(downsample(i)< b5 && downsample(i)>b4)
output(i)=-1;
elseif( downsample(i)>b5)
output(i)=1;
end
end
for i=len_downsample:-1:1
if(i>1)
output(i)=output(i-1);
end
end
% Burst Extractor
j=1;
for i=1:len_downsample
if(i>69 && i<870)
burst_received(j)=output(i);
j=j+1;
end
end
len_burst=length(burst_received);
% Decoding
for i=1:len_burst
if(burst_received(i)==-1)
l(i)=0;
else
l(i)=1;
end
end
len_l=length(l);
received=l(1:len_l-2);
len_received=length(received);
H=[1 0 1 1 0 0; 1 1 1 0 1 0; 0 1 1 0 0 1];
j=1;
for i=1:6:len_received
r_mat(j,:)=received(i:i+5);
syn(j,:)=H*r_mat(j,:)';
j=j+1;
end
r_cat_val = (len_received)/6;
for i=1:r_cat_val
for k=1:3
if(syn(i,k)>1)
53
if(mod(syn(i,k),2)==0)
syndrom(i,k)=0;
else
syndrom(i,k)=1;
end
else
syndrom(i,k)=syn(i,k);
end
end
end
[row col]=size(syndrom);
for i=1:row
error(i,:)=error_calculate(syndrom(i,:));
estimated(i,:)=r_mat(i,:)+error(i,:);
end
received=[];
for p=1:len_estimated
received=cat(2,received,estimated(p,:));
end
ber=0;
for i=70:870
if (received(i)~=burst_modulation(i))
ber=ber+1;
end
end
BER(count)=ber/800;
end
BER=sum(BER)/4000;
Bit_ERR(SNR)=BER;
end
figure;
snr5=[6 8 10 12 14 16 18 20];
semilogy(snr5,Bit_ERR);
title('plot of raw BER vs SNR for MDD channel equlization ');
xlabel('Signal to noise ratio(SNR) in dB ->');
ylabel('raw bit error ->');
grid on;
FUNCTIONS USED FOR CODE 5.2
function error=error_calculate(syndrom)
% syndrom=[1 0 0]';
if(syndrom==[0 0 0])
error=[0 0 0 0 0 0];
elseif (syndrom==[0 0 1])
error=[0 0 0 0 0 1];
elseif (syndrom==[0 1 0])
error=[0 0 0 0 1 0];
elseif (syndrom==[1 0 0])
error=[0 0 0 1 0 0];
elseif (syndrom==[1 1 1])
error=[0 0 1 0 0 0];
elseif (syndrom==[0 1 1])
54
error=[0 1 0 0 0 0];
elseif (syndrom==[1 1 0])
error=[1 0 0 0 0 0];
elseif (syndrom==[1 0 1])
error=[0 0 0 1 0 1];
end
Code for Q.6
% comparision
snr1=[6 7 8 9 10 11 12]; % since it gives zero value for snr >12
snr2=[6 8 10 12 14 16 18 20]; % to get good response
snr3=[6 8 10 12 14 16 18 20]; % to get good response
snr4=[6 6.2 6.6 6.8 7 7.2 7.4 7.6 7.8 8]; % since it gives zero value for
snr> 8
snr5=[6 8 10 12 14 16 18 20];
snr6=[8 10 12 14 16 18 20];
[snr1,final_ber1]= rawBER_MDD(); % code for Q2 is rawBER_MDD();
[snr3,final_ber2]= raw_theoretical_MDD();code for Q4 is
raw_theoreticalB_MDD();
figure;
semilogy(snr1,final_ber1,snr3,final_ber2);
legend('raw BER MDD ','raw BER theoretical MDD');
grid on;
[snr2,final_ber3]= rawBER_MLSE();code for Q3 is rawBER_MLSE();
[snr4,final_ber4]= codedBER_MDD();code for Q5.1 is codedBER_MDD();
[snr5,final_ber5]= codedBER_MLSE();code for Q5.2 is codedBER_MLSE();
semilogy(snr1,final_ber1,'-o',snr2,final_ber2,'-o',snr3,final_ber3,'o',snr4,final_ber4,'-o',snr5,final_ber5,'-o');
legend('raw BER MDD ','raw BER theoretical MDD','raw BER MLSE','coded BER
MDD','coded BER MLSE' );
grid on;
55
REFERENCES
1. Class Notes by Dr. Liang
2. Class Handouts by Dr. Liang
3. Viterbi, Andrew J. and Audrey M. Viterbi, “Nonlinear Estimation of PSK
4. Modulated Carrier Phase with Application to Burst Digital Transmission,”IEEE Trans.
Information Theory, vol. IT-29, no. 4, pp. 543-551, July 1983.
5. John Proakis, Digital Communications, 4th ed, McGraw-Hill Higher Education, 2000.
6. http://zone.ni.com/cms/images/devzone/tut/code%2041.jpg
7. http://merganser.math.gvsu.edu/david/reed05/projects/jimenez/state.png
56
57