This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
DSP C5000DSP C5000
Chapter 22Chapter 22
Implementation of Viterbi Implementation of Viterbi Algorithm/Convolutional CodingAlgorithm/Convolutional Coding
Explain the Explain the Viterbi AlgorithmViterbi Algorithm E.g.: detection of sequence of symbolsE.g.: detection of sequence of symbols
Example of application on the Example of application on the GSM convolutional codingGSM convolutional coding
Present its Present its implementation on the C54x implementation on the C54x Specific hardwareSpecific hardware Specific instructionsSpecific instructions
Dynamic programmingDynamic programming Finds the most likely state transitions in a state diagram, given a noisy sequence Finds the most likely state transitions in a state diagram, given a noisy sequence
of symbols or an observed signal.of symbols or an observed signal. Applications inApplications in
Digital communications:Digital communications: Channel equalization, Detection of sequence of symbolsChannel equalization, Detection of sequence of symbols Decoding of convolutional codesDecoding of convolutional codes
Speech recognition (HMM)Speech recognition (HMM) Viterbi can be applied when the problem can be formulated by a Markov chain.Viterbi can be applied when the problem can be formulated by a Markov chain.
If values of If values of k k form a countable set, it is form a countable set, it is a Markov chain. a Markov chain. kk state of the Markov chain at time k state of the Markov chain at time k
Example: Detection of a Sequence of Symbols Example: Detection of a Sequence of Symbols in Noisein Noise
Ak hk
Sk
Nk
Yk
Emitted Emitted symbolssymbols
Equivalent Equivalent Discrete Discrete model of the model of the channel channel
NoiseNoise
Observed noisy Observed noisy sequencesequence
The problem of the The problem of the detection of a sequence of symbolsdetection of a sequence of symbols is to find is to find the best state sequence for a given sequence of observations Yk the best state sequence for a given sequence of observations Yk with k in the interval [1,K].with k in the interval [1,K].
Y S Nk k k S h Ak i k ii
p
1
Sk is a signal generated by a Markov chainSk is a signal generated by a Markov chain
Example: Detection of a Sequence of Symbols Example: Detection of a Sequence of Symbols in Noisein Noise
k k k
k k k
k k k
A A
A A
S f
( , )
( , )
( , )
1
1 1
1
There are 4 states in the Markov chain.There are 4 states in the Markov chain.
The transition between the different states can be The transition between the different states can be represented by a represented by a State DiagramState Diagram, or by a , or by a TrellisTrellis..
Example: Detection of a Sequence of Symbols Example: Detection of a Sequence of Symbols in Noise, in Noise, Trellis RepresentationTrellis Representation
k=0 k=1 k=5 k=K-2 k=K-1 k=Kk=4k=3k=2
Hypothesis: initial condition = state 00, final condition = state 00Hypothesis: initial condition = state 00, final condition = state 00
Trellis with 4 states: (0,0) (0,1) (1,0) (1,1)Trellis with 4 states: (0,0) (0,1) (1,0) (1,1)
Example: Detection of a Sequence of SymbolsExample: Detection of a Sequence of Symbols
Each path in the trellis corresponds to Each path in the trellis corresponds to an input sequence Ak.an input sequence Ak.
From the sequence of observations Yk, From the sequence of observations Yk, the receiver must choose among all the the receiver must choose among all the possible paths of the trellis, the path possible paths of the trellis, the path that best corresponds to the Yk for a that best corresponds to the Yk for a given criterion.given criterion.
To choose a path in the trellis, is To choose a path in the trellis, is equivalent to choose a sequence of states equivalent to choose a sequence of states kk, or of A, or of Akk or of S or of Skk..
We suppose that the criterion is a We suppose that the criterion is a quadratic distance.quadratic distance.
Example: Detection of a Sequence of SymbolsExample: Detection of a Sequence of Symbols
min Y Sk kk
K
2
0
Choose the sequence that minimizes the total distance:Choose the sequence that minimizes the total distance:
The number of possible paths of length K in a trellis increases as The number of possible paths of length K in a trellis increases as MMKK, where M is the number of states., where M is the number of states.
The Viterbi algorithm allows to solve the problem with a The Viterbi algorithm allows to solve the problem with a complexity proportional to Kcomplexity proportional to K (not proportional to M (not proportional to MKK).).
It is derived from dynamic programming techniques (Bellman, It is derived from dynamic programming techniques (Bellman, Omura, Forney, Viterbi).Omura, Forney, Viterbi).
Let us consider the binary case: Let us consider the binary case: 2 branches arrive at each node2 branches arrive at each node 2 branches leave each node2 branches leave each node All the paths going through 1 node use one All the paths going through 1 node use one
of the 4 possible paths.of the 4 possible paths. If the best path goes through one node, If the best path goes through one node,
it will arrive by the better of the 2 it will arrive by the better of the 2 arriving branches.arriving branches.
The receiver keeps only one path, The receiver keeps only one path, among all the possible paths at the left among all the possible paths at the left of one node.of one node. This best path is called the survivor.This best path is called the survivor.
k-1 k
??
For each node the receiver stores For each node the receiver stores at time k: at time k: the cumulated distance from the the cumulated distance from the
origin to this node origin to this node the number of the surviving branch.the number of the surviving branch.
Viterbi Algorithm: 2 Steps 1 of 3Viterbi Algorithm: 2 Steps 1 of 3
There are 2 steps in the Viterbi There are 2 steps in the Viterbi algorithmalgorithm A left to right step from k=1 to k=K in A left to right step from k=1 to k=K in
which the distance calculations are donewhich the distance calculations are done Then a right to left step called traceback Then a right to left step called traceback
that simply reads back the results from the that simply reads back the results from the trellis.trellis.
Viterbi Algorithm: 2 steps 2 of 3Viterbi Algorithm: 2 steps 2 of 3
The left to right step from k=1 to k=K:The left to right step from k=1 to k=K: For each stage k and each node, calculate For each stage k and each node, calculate
the cumulated distance D for all the the cumulated distance D for all the branches arriving at this node.branches arriving at this node.
Distance calculations are done recursively:Distance calculations are done recursively: The cumulated distance at time k for a node i: D(k,i) The cumulated distance at time k for a node i: D(k,i)
reached by 2 branches coming from nodes m and n is reached by 2 branches coming from nodes m and n is the minimum of:the minimum of:
D(k-1,n) + d(n,i)D(k-1,n) + d(n,i) D(k-1,m) + d(m,i)D(k-1,m) + d(m,i) Where d(n,i) is the local distance on the branch from Where d(n,i) is the local distance on the branch from
node n at time k-1 to node i at time k.node n at time k-1 to node i at time k. d(n,i)=(Yk-Sk(n,i))d(n,i)=(Yk-Sk(n,i))22 where Sk(n,i) is the output when where Sk(n,i) is the output when
going from node n to node i.going from node n to node i.
Viterbi Algorithm: 2 steps 3 of 3Viterbi Algorithm: 2 steps 3 of 3
At the end of the first step:At the end of the first step: The receiver has an array of size KxM The receiver has an array of size KxM
containing for each node at each stage the containing for each node at each stage the number of the survivor,number of the survivor,
and the set of values=cumulated distances and the set of values=cumulated distances from the origin to each node of the last from the origin to each node of the last stage.stage.
The second step is called The second step is called traceback.traceback. It is simply the reading of the best path It is simply the reading of the best path
from the right to the left of the trellis.from the right to the left of the trellis. The best path arrives at the best final node, The best path arrives at the best final node,
so we just have to start from it and read the so we just have to start from it and read the array of survivors from node to node until array of survivors from node to node until the origin is reached.the origin is reached.
Convolutional DecodingConvolutional DecodingHard or Soft DecisionHard or Soft Decision
Hard decisionHard decision: data represented by a single bit => Hamming distance: data represented by a single bit => Hamming distance Soft decisionSoft decision: data represented by several bits => Euclidian or probabilistic distance: data represented by several bits => Euclidian or probabilistic distance
Example 3 bits quantized valuesExample 3 bits quantized values 011=most confidence value 011=most confidence value 111=less conf. neg. value111=less conf. neg. value 010010 110110 001001 101101 000=Less conf. pos. value000=Less conf. pos. value100=most conf. neg. val.100=most conf. neg. val.
For the GSM coding example, at each new step n, the receiver receives 2 hard or soft For the GSM coding example, at each new step n, the receiver receives 2 hard or soft values.values. Soft decision values will be noted SDSoft decision values will be noted SD00 and SD and SD11
Evaluation of the Local DistanceEvaluation of the Local Distancefor Soft Decoding R=0.5for Soft Decoding R=0.5
dist_loc(j)=SDdist_loc(j)=SD00GG00(j)+SD(j)+SD11GG11(j)(j) 4 possible values (24 possible values (21/R1/R) :) :
d = SDd = SD0 0 + SD+ SD11
d’ = SDd’ = SD0 0 - SD- SD11
- d- d - d’- d’
Use of symmetryUse of symmetry Only 2 distances are calculatedOnly 2 distances are calculated Paths leading to the same state are complementaryPaths leading to the same state are complementary
Maximize distance instead of minimize because of Maximize distance instead of minimize because of the minus sign.the minus sign.
Calculation of Accumulated Distances Calculation of Accumulated Distances using Butterfly Structureusing Butterfly Structure
One butterfly: 2 starting and ending states (joined by One butterfly: 2 starting and ending states (joined by the paths) are paired in a butterfly. the paths) are paired in a butterfly. For R=0.5 , state 2J and 2J+1 with J and J+8For R=0.5 , state 2J and 2J+1 with J and J+8
Symmetry is used to simplify calculationsSymmetry is used to simplify calculations One local_distance per butterfly is usedOne local_distance per butterfly is used Old possible metric values are the same for both new states => Old possible metric values are the same for both new states =>
To implement the Viterbi algorithm on To implement the Viterbi algorithm on C54x we need:C54x we need: Compare store and Select UnitCompare store and Select Unit One AccumulatorOne Accumulator Specific instructionsSpecific instructions
DADSTDADST Double-Precision Load With T Add orDouble-Precision Load With T Add or Dual 16-Bit Load With T Add/Subtract)Dual 16-Bit Load With T Add/Subtract)
DSADTDSADT Long-Word LoadLong-Word Load With T Add orWith T Add or Dual 16-Bit Load With T Subtract/Add)Dual 16-Bit Load With T Subtract/Add)
C16=1, ALU dual 16-bit operationsC16=1, ALU dual 16-bit operations, 2 additions or , 2 additions or subtractions in 1 cyclesubtractions in 1 cycle
C16=0, ALU standard mode, single operation C16=0, ALU standard mode, single operation double precisiondouble precision
C16=1C16=1 1 addition and 1 subtraction using the T register1 addition and 1 subtraction using the T register
C16=0, not of interest for ViterbiC16=0, not of interest for Viterbi DADST: dst=Lmem + (T+T<<16)DADST: dst=Lmem + (T+T<<16) DSADT: dst=Lmem - (T+T<<16)DSADT: dst=Lmem - (T+T<<16)
and enabled)and enabled) Initialization of metric valuesInitialization of metric values Block repeat counter = number of output bits -1Block repeat counter = number of output bits -1
in one circular buffer:in one circular buffer: Buffer size 2 x 2Buffer size 2 x 2K-1K-1. Register BK initialized at 2 x 2. Register BK initialized at 2 x 2K-1K-1
index pointer AR0=index pointer AR0= 22K-2K-2 + 1 + 1 All states except starting one 0 are set to the All states except starting one 0 are set to the
VA Metric UpdateVA Metric UpdateLoop for all Symbol IntervalsLoop for all Symbol Intervals
Calculate local distance between input and Calculate local distance between input and each possible path. For R=0.5, only 2 valueseach possible path. For R=0.5, only 2 values LD LD *AR1+,16,A*AR1+,16,A
;A=SD0(2i);A=SD0(2i) SUB SUB *AR1,16,A,B*AR1,16,A,B ;B=SD0(2i)-;B=SD0(2i)-
Accumulate total distance for each stateAccumulate total distance for each state Using the split ALU, the C54x accumulates metrics for 2 paths Using the split ALU, the C54x accumulates metrics for 2 paths
in 1 cycle (if local dist in T) with DADST and DSADT.in 1 cycle (if local dist in T) with DADST and DSADT. Select and save minimum distanceSelect and save minimum distance Save indication of chosen pathSave indication of chosen path
The 2 last steps can be done in one cycle using CMPS The 2 last steps can be done in one cycle using CMPS (Compare Select Store) on the CSSU.(Compare Select Store) on the CSSU.
VA Metric UpdateVA Metric Updateuse of Buffersuse of Buffers
Old metrics accessed in consecutive orderOld metrics accessed in consecutive order One pointer for addressing 2One pointer for addressing 2K-1K-1 words. words.
New metric accessed in order : New metric accessed in order : 0, 20, 2K-2K-2, 1, 2, 1, 2K-2K-2+1, 2, 2+1, 2, 2K-2K-2+2 ...+2 ... 2 pointers for addressing.2 pointers for addressing.
At the end, both buffers are swappedAt the end, both buffers are swapped The transition register TRN (16bits) must be saved every 8 butterflies (2 The transition register TRN (16bits) must be saved every 8 butterflies (2
Code for the Metric UpdateCode for the Metric Updatein a Direct Butterflyin a Direct Butterfly
LDLD *AR2 T*AR2 T ;load d in T;load d in T DADSTDADST *AR5,A*AR5,A ;D;D2J2J+d and D+d and D2J+12J+1-d-d DSADTDSADT *AR5+,B*AR5+,B ;D;D2J2J-d and D-d and D2J+12J+1+d+d CMPSCMPS A,*AR4+A,*AR4+ ;compares the distances ;compares the distances
ofof ;the 2 paths arriving at ;the 2 paths arriving at
JJ ;stores the ;stores the
best.TRN=TRN<<1.best.TRN=TRN<<1. ;TRN(0)=1 if D;TRN(0)=1 if D2J2J+M < D+M < D2J+12J+1--
M,M, ;TRN(0)=0 if D;TRN(0)=0 if D2J2J+M > D+M > D2J+12J+1--
MM CMPSCMPS B,*AR3+ B,*AR3+ ;;compares the distances compares the distances
ofof ;2 paths arriving at ;2 paths arriving at
J+2J+2(K-2),(K-2),
;stores the ;stores the best.TRN=TRN<<1.best.TRN=TRN<<1.
; TRN(0)=1 si D; TRN(0)=1 si D2J2J-M < -M < DD2J+12J+1+M,+M,
; TRN(0)=0 si D; TRN(0)=0 si D2J2J-M > -M > DD2J+12J+1+M+M
Update of metrics buffer pointers for next Update of metrics buffer pointers for next symbol interval :symbol interval : As metric buffers are set up in circular As metric buffers are set up in circular
buffer, no overhead.buffer, no overhead. Use Use *ARn+0%*ARn+0% in the last butterfly (AR0 was in the last butterfly (AR0 was
initialized with 2initialized with 2(K-2)(K-2)+1 = 9+1 = 9 Note long word incrementing Lmem: *ARn+Note long word incrementing Lmem: *ARn+
The transition data buffer pointer is The transition data buffer pointer is incremented by 1 (each TRN is a 16-bit incremented by 1 (each TRN is a 16-bit word)word)
VA Traceback FunctionVA Traceback Function Trace the maximum likelihood path backward through the trellis to obtain Trace the maximum likelihood path backward through the trellis to obtain
N bits.N bits. Final state known (by insertion of tail bits in the emitter) or estimated (best Final state known (by insertion of tail bits in the emitter) or estimated (best
final metric).final metric). In the transition buffer :In the transition buffer :
1 = previous state is the lower path1 = previous state is the lower path 0 = previous state is the upper path0 = previous state is the upper path
Previous state is obtained by shifting transition value in the LSB of the statePrevious state is obtained by shifting transition value in the LSB of the state
VA Traceback Function (cont.)VA Traceback Function (cont.)
The data sequence is obtained from the The data sequence is obtained from the reconstructed sequence of states. reconstructed sequence of states. (MSB).(MSB).
The data sequence is (often) in reversed The data sequence is (often) in reversed order. order.
VA Traceback Function (cont.)VA Traceback Function (cont.)Transition Data BufferTransition Data Buffer
The transition data buffer has:The transition data buffer has: 22K-5K-5 transition words for each symbol interval. transition words for each symbol interval. For N trellis stages or symbol intervals, there are For N trellis stages or symbol intervals, there are
N 2N 2K-5K-5 words in the transition data buffer. words in the transition data buffer. For GSM, 2For GSM, 2K-5K-5 = 1. = 1.
Stored transition data are scrambled.Stored transition data are scrambled. E.g. GSM, 1 trans. Word/stage, state E.g. GSM, 1 trans. Word/stage, state
Calculate position of the current state in the Calculate position of the current state in the transition data buffer for each symbol transition data buffer for each symbol interval.interval.
VA Traceback: Find the Word to Read in the VA Traceback: Find the Word to Read in the Transition Data BufferTransition Data Buffer
For a given node j at time t, find the correct For a given node j at time t, find the correct transition word and the correct bit in that transition word and the correct bit in that word.word. For the GSM example there is only 1 transition For the GSM example there is only 1 transition
word per symbol interval. word per symbol interval. In the general case, there are 2In the general case, there are 2K-5K-5 transition words transition words
and if the state number is written in binary:and if the state number is written in binary: j = bj = bK-2K-2 … b … b33 b b22 b b11 b b0, 0,
The number of the transition word for node j is obtained The number of the transition word for node j is obtained by setting MSB of j to 0 and shifting the result 3 bits to the by setting MSB of j to 0 and shifting the result 3 bits to the right.right.
Trn_Word_number(j) = bTrn_Word_number(j) = bK-2K-2 … b … b44 b b3, 3,
VA Traceback: Find Bit to read in the VA Traceback: Find Bit to read in the Correct Word of the Transition Data BufferCorrect Word of the Transition Data Buffer
Find the number of the correct bit in the Find the number of the correct bit in the transition word. transition word.
Number 0 = MSB, number 15 = LSB.Number 0 = MSB, number 15 = LSB.
If state number j = bIf state number j = bK-2K-2 b b33 b b22 b b11 b b00 in in binary,binary, Bit number (Bit#) in the in the transition Bit number (Bit#) in the in the transition
word is:word is: Bit # = Bit # = bb33 b b22 b b11 b b00 b bK-2 K-2 (for the GSM (for the GSM
example)example) Bit# = 2 x state +(state >> (K-2))&1Bit# = 2 x state +(state >> (K-2))&1 Bit# = 2 x state + MSB(state)Bit# = 2 x state + MSB(state)
This bit number (in fact 15-Bit#) is This bit number (in fact 15-Bit#) is loaded in T for next step.loaded in T for next step.
VA Traceback: Determine Preceding NodeVA Traceback: Determine Preceding Node
Read and test selected bit to determine the Read and test selected bit to determine the state in the preceding symbol interval t-1,state in the preceding symbol interval t-1, Instruction Instruction BITTBITT copy this bit in TC. copy this bit in TC. Set up Address in the transition buffer for next Set up Address in the transition buffer for next
iteration.iteration. Instruction Instruction BITTBITT (Test Bit Specified by T) (Test Bit Specified by T)
Tests bit n° 15-T(3-0)Tests bit n° 15-T(3-0) Update node value with new bitUpdate node value with new bit
New state obtained with inst. New state obtained with inst. ROLTCROLTC:: ROLTCROLTC shifts ACCU 1 bit left and shifts TC bit shifts ACCU 1 bit left and shifts TC bit
into the ACCU LSB.into the ACCU LSB. So if j = bSo if j = bK-2K-2 b b33 b b22 b b11 and transition bit = TC and transition bit = TC
The precedent node has number: bThe precedent node has number: b33 b b22 b b11 TC (for GSM) TC (for GSM)
VA Traceback Function (cont.)VA Traceback Function (cont.)
Traceback algorithm is implemented in Traceback algorithm is implemented in a loop of 16 stepsa loop of 16 steps The single decoded bits are packed in 16-The single decoded bits are packed in 16-
bits wordsbits words Bit reverse orderingBit reverse ordering
VA Traceback RoutineVA Traceback Routine A = state valueA = state value B = tmp storageB = tmp storage K = constraint lengthK = constraint length MASK = 2MASK = 2(K-5)(K-5)-1-1 ONE=1ONE=1 Final state is assumed to be 0Final state is assumed to be 0 AR2 points on the transition data bufferAR2 points on the transition data buffer TRANS_END=end address of trans. bufferTRANS_END=end address of trans. buffer AR3 points on the output bit bufferAR3 points on the output bit buffer OUTPUT = address of the output bit bufferOUTPUT = address of the output bit buffer NBWORDS = Nb of words of output buffer NBWORDS = Nb of words of output buffer
packed by packs of 16 bits.packed by packs of 16 bits.