A kind of Turbo code interleaver and deinterleaving method thereof
Technical field
The present invention relates to the interleaving technology in the mobile communication, specifically, relate to a kind of Turbo code interleaver and interweaving method thereof.
Background technology
The Turbo code interleaver is the important component part of Turbo coder, the excellent properties that Turbo code has, and its basic reason is that interleaver has been realized pseudo-randomness in the implementation of Turbo code.At transmitting terminal, its pseudo-randomness is realized by encoder and parallel cascade mode; At the decoding end, then utilize the feedback iterative decoding of interleaver to realize with soft input/soft output characteristic.As seen, interleaver is very important, and its performance directly influences the performance of Turbo code.3GPP (3G (Third Generation) Moblie partner plan) agreement has provided a kind of irregular algorithm that interweaves, and this interleaver alogithm is very complicated and also different with its algorithm of difference of interleaving block length.
Stipulate that according to 3GPP interweaving of Turbo code comprises the bit input matrix, interior exchange of the row of matrix and exchange in the ranks when the bit in the matrix is exported are deleted original non-existent bit.The interleaving process of relevant Turbo code in the following description protocol.
If the input bit that interweaves of Turbo code is designated as x
1, x
2, x
3..., x
K, K is the bit number machine weaving length of input, and 40≤K≤5114.The input bit sequence x that Turbo code interweaves
kWrite matrix as follows.
(1) determine the line number R of matrix:
The line number of matrix is designated as 0,1,2 from top to bottom ..., R-1.
(2) determine that matrix column counts C:
Wherein, p is a prime number.The matrix column number from left to right is designated as 0,1,2 ..., C-1.
(3) with bit sequence x
kDelegation of delegation writes R * C matrix, bit x
1List at 0 of 0 row:
Behind bit input R * C matrix, exchange is undertaken by following algorithm in the exchange in the ranks of matrix and the row:
(1) selects primitive root v from table 1
(2) exchange basic sequence s (i) in the structure row
s(i)=[v×s(i-1)]mod p,i=1,2,…,(p-2),and s(0)=1。
Wherein i is the rectangular array sequence number.
(3) with q
0=1 is { q
jIn first prime number, press following formula and select continuous least prime { q
j(j=1,2 ..., R-1 is the row matrix sequence number):
G.c.d{q
j, p-1}=1, q
j>6, q
j>q
(j-1), wherein g.c.d. is a greatest common divisor.
(4) conversion { q
jObtain exchanging prime number { r
j}
r
T(j)=q
j,j=0,1,...,R-1,
Wherein T (j) (j=0,1,2 ..., R-1) be switch mode in the ranks, determine by following formula four kinds in the ranks one of switch mode: Pat1, Pat2, Pat3 and Pat4
Pat1, Pat2, Pat3 and Pat4 are as follows respectively:
Pat1:{19,9,14,4,0,2,5,7,12,18,10,8,13,17,3,1,16,6,15,11}
Pat2:{19,9,14,4,0,2,5,7,12,18,16,13,17,15,3,1,6,11,8,10}
Pat3:{9,8,7,6,5,4,3,2,1,0}
Pat4:{4,3,2,1,0}
(5) j (j=0,1,2 ..., R-1) exchange is as follows in the row:
If C=p a., so
U
j(i)=s([i×r
j]mod(p-1)),i=0,1,2,...,(p-2),andU
j(p-1)=0,
U wherein
j(i) be the pass through position of input bit of i output after the space inner conversion of j.
If C=p+1 b., so
U
j(i)=s([i×r
j]mod(p-1)),i=0,1,2,...,(p-2),U
j(p-1)=0,and U
j(p)=p,
U wherein
j(i) be the pass through position of input bit of i output after the space inner conversion of j, and
And if K=C * R, exchange U so
R-1(p) and U
R-1(0) position.
If C=p-1 c., so
U
j(i)=s([i×r
j]mod(p-1))-1,i=0,1,2,...,(p-2),
U
j(i) be the pass through position of i the later input bit of exporting of exchange in the space of j.
(6) based on pattern T (j) (j=0,1,2 ..., R-1) in the ranks exchange, T (j) is the home position of j exchange row.
p |
v |
p |
v |
p |
v |
p |
v |
p |
v |
7 |
3 |
47 |
5 |
101 |
2 |
157 |
5 |
223 |
3 |
11 |
2 |
53 |
2 |
103 |
5 |
163 |
2 |
227 |
2 |
13 |
2 |
59 |
2 |
107 |
2 |
167 |
5 |
229 |
6 |
17 |
3 |
61 |
2 |
109 |
6 |
173 |
2 |
233 |
3 |
19 |
2 |
67 |
2 |
113 |
3 |
179 |
2 |
239 |
7 |
23 |
5 |
71 |
7 |
127 |
3 |
181 |
2 |
241 |
7 |
29 |
2 |
73 |
5 |
131 |
2 |
191 |
19 |
251 |
6 |
31 |
3 |
79 |
3 |
137 |
3 |
193 |
5 |
257 |
3 |
37 |
2 |
83 |
2 |
139 |
2 |
197 |
2 |
|
|
41 |
6 |
89 |
3 |
149 |
2 |
199 |
3 |
|
|
43 |
3 |
97 |
5 |
151 |
6 |
211 |
2 |
|
|
Table 1: prime number p and relevant primitive root v
Exchange in space and in the ranks, the bit of matrix is designated as y ':
The output bit that Turbo code interweaves is that the matrix R * C with exchange in space and in the ranks press leu and exports initial bits y '
1At 0 row of 0 row, end bit y '
CRR-1 at the C-1 row is capable.During output, non-existent bit in the list entries is removed, that is to say, corresponding to x '
kBit y '
kIf the bit y ' of k>K in space and is in the ranks arranged in the switching matrix
k, then when output, to remove.Output after interweaving is designated as x '
1, x '
2..., x '
K, x '
1Corresponding to y ' through arrangement
k, k is a smallest sequence number, x '
2Corresponding to y ' through arrangement
k, k is a time little sequence number.The output bit number that interweaves is K, and needing the bit number of deletion is R * C-K.
The algorithm that interweaves of above-mentioned agreement regulation in the coding and decoding application of reality, generates the table that interweaves according to the algorithm that interweaves usually in advance, obtains input bit that is used to interweave and the corresponding relation of exporting the bit position by tabling look-up, to save complicated algorithm in the interleaving process.For example, a kind of scheme is, according to all weaving lengths of stipulating in the agreement, set up the position table of the corresponding relation of input bit and output bit position for the special value of some weaving length, being the base table or the table that interweaves, is 40 bits, 50 bits, the 55 position tables than top grade such as setting up weaving length respectively, generally comprises 220, at first select corresponding position table, the position of searching the output bit of current input bit correspondence then when interweaving according to the position table according to weaving length; Another kind of scheme is, the type of service and the weaving length that need provide are provided, and sets up the position table according to weaving length, with the interweave memory space of table of minimizing, the position of directly searching the output bit of current input bit correspondence according to the position table when interweaving.
No matter adopt which kind of mode to set up the table that interweaves, this mode that interweaves by the realization of tabling look-up can reduce the operand of the algorithm that interweaves to a certain extent, but when the memory space of the table that interweave very big, required thus search operand and the time of searching also very big, and be unfavorable for very much the realization of hardware.
Summary of the invention
In view of this, the object of the present invention is to provide a kind of Turbo code interleaver,, avoid the shortcoming that interweaves by the lookup table mode realization in the prior art with the algorithm of realizing with hardware circuit stipulating in the agreement that interweaves; Another object of the present invention is to provide a kind of Turbo code deinterleaving method, with interweaving of being used in interleaver realization agreement provided by the invention, stipulating.
Interleaver of the present invention is achieved through the following technical solutions:
A kind of Turbo code interleaver is characterized in that described interleaver comprises initialization module, computing module, and, the cache module that control circuit and being used to is stored the buffer of effective interleaving address included, clock signal from the outside is delivered to above-mentioned module respectively, wherein
After initialization module receives initialization enabling signal from the outside, read line number, columns, prime number and the primitive root of bit input matrix from external memory storage according to the weaving length of current business, calculate all row interior exchange basic sequence and storages of current business according to the above-mentioned parameter that reads, to outside output initialization end mark, and comprise the parameter group of weaving length, line number, columns and prime number and be used to read switch mode in the row and exchange the base address of prime number to computing module output;
After computing module receives the enabling signal that external module produces according to the initialization end mark of initialization module output, base address according to current line sequence number and initialization module output, calculating is used to read the switch mode and the address of reading that exchanges prime number in the row of reading that is stored in external memory storage, read switch mode and exchange prime number in the row according to reading the address, and read from the positive backward sign of outside and be stored in the row in the initialization module and exchange basic sequence, according to switch mode in the row that reads, exchange basic sequence in exchange prime number and the row, press the relation of columns and prime number, select following formula to calculate the corresponding interleaving address of the capable i row of j of bit input matrix:
If columns and prime number are equal, then
If columns equals prime number and 1 sum, then,, then calculate by formula (b) if unequal with the line number and long-pending the comparing of columns of weaving length and bit input matrix, if equate, then calculate by formula (c),
If columns equals the poor of prime number and 1, then
intterleaver_address=T(j)*C+s((i*r
T(j))mod(p-1))-1,[i=0,...,p-2;j=0,...,R-1] (d)
Wherein, T (j) is switch mode in the ranks, and C is the columns of bit input matrix, and R is the line number of bit input matrix, and p is a prime number, s ((i*r
T (j)Mod (p-1)) basic sequence for exchanging in the row, r
T (j)Be the exchange prime number;
Described computing module exports effective interleaving address sign, the interleaving address that calculates and beginning storage control signal in the cache module control circuit after calculating interleaving address;
Control circuit in the cache module is according to described enabling signal, beginning storage control signal and effective interleaving address sign from the outside, write enable signal to the buffer output that is used to store effective interleaving address, and write address output and read the address to described buffer; The control of the controlled circuit of buffer will write from the effective interleaving address in the interleaving address of computing module output, and requires output buffers in the interleaving address of described buffer according to the sequential of reading of external module.
Deinterleaving method of the present invention is realized by following technological means:
A kind of Turbo code deinterleaving method is characterized in that, this method comprises,
A) read the line number and the columns of bit input matrix according to weaving length; Calculate exchange basic sequence in the row according to prime number that reads and primitive root, and storage; The capable sequence number of initialization bit input matrix and row sequence number;
B) columns and prime number are compared,
If columns and prime number equate, then read in the ranks switch mode and exchange prime number, by the corresponding interleaving address of the capable i row of j of formula (a) calculating bit input matrix,
If columns equals prime number and 1 sum, then line number and the amassing of columns with weaving length and bit input matrix compares, if it is unequal, then read in the ranks switch mode and exchange prime number, calculate the corresponding interleaving address of the capable i row of j of bit input matrix by formula (b), if equate, then calculate described interleaving address by formula (c)
If columns equals the poor of prime number and 1, then read in the ranks switch mode and exchange prime number, the capable i of j that calculates the bit input matrix by formula (d) is listed as corresponding interleaving address,
intterleaver_address=T(j)*C+s((i*r
T(j))mod(p-1))-1,[i=0,...,p-2;j=0,...,R-1] (d)
Wherein, T (j) is switch mode in the ranks, and C is the columns of bit input matrix, and R is the line number of bit input matrix, and p is a prime number, s ((i*r
T (j)Mod (p-1)) is exchange basic sequence in the row, r
T (j)Be the exchange prime number;
C) more current interleaving address that calculates and weaving length if the interleaving address that calculates greater than weaving length, then forbids exporting the interleaving address of current calculating, otherwise are exported the current interleaving address that calculates.
The present invention finds out rule wherein on the basis that algorithm that 3GPP Turbo is interweaved is studied, a few class situations at the long-pending relation of columns and prime number, weaving length and columns and line number, provide the mapping relations of address before and after interweaving, greatly save memory space, optimized the algorithm that interweaves.According to the sequential requirement of the calculating rule and the Turbo coder of above-mentioned interleaving address, thereby the hardware circuit of interleaver is designed, proposed its hardware implementations.For the mode that interweaves to table look-up in the prior art, deinterleaving method provided by the invention and interleaver are because its parameter can therefore have certain flexibility, and the memory space that takies be few by being provided with to adapt to the needs of different business; And by of the control of positive backward sign to computing module in the interleaver, make the positive sequence of interleaving address calculate and backward calculate can shared same hardware configuration, be more suitable for realizing especially ASIC realization in the hardware of Turbo code encoding and decoding algorithm.
Description of drawings
Fig. 1 a and Fig. 1 b are for calculating the flow chart of positive sequence interleaving address.
Fig. 2 shows the The general frame of Turbo code interleaver.
Fig. 3 shows the computing module hardware elementary diagram.
Fig. 4 is a multiplication and division arithmetic pipelining schematic diagram.
Fig. 5 shows the cache module circuit theory diagrams.
Fig. 6 is the timing diagram of interleaver input and output.
Fig. 7 is for writing sequential and reading sequential cache module circuit theory diagrams when identical.
Embodiment
The present invention passes through summary and the conclusion to the deinterleaving method of 3GPP agreement regulation, obtains under different interleaving length, and the position of each bit in the pairing output bit sequence in back that interweaves in the bit input matrix, that is, and the mapping relations of address before and after obtaining interweaving.Concrete grammar is as follows:
At first, select the corresponding calculated formula, the position in the compute matrix in the output bit sequence of the input bit correspondence of the capable i row of j, i.e. interleaving address according to matrix columns in the current bit input matrix;
(1) when C=p,
(2) when C=p+1
A. if K ≠ C * R
B. if K=C * R
(3) when C=p-1
intterleaver_address=T(j)*C+s((i*r
T(j))mod(p-1))-1,[i=0,...,p-2;j=0,...,R-1]
Then, relatively interleaving address of Ji Suaning and weaving length are if interleaving address greater than weaving length, then removes this interleaving address.
Fig. 1 a and Fig. 1 b are for calculating the flow chart of positive sequence interleaving address.From flow chart as seen, calculate with i as outer circulation (i=0 ..., C-1), with j as interior circulation (j=0 ..., R-1), to (2) kind situation, i.e. C=p+1 when K=C * R, is a kind of special circumstances, regulation will be with U in the 3GPP agreement
R-1(p) and U
R-1(0) position exchanges, and can obtain by computing formula in the present invention.If calculate the backward interleaving address, only need when initialization, will go sequence number and row sequence number to be made as R-1 and C-1 respectively, row sequence number and row sequence number are by the variation of successively decreasing in the flow process.
The computational methods of above-mentioned interleaving address can adopt hardware circuit to realize.Referring to shown in Figure 2, Fig. 2 shows the The general frame of Turbo code interleaver, comprise initialization module, interleaving address computing module and the cache module that is used to carry out the input and output rate transition, this cache module includes control circuit and is used to store the buffer of effective interleaving address.Wherein,
After initialization module is received initialization enabling signal start_ini, current weaving length, the service parameter table index address sent here according to external module, from a ROM memory of interleaver outside, read the parameter group that comprises prime number p, primitive root v and bit input matrix columns C, line number R, and deliver to computing module; By exchange basic sequence s (i) in all row of the calculation of parameter current business that reads, and deposit RAM in the initialization module in according to consensus standard, wherein, when C=p-1, the value of the s (i) that calculates is subtracted the RAM that deposits in after 1 in the initialization module; After the calculating of exchange basic sequence finishes in the row, to interleaver external module output initialization end mark flag; Computing module is delivered in the base address;
After external module is received the initialization end mark, control circuit in computing module and cache module sends enabling signal start_cp, simultaneously, computing module reads the positive backward sign up_down from the outside, still is to calculate interleaving address by backward to determine by positive sequence; Computing module reads in the ranks switch mode T (j) and exchange prime number r from the 2nd ROM memory of interleaver outside
T (j), the T (j) and the r that exchange basic sequence s (i), read in the row according to RAM storage in the initialization module
T (j), and from the parameter group of initialization module, the relation of C and p of pressing selects the corresponding calculated formula to calculate the interleaving address of output sequence, and export this interleaving address and control signal to cache module, wherein control signal comprises beginning storage control signal start_save and effective interleaving address sign valid_flag;
The control circuit of cache module is from the described enabling signal of outside, beginning storage control signal and effectively under the control of interleaving address sign, write enable signal to the buffer output that is used to store effective interleaving address, effective effect address in the interleaving address that calculates is write buffer, and buffer is being read the interleaving address that output writes under the time sequence control; And read sequential when inequality what write sequential and external module, if write address equals the write address threshold value, then stop signal calculated stop_work effectively to stop the calculating of interleaving address to computing module output, and stop write operation, equal to read address threshold if read the address, it is invalid then to stop signal calculated stop_work to computing module output, with calculating and the startup write operation that starts interleaving address.
Below to require interleaving address of per 4 clock cycle output of interleaver with the Turbo code coder be example, the circuit theory of above-mentioned each module is described.
Referring to shown in Figure 3, Fig. 3 shows the computing module hardware elementary diagram.From the Enable Pin that signal calculated stop_work and outside start_cp signal are delivered to first state machine with three states that stops of cache module, described state machine essence is the counter of 3 systems.When stop_work invalidating signal and start_cp signal were effective, first state machine began counting output, provides clock signal with linage-counter in computing module, column counter, each latch and output delay unit.Address calculation is according to the capable sequence number j that exports from the base address and the linage-counter of initialization module, calculate in the ranks switch mode T (j) and the corresponding memory address of exchange prime number rT (j), the address end of reading to the 2nd ROM memory is exported this address, and second memory is according to T of switch mode in the ranks (j) that reads the address search correspondence and exchange prime number r
T (j), export first multiplier and second multiplier respectively to, wherein first multiplier outputs to first latch after calculating the product of columns C and switch mode T (j) in the ranks, and second multiplier calculates exchange prime number r
T (j)Behind the product of the row sequence number i of column counter output, output to second latch.Second latch exports divider to, and divider carries out modular arithmetic with the output and the p-1 of second latch, to calculate factor (i*r
T (j)) mod (p-1), divider output result of calculation to the three latchs.The 3rd latch exports this result of calculation to stored in the initialization module that exchanges basic sequence s (i) in the row RAM as reading the address, this RAM is according to exchanging basic sequence s (i) in the row of reading to export this address correspondence in the address to multiplexer, multiplexer according to the relation of columns C and prime number p and when the C=p+1 relation of K and C*R, 0 value from multiplexer, the p value, it is multiplexing that the input signal of selecting to satisfy the interleaving address calculating formula in s (i) or the 1 value input signal carries out selectivity, export adder after multiplexing to, adder will superpose from the calculated value of first latch and value from selector, export quad latch then to, this moment, the output valve of adder was the interleaving address that calculates by the computing formula that interweaves.Comparator compares the output valve and the weaving length of quad latch, if the output valve of quad latch is smaller or equal to weaving length, then comparator is exported effective value to the five latchs of effective interleaving address sign valid_flag, export by the 5th latch, otherwise comparator is exported invalid value to the five latchs of effective interleaving address sign valid_flag.Simultaneously, after will postponing a clock cycle from the interleaving address of quad latch, the output delay unit exports the buffer in the cache module to, promptly, to cache module output signal cp_output, so that the output of interleaving address is consistent with the sequential of the effectively output of interleaving address sign valid_flag.
In the aforementioned calculation module, each latch requires for the sequential that satisfies interleaver and quotes; Can have frequency divider in the linage-counter, being implemented in the calculation process, with i as outer circulation (i=0 ..., c-1), with j as interior circulation (j=0 ..., R-1) calculate.Input to the control end of linage-counter and column counter respectively from the positive backward sign up_down signal of outside, to control when carrying out the calculating of positive sequence interleaving address, linage-counter and column counter adopt the incremental manner counting, when carrying out the calculating of backward interleaving address, adopt the mode of successively decreasing to count.The output signal of linage-counter and column counter is also delivered to control logic respectively, and this control logic begins storage control signal start_save to cache module output in calculating the sequential of interleaving address.
Most crucial part is the calculating of multiplier-divider, and it will determine the operating rate of interleaver, in the present invention, uses the method for streamline to finish the computing of multiplier-divider, and multiplier and divider calculate once (i*r
T (j)) mod (p-1) because use that the state 2 of first state machine latchs, the reading of data, so the calculating of multiplication and division all is each with 3 clock cycle, the speed of multiplication and division computing all can meet the demands.The multiplication and division arithmetic pipelining is seen Fig. 4, and this is 2 grades of flowing water.Adopt the mode of streamline to double than the speed of no pipeline system.Divider can adopt the storehouse in the EDA synthesis tool directly to generate, and does not need oneself to write the VHDL program, and is not only easy to use, and area is little, multiple functional.
Referring to shown in Figure 5, Fig. 5 shows the cache module circuit theory diagrams.Wherein, be used to provide 3 system third state machines of write operation address control, the four condition machine that is used to provide 4 systems of read operation address control, write address counter, read address counter, with door and stop the signal calculated generation module and formed control circuit.Input to the counting Enable Pin of third state machine and four condition machine respectively from the enabling signal start_cp of outside, the RAM that clock signal offers third state machine, four condition machine respectively and is used for the buffer memory interleaving address, from the beginning storage control signal start_save of computing module, from the output signal of effective interleaving address sign valid_flag of computing module and third state machine input to door carry out with logical operation after output to the buffer memory interleaving address buffer write Enable Pin.The output signal of third state machine also exports write address counter to, and the output signal of four condition machine exports read address counter to, thereby makes per 3 clocks of write operation carry out once, and per 4 clocks of read operation are carried out once.The output of write address counter be input to respectively the buffer memory interleaving address buffer the write address end and stop the signal calculated generation module, the output of read address counter is input to the reading the address end and stop the signal calculated generation module of buffer of buffer memory interleaving address respectively.Stop the signal calculated generation module and judge the write address threshold value whether current write address equals to set, if then the counting Enable Pin of first state machine in counting module output stop_work is effective according to the write address of input; The current address threshold of reading whether the address equal to set of reading is judged in the address of reading according to input, if then to export stop_work invalid for the counting Enable Pin of first state machine in counting module.Export the data terminal of the buffer of buffer memory interleaving address to from the cp_output of the output delay unit in the counting module.
From the composition of cache module as can be seen, the buffer of per three clock cycle to the buffer memory interleaving address writes an interleaving address, per four clock cycle are read an effective interleaving address from buffer, because the speed of writing is fast, the speed of reading is slow, and memory space is limited, and the calculating of interleaving address is real-time, therefore when read-write proceeds to a certain degree, calculating to be stopped, restart calculating after treating to read a part of data again, be not capped in order to avoid interleaving address also just reads out.The above-mentioned signal calculated generation module that stops to be realized the control of reading and writing by output stop_work signal.
Referring to shown in Figure 6, Fig. 6 is the timing diagram of interleaver input and output.When the start_ini signal is effective, initialization module is started working, and by the parameter group of input, relevant parameters (comprises p under the selection current business, v, R C), and calculates the value that exchanges basic sequence s (i) in the row in real time, store among the RAM in the initial module, after initialization finishes, export an initialization end mark flag, feed back to external module; After external module receives the flag signal, send start_cp to computing module and cache module, the interleaver computing module is read the positive backward sign up_down that the outside is sent here simultaneously, and lock in the register, when up_down=' 1 ', represent positive sequence, represent backward during for ' 0 ', so begin to carry out the calculating of interleaving address, the 23rd clock cycle after the start_cp signal is effective whenever calculates an interleaving address, then exports a beginning storage control signal start_save.
The interleaving address that is calculated in computing module comprises effective interleaving address and invalid interleaving address, interleaving address of per three clock cycle output.At cache module, per 3 clock cycle write an effective interleaving address, and per 4 clock cycle are read an effective interleaving address.Because the invalid address all at first row of bit input matrix, therefore just has 1 invalid interleaving address every 20 interleaving address at least.
If the control circuit in the cache module is read sequential when identical what write sequential and external module, in the interleaver at this moment shown in Figure 2, will not stop signal calculated and feed back to computing module, and the circuit theory of cache module as shown in Figure 7.Control circuit comprises, write address counter, read address counter, with the door and second state machine, wherein, input to the Enable Pin of second state machine from the described enabling signal of outside, described clock signal inputs to the input of second state machine, the output of second state machine is connected to the input of write address counter and read address counter respectively, and also input to the door input; Input to input with door from effective interleaving address sign of computing module and beginning storage control signal, be connected to the Enable Pin of writing of buffer with the output of door; The write address counter write address output is to the write address end of buffer, and read address counter output is read the address and read the address end to buffer.