# firhalfband

Halfband FIR filter design

## Syntax

``b = firhalfband(n,fp)``
``b = firhalfband(n,win)``
``b = firhalfband(n,dev,'dev')``
``b = firhalfband('minorder',fp,dev)``
``b = firhalfband('minorder',fp,dev,'kaiser')``
``b = firhalfband(___,'high')``
``b = firhalfband(___,'minphase')``

## Description

````b = firhalfband(n,fp)` designs a lowpass FIR halfband filter of order `n` with an equiripple characteristic. `n` must be an even integer. `fp` determines the passband edge frequency such that 0 < `fp` < 1/2, where 1/2 corresponds to π/2 rad/sample.```
````b = firhalfband(n,win)` designs a lowpass `n`th-order filter using the truncated windowed-impulse response method instead of the equiripple method. `win` should be an `n`+1 length vector. The function truncates the ideal response to length `n`+1, then multiplies it point-by-point with the window specified in `win`.```
````b = firhalfband(n,dev,'dev')` designs an `n`th-order lowpass halfband filter with an equiripple characteristic. `dev` sets the value for the maximum passband and stopband ripple.```

example

````b = firhalfband('minorder',fp,dev)` designs a lowpass minimum-order filter with passband edge `fp`. The peak ripple is constrained by the scalar `dev`. This design uses the equiripple method.```
````b = firhalfband('minorder',fp,dev,'kaiser')` designs a lowpass minimum-order filter with passband edge `fp`. The peak ripple is constrained by the scalar `dev`. This design uses the Kaiser window method.```
````b = firhalfband(___,'high')` returns a highpass halfband FIR filter.```
````b = firhalfband(___,'minphase')` designs a minimum-phase FIR filter such that the filter is a spectral factor of a halfband filter. Recall that `h = conv(b,fliplr(b))` is a halfband filter. This can be useful for designing perfect reconstruction two-channel FIR filter banks. The `'minphase'` option is not available for window-based halfband filter designs such as `b = firhalfband(n,win)` and ```b = firhalfband('minorder',fp,dev,'kaiser')``` .In the minimum phase case, the filter order `n` must be odd.```

## Examples

collapse all

Design a minimum order halfband filter with maximum ripple set to 0.0001.

```b = firhalfband('minorder',.45,0.0001); impz(b)``` The impulse response is zero for every alternate sample.

## Input Arguments

collapse all

FIR halfband filter order, specified as an integer

If you specify the `firhalfband` function to design a minimum phase filter using the `'minphase'` argument, the filter order must be odd. In all other cases, the filter order must be even.

Data Types: `single` | `double`

Passband edge frequency, specified as a scalar in the range (0,½), where ½ corresponds to π/2 rad/sample.

Data Types: `single` | `double`

Window to apply to the filter, specified as an n+1 length vector. The function truncates the ideal response to length n+1, then multiplies it point-by-point with the window specified in `win`.

Data Types: `single` | `double`
Complex Number Support: Yes

Maximum passband and stopband ripple in the halfband filter, specified as a scalar.

Data Types: `single` | `double`

## Output Arguments

collapse all

FIR halfband filter coefficients, returned as a vector.

Data Types: `single` | `double`
Complex Number Support: Yes

collapse all

### Halfband Filters

The ideal lowpass halfband filter is given by

`$h\left(n\right)=\frac{1}{2\pi }{\int }_{-\pi /2}^{\pi /2}{e}^{j\omega n}d\omega =\frac{\mathrm{sin}\left(\frac{\pi }{2}n\right)}{\pi n}.$`

The ideal filter is not realizable because the impulse response is noncausal and not absolutely summable. However, the impulse response of the ideal lowpass filter possesses some important properties that are required of a realizable approximation. Specifically, the ideal lowpass halfband filter’s impulse response is:

• Equal to 0 for all even-indexed samples.

• Equal to 1/2 at n=0. You can see this by using L’Hopital’s rule on the continuous-valued equivalent of the discrete-time impulse response.

The ideal highpass halfband filter is given by

`$g\left(n\right)=\frac{1}{2\pi }{\int }_{-\pi }^{-\pi /2}{e}^{j\omega n}d\omega +\frac{1}{2\pi }{\int }_{\pi /2}^{\pi }{e}^{j\omega n}d\omega .$`

Evaluating the preceding integral gives the following impulse response

`$g\left(n\right)=\frac{\mathrm{sin}\left(\pi n\right)}{\pi n}-\frac{\mathrm{sin}\left(\frac{\pi }{2}n\right)}{\pi n}.$`

The ideal highpass halfband filter’s impulse is:

• Equal to 0 for all even-indexed samples

• Equal to 1/2 at n=0

The `firhalfband` function uses a causal FIR approximation to the ideal halfband response, which is based on minimizing the ${\ell }^{\infty }$ norm of the error (minimax).

### Kaiser Window

The coefficients of a Kaiser window are computed using this equation:

`$w\left(n\right)=\frac{{I}_{0}\left(\beta \sqrt{1-{\left(\frac{n-N/2}{N/2}\right)}^{2}}\right)}{{I}_{0}\left(\beta \right)},\text{ }\text{ }0\le n\le N,$`

where I0 is the zeroth-order modified Bessel function of the first kind.

To obtain a Kaiser window that represents an FIR filter with stopband attenuation of α dB, use this β.

`$\beta =\left\{\begin{array}{ll}0.1102\left(\alpha -8.7\right),\hfill & \alpha >50\hfill \\ 0.5842{\left(\alpha -21\right)}^{0.4}+0.07886\left(\alpha -21\right),\hfill & 50\ge \alpha \ge 21\hfill \\ 0,\hfill & \alpha <21\hfill \end{array}$`

The filter order n is given by:

`$n=\frac{\alpha -7.95}{2.285\left(\Delta \omega \right)}$`

where Δω is the transition width.

For more details, see Algorithms.

## Algorithms

The `firhalfband` function uses the equiripple or the Kaiser window method to design the FIR halfband filter. You can also specify a custom window using the `win` argument.

Halfband Equiripple Design

In the equiripple method, the algorithm uses a minimax (minimize the maximum error) FIR design to design a fullband linear phase filter with the desired specifications. The algorithm upsamples a fullband filter to replace the even-indexed samples of the filter with zeros and creates a halfband filter. It then sets the filter tap corresponding to the group delay of the filter in samples to 1/2. This yields a causal linear-phase FIR filter approximation to the ideal halfband filter defined in Halfband Filters. See  for a description of this filter design method using the Remez exchange algorithm. As you can design a filter using this approximation method with a constant ripple both in the passband and stopband, the filter is also known as the equiripple filter.

Window-based Design

In the window-based design method, the algorithm first truncates the ideal halfband filter defined in Halfband Filters, then it applies the user-specified window. This yields a causal linear-phase FIR filter approximation to the ideal halfband filter. If you provide the `'kaiser'` argument, the function calculates the window as mentioned in Kaiser Window.

For more information on designing FIR halfband filters, see FIR Halfband Filter Design.

 Saramaki, T, “Finite Impulse Response Filter Design,” Handbook for Digital Signal Processing. S.K. Mitra and J.F. Kaiser Eds. Wiley-Interscience, N.Y., 1993, Chapter 4.

 Harris, F.J. Multirate Signal Processing for Communication Systems, Prentice Hall, 2004, pp. 208–209.