Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this document? Why not share!

3,612 views

Published on

Application of viterbi decode in GSM mobile

from Freescale

No Downloads

Total views

3,612

On SlideShare

0

From Embeds

0

Number of Embeds

4

Shares

0

Downloads

184

Comments

0

Likes

2

No embeds

No notes for slide

- 1. GSM Soft Decision Viterbi Decoder GSM Soft-Decision Viterbi Decoder 1. Introduction 1.1 Encoding 1.2 Decoding 1.3 Frame Composition 2. AltiVec Implementation 2.1 Setup Constants 2.2 Metric Update 2.2.1 Determining the Branch Metrics 2.2.2 Accumulate Path Metrics 2.2.3 Store Prior States 2.3 Path Selection 2.4 Traceback 2.5 Store Result 3.Code Samples 3. Performance 4. References 1. Introduction The AltiVec extensions to the PowerPC architecture include single-instruction, multiple-data (SIMD) instructions. This note presents an example of code that exploits these instructions using the AltiVec C/C++ programming model to implement a soft-decision Viterbi decoder used in a GSM receiver. In many of today's digital communications systems, the signal-to-noise ratio (SNR) of the link has become the most severe limitation. Convolutional encoding with maximum-likelihood (Viterbi) decoding [1] can improve the SNR of a link without increasing the power budget and has become an important technique in satellite and deep-space communications systems. The coding gain of a Viterbi system is primarily determined by the constraint length K of the code, while the complexity of the decoder increases exponentially with K. The GSM CC(2,1,5) TCH frame decoder is a half rate (two bits of output for every input bit), binary (single input bit) code with a constraint length of five. The Viterbi decoder described in this note is a soft-decision decoder, which provides maximum- likelihood decoding of the convolutionally encoded signal in the presence of noise. 1.1 Encoding The decoder decodes data convolutionally encoded with the following generator polynomials: g0 = 1 + M3 + M4 g1 = 1 + M + M3 + M4 Page 1 of 8
- 2. GSM Soft Decision Viterbi Decoder These equations can also be illustrated as shown below. 1.2 Decoding The decoder takes sets of two bits (g0g1) and reconstructs the input sequence. Noise in the communication channel can corrupt some of the input bits. Cumulative path metrics are used to judge which of the possible decoding of the input bits is most likely to have occurred. The decoder has sixteen states each of which can be entered by two paths. Each state can transition to the next state by two paths as shown below in Figure 1. l Page 2 of 8
- 3. GSM Soft Decision Viterbi Decoder 1.3 Frame Composition Each TCH (traffic channel) frame contains 189 bits (or symbols), which are encoded into 378 bits. Figure 2 shows the classification of the original data in the frame. The input to the soft-decision decoder is a series of soft-decision values (soft bits) generated by the demodulator. This version uses 8-bit values between 0 and 255. An input 0 bit is ideally represented by 0 and the ideal for a 1 bit is 255. This provides 256 quantization levels to decide whether a 0 or a 1 has been transmitted for each value. Two soft bits are required for each symbol, and this algorithm assumes that the number of symbols to be processed is a multiple of 8, therefore the number of soft bits must be a multiple of 16. Because TCH has 189 symbols per frame, which is not a multiple of 8, 3 zero symbols (6 soft bits) have been added to each frame. 2. AltiVec Implementation This implementation uses two major phases to decode symbols. The first phase is responsible for evaluating the potential paths and determining the most likely one based on the soft bit input values, known as the metric update phase. The traceback phase takes the path with the lowest cumulative path metric and walks back through the possible prior states emitting the symbols that correspond to each state traversed. The implementation is discussed in terms of the following steps: Page 3 of 8
- 4. GSM Soft Decision Viterbi Decoder Setup permutation and arithmetic constants. Determine the most likely path for all input soft bit pairs in the metric update phase. Calculate the distance metrics for each state transition based on the soft-bit values. Incorporate the distance metrics with the existing path metrics in order to evaluate the 32 potential paths. Based on the path intersect points (next state incoming branches in Figure 1), and the path metrics on potential paths, eliminate the unlikely 16 paths and record the prior states for the remaining paths. Use the path metrics to select the lowest value to determine the final state of the most likely path. Work backward through the prior states to determine the output sequence of decoded bits in the traceback phase. Store the decoded sequence in memory 2.1 Setup Constants In this algorithm several constants are used for arithmetic calculations, shifting, and selecting. Because the values are all known at compile time, they can be expressed as declarations or as explicit assignments. For example: const vector unsigned char zero = (vector unsigned char)(0); vector unsigned char shift1; shift1 = (vector unsigned char)(1); In each of the above cases the value is propagated into all elements of the vector. Should a different value be required in each element, this could be coded as follows: const vector unsigned char x_select = (vector unsigned char) (0x10, 0x00, 0x12, 0x02, 0x14, 0x04, 0x16, 0x06, 0x18, 0x08, 0x1A, 0x0A, 0x1C, 0x0C, 0x1E, 0x0E ); Determining whether to declare constants or assign constant values to variables depends on the nature and size of your application. If it is fairly large code with many variables, it may be best to localize the declaration of the constants near their uses (minimizing potential spilling effects). The best method tends to depend on the compiler's behavior and optimization capabilities. 2.2 Metric Update The metric update section accumulates branch distance metrics into path metrics. The lowest path metric at the end of processing is considered to denote the path most likely to contain the correct decoding of the input. The lowest path metric is used since saturation is possible when adding up 189 individual 8-bit values in a 16-bit accumulator. Input is processed in groups of 16 soft bit values with 8 bits of data per soft bit value, making up an unsigned char vector. This input decodes into eight symbols. The first and last group of eight symbols require special processing. The first group does not require prior state information to be saved for the first four transitions, which allows a saving of calculations to be performed. See Figure 3 for an example of processing the first four sets of soft bits. The last group does not use all eight sets, so processing only occurs until the last expected soft bit set is encountered. Page 4 of 8
- 5. GSM Soft Decision Viterbi Decoder Page 5 of 8
- 6. GSM Soft Decision Viterbi Decoder The metric update section generally consists of reading in a group of symbols, calculating the branch metrics for a set of input values, and then accumulating the branch metrics into the path metrics, for the most likely branch (that is the one with the smallest value). After the incoming branch is selected then the prior state is saved. This helps to facilitate reconstruction during the traceback phase. 2.2.1 Determining the Branch Metrics Branch metrics represent the likelihood a specific input pair corresponds to a signal. These are effectively the additional distances to be added to the path metrics for transition from the previous state to the current one. The closer each metric is to zero, the higher the likelihood that the specific signal it denotes has been received. The input signals (soft bits) received from the demodulator use 8 bits for each potential value. The soft bit values range from 0 to 255. A pair of input signals is required for each translated symbol. The values in a pair are denoted as the x value and y value. These are used to form the following metrics: m0 : denotes that the signal is (0,0), formed by x+y m1: denotes that the signal is likely (1,1), formed by (255-x)+(255-y) = 510 - m0 m2: denotes that the signal is likely (0,1), formed by x + (255-y) = 255 + ( x - y ) m3: denotes that the signal is likely (1,0), formed by (255 - x ) + y = 255 - (x - y) This clearly identifies the special-case handling where the last few symbols' values are calculated and used directly. m0 = vec_add(x,y); m1 = vec_sub(v_510,m0); m2 = vec_add(v_255,x); m3 = vec_add(v_255,y); m2 = vec_sub(m2,y); m3 = vec_sub(m3,x); The metrics are interleaved to improve the efficiency inside the loop. That is to say, part of the m0 values (denoted m0s in the comments) resides in m0 and m1. The actual m1 values (denoted m1s in the comments) reside in m0 and m1 as well, interleaved with the m0 values. The m2 and m3 values share a similar relationship. These calculations occur in 16-bit integers, so there is no possibility of saturation at this point. #define DEFINE_BRANCH_METRICS(x,y) m0 = vec_add(x,y); /* m0s = x + y */ temp = vec_sub(v_510,m0); /* m1s = 510 - m0s */ m1 = vec_mergel(m0,temp); /* m1 = second 4 m0s, m1s */ m0 = vec_mergeh(m0,temp); /* m0 = first 4 m0s, m1s */ temp = vec_add(v_255,x); /* bm0 = x + 255 */ m3 = vec_add(v_255,y); /* m3 = y + 255 */ temp = vec_sub(temp,y); /* m2s = 255+(x-y) */ m3 = vec_sub(m3,x); /* m3s = 255-(x-y) */ m2 = vec_mergeh(temp,m3); /* m2 = first 4 m2s, m3s */ m3 = vec_mergel(temp,m3); /* m3 = second 4 m2s, m3s */ The above code sample produces the following data structures for use in the loop. Page 6 of 8
- 7. GSM Soft Decision Viterbi Decoder These values are then distributed to form the branch metrics denoted bm0 and bm1 2.2.2 Accumulate Path Metrics There are 16 possible paths on which metrics are accumulated. Each branch introduces the possibility of two new paths. The next state has 32 possible paths leading to it (see Figure 1). When two paths join at the next state (i.e. trellis intersect point), the least likely of the two merging paths is discarded. This results in the lowest value of the two merging paths being recorded as the path metric to this point. The path metric accumulators are separated into two vectors, pm0 and pm1, because each vector only holds eight values. At each transition from the present state to the next state, there are 32 possible paths to consider. The possible values are stored in the quot;dmquot; prefixed vectors. The dm vectors are formed by adding the path distances up to that point to the current branch distances (bm0 and bm1). Saturating arithmetic is used because there is the possibility of overflow on the least-likely paths. The two paths leading to the same state are then compared and the path with the lower value is then recorded as the current path metric. This is performed in the ACCUMULATE_PATH_METRICS macro. /* partition the paths into groups of 8 values, grouped by possible output value */ dm00 = vec_perm(pm0,pm1,extract_even); dm10 = vec_perm(pm0,pm1,extract_odd); /* add branch metrics to form the possible paths metrics */ dm01 = vec_adds(dm00,bm1); dm00 = vec_adds(dm00,bm0); dm11 = vec_adds(dm10,bm0); dm10 = vec_adds(dm10,bm1); /* assign new path metrics from the best (lowest) path */ pm0 = vec_min(dm10,dm00); pm1 = vec_min(dm11,dm01); 2.2.3 Store Prior States When the path has been determined, it is important to record its prior state. Because each state has two possible input paths, it is important to select the one corresponding to the path metric recorded in pm0, pm1. The state associated with that path is then recorded in the ps vector, which is saved in the past_states working storage area in preparation for the traceback phase of the algorithm. This work is performed in the STORE_STATE macro. /* determine which of the paths has the lower metric */ mask0 = vec_cmpgt(dm00,dm10); mask1 = vec_cmpgt(dm01,dm11); /* select 16 states from the 32 possible paths */ ps = vec_pack((vector unsigned short)mask0, (vector unsigned short)mask1 ); ps = vec_sel(as0,as1,ps); /* store the prior states in the working storage area */ vec_st(ps,ps_offset,past_states); ps_offset += CHARS_PER_VECTOR; 2.3 Path Selection When all the input symbols have been processed, the path metrics vector would normally be analyzed to determine the path with the lowest metric. However, the GSM standard requires four trailing zeros to be added to the input stream (part of the 189 input symbols), to ensure that the best path always ends up in the zero state position of the ps vector. Page 7 of 8
- 8. GSM Soft Decision Viterbi Decoder 2.4 Traceback After the best path has been determined, the prior states are traversed to extract the decoded symbols. The first element in current is always the current state in the best path. The paths are encoded as the state's positions, and the path is reconstructed by using the prior state to permute the current. This is used for all states along the path, except for the first four, which are deterministic. Symbols at position 5 through 189 are decoded inside the loop. The state in the first element of current can be decoded to determine which value should be emitted to output. States 0-7 imply a 0, while states 8-15 imply a 1 (see Figure 1). The code to decode the symbols is given in the LOAD_STATE and DECODE_AND_SAVE_SYMBOL macros. /* Work backwards through the states */ ps_offset -= 16; /* chars per vector */ current = vec_ld( ps_offset, past_states); /* Obtain the current state from a permutation of prior state. */ current = vec_perm(current,zero,prior); /* Copy the current state into prior state for next iteration. */ prior = current; /* Extract the output bit from the most significant bit of the state and shift it into the output vector. */ output = vec_srl(output,(vector unsigned char)(1)); temp = vec_sll(current,(vector unsigned char)(4)); output = vec_sel(output,temp,(vector unsigned char) (0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)); The first four symbols correspond to deterministic paths. The ending point of the prior decoding indicates what the remaining bits will be (see possible_values). 2.5 Store Result As each bit is shifted into place from the traceback portion of the algorithm, it becomes necessary to save the results to the area pointed to by output_ptr. Since the area pointed to by output_ptr is already aligned, it is necessary only to use vec_st() to save the data. No explicit alignment of the vector with the storage area is required. 3.Code Samples C source for the entire function (quot;GSMSDVDCCODquot; on web). Assembly output of a compiler (quot;GSMSDVDSCODquot; on web). 4. Performance Performance results are given in clock cycles for a typical implementation of AltiVec. Performance for a specific AltiVec implementation may vary. Also, performance can vary depending on the C compiler used and can improve as the quality of a compiler improves from release to release. It is assumed that all required instructions and data are present in the L1 cache. It takes 11.8 cycles to process each symbol in the metric update section. The overall processing (metric update and traceback) of a TCH frame took 3084 cycles, which works out to 16.3 cycles per symbol. This time includes the function call overhead. 5. References [1] S.M. Redl, M.K. Weber, M.AW. Oliphant, quot;An Introduction to GSM,quot; Artech House Inc., 1995. [2] S. Twelves, X. Yang, P. Kritzinger, E. Leonardo, quot;Design and Implementation of an Efficient Viterbi Decoder Using AltiVec,quot; Motorola internal communication, 1998. Page 8 of 8

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment