**3. Discrete Fourier Transform vs. Discrete Cosine Transform**

There are several variants of the DCT with slightly modified definitions. The DCT-I is exactly equivalent (up to an overall scale factor of 2), to a DFT of 2N - 2 real numbers with even symmetry. The most commonly used form of the Discrete Cosine Transform is DCT-II.

$$\bar{X}\_k = \alpha\_k \sum\_{n=0}^{N-1} x\_n \cos \left( \frac{\pi}{N} (n + \frac{1}{2}) k \right) \tag{1}$$

Experiments 5

<sup>383</sup> An Optimization of 16-Point Discrete Cosine Transform Implemented into a FPGA as a Design for a Spectral First Level Surface Detector Trigger in Extensive Air Shower Experiments

symmetric, the imaginary part is asymmetric. The useful information is contained only in 1*st*

The analog section of the FEB has been designed to have a pedestal of ca. 10 % of the full FADC range in order to investigate undershoots. However, the pedestal is relatively sensitive on the temperature. Daily variation of the pedestal may reach 5 ADC-counts. The trigger pedestal-independent is very welcome. Let us consider signal with a constant pedestal:

spectral line of *X*¯ *<sup>k</sup>* , k = 0,1,...,N-1 is lying on a symmetry axis: the real part is

*N*−1 ∑ *n*=0

> 1 2 )

<sup>=</sup>

<sup>2</sup> <sup>=</sup> 2 and *<sup>k</sup>* <sup>=</sup> 0, *<sup>N</sup>*

 

2 *N* <sup>2</sup> −1 ∑ *n*=0

<sup>2</sup> . For *<sup>k</sup>* <sup>=</sup> *<sup>N</sup>*

*<sup>N</sup>* (*<sup>n</sup>* <sup>+</sup>

*<sup>k</sup>* <sup>−</sup> *<sup>k</sup><sup>π</sup>* 2

*<sup>F</sup>*(*k*, *<sup>n</sup>*) = *<sup>X</sup>*¯ *<sup>k</sup>* <sup>+</sup> *ped* <sup>×</sup> *<sup>W</sup>* (3)

0 , *k* − *odd*

*F*(*k*, *n*) , *k* − *even*

2

<sup>=</sup> <sup>0</sup> (6)

*<sup>N</sup>*∆*<sup>t</sup>* ,

(4)

(5)

(7)

spectral lines for k = 0,1,...,N/2 corresponding to frequencies *fk* <sup>=</sup> *<sup>k</sup>* · *<sup>f</sup>*<sup>0</sup> <sup>=</sup> *<sup>k</sup>* <sup>1</sup>

and *<sup>N</sup>* 2 *th*

changing from zero to *fsmpl*

**3.1 Pedestal independence**

*X*¯ *<sup>k</sup>*(*ped*) =

*W* = 2

**3.2 Scaling**

*N* <sup>2</sup> −1 ∑ *n*=0

*cos <sup>k</sup><sup>π</sup>* 2 *cos <sup>π</sup> N n* + 1 2 

By a recursion, repeating (5) we get finally *<sup>N</sup>*

higher DCT coefficients (scaled to the 1st harmonics)

*N*−1 ∑ *n*=0

<sup>2</sup> with *fsmpl*

*<sup>N</sup>* grid.

(*xn* + *ped*)*F*(*k*, *n*) = *X*¯ *<sup>k</sup>* + *ped*

1 ∑ *n*=0 *cos <sup>π</sup>* 2 *n* + 1 2

In a consequence for k > 0 the DCT coefficients are independent of the pedestal.

The DCT algorithm has a significant advantage in comparison to the FFT one. The structure of DCT coefficients is much simpler for interpretation and for a trigger implementation than the structure of the FFT real and imaginary coefficients (compare 4th of the FFT data vs. 2nd row for the DCT coefficients in Fig. 3). For the exponentially attenuated signals from the PMTs

> *<sup>ξ</sup><sup>k</sup>* <sup>=</sup> *<sup>X</sup>*¯ *<sup>k</sup> X*¯ 1

are almost negligible, while both real and imaginary parts of the FFT (scaled to the module of the 1st harmonics) give relatively significant contributions and are not relevant for triggering. When a peak appears in the pure attenuated signal (last column in Fig. 3) the structure of the DCT dramatically changes and trigger condition immediately expires, while modules of FFT components almost do not change. The structure of FFT harmonics for the last graph in Fig. 3 would be more suitable for a trigger (almost negligible imaginary part for higher harmonics and also relatively low real harmonics), however it corresponds just to situation, when the

*<sup>F</sup>*(*k*, *<sup>n</sup>*) = *cos <sup>k</sup><sup>π</sup>*

Due to symmetry and parity of the cosine, we get for odd and even indices respectively:

 *<sup>N</sup>* <sup>2</sup> + 1 

Fig. 2. FADC traces (in ADC-counts) of a horizontal shower (no. 01145055: *θ* = 83.3◦) registered in three detectors: Ramon, Christian and Juancho, respectively, and shown for the range of (240 - 265) time bins. Only the signal in the Ramon detector (1.93 *IVEM*) is above the standard threshold of 1.75 *IVEM*. Signals in Cristian (1.64 *IVEM*) and Juancho (1.68 *IVEM*) detectors are below the standard thresholds and they are detected by chance (compare a registration efficiency for a similar event shown in Fig. 1). For all very inclined showers the rising edge corresponds to one or two time bins.

where *α*<sup>0</sup> = √ 1 *<sup>N</sup>* and *<sup>α</sup><sup>k</sup>* <sup>=</sup> <sup>√</sup> 2 *<sup>N</sup>* for *<sup>k</sup>* <sup>≥</sup> 1.

The DCT-III form is sometimes simply referred to as "the inverse DCT" (IDCT). A variant of the DCT-IV, where data from different transforms are overlapped, is called the Modified Discrete Cosine Transform (MDCT). The DCT is a Fourier-related transform similar to the DFT, but using only real numbers. DCT are equivalent to DFT of roughly twice the length, operating on real data with even symmetry (since the Fourier transform of a real and even function is real and even), where in some variants the input and/or output data are shifted by half a sample. The DCT-II and DCT-IV are considered as the alternative approach to the FFT. In fact, the FFT routine can be supplied in an interleaving mode, even samples treated as real data, odd samples as imaginary data. A trigger based on Discrete Fourier Transform (DFT) (Radix-2 FFT) (Szadkowski, 2006) has already been implemented in the 3rd generation of the Front FEB based on Cyclone™ Altera® chip (Szadkowski, 2005b). However, for real signal *xn*

$$\bar{X}\_{\frac{N}{2}+k} = \sum\_{n=0}^{N-1} x\_n e^{-j\frac{2\pi}{N}\left(\frac{N}{2}+k\right)n} = \sum\_{n=0}^{N-1} x\_n (-1)^n \left[e^{j\frac{2\pi}{N}kn}\right]^\* = \bar{X}\_{\frac{N}{2}-k}^\* \tag{2}$$

and *<sup>N</sup>* 2 *th* spectral line of *X*¯ *<sup>k</sup>* , k = 0,1,...,N-1 is lying on a symmetry axis: the real part is symmetric, the imaginary part is asymmetric. The useful information is contained only in 1*st <sup>N</sup>* <sup>2</sup> + 1 spectral lines for k = 0,1,...,N/2 corresponding to frequencies *fk* <sup>=</sup> *<sup>k</sup>* · *<sup>f</sup>*<sup>0</sup> <sup>=</sup> *<sup>k</sup>* <sup>1</sup> *<sup>N</sup>*∆*<sup>t</sup>* , changing from zero to *fsmpl* <sup>2</sup> with *fsmpl <sup>N</sup>* grid.

#### **3.1 Pedestal independence**

4 Will-be-set-by-IN-TECH

240

160 C counts

80 ADC

0

FADC traces from "Juancho"

240 244 248 252 256 260 time bin

The DCT-III form is sometimes simply referred to as "the inverse DCT" (IDCT). A variant of the DCT-IV, where data from different transforms are overlapped, is called the Modified Discrete Cosine Transform (MDCT). The DCT is a Fourier-related transform similar to the DFT, but using only real numbers. DCT are equivalent to DFT of roughly twice the length, operating on real data with even symmetry (since the Fourier transform of a real and even function is real and even), where in some variants the input and/or output data are shifted by half a sample. The DCT-II and DCT-IV are considered as the alternative approach to the FFT. In fact, the FFT routine can be supplied in an interleaving mode, even samples treated as real data, odd samples as imaginary data. A trigger based on Discrete Fourier Transform (DFT) (Radix-2 FFT) (Szadkowski, 2006) has already been implemented in the 3rd generation of the Front FEB based on Cyclone™ Altera® chip (Szadkowski, 2005b). However, for real signal *xn*

<sup>2</sup> <sup>+</sup>*k*)*<sup>n</sup>* =

*N*−1 ∑ *n*=0

*xn*(−1)*<sup>n</sup>*

 *e<sup>j</sup>* <sup>2</sup>*<sup>π</sup> <sup>N</sup> kn*<sup>∗</sup>

= *X*¯ <sup>∗</sup> *N*

<sup>2</sup> <sup>−</sup>*<sup>k</sup>* (2)

Fig. 2. FADC traces (in ADC-counts) of a horizontal shower (no. 01145055: *θ* = 83.3◦) registered in three detectors: Ramon, Christian and Juancho, respectively, and shown for the range of (240 - 265) time bins. Only the signal in the Ramon detector (1.93 *IVEM*) is above the standard threshold of 1.75 *IVEM*. Signals in Cristian (1.64 *IVEM*) and Juancho (1.68 *IVEM*) detectors are below the standard thresholds and they are detected by chance (compare a registration efficiency for a similar event shown in Fig. 1). For all very inclined showers the

FADC traces from "Christian"

240 244 248 252 256 260 time bin

PMT1 PMT2 PMT3

1.75 VEM 1.68 VEM PMT1 PMT2 PMT3

1.75 VEM 1.64 VEM

PMT1 PMT2 PMT3

1.93 VEM 1.75 VEM

240

160 C counts

80 ADC

0

where *α*<sup>0</sup> = √

1

*X*¯ *<sup>N</sup>* <sup>2</sup> <sup>+</sup>*<sup>k</sup>* <sup>=</sup>

FADC traces from "Ramon"

240 244 248 252 256 260 time bin

240

160 counts

80 ADC

0

rising edge corresponds to one or two time bins.

2

*N*−1 ∑ *n*=0 *xne* <sup>−</sup>*<sup>j</sup>* <sup>2</sup>*<sup>π</sup> <sup>N</sup>* ( *<sup>N</sup>*

*<sup>N</sup>* for *<sup>k</sup>* <sup>≥</sup> 1.

*<sup>N</sup>* and *<sup>α</sup><sup>k</sup>* <sup>=</sup> <sup>√</sup>

The analog section of the FEB has been designed to have a pedestal of ca. 10 % of the full FADC range in order to investigate undershoots. However, the pedestal is relatively sensitive on the temperature. Daily variation of the pedestal may reach 5 ADC-counts. The trigger pedestal-independent is very welcome. Let us consider signal with a constant pedestal:

$$\bar{X}\_k(ped) = \sum\_{n=0}^{N-1} (\mathbf{x}\_n + ped) F(k, n) = \bar{X}\_k + ped \sum\_{n=0}^{N-1} F(k, n) = \bar{X}\_k + ped \times \mathcal{W} \tag{3}$$

$$F(k,n) = \cos\left(\frac{k\pi}{N}(n+\frac{1}{2})\right) \tag{4}$$

Due to symmetry and parity of the cosine, we get for odd and even indices respectively:

$$W = 2\sum\_{n=0}^{\frac{N}{2}-1} \left\{ \cos\left(\frac{k\pi}{2}\right) \cos\left[\frac{\pi}{N}\left(n + \frac{1}{2}\right)k - \frac{k\pi}{2}\right] \right\} = \begin{cases} 0 & , \, k-odd\\ 2\sum\_{n=0}^{\frac{N}{2}-1} F(k,n) \,\, \lambda - even \end{cases} \tag{5}$$

By a recursion, repeating (5) we get finally *<sup>N</sup>* <sup>2</sup> <sup>=</sup> 2 and *<sup>k</sup>* <sup>=</sup> 0, *<sup>N</sup>* <sup>2</sup> . For *<sup>k</sup>* <sup>=</sup> *<sup>N</sup>* 2

$$\sum\_{n=0}^{1} \cos\left(\frac{\pi}{2}\left(n + \frac{1}{2}\right)\right) = 0\tag{6}$$

In a consequence for k > 0 the DCT coefficients are independent of the pedestal.

#### **3.2 Scaling**

The DCT algorithm has a significant advantage in comparison to the FFT one. The structure of DCT coefficients is much simpler for interpretation and for a trigger implementation than the structure of the FFT real and imaginary coefficients (compare 4th of the FFT data vs. 2nd row for the DCT coefficients in Fig. 3). For the exponentially attenuated signals from the PMTs higher DCT coefficients (scaled to the 1st harmonics)

$$
\xi\_k = \frac{\bar{X}\_k}{\bar{X}\_1} \tag{7}
$$

are almost negligible, while both real and imaginary parts of the FFT (scaled to the module of the 1st harmonics) give relatively significant contributions and are not relevant for triggering. When a peak appears in the pure attenuated signal (last column in Fig. 3) the structure of the DCT dramatically changes and trigger condition immediately expires, while modules of FFT components almost do not change. The structure of FFT harmonics for the last graph in Fig. 3 would be more suitable for a trigger (almost negligible imaginary part for higher harmonics and also relatively low real harmonics), however it corresponds just to situation, when the

Experiments 7

<sup>385</sup> An Optimization of 16-Point Discrete Cosine Transform Implemented into a FPGA as a Design for a Spectral First Level Surface Detector Trigger in Extensive Air Shower Experiments

pure attenuated signal is distorted by some peak on the tail and a trigger condition has been

The plot in the 4th row and 3rd column on Fig. 3 shows a contribution of the DFT vs. the absolute value of the 1st harmonic. For an exponential attenuated signal (with the attenuation factor = *β*) the contribution of both real and imaginary coefficients decreases monotonically

*<sup>N</sup> <sup>n</sup>* <sup>=</sup> *<sup>A</sup>* <sup>1</sup> <sup>−</sup> *<sup>e</sup>*−*N<sup>β</sup>*

<sup>1</sup> <sup>−</sup> *<sup>e</sup>β*+*<sup>j</sup>* <sup>2</sup>*<sup>π</sup>*

<sup>2</sup> + *<sup>e</sup>*−2*βsin*2*<sup>φ</sup>*

<sup>2</sup>*<sup>N</sup>* grid. DCT vs. DFT gives twice better resolution.

*xn* + (−1)*kxN*−1−*<sup>n</sup>*

<sup>2</sup> − 1)

<sup>2</sup> , ..., *<sup>N</sup>* <sup>−</sup> <sup>1</sup>) (12)

*<sup>N</sup> <sup>k</sup>* (8)

 

(10)

(11)

(13)

(9)

with a significant value for all real coefficients. From the DFT definition we get:

*e<sup>β</sup>ne* <sup>−</sup>*<sup>j</sup>* <sup>2</sup>*π<sup>k</sup>*

*<sup>X</sup>*¯ <sup>1</sup> <sup>=</sup> (<sup>1</sup> <sup>+</sup> *<sup>e</sup>*−*βN*) 

<sup>1</sup> − *<sup>e</sup>*−*βcos<sup>φ</sup>*

Calculating (8) for boundary factors *β* = (0.28, 0.42) (from the Auger database) and for k = N/2 (as the lowest in a monotonically decreasing chain), we obtain for N = 16: *ξ* = 24% and 28%, respectively. These values are too large to be use for triggering. Even an extension of the DFT size does not help very much. For N = 32: we get still large values: *ξ* = 17% and 23%. Almost vanishing higher DCT coefficients provide much natural trigger conditions. 32-point

The DCT for real signal *xn* gives independent spectral coefficients for k = 0,1,...,N-1, changing

*xn* <sup>+</sup> *xN*−1−*<sup>n</sup>* (*<sup>n</sup>* <sup>=</sup> 0, ..., *<sup>N</sup>*

*Ancos <sup>π</sup> N n* + 1 2 *k* 

Let us notice that (13) for even indices has the same structure as (1) with only shorter range of indices. Recurrently we can introduce new sets of variables for the set of indices k = 2p, where

*xN*−1−*<sup>n</sup>* <sup>−</sup> *xn* (*<sup>n</sup>* <sup>=</sup> *<sup>N</sup>*

<sup>−</sup> *xN*−1−*ncos <sup>π</sup>*

*N N* − *n* + 1 2 *<sup>k</sup>*

*N*−1 ∑ *n*=0

FFT (roughly equivalent to 16-point DCT) does not offer better stability.

<sup>2</sup> but with *fsampl*

*cos <sup>π</sup> N n* + 1 2 *k* × 

DCT coefficients can be separated for even and odd indices respectively:

*N* <sup>2</sup> −( 1 0) ∑ *n*=( <sup>0</sup> *<sup>N</sup>*−<sup>1</sup>)

Splitting the sum (1) and redefine the indices we get:

*xncos <sup>π</sup> N n* + 1 2 *k* 

> *N* <sup>2</sup> −1 ∑ *n*=0

*An* =

*X*¯ ( *even odd* ) = *<sup>α</sup><sup>k</sup>*

*X*¯ *<sup>k</sup>* = *A*

*<sup>ξ</sup>* <sup>=</sup> *Re*(*X*¯ *<sup>k</sup>*)

violated.

where *φ* = <sup>2</sup>*π<sup>k</sup>*

*<sup>N</sup>* .

**4. Genaral DCT algorithm**

*fk* also from zero to *fsampl*

 

*N* <sup>2</sup> −1 ∑ *n*=0

Due to symmetry of the cosine function

*X*¯ *<sup>k</sup>* = *α<sup>k</sup>*

We can introduce the new set of variables:

*X*¯ *<sup>k</sup>* = *α<sup>k</sup>*

Fig. 3. A propagation of the pulse (1st row) through the shift register, DCT-II coefficients (2nd row), absolute values of the DFT (3rd row) and corresponding real (Re), imaginary parts (Im) (4th row). The 1st column shows the pulse (shape A), when two time bins are on the pedestal level, the 2nd one (shape B), when only the one time bin is still on the pedestal level, while the 3rd one (shape C) shows the pulse fully fulfilled the range of investigating shift registers. For a signal shape related to the exponential attenuation (shape C), the contribution of higher DCT coefficients is small and suitable for a trigger. When a peak appears in the declining signal (last column - shape D), the DCT coefficients immediately excesses assumed relatively narrow acceptance range for triggers. The DFT coefficients (Re and Im in 4th row) have similar structure as the DCT, however for the pure exponentially declining signal the higher real DFT harmonics have relatively high values and they are not suitable for triggering. Absolute values of DFT components (3rd row) are clearly insensitive on discussed conditions.

pure attenuated signal is distorted by some peak on the tail and a trigger condition has been violated.

The plot in the 4th row and 3rd column on Fig. 3 shows a contribution of the DFT vs. the absolute value of the 1st harmonic. For an exponential attenuated signal (with the attenuation factor = *β*) the contribution of both real and imaginary coefficients decreases monotonically with a significant value for all real coefficients. From the DFT definition we get:

$$\bar{X}\_k = A \sum\_{n=0}^{N-1} e^{\beta^n} e^{-j\frac{2\pi k}{N}n} = A \frac{1 - e^{-N\beta}}{1 - e^{\beta + j\frac{2\pi}{N}k}} \tag{8}$$

$$\zeta = \frac{\text{Re}(\bar{X}\_k)}{||\bar{X}\_1||} = \frac{(1 + e^{-\beta N})}{\sqrt{\left(1 - e^{-\beta}\cos\phi\right)^2 + e^{-2\beta}\sin^2\phi}}\tag{9}$$

where *φ* = <sup>2</sup>*π<sup>k</sup> <sup>N</sup>* .

6 Will-be-set-by-IN-TECH

time (ns)

index (k)

index (k)

Re Im

index (k)


Fig. 3. A propagation of the pulse (1st row) through the shift register, DCT-II coefficients (2nd row), absolute values of the DFT (3rd row) and corresponding real (Re), imaginary parts (Im) (4th row). The 1st column shows the pulse (shape A), when two time bins are on the pedestal level, the 2nd one (shape B), when only the one time bin is still on the pedestal level, while the 3rd one (shape C) shows the pulse fully fulfilled the range of investigating shift registers. For a signal shape related to the exponential attenuation (shape C), the contribution of higher DCT coefficients is small and suitable for a trigger. When a peak appears in the declining signal (last column - shape D), the DCT coefficients immediately excesses assumed relatively narrow acceptance range for triggers. The DFT coefficients (Re and Im in 4th row) have similar structure as the DCT, however for the pure exponentially declining signal the higher real DFT harmonics have relatively high values and they are not suitable for triggering. Absolute values of DFT components (3rd row) are clearly insensitive on discussed

ȟk (%)

%

%

ADC counts

0 50 100 150 200 250

Shape\_A Shape\_B Shape\_C Shape\_D

1 3 5 7 9 11 13 15


123456

(XFFT.Re,Im)k/|XFFT1|

12345678

DCT - II

ADC samples: x0 = max

time (ns)

index (k)

index (k)

Re Im

index (k)

ȟk (%)

%

%

ADC counts

0 50 100 150 200 250

DCT - II

1 3 5 7 9 11


123456

(XFFT.Re,Im)k/|XFFT1|

12345678

ADC samples : a new small incoming pulse

time (ns)

index (k)

index (k)

Re Im

index (k)

ȟk (%)

%


conditions.


0

50

%

ADC counts

0 50 100 150 200 250

1 3 5 7 9 11 13 15


123456

(XFFT.Re,Im)k/|XFFT1|

123456

DCT - II

ADC samples: x0 = x1 = 0

time (ns)

index (k)

index (k)

index (k)

Re Im


0 40

ȟk (%)

%

%

ADC counts

0 50 100 150 200 250

1 3 5 7 9 11 13 15


123456

12345678

(XFFT.Re,Im)k/|XFFT1|

DCT - II

ADC samples: x0 = 0

Calculating (8) for boundary factors *β* = (0.28, 0.42) (from the Auger database) and for k = N/2 (as the lowest in a monotonically decreasing chain), we obtain for N = 16: *ξ* = 24% and 28%, respectively. These values are too large to be use for triggering. Even an extension of the DFT size does not help very much. For N = 32: we get still large values: *ξ* = 17% and 23%. Almost vanishing higher DCT coefficients provide much natural trigger conditions. 32-point FFT (roughly equivalent to 16-point DCT) does not offer better stability.
