**2.1. Basic design of FIR Hilbert transformers with MATLAB**

Since the phase requirement in FIR Hilbert transformers is accomplished, the design of a FIR Hilbert transformer consists on finding the impulse response *h*(*n*), for *n* = 0 to *L*–1, which satisfies the following magnitude response specification,

$$\left| (1 - \delta) \le \left| H(e^{j\phi}) \right| \le (1 - \delta) \qquad \text{for} \quad o\_L \le o \le o\_{H'} \tag{17}$$

where *δ* is the allowed pass-band ripple, *ωL* is the lower pass-band edge and *ωH* is given as *ωH* =*π*– *ωL* if the desired Hilbert transformer is a Type III filter or *ωH* =*π* if it is Type IV. The values *ωL* and *ωH* can be made to approach 0 and *π*, respectively, as closely as desired by increasing the length *L* of the filter. For Hilbert transformers, the value *ωL*/2*π* is considered the transition band.

The design of optimum equiripple Type III and Type IV FIR linear phase Hilbert transformers is usually performed by Parks-McClellan algorithm. With the MATLAB Signal Processing Toolbox this becomes a straightforward procedure through the function firpm. The order of the filter, *L*–1, must be estimated in advance. A useful formula to estimate *L*, presented in [10], is

$$L \approx \rho(\delta, \ o\_{\perp}) = \left[ 0.002655 \left( \log\_{10}(\delta) \right)^{3} + 0.031843 \left( \log\_{10}(\delta) \right)^{2} - \dots \right. \tag{18}$$
 
$$0.554993 \log\_{10}(\delta) - 0.049788 \left] / \left( \frac{o\_{\parallel}}{2\pi} \right) + 1.$$

**Example 1.** The following code example illustrates the design of a Type III Hilbert transformer with *δ*= 0.01, *ωL*= 0.1*π* and *ωH*= *π*– *ωL*= 0.9*π* using the MATLAB Signal Processing Toolbox. From (18), *L* is estimated as *L* 24.3266. For convenience, we use *L* = 4*k*+3 with *k* integer and the closest value for *L*, higher than the estimated value, is chosen. In this case we use *L* = 4\*6+3 = 27.

```
d = 0.01; w_L = 0.1*pi; w_H = 0.9*pi; L = 27; 
h = firpm(L-1,[w_L/pi w_H/pi],[1 1],'hilbert'); 
[H w] = freqz(h,1); 
figure; stem(0:length(h)-1, h,'fill') 
figure; plot(w/pi, abs(H))
```
452 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

range of frequencies (a pass-band region) which does not include these extremes.

**2.1. Basic design of FIR Hilbert transformers with MATLAB** 

(1 ) ( ) (1 ) for

satisfies the following magnitude response specification,

pass filters are quite nearly a Hilbert transformer.

the design of FIR Hilbert transformers.

the transition band.

presented in [10], is

systems whose phase responses differ by approximately *π*/2 over some well-defined portion of the band 0 < |*ω*|<*π*. By taking the outputs of the two all-pass filters as the real and imaginary parts of a complex signal it can be found that the spectrum of such signal nearly vanishes over much of the negative frequency interval. As such, the outputs of the two all-

FIR Hilbert transformers with constant group delay can be easily designed. The *π*/2 phase shift is realized exactly, with an additional linear phase component required for a causal FIR system. By evaluating (16) over some positive and negative values of *n*, it can be seen that the impulse response is anti-symmetric. Therefore, FIR Hilbert transformers are based on either Type III (i.e., anti-symmetric impulse response with odd length *L*) or Type IV (i.e., antisymmetric impulse response with even length *L*) symmetry. Filters with Type III symmetry have amplitude equal to zero in *ω* = 0 and *ω* = *π* and filters with Type IV symmetry have amplitude equal to zero only in *ω* = 0. Thus, the FIR approximation is acceptable over a given

The exactness of the phase of Type III and Type IV FIR systems is a compelling motivation for their use in approximating Hilbert transformers. Additionally, whereas IIR Hilbert transformers can present instability and they are sensitive to rounding error in their coefficients, FIR filters have guaranteed stability, are less sensitive to the coefficients rounding and their phase response is not affected by this rounding. Because of this, FIR Hilbert transformers are often preferred [8]-[15]. The rest of this chapter will be focused on

Since the phase requirement in FIR Hilbert transformers is accomplished, the design of a FIR Hilbert transformer consists on finding the impulse response *h*(*n*), for *n* = 0 to *L*–1, which

where *δ* is the allowed pass-band ripple, *ωL* is the lower pass-band edge and *ωH* is given as *ωH* =*π*– *ωL* if the desired Hilbert transformer is a Type III filter or *ωH* =*π* if it is Type IV. The values *ωL* and *ωH* can be made to approach 0 and *π*, respectively, as closely as desired by increasing the length *L* of the filter. For Hilbert transformers, the value *ωL*/2*π* is considered

The design of optimum equiripple Type III and Type IV FIR linear phase Hilbert transformers is usually performed by Parks-McClellan algorithm. With the MATLAB Signal Processing Toolbox this becomes a straightforward procedure through the function firpm. The order of the filter, *L*–1, must be estimated in advance. A useful formula to estimate *L*,

 , *<sup>j</sup> H e L H* (17) Figure 5a shows the impulse response and Figure 5b shows the magnitude response of the obtained Hilbert transformer.

As we mentioned earlier, the most expensive elements in digital filters are multipliers. For a Type III Hilbert transformer, the number of multipliers, *m*, is (*L*+1)/4 if *L* = 4*k*+3, or (*L*–1)/4 if *L* = 4*k*+1, with *k* integer. In this last case the impulse response values *h*(0) and *h*(*L*–1) are zero. For a Type IV Hilbert transformer, the number of multipliers is *L*/2. This number can be simplified as

$$
\mathbf{m} \approx \mathbf{C} \cdot \mathbf{L} \tag{19}
$$

where *C* = 0.25 for a Type III Hilbert transformer or *C* = 0.5 for a Type IV Hilbert transformer.

**Figure 5.** (a) Impulse response and (b) Magnitude response of a digital FIR Hilbert transformer.

It is worth highlighting the following point. A Type III Hilbert transformer can be derived from a Type IV Hilbert transformer by adding one zero-valued impulse response sample between each two impulse response samples of the Type IV Hilbert transformer. This is equivalent to replacing each *z*–1 in the transfer function of this filter by *z*–2. The opposite procedure can be straightforwardly followed to derive a Type IV Hilbert transformer from a Type III Hilbert transformer.

From (18), it can be seen that the length *L* increases inversely proportional with the transition band *ωL*/2*π*. Hence, for cases with narrow transition band and small ripple the implementation cost becomes very high. As a simple example, the estimated length for a Hilbert transformer with*δ*= 0.001 and *ωL*= 0.001*π* is *L* 3661.2. It implies approximately 915.3 multipliers, which is impractical. Therefore, the design of FIR Hilbert transformers with strict specifications requires specialized techniques to reduce the number of multipliers and the computational complexity of the filter. Before of the revision of these techniques, in the next section we will highlight the relation between Hilbert transformers and half-band filters because this relation is crucial for developing the specialized techniques to design low-complexity FIR Hilbert transformers.

### **3. The Hilbert transformer and its relation with the half-band filter**

Half-band filters have their transfer function given by

$$H\_{\rm Hb}(z) = \sum\_{n=0}^{2M} h\_{\rm Hb}(n) z^{-n},\tag{20}$$

where *hHb*(*n*) is the impulse response, *M* is an odd integer and 2*M*isthe filter order [21]. The coefficients are symmetric with respect to the central coefficient *hHb*(*M*), namely, they accomplish the following relation,

$$h\_{Hb}(\mathcal{D}M - n) = h\_{Hb}(n) \quad \text{ for} \quad n = 0, 1, \ldots, \mathcal{D}M. \tag{21}$$

The length of the filter, *L*, is an odd number given as *L* = 2*M* + 1 with *M* = 1, 3, 5… etc. In a lineal phase half-band filter, almost a half of the coefficients are zero. Figure 6 shows the procedure to design a half-band filter. It starts with the transfer function of a Type II lineal phase filter, i.e., a filter with symmetric impulse response whose length is even. For this filter we have,

$$Q(z) = \sum\_{n=0}^{M} q(n)z^{-n} \quad \text{for} \quad q(M-n) = q(n). \tag{22}$$

First, samples with value zero are introduced between the *q*(*n*) impulse samples (see Figure 6a and 6c). This generates a transfer function with Type I symmetry, whose order is 2*M*, given by

Type III Hilbert transformer.

low-complexity FIR Hilbert transformers.

accomplish the following relation,

filter we have,

given by

Half-band filters have their transfer function given by

It is worth highlighting the following point. A Type III Hilbert transformer can be derived from a Type IV Hilbert transformer by adding one zero-valued impulse response sample between each two impulse response samples of the Type IV Hilbert transformer. This is equivalent to replacing each *z*–1 in the transfer function of this filter by *z*–2. The opposite procedure can be straightforwardly followed to derive a Type IV Hilbert transformer from a

From (18), it can be seen that the length *L* increases inversely proportional with the transition band *ωL*/2*π*. Hence, for cases with narrow transition band and small ripple the implementation cost becomes very high. As a simple example, the estimated length for a Hilbert transformer with*δ*= 0.001 and *ωL*= 0.001*π* is *L* 3661.2. It implies approximately 915.3 multipliers, which is impractical. Therefore, the design of FIR Hilbert transformers with strict specifications requires specialized techniques to reduce the number of multipliers and the computational complexity of the filter. Before of the revision of these techniques, in the next section we will highlight the relation between Hilbert transformers and half-band filters because this relation is crucial for developing the specialized techniques to design

**3. The Hilbert transformer and its relation with the half-band filter** 

 2

*Hb Hb n*

0 () () , *<sup>M</sup> <sup>n</sup>*

where *hHb*(*n*) is the impulse response, *M* is an odd integer and 2*M*isthe filter order [21]. The coefficients are symmetric with respect to the central coefficient *hHb*(*M*), namely, they

The length of the filter, *L*, is an odd number given as *L* = 2*M* + 1 with *M* = 1, 3, 5… etc. In a lineal phase half-band filter, almost a half of the coefficients are zero. Figure 6 shows the procedure to design a half-band filter. It starts with the transfer function of a Type II lineal phase filter, i.e., a filter with symmetric impulse response whose length is even. For this

*<sup>M</sup> <sup>n</sup>*

First, samples with value zero are introduced between the *q*(*n*) impulse samples (see Figure 6a and 6c). This generates a transfer function with Type I symmetry, whose order is 2*M*,

( ) ( ) for ( ) ( ).

*n*

0

(2 ) ( ) for 0,1,...,2 . *Hb Hb h Mn h n n M* (21)

*Qz qnz qM n qn* (22)

*H z h nz* (20)

**Figure 6.** Low-pass half-band filter design. (a) Impulse response of a Type II filter with order *M*, *q*(*n*). (b) Zero-phase frequency response of the Type II filter with order *M*, *Q*(*ω*). (c) Impulse response of a Type I filter with order 2*M*, *f*(*n*). (d) Zero-phase frequency response of the Type I filter with order 2*M*, *F*(*ω*). (e) Impulse response of a half-band filter, *hHb*(*n*). (f) Zero-phase frequency response of the halfband filter, *HHb*(*ω*).

$$F(z) = \sum\_{n=0}^{2M} f(n)z^{-n} = Q(z^2) = \sum\_{n=0}^{M} q(n)z^{-2n}.\tag{23}$$

Then, the zero-valued sample with index *n* = *M* is replaced by the value 1/2 (See Figure 6e). Thus we obtain

$$H\_{Hb}(z) = \frac{1}{2}z^{-M} + F(z) = \frac{1}{2}z^{-M} + \sum\_{n=0}^{M} q(n)z^{-2n}.\tag{24}$$

The coefficients of the half-band filter are obtained from (20) and (24) as

$$h\_{\rm Hb}(M) = \frac{1}{2}, \quad h\_{\rm Hb}(n) = q\left(\frac{n}{2}\right) \text{ for } n \text{ even},\tag{25}$$

$$h\_{\rm Hb}(n) = 0,\text{ for } n \text{ odd and } \: n \neq M,\tag{26}$$

and the zero-phase frequency response of *HHb*(*z*) is

$$H\_{Hb}(\alpha) = \frac{1}{2} + Q(2\alpha) = \frac{1}{2} + F(\alpha). \tag{27}$$

Based on the previous relations, the design of a half-band low-pass filter with pass-band frequency *ωp* and pass-band ripple *δ* can be carried out by designing the *Q*(*z*) filter, such that its zero-phase frequency response, *Q*(*ω*), oscillates within 1/2 ± *δ* over the range of frequencies [0, 2*ωp*] (See Figure 6b). Since *Q*(*z*) has a Type II transfer function, it presents a fixed zero in *z* = –1 (*ω* = *π*). Note from Figure 6b that *Q*(*ω*) oscillates within –1/2 ± *δ* over the range of frequencies [2*π* – 2*ωp*, 2*π*]. The corresponding zero-phase frequency response of the filter *F*(*z*), given as *F*(*ω*) = *Q*(2*ω*), remains within 1/2 ± *δ* over the range of frequencies [0, *ωp*] and within –1/2 ± *δ* over the range of frequencies [*π* – *ωp*, *π*] (See Figure 6d). Finally, *HHb*(*ω*) oscillates around 1 over the range of frequencies [0, *ωp*] with tolerance *δ* and around 0 over the range of frequencies [*π* – *ωp*, *π*] with the same tolerance *δ* (See Figure 6f). Note that, as a low-pass filter, the half-band filter has the relations *ωs* = *π*–*ωp* and *δp* = *δs*.

**Example 2.** The following code example illustrates the design of a half-band filter with *δp*=*δs*= 0.005, *ωp*= 0.4*π* and *ωs*= *π*– *ωp*= 0.5*π* using the MATLAB Filter Design Toolbox. Eq. (18) can be applied to estimate the filter length *L*, by substituting *ωL* = (*π*/2) – *ωp* and *δ*= 2*δp*. The length *L* is estimated as *L* 24.3266. Since *L* must be represented as *L* = 2*M*+1 with *M* odd to avoid zero-valued impulse response samples in the left and right extremes of the impulse response, we use *L* =2\*13 + 1 = 27.

```
dp = 0.005;w_p = 0.4*pi;w_s = 0.5*pi; L = 27; 
h_half = firhalfband(L-1, w_p/pi); 
[H_half w] = freqz(h_half,1); 
figure; stem(0:length(h_half)-1, h_half,'fill') 
figure; plot(w/pi, abs(H_half))
```
#### **3.1. Hilbert transformer derived from a half-band filter**

A Hilbert transformer filter can be designed from a half-band filter. First,the sample with value 1/2, located in the index *n* = *M*, is replaced by the value 0 (See Figures 7a and 7d). Thus we obtain

$$
\tilde{H}(z) = H\_{\rm Hb}(z) - \frac{1}{2}z^{-M}.\tag{28}
$$

The subtraction of this coefficient, drawn in Figure 7d, causes the zero-phase frequency response of the half-band filter to be shifted downwardly, as illustrated in Figure 7c. The filter *H* ( ) must be shifted by *π*/2 on the horizontal direction in the frequency domain. This is accomplished by multiplying the remaining coefficients, *h n*( ) , by (*j*)*–n*. The effect of this action produces a Hilbert transformer with odd length and a pass-band gain equal to 0.5. Therefore, a Hilbert transformer with unitary gain will be obtained by scaling all the coefficients by 2. This is illustrated in Figure 8. The transfer function of the Hilbert transformer given in terms of the transfer function of a half-band filter is

$$H(\mathbf{z}) = 2\left[H\_{\mathrm{Hb}}(j\mathbf{z}) - \frac{1}{2}(j\mathbf{z})^{-M}\right] = 2\sum\_{\substack{n=0\\n\neq M}}^{2M} h\_{\mathrm{Hb}}(n)(j\mathbf{z})^{-n} \,. \tag{29}$$

The impulse response of the Hilbert transformer is related with the impulse response of the half-band filter through the following expression,

$$h(n) = \begin{cases} 0; & n = 2k + 1, \\ 2(-1)^{k-1} h\_{\text{Hb}}(n); & n = 2k \end{cases} \quad \text{with} \quad k = 0, 1, 2, \dots, M. \tag{30}$$

It was mentioned earlier that the useful bandwidth in a Hilbert transformer is restricted to some range given as 0 < *ωL* ≤ *ω* ≤ *ωH* < *π*, where *ωH*= *π* – *ωL*. The relation of the low-pass edge frequency *ωL* with the band-edge frequencies of the half-band filter, *ωp* and *ωs*, is given by

$$
\alpha\_L = (\pi/2) - \alpha\_{p'} \tag{31}
$$

$$
\alpha \alpha\_L = \alpha\_s - (\pi \text{ / } \text{\textdegree })\tag{32}
$$

where *ωs* = *π* – *ωp*.

456 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

<sup>1</sup> ( ) , ( ) for even, 2 2 *Hb Hb*

 

Based on the previous relations, the design of a half-band low-pass filter with pass-band frequency *ωp* and pass-band ripple *δ* can be carried out by designing the *Q*(*z*) filter, such that its zero-phase frequency response, *Q*(*ω*), oscillates within 1/2 ± *δ* over the range of frequencies [0, 2*ωp*] (See Figure 6b). Since *Q*(*z*) has a Type II transfer function, it presents a fixed zero in *z* = –1 (*ω* = *π*). Note from Figure 6b that *Q*(*ω*) oscillates within –1/2 ± *δ* over the range of frequencies [2*π* – 2*ωp*, 2*π*]. The corresponding zero-phase frequency response of the filter *F*(*z*), given as *F*(*ω*) = *Q*(2*ω*), remains within 1/2 ± *δ* over the range of frequencies [0, *ωp*] and within –1/2 ± *δ* over the range of frequencies [*π* – *ωp*, *π*] (See Figure 6d). Finally, *HHb*(*ω*) oscillates around 1 over the range of frequencies [0, *ωp*] with tolerance *δ* and around 0 over the range of frequencies [*π* – *ωp*, *π*] with the same tolerance *δ* (See Figure 6f). Note that, as a

**Example 2.** The following code example illustrates the design of a half-band filter with *δp*=*δs*= 0.005, *ωp*= 0.4*π* and *ωs*= *π*– *ωp*= 0.5*π* using the MATLAB Filter Design Toolbox. Eq. (18) can be applied to estimate the filter length *L*, by substituting *ωL* = (*π*/2) – *ωp* and *δ*= 2*δp*. The length *L* is estimated as *L* 24.3266. Since *L* must be represented as *L* = 2*M*+1 with *M* odd to avoid zero-valued impulse response samples in the left and right extremes of the impulse

A Hilbert transformer filter can be designed from a half-band filter. First,the sample with value 1/2, located in the index *n* = *M*, is replaced by the value 0 (See Figures 7a and 7d). Thus

<sup>1</sup> () () <sup>2</sup>

*<sup>M</sup> Hz H z z Hb* . (28)

*<sup>n</sup> hM hnq n* (25)

( ) 0, for odd and , *Hb h n n nM* (26)

1 1 ( ) (2 ) ( ). 2 2 *H QF Hb* (27)

 

The coefficients of the half-band filter are obtained from (20) and (24) as

low-pass filter, the half-band filter has the relations *ωs* = *π*–*ωp* and *δp* = *δs*.

and the zero-phase frequency response of *HHb*(*z*) is

response, we use *L* =2\*13 + 1 = 27.

h\_half = firhalfband(L-1, w\_p/pi);

[H\_half w] = freqz(h\_half,1);

figure; plot(w/pi, abs(H\_half))

we obtain

dp = 0.005;w\_p = 0.4\*pi;w\_s = 0.5\*pi; L = 27;

figure; stem(0:length(h\_half)-1, h\_half,'fill')

**3.1. Hilbert transformer derived from a half-band filter** 

**Figure 7.** (a) Ideal zero-phase frequency response of the half-band filter *HHb*(*ω*). (b) Impulse response of the half-band filter *hHb*(*n*). (c) Ideal zero-phase frequency response resulting of the subtraction of the central coefficient, located at *n* = *M*, 1 <sup>2</sup> () () *Hb H H* . (d) Impulse response, *h n*( ) .

Hilbert transformers designed from half-band filters have odd length. In these cases, there is a coefficient of value zero between each coefficient of its impulse response. Thus, a Hilbert transformer with even length can be obtained by eliminating these zero-valued coefficients.

**Figure 8.** Hilbert transformer design, (a) Ideal zero-phase frequency response of the Hilbert transformer obtained from *HHb*(*ω*). (b) Impulse response *h*(*n*).

**Example 3.** The following code example illustrates a simple way to obtain the impulse response of a Hilbert transformer from the impulse response of a half-band filter. If we consider that the code of Example 2 has been previously run, it can be assumed that h\_half and L are already defined. The resulting Hilbert transformer coefficients in h are the same as the ones obtained in Example 1, since the half-band filter generated in Example 2 accomplish the relations *ωL* = (*π*/2) – *ωp* and *δ*= 2*δp*with regard to the specifications in Example 1.

index = [1:L]; middle\_sample = [zeros(1,(L-1)/2) 1/2 zeros(1,(L-1)/2)]; m = (ones(1,L)\*i).^(-(index-1)); h = 2\*(h\_half.\*m - middle\_sample.\*m);
