Gustavo Cancelo

CEPA/ESE-CD

Feb. 24^th^ 2005

**The Envelope Filter**

## Introduction

The current document describes the Envelope Filter for measuring beam
position at the Tevatron. The filter is implemented using the digital
filters inside the Graychips located in the Echotek modules. The
Envelope Filter idea is described in Section 1.4 and the results are
provided in Section 1.4.3. To make this document more self contained the
first few sections describe the Graychip characteristics. The Graychip
specification is reference in \[1\].

## Graychip Block Diagram

![](media/image1.png){width="6.25in" height="2.1277777777777778in"}

Figure 1: Graychip block diagram

The Graychip has four identical channels as shown in the block diagram
(Figure 1). The Graychip basic building blocks are:

-   Data input format and zero pad

-   Down-converter

-   CIC filter

-   CFIR filter

-   PFIR filter

-   Resampler

Each Down-converter contains a Numerically Controlled Oscillator (NCO)
with the following characteristics:

-   The frequency can be tuned to 2\^-32 of Fclk (clock freq.)

-   The phase can be adjusted by 2-16 of 2π.

-   Dither generator to provide a 121bd spur free clock.

### Down converter 

The down converter multiplies the incoming signal by a high frequency
sinusoid of tunable frequency and phase. In time domain the Down
converter function can be modeled by:

![](media/image2.wmf){width="1.875in" height="1.1395833333333334in"}

I and Q are the Hilbert transform components of s(n) obtained by
sampling s(n) with two sine waves whose relative phase are in
quadrature. If s(n) is real and causal I and Q are the real and
imaginary portion of the envelope of s(n).

Downconverter in frequency domain

-   If the sampling frequency fs is above the Nyquist frequency of the
    signal s(n) (fs ≥ 2 fc), multiplying the s(n) spectrum by exp(jωc)
    makes s(n) return to baseband. A s(n) image is also created at 2ωc.

-   The amplitude of the I and Q components depends on the sampling
    frequency and phase.

-   The sum of I+Q signal power in each of the 2 images equals that of
    s(n).

![](media/image3.jpeg){width="4.375in" height="3.28125in"}

Figure 2: Graychip down conversion

### The CIC filter 

The CIC filter is a cascade of digital integrators followed by a cascade
of combs (digital differentiators) in equal number. In the Graychip this
number is fixed and equal to 5. Between the integrators and the combs
there is a digital switch or decimator, used to lower the sampling
frequency of the combs signal with respect to the sampling frequency of
the integrators.

Each integrator contributes to the CIC transfer function with a pole.
The transfer function of each integrator stage is

$H_{i}(z) = \frac{1}{1 - z^{- 1}}$

Each comb section contributes with a zero of order D, where D is the
frequency decimation ratio.

The transfer function of each comb stage, referenced at the input
sampling rate fs, is

$H_{c}(z) = 1 - z^{- D}$

The CIC transfer function in the Z-plane becomes:

$H(z) = H_{I}^{N}(z)H_{C}^{N}(z) = \frac{\left( 1 - z^{- D} \right)^{N}}{\left( 1 - z^{- 1} \right)^{N}} = \left\lbrack \sum_{k = 0}^{D - 1}z^{- k} \right\rbrack^{N}$
(1)

![](media/image4.wmf){width="0.6700787401574804in"
height="0.2925196850393701in"}![](media/image5.wmf){width="0.6700787401574804in"
height="0.2846456692913386in"}

Figure 3: CIC block diagram

The Graychip CIC has the following characteristics:

-   Decimator by 8 to 4096.

-   Input signal gain correction module (not shown) to correct the N\^5
    gain factor introduced by the CIC. D is the decimation rate.

The Fourier transform is obtained evaluating z at$e^{i2\pi f}$

If the output is referred to the output sampling frequency fs/N, the z
transform must be evaluated at $e^{i2\frac{\pi f}{D}}$

For 5 stages of I/D the CIC transfer function becomes:

$H(f) = \left\lbrack \frac{\text{sin}\pi f}{\text{sin}\pi f/D} \right\rbrack^{5}$
(2)

The CIC transfer function is plotted in Figure 4

![](media/image6.jpeg){width="4.875in" height="3.65625in"}

Figure 4: CIC Transfer function

The performance of the CIC filter in time domain is very interesting and
has been analyzed in \[4\].

$\begin{matrix}
h_{j}(k) = \sum_{l = 0}^{\left\lceil \frac{k}{N} \right\rceil}{{( - 1)}^{- l}\begin{pmatrix}
5 \\
l
\end{pmatrix}}\begin{pmatrix}
5 - j + k - \text{Nl} \\
k - \text{Nl}
\end{pmatrix} & ,j = 1,\text{.}\text{.},5
\end{matrix}$The CIC filter coefficients can be obtained by:

\(3\) Integrators

$\begin{matrix}
h_{j}(k) = {( - 1)}^{- l}\begin{pmatrix}
\text{11} - j \\
k
\end{pmatrix} & ,j = 6,\text{.}\text{.},\text{10}
\end{matrix}$ (4) Combs

Equations (3) and (4) have already simplified the more general equations
using 5 integrators/differentiators since these are fixed numbers in the
Graychip.

The derivation of these equations due to E. Hogenauer, can be found at
\[2\].

### CFIR and PFIR

The CFIR and PFIR filters are equivalent. They only differ in the number
of TAPS. In frequency domain their transfer function is:

$H(z) = \sum_{k = 0}^{N - 1}{h(k)z^{- k}}$ Z-transform (5)

$H(e^{i\omega}) = \sum_{k = 0}^{N - 1}{h(k)e^{- i\omega k}}$ Fourier
transform (6)

In time domain the filter's impulse response convolves the input signal

$y(n) = x(n) \ast h(n) = \sum_{k = 0}^{2(N - 1)}{x(k)h(n - k)}$ (7)

For most applications the filtering function is specified by the
filter's frequency response. Hence, the filter coefficients are obtained
working in the frequency domain. The filter coefficients are obtained as
parameters in a linear fitting with constrains. However, sometimes the
filter coefficients are obtained directly working in the time domain.
(e.g. time window averaging). The algorithms used to obtain the filter
coefficients are very diverse and application oriented.

Decimation creates mirror images of the spectrum at fs/D, where D is the
decimation rate.

The images must be filtered by the FIR If the input spectrum is not band
limited (the band limit requirement is BW\<π fs/D) the decimation will
generate aliasing. An important point is that the decimation function is
not shift invariant. The transfer function of a filter-decimator is:

$h(n) = h_{\text{FIR}}(n - m)\text{.}h_{\text{DEC}}(n)$ (8)

Where hFIR and hDEC are the impulse response functions of the FIR and
decimator respectively. The *m* in the equation is a delay that
represents the way the filter responds to a delayed delta input. The
decimator does not care about the delay, so the combined response is not
shift invariant.

## Test Signal

The test signal used to design the Envelope Filter is based on
measurements done at the output of the "ringing" filter. These signals A
and B were sampled at 2Gs/sec (1000 samples in 500ns) using a digital
oscilloscope (Figure 5).

![](media/image7.jpeg){width="4.125in" height="3.129861111111111in"}

Figure 5: signals A and B sampled at 2Gs/sec.

Typical Tevatron bunch loads are generated using the signal in Figure 5.
To generate a Test Signal ensamble we have done the following:

-   1st step single bunch: A and B shortened to 396ns (792 samples)

-   2nd step signal batch: each batch is a train of N bunches. N between
    1 and 12.

-   3rd step include abort gaps.

-   4th step signal sampled at 74.345MHz

The test signal ensamble is shown in Figure 6. The upper plot shows the
test signal for 1 accelerator lap (i.e. \~20.9μs). The lower plot shows
one bunch sampled at 74.34MHz which the sampling frequency used by the
Graychips.

![](media/image8.jpeg){width="3.875in" height="2.90625in"}

Figure 6: Test signal ensamble

### Signal spectrums

-   Spectrum of A shows alias due to under-sampling.

-   A and I (Q) spectrums show tall power density lines at harmonics of
    the analog filter's BW.

-   Down-conversion creates alias at 32.7MHz

![](media/image9.jpeg){width="4.375in" height="3.28125in"}

Graychip setup

The maximum sampling rate supported by the Graychip is 100MHz. The
Ecotek supports only 80MHz.

The minimum decimation using a single Graychip channel is:

-   CIC filter: D=8

-   CFIR filter: D=2

-   PFIR filter: D=2

-   Total D=32

Using multiple channels we can decimate as low as D=8 combining CIC,
CFIR and PFIR. The current Graychip setup samples at 74.345MHz,
bypassing the resampler the maximum sampling rate after the Graychip is
9.29MHz. That means that we can see things moving as fast as 4.65MHz.

## The Envelope Filter

The on-line filtering of the A and B signals for beam position
measurement is a combination of digital filtering and data processing on
firmware. Since beam position variations are "slow" with respect to the
signal spectrum fastest components, the envelope of the batch of bunches
must be enough to estimate position (1st harmonic is at \~150KHz).

![](media/image10.jpeg){width="4.875196850393701in"
height="3.8744094488188976in"}

The beam position estimation was done in three steps. The first step is
done by the Graychip filters, the 2^nd^ and 3^rd^ steps are implemented
in firmware on the Echotek's FPGA.

-   First step: filter the down-converted signal to obtain the the I and
    Q that determine the envelope of a batch of bunches.

-   Second step: Select I and Q samples above a certain threshold and
    filter out the rest.

-   Third step: Average Is and Qs to reduce the number of samples that
    are readout from the Echotek's memory. Obtain one I-Q pair every N
    batches. Averaging more samples will help to achieve a position
    estimation error distribution with low sigma. Observation: N must be
    large enough to achieve the desired digital bandwidth at the output
    of the Ecotek.

The Graychip setup in the Envelope Filter implementation is:

-   Input signal sampled at 74.345MHz

-   Oscillator frequency fosc = 53.01MHz

-   CIC decimation = 4 (by combining two channels)

-   CFIR decimates by 2, fc = 2.5MHz

-   PFIR decimates by 2, fc = 350 KHz

### Filter's frequency response

The CIC filter in the Graychip only has one free variable, the
decimation ratio. We have chosen the minimum decimation (i.e. 8) in
order to maximize the number of signal samples at the output of the
filter. A total decimation of 4 is reached in the CIC, combining two
Graychip channels. The CFIR filter is used to equalize the "droop"
generated by the CIC in the filter's passband. The CFIR design does not
put much emphasis in a fast transition slope. The PFIR, instead, has a
fast transition band response. The cutoff frequency of the filter has
been chosen equal to 300KHz. Figure 7 shows the filter's frequency
responses.

![](media/image11.jpeg){width="5.041666666666667in" height="3.78125in"}

Figure 7: CIC, CFIR and PFIR frequency responses

Figure 8 shows the power spectrum densities after each stage of
filtering. The Envelope filter does a good work at keeping the low
frequency content of the spectrum, enough to produce a signal with a
fast rise time and filters all the high frequency content including down
conversion images and high frequency noise. Also note that the spectrum
amplitudes decay with 1/decimation_ratio, so it is important to keep the
decimation ratio low in order to have a good signal to noise ratio. This
last topic is analyzed with more detail in \[4\].

![](media/image12.jpeg){width="4.845669291338583in"
height="3.6346456692913387in"}![](media/image13.jpeg){width="2.8263779527559056in"
height="2.12007874015748in"}

Figure 8: Power Spectrum Densities at each filtering stage

The Graychip outputs filter the I and Q samples. Figure 9 shows
waveforms of \|A\|, \|B\|, beam intensity (i.e. \|A\|+\|B\|) and
position (i.e. \|A\|-\|B\|/\|A\|+\|B\|) using the I's and Q's at the
Graychip output. The signals on Figure 9 were plotted offline using
Matlab. The I's and Q's have not been plotted to avoid overloading the
figure. However, the number of I and Q samples out of the Graychip
matches the number of dots shown in both the beam intensity and the
position traces. In the current application, the number of I and Q
samples is further reduced by filter post processing in the Echotek's
FPGA. From Figure 9 we observe that:

-   \|A\|-\|B\|/\|A\|+\|B\| is fairly constant for
    \|A\|+\|B\|\>Threshold.

-   There are about 25 useful points per batch.

-   A simple threshold based on the intensity plot can be implemented to
    separate the interesting I's and Q's from the non-interesting ones.

![](media/image14.jpeg){width="5.9992125984251965in"
height="4.4992125984251965in"}

Figure 9: Envelope Filter waveforms

Figure 10 shows the ACNET output of one of the 1^st^ tests with the
Envelope Filter before implementing the Post processing filter in the
FPGA. In this figure we see the I and Q traces for A and B channels,
along with the intensity and position traces generated by all the
samples output by the Graychip. The Post processing filter in the FPGA
reduces the number of I Q pairs to one pair every N batches.

> ![](media/image16.png){width="4.0in" height="3.326388888888889in"}

Figure 10: ACNET output of one of the 1^st^ tests with the Envelope
Filter before implementing the Post processing filter in the FPGA

### Post processing filter in the Echotek's FPGA

The post processing filter implemented in firmware:

-   Selects I and Q samples above a certain threshold and filter out the
    rest.

-   Averages Is and Qs to reduce the number of samples that are readout
    from the Echotek's memory. The number of samples averaged in the
    FPGA is tied to the desired digital bandwidth at the output of the
    Ecotek.

The block diagram of the Post processing filter is shown in Figure 11.

![](media/image17.wmf){width="0.24291338582677166in"
height="0.20708661417322835in"}![](media/image17.wmf){width="0.24291338582677166in"
height="0.20708661417322835in"}

Figure 11: Block diagram of the Post processing filter

> To measure its performance we have tested the Envelope Filter using
> signals with bunch loads from 1 to 36. The maximum number of bunches
> in one batch is 12, two batches are separated by an abort gap and
> there is a total of 3 equally spaces batches in one accelerator lap.
> The envelope filter responds well to beam loads with few bunches per
> batch.

![](media/image18.jpeg){width="5.375in" height="4.03125in"}

Figure 12: beam load configurations of batches with 1 to 12 bunches

### Envelope Filter Performance

Figures 13, 14 and 15 show the performance of the Envelope Filter for
bunch loads from 1 to 36. The Test Stand setup includes Jim Steimel's
beam simulator inputs, a band-pass ringing filter, a splitter to
generate A and B inputs, an Echotek module, a BPM timing card and BPM
processor. In order to generate good statistics each bunch load test
represents a run of more than 10,000 input samples. Since the inputs A
and B come from a splitter they should be identical and the measured
position should be zero. However, the splitter attenuates one signal
more than the other generating an offset in the position measurement of
about 84μ. This offset is exactly the same seen by Jim Steimel using a
completely different filter.

It is expected that the Envelope Filter performs better to bunch loads
with more bunches because the digital filter's bandwidth is only 300KHz.
However, it can be appreciated in Figure 13 that the Envelope Filter
responds very well to bunch loads with a small number of bunches. The
major effect in the filter's performance is an increase in the sigma of
the error distribution of position measurement. The larger error in the
position measurement for loads with less bunches can be compensated by a
larger average in the FPGA or in the offline processing.

![](media/image19.jpeg){width="5.75in" height="3.5548611111111112in"}

Figure 13: Mean position measurement vs. number of bunches in the beam
load

-   Single envelope p measurements = one I-Q pair \~ every 7usec
    (\~142KHz)

-   3-envelope avrg. P measurements = one I-Q pair per lap, \~21usec
    (\~45KHz)

-   9-envelope avrg. P measurements = one I-Q pair every 3 laps,
    \~63usec (\~18KHz)

> Figure 14 shows the same position measurement plot of last slide but
> including the error bars. Note that as more envelopes are considered
> to calculate the position measurement the error bars get smaller.

![](media/image20.jpeg){width="4.75in" height="3.5625in"}

Figure 14: Mean position measurement with error bars

> The sigma of position measurements shown in Figure 14 are plotted
> again to show the effect of more bunches in the beam load (i.e. better
> signal to noise ratio). All 3 sigma trends should be monotonic. The
> few point that fail to achieve that are probably due to the some
> non-Gaussian noise in the test-stand or we may need longer data runs.

![](media/image21.jpeg){width="5.041666666666667in"
height="3.4493055555555556in"}

Figure 15: Sigma in the distribution of the mean position measurement

## References:

\[1\] Texas Instrument, "Greaychip 4016 Data Sheet rev1.0", Aug. 2001.

\[2\] E. Hogenauer, "An economical class of digital filters for
decimation and interpolation", IEEE Transactions on ASSP, vol ASSP-29,
No 2, April 1981.

\[3\] G. Cancelo, "Some models of the BPM signal", Fermilab
Beams-doc-1590, Feb 25, 2005.

\[4\] G. Cancelo, "The CIC filter", Fermilab Beams-doc-1591, Feb 25,
2005

\[5\] G. Cancelo, "The phase shift problem in the Tevatron BPM signals",
Beams-doc-1592, Feb 25, 2005