• No results found

mentations on Altera FPGAs

4.3 Efficient implementation of the correlation on Altera FPGAs

4.3.4 Separation by downsampling

Matrix view

Using the matrix notation, the circular correlation ynof two sequences hnand xnof length N can be expressed as

If we separate ynin even and odd samples, we have

where H0and H1are circulant matrices corresponding to the even and odd samples of hn, x0

and x1are vectors corresponding to the even and odd samples of xn, and P is the following

FFT

N/2

FFT

N/2

FFT

N/2*

FFT

N/2*

IFFT

N/2

IFFT

N/2

FFT

N/2

z

x2n

x2n+1

h2n

h2n+1

y2n

y2n+1 X0,k

X1,k

Y1,k Y0,k H0,k

H1,k

H*

H*

Figure 4.10: Computation of a circular correlation of N points using N /2-point FFTs (algorithm obtained using matrices).

permutation matrix,

P =

0 1 0 · · · 0 0 0 0 0 1 · · · 0 0 0 0 0 0 · · · 0 0 0 ... ... ... . .. ... ... ...

0 0 0 · · · 0 1 0 0 0 0 · · · 0 0 1 1 0 0 · · · 0 0 0

. (4.28)

The permutation matrix implies a circular shift of one sample of the signal. Since the matrices H0and H1are circulant, we can use the FFT to implement the matrix-vector products, which gives Fig. 4.10. However, since a circular shift of one sample in the time domain of a sequence of N samples corresponds to a multiplication by ej 2Nπk in the frequency domain (Oppenheim and Schafer [2009], pp. 564-567), one FFT can be removed and then we obtain Fig. 4.11.

Z transform view

The circular correlation can also be expressed as

Y (z) = H(1/z)X (z) mod (z−N− 1), (4.29)

FFT

N/2

FFT

N/2

FFT

*

N/2

FFT

*

N/2

IFFT

N/2

IFFT

N/2

e j2πk/(N/2) x2n

x2n+1

h2n

h2n+1

y2n

y2n+1

Y1,k

Y0,k

X0,k

X1,k

H0,k

H1,k

H*

H*

Figure 4.11: Computation of a circular correlation of N points using N /2-point FFTs (al-gorithm obtained using matrices replacing the time domain shift by a frequency domain multiplication).

with Y (z), H (z) and X (z), the z transforms of yn, hnand xn, respectively, and N is the length of the sequences. By separating the even and odd samples of the sequence xn, we can write

X (z) =

N /2−1

X

n=0

x2nz−2n+

N /2−1

X

n=0

x2n+1z−(2n+1). (4.30)

Defining

X0(z) =

N /2−1

X

n=0

x2nz−n, X1(z) =

N /2−1

X

n=0

x2n+1z−n, (4.31)

which are the z transforms of the sequences from the even and odd samples of xn, we can write

X (z) = X0¡z2¢ + z−1X1¡z2¢. (4.32)

This is the polyphase representation (Vaidyanathan [1993] pp. 120–122). Note that X0¡z2¢ and X1¡z2¢ contain only even powers of z. In the same way, we have

Y (z) = Y0¡z2¢ + z−1Y1¡z2¢, (4.33)

with

Y0(z) =

N /2−1

X

n=0

y2nz−n, Y1(z) =

N /2−1

X

n=0

y2n+1z−n, (4.34)

and

H(1/z) =

N −1X

n=0

hnzn

=

N /2−1

X

n=0

h2nz2n+

N /2−1

X

n=0

h2n+1 z2n+1

= H0¡(1/z)2¢ + z H1¡(1/z)2¢,

(4.35)

with

H0(z) =

N /2−1

X

n=0

h2nz−n, H1(z) =

N /2−1

X

n=0

h2n+1z−n. (4.36)

Applying this to Eq. (4.29), we have Y0¡z2¢ + z−1Y1¡z2¢ =³

H0¡(1/z)2¢ + z H1¡(1/z)2¢´³

X0¡z2¢ + z−1X1¡z2¢´

mod¡z−N− 1¢

H0¡(1/z)2¢X0¡z2¢ + H1¡(1/z)2¢X1¡z2¢´

mod¡z−N− 1¢ + z−1³

H0¡(1/z)2¢X1¡z2¢ + z2H1¡(1/z)2¢X0¡z2¢´

mod¡z−N− 1¢ (4.37) Inside both parenthesis, there are only even powers of z. The second parenthesis being multiplied by z−1, this term contains only odd powers of z. If N is even, after the modulo operation, the parity of the powers of z are unchanged. Consequently, we have

Y0¡z2¢ =³

H0¡(1/z)2¢X0¡z2¢ + H1¡(1/z)2¢X1¡z2¢´

mod¡z−N− 1¢

(4.38) and

Y1¡z2¢ =³

H0¡(1/z)2¢X1¡z2¢ + z2H1¡(1/z)2¢X0¡z2¢´

mod¡z−N− 1¢ . (4.39)

Evaluating the previous equations for z = ej 2Nπk with k = 0,1,..., N − 1, we obtain

Y0,k= H0,k X0,k+ H1,k X1,k, (4.40)

and

Y1,k= H0,k X1,k+ ej 2πkN /2H1,k X0,k, (4.41)

where Y0,kand Y1,kare the DFTs of y2nand y2n+1, H0,kand H1,kare the DFTs of h2nand h2n+1, and X0,k and X1,kare the DFTs of x2nand x2n+1. We obtain the same result as using the matrix notation, and the corresponding implementation is in Fig. 4.11.

e j2πk/(N/2)

FFT

N/2

FFT

N/2

FFT *

N/2

FFT *

N/2

IFFT

N/2

IFFT

N/2

– –

x2n

x2n+1

h2n

h2n+1

X0,k

X1,k

Y0,k

Y1,k

y2n

y2n+1

H0,k

H1,k

H*

H*

Figure 4.12: Computation of a circular correlation of N points using N /2-point FFTs and the minimum number of multipliers, where the inputs and the output are separated by parity.

Reduction of multipliers

The developments presented previously can be adapted to separate the sequences into 3, 4 or more sub-sequences. If each sequence is split in S sub-sequences, the number of multipliers is S2+S−1 (S2for the products between the FFTs, and S−1 for the products with the exponentials) and the number of adders is S(S−1). However, it is possible to reduce the number of multipliers.

For example, noting that

¡H0,k + H1,k ¢¡X0,k+ X1,k¢ = H0,k X0,k+ H1,k X1,k+ H0,k X1,k+ H1,k X0,k, (4.42) Eq. (4.40) becomes

Y0,k=¡H0,k + H1,k ¢¡X0,k+ X1,k¢ − H0,k X1,k− H1,k X0,k. (4.43) Therefore, using Eqs. (4.43) and (4.41), the circular correlation can be computed using 4 multipliers and 5 adders as shown in Fig. 4.12, compared to 5 multipliers and 2 adders using Eqs. (4.40) and (4.41). These developments are based on the same principle as the fast FIR (finite impulse response) algorithms (FFA) (Mou and Duhamel [1991], Parker and Parhi [1997], Parhi [1999] Chap. 9), except that they are adapted to the circular correlation implemented with FFTs.

However, the FFAs do not always provide the minimum number of multipliers, but only a sub-optimal reduction. The minimum number of multipliers that can be obtained is 3S − 2.

Algorithm Number of Number of Number of sub-sequences (S) complex multipliers complex adders

No reduction of the multipliers

2 5 2

3 11 6

4 19 12

Sub-optimal reduction of the multipliers

2 4 5

3 8 13

4 13 25

Optimal reduction of the multipliers

2 4 5

3 7 25

4 10 78

Table 4.4: Number of operations for the different algorithms.

Indeed, if we express the relation between the FFTs using matrices, we have

"

Y0,k Y1,k

#

=

"

H0,k H1,k

ej 2πkN /2 H1,k H0,k

#"

X0,k X1,k

#

. (4.44)

If we split the sequences in three sub-sequences, we have

Y0,k Y1,k Y2,k

 =

H0,k H1,k H2,k ej 2πkN /2H2,k H0,k H1,k ej 2N /2πkH1,k ej 2N /2πkH2,k H0,k

X0,k X1,k X2,k

. (4.45)

It can be seen that the matrix in Eq. (4.45) is a Toeplitz matrix (see Section A.2.3), and it is known that the minimum number of multiplications required to compute the product between a Toeplitz matrix of size S × S and a vector of length S is 2S − 1 (Lafon [1974]). Since there are also S − 1 multipliers needed for the multiplication with the complex exponentials, the total minimum number of multipliers is 3S − 2. However, when the number of multipliers is minimum, the number of adders increases very fast, as shown in Table 4.4 for the some small values of S (Leclère et al. [2012]).

Note that when splitting the signals in two (i.e. S = 2), it could be possible to have only two multipliers for the product between the FFTs, but this requires that the length of the sequences be the product of two coprime numbers (Garg [1998] pp. 313–316). Therefore, this cannot be applied when the length of the sequences is a power of two.

Hi,k

H*

6

1 2

N/2

LN/2 hi,n

xi,n 1 2

3 4 5 6 7 8

3 4 5 6 7 8

Xi,k

7

1 2 3 4 5 6

1 2 3 4 5 6 7

Yi,k

LN/2 yi,n

7

1 2 3 4 5 6

1 2 3 4 5

i ∈ {0,1}

Figure 4.13: Timing diagram corresponding to Fig. 4.12 using Altera FFTs. The number in the boxes identifies the sequences.

4.3.5 Application to reduce the processing time

Implementations of Figs. 4.8 and 4.9 require 5 multipliers and 6 adders, and the implementa-tion of Fig. 4.12 requires 4 multipliers and 5 adders. Since this last implementaimplementa-tion uses less DSP resources, we consider it for the evaluation of the resources in this section.

The timing diagram corresponding to Fig. 4.12 using the Altera FFT is depicted Fig. 4.13. It can be seen that the P th correlation result is fully available after N2 + LN /2+N2 + LN /2+ PN2 = (P + 2)N2 + 2LN /2clock cycles. Therefore, compared to the traditional implementation of the circular correlation (Fig. 4.6), the processing time is approximately halved (see Fig. 4.7).

For the evaluation of the resources, we consider N = 2048. As previously, the resources for the FFT and the NCO are estimated with the Altera MegaWizard Plug-In Manager (the parameters for the NCO are keep to the default ones), and the models defined in Appendix C are used for the other elements (multiplier and adder). The summary of the resources is given Table 4.5. It can be seen that the resources are higher for the implementation of Fig. 4.12 than Fig.

4.6. However, we have seen just before that the processing time for Fig. 4.12 was divided by a factor two. Since the resources are increased by a factor less than two, the implementation of Fig. 4.12 is more efficient than the implementation of Fig. 4.6.

Implementation Function Logic usage Memory usage Multipliers usage

(ALUT) (M9K) (DSP element)

6 1024-point FFTs 6 × 5248 6 × 19 6 × 12

NCO 180 2 4

Fig. 4.12 4 Multipliers 0 0 4 × 4

5 Adders 5 × 36 0 0

Total 31 848 116 92

3 2048-point FFTs 3 × 6906 3 × 38 3 × 24

Fig. 4.6 1 Multiplier 0 0 4

Total 20 718 114 76

Ratio 1.54 1.02 1.21

Table 4.5: Comparison of the resources for Fig. 4.12 and Fig. 4.6 using the Altera FFT with N = 2048.

4.3.6 Application to reduce the resources

In the previous section, the proposed implementation was more efficient, but the resources were increased. In this section, we adapt it to use only three FFTs instead of six, at the expense of an additional memory. In this case, the implementations based on the CRT (Fig. 4.9) is more interesting because it requires less memory. Indeed, each IFFT output is obtained using only two FFTs results, whereas in Fig. 4.11 the four FFTs results are needed to compute the each IFFT output. The implementation is given Fig. 4.14, and the corresponding timing diagram is given Fig. 4.15.

Here is a summary of how works Fig. 4.14 :

1. Compute the FFTs of h0,nand x0,n. 2. Compute the product of the FFTs.

3. Compute the IFFT to obtain y0,n. 4. Store y0,nin a memory.

5. Repeat the first three steps for h1,nand x1,n(which are before multiplied by the com-plex exponential) to obtain y1,n (which involved also a product with a the complex exponential).

6. When y1,nis available, read y0,nfrom the memory and compute their sum and differ-ence.

FFT

*

N/2

FFT

N/2

hi,n

xi,n

e −j2πn/N e −j2πn/N

e j2πn/N

IFFT

N/2

yn

Xi,k yi,n

mIN,n mOUT,n

Memory Hi*(k)

Figure 4.14: Computation of the correlation using three N /2-point FFTs and a memory.

Implementation Function Logic usage Memory usage Multipliers usage

(ALUT) (M9K) (DSP element)

Fig. 4.14

3 1024-point FFTs 3 × 5248 3 × 19 3 × 12

1 NCO 180 2 4

4 Multipliers 0 0 4 × 4

4 Adders 4 × 36 0 0

1 Memory 22 4 0

Total 16 090 63 56

3 2048-point FFTs 3 × 6906 3 × 38 3 × 24

Fig. 4.6 1 Multiplier 0 0 4

Total 20 718 114 76

Ratio 0.78 0.55 0.74

Table 4.6: Comparison of the resources for Fig. 4.14 and Fig. 4.6 using the Altera FFT with N = 2048.

7. Output their sum, which corresponds to yn, and store in the memory their difference, which corresponds to yn+N /2.

8. Read the memory to output yn+N /2.

In this way the correlation result is provided in the exact same order as with Fig. 4.6. In this case, the P th correlation result is fully available afterN2+LN /2+N2++N2+P N = (P +32)N +2LN /2

clock cycles, which is about N /2 cycles less than for Fig. 4.6 because of the lower latency.

The corresponding resources are given Table 4.6, still with N = 2048. For the memory, we need to store twice (because the signal is complex) 1024 × 18 bits, which requires 4 M9K memories, and we consider few logic for the addressing. It can be seen that the resources are reduced, by about 22 % for the logic, 45 % for the memory, and 26 % for the DSP elements, which is not negligible.

xi,n

h0,n

N/2

LN/2

h1,n h0,n h1,n h0,n h1,n

hi,n

Hi,k Xi,k yi,n mIN,n

mOUT,n

h0,n h1,n

H0,k H1,k H0,k H1,k H0,k H1,k H0,k

X0,k X1,k X0,k X1,k X0,k X1,k X0,k

y0,n y1,n y0,n y1,n y0,n y1,n

yn

yn+N/2 yn+N/2 yn+N/2

LN/2

x0,n x1,n x0,n x1,n x0,n x1,n x0,n x1,n

y0,n y0,n y0,n

y0,n yn+N/2 y0,n y0,n

yn+N/2

yn+N/2

yn+N/2

yn yn yn

Figure 4.15: Timing diagram corresponding to Fig. 4.14 using Altera FFTs. The colors inside the boxes identify the sequences.

4.4 Summary

In this chapter, we have shown different ways to compute an FFT in Altera FPGAs, with lower resources and the same processing time than the direct implementation of one Altera FFT.

Then, it was shown also that it is possible to reduce the resources for an FFT-based circular correlation compared to the direct implementation that uses three FFTs.

It has been shown that all the resources can be reduced, i.e the logic, the memory and the DSP blocks, but it is mainly the memory that is reduced (33 % for the FFT and 45 % for the correlation with sequences of 2048 samples). If we extrapolate to other transform lengths, the results regarding the logic and the memory would be about the same, however for the DSP elements the results would be not as good because the number of DSP elements does not increase when we increase the transform length above 2048.

The algorithms presented do not make any assumptions about the input or output signals, therefore they can be applied not only for GNSS but for any other systems computing FFTs, convolutions, or correlations. Besides, in addition to the implementations proposed in this

chapter, it is possible to use the method for computing the FFT of two real sequences using the complex Altera FFT (see Appendix B), which is useful in GNSS since the local code is real.

Some other examples are also given in (Leclère et al. [2012]).