# dsp.FIRHalfbandDecimator

Halfband decimator

## Description

The `dsp.FIRHalfbandDecimator`

System object™ performs an efficient polyphase decimation of the input signal by a
factor of two. You can use `dsp.FIRHalfbandDecimator`

to implement the
analysis portion of a two-band filter bank to filter a signal into lowpass and highpass
subbands. `dsp.FIRHalfbandDecimator`

uses an FIR equiripple design to
construct the halfband filters and a polyphase implementation to filter the
input.

To filter and downsample your data:

Create the

`dsp.FIRHalfbandDecimator`

object and set its properties.Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

## Creation

### Syntax

### Description

returns a halfband decimator, `firhalfbanddecim`

= dsp.FIRHalfbandDecimator`firhalfbanddecim`

, with the
default settings. Under the default settings, the System object filters and downsamples the input data with a halfband frequency
of `11025`

Hz, a transition width of `4.1`

kHz, and a stopband attenuation of `80`

dB.

returns a halfband decimator, with additional properties specified by one or
more `firhalfbanddecim`

= dsp.FIRHalfbandDecimator(`Name,Value`

)`Name,Value`

pair arguments.

**Example:**

```
firhalfbanddecim =
dsp.FIRHalfbandDecimator('Specification','Filter order and stopband
attenuation')
```

creates an FIR halfband decimator object with filter
order set to 52 and stopband attenuation set to 80 dB.## Properties

Unless otherwise indicated, properties are *nontunable*, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
`release`

function unlocks them.

If a property is *tunable*, you can change its value at
any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

`Specification`

— Filter design parameters

```
'Transition width and stopband
attenuation'
```

(default) | `'Filter order and stopband attenuation'`

| `'Filter order and transition width'`

| `'Coefficients'`

Filter design parameters, specified as a character vector. When you set
`Specification`

to one of the following, you choose
two of the three available design parameters to design the FIR Halfband
filter.

`'Transition width and stopband attenuation'`

–– Transition width and stopband attenuation are the design parameters.`'Filter order and stopband attenuation'`

–– Filter order and stopband attenuation are the design parameters.`'Filter order and transition width'`

–– Filter order and transition width are the design parameters.

The filter is designed using the optimal equiripple filter design method.

When you set `Specification`

to
`'Coefficients'`

, you specify the halfband filter
coefficients directly through the `Numerator`

property.

`FilterOrder`

— Filter order

`52`

(default) | even positive integer

Filter order, specified as an even positive integer.

#### Dependencies

This property applies when you set `Specification`

to either `'Filter order and stopband attenuation'`

or
`'Filter order and transition width'`

.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`StopbandAttenuation`

— Stopband attenuation

`80`

(default) | positive real scalar

Stopband attenuation in dB, specified as a positive real scalar.

#### Dependencies

This property applies when you set `Specification`

to either `'Filter order and stopband attenuation'`

or
```
'Transition width and stopband
attenuation'
```

.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`TransitionWidth`

— Transition width

`4100`

(default) | positive real scalar

Transition width in Hz, specified as a positive real scalar. The value of the transition width in Hz must be less than 1/2 the input sample rate.

#### Dependencies

This property applies when you set `Specification`

to either `'Transition width and stopband attenuation'`

or `'Filter order and transition width'`

.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`Numerator`

— FIR halfband filter coefficients

`firhalfband('minorder',0.407,1e-4)`

(default) | row vector

FIR halfband filter coefficients, specified as a row vector. The
coefficients must comply with the FIR halfband impulse response format. For
details on this format, see Halfband Filters and FIR Halfband Filter Design. If
half the order of the filter, `(length(Numerator) - 1)/2`

,
is even, every other coefficient starting from the first coefficient must be
a zero except for the center coefficient which must be a 0.5. If half the
order of the filter is odd, the sequence of alternating zeros with a 0.5 at
the center starts at the second coefficient.

#### Dependencies

This property applies when you set `Specification`

to `'Coefficients'`

.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`SampleRate`

— Input sample rate

`44100`

(default) | positive real scalar

Input sample rate in Hz, specified as a positive real scalar. The input sample rate defaults to 44100 Hz. If you specify transition width as one of your filter design parameters, the transition width cannot exceed 1/2 the input sample rate.

**Data Types: **`single`

| `double`

### Fixed-Point Properties

`CoefficientsDataType`

— Word and fraction lengths of coefficients

`numerictype(1,16)`

(default) | `numerictype`

object

Word and fraction lengths of coefficients, specified as a signed or
unsigned `numerictype`

object. The default,
`numerictype(1,16)`

corresponds to a signed numeric
type object with 16-bit coefficients and a fraction length determined
based on the coefficient values, to give the best possible
precision.

This property is not tunable.

Word length of the output is same as the word length of the input. Fraction length of the output is computed such that the entire dynamic range of the output can be represented without overflow. For details on how the fraction length of the output is computed, see Fixed-Point Precision Rules for Avoiding Overflow in FIR Filters.

`RoundingMethod`

— Rounding method for output fixed-point operations

`'Floor'`

(default) | `'Ceiling'`

| `'Convergent'`

| `'Nearest'`

| `'Round'`

| `'Simplest'`

| `'Zero'`

Rounding method for output fixed-point operations, specified as a character vector. For more information on the rounding modes, see Precision and Range.

## Usage

### Description

`[`

computes the `ylow`

,`yhigh`

] = firhalfbanddecim(`x`

)`ylow`

and `yhigh`

, of the
analysis filter bank, `firhalfbanddecim`

for input
`x`

. A *Ki*-by-*N*
input matrix is treated as *N* independent channels. The
System object generates two power-complementary output signals by adding and
subtracting the two polyphase branch outputs respectively.
`ylow`

and `yhigh`

are of the same
size (*Ko*-by-*N*) and data type.
*Ko* = *Ki*/2, where `2`

is the decimation factor.

### Input Arguments

`x`

— Data input

column vector | matrix

Data input, specified as a column vector or a matrix. If the input signal is a matrix, each column of the matrix is treated as an independent channel. The number of rows in the input signal must be a multiple of 2.

This object supports variable-size input signal.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `fi`

**Complex Number Support: **Yes

### Output Arguments

`ylow`

— Lowpass subband of decimator output

column vector | matrix

Lowpass subband of decimator output, returned as a column vector or a
matrix. The output, `ylow`

is a lowpass halfband
filtered and downsampled version of the input `x`

.
Due to the halfband nature of the filter, the downsampling factor is
always 2.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `fi`

**Complex Number Support: **Yes

`yhigh`

— Highpass subband of decimator output

column vector | matrix

Highpass subband of decimator output, returned as a column vector or a
matrix. The output, `yhigh`

is a highpass halfband
filtered and downsampled version of the input `x`

.
Due to the halfband nature of the filter, the downsampling factor is
always 2.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `fi`

**Complex Number Support: **Yes

## Object Functions

To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named `obj`

, use
this syntax:

release(obj)

### Specific to `dsp.FIRHalfbandDecimator`

`freqz` | Frequency response of discrete-time filter System object |

`fvtool` | Visualize frequency response of DSP filters |

`info` | Information about filter System object |

`cost` | Estimate cost of implementing filter System object |

`coeffs` | Returns the filter System object coefficients in a structure |

`polyphase` | Polyphase decomposition of multirate filter |

## Examples

### Impulse and Frequency Response of Halfband Decimation Filter

Create a lowpass halfband decimation filter for data sampled at 44.1 kHz. The output data rate is 1/2 the input sampling rate, or 22.05 kHz. Specify the filter order to be 52 with a transition width of 4.1 kHz.

Fs = 44.1e3; filterspec = 'Filter order and transition width'; Order = 52; TW = 4.1e3; firhalfbanddecim = dsp.FIRHalfbandDecimator(... 'Specification',filterspec, ... 'FilterOrder',Order, ... 'TransitionWidth',TW, ... 'SampleRate',Fs);

Plot the impulse response. The zeroth-order coefficient is delayed 26 samples, which is equal to the group delay of the filter. This yields a causal halfband filter.

fvtool(firhalfbanddecim,... 'Analysis','impulse')

Plot the magnitude and phase response.

fvtool(firhalfbanddecim,... 'Analysis','freq')

### Extract Low Frequency Subband From Speech

Use a halfband analysis filter bank and interpolation filter to extract the low frequency subband from a speech signal.

**Note**: If you are using R2016a or an earlier release, replace each call to the object with the equivalent `step `

syntax. For example, `obj(x) `

becomes `step(obj,x)`

.

**Note:** The `audioDeviceWriter`

System object™ is not supported in MATLAB Online.

Set up the audio file reader, the analysis filter bank, audio device writer, and interpolation filter. The sampling rate of the audio data is 22050 Hz. The order of the halfband filter is 52, with a transition width of 2 kHz.

afr = dsp.AudioFileReader(... 'speech_dft.mp3',... 'SamplesPerFrame',1024); filtSpec = 'Filter order and transition width'; Order = 52; TW = 2000; firhalfbanddecim = dsp.FIRHalfbandDecimator(... 'Specification',filtSpec,... 'FilterOrder',Order,... 'TransitionWidth',TW,... 'SampleRate',afr.SampleRate); firhalfbandinterp = dsp.FIRHalfbandInterpolator(... 'Specification',filtSpec,... 'FilterOrder',Order,... 'TransitionWidth',TW,... 'SampleRate',afr.SampleRate/2); adw = audioDeviceWriter('SampleRate',... afr.SampleRate);

View the magnitude response of the halfband filter.

fvtool(firhalfbanddecim)

Read the speech signal from the audio file in frames of 1024 samples. Filter the speech signal into lowpass and highpass subbands with a halfband frequency of 5512.5 Hz. Reconstruct a lowpass approximation of the speech signal by interpolating the lowpass subband. Play the filtered output.

while ~isDone(afr) audioframe = afr(); xlo = firhalfbanddecim(audioframe); ylow = firhalfbandinterp(xlo); adw(ylow); end

Wait until the audio file is played to the end, then close the input file and release the audio output resource.

release(afr); release(adw);

### Two-Channel Filter Bank

Use a halfband decimator and interpolator to implement a two-channel filter bank. This example uses an audio file input and shows that the power spectrum of the filter bank output does not differ significantly from the input.

**Note**: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).

**Note**: The `audioDeviceWriter`

System object™ is not supported in MATLAB Online.

Set up the audio file reader and device writer. Construct the FIR halfband decimator and interpolator. Finally, set up the spectrum analyzer to display the power spectra of the filter-bank input and output.

AF = dsp.AudioFileReader('speech_dft.mp3','SamplesPerFrame',1024); AP = audioDeviceWriter('SampleRate',AF.SampleRate); filterspec = 'Filter order and transition width'; Order = 52; TW = 2000; firhalfbanddecim = dsp.FIRHalfbandDecimator(... 'Specification',filterspec,'FilterOrder',Order,... 'TransitionWidth',TW,'SampleRate',AF.SampleRate); firhalfbandinterp = dsp.FIRHalfbandInterpolator(... 'Specification',filterspec,'FilterOrder',Order,... 'TransitionWidth',TW,'SampleRate',AF.SampleRate/2,... 'FilterBankInputPort',true); SpecAna = dsp.SpectrumAnalyzer('SampleRate',AF.SampleRate,... 'PlotAsTwoSidedSpectrum',false,'ReducePlotRate',false,... 'ShowLegend',true,... 'ChannelNames',{'Input signal','Filtered output signal'});

Read the audio 1024 samples at a time. Filter the input to obtain the lowpass and highpass subband signals decimated by a factor of two. This is the analysis filter bank. Use the halfband interpolator as the synthesis filter bank. Display the running power spectrum of the audio input and the output of the synthesis filter bank. Play the output.

while ~isDone(AF) audioInput = AF(); [xlo,xhigh] = firhalfbanddecim(audioInput); audioOutput = firhalfbandinterp(xlo,xhigh); spectrumInput = [audioInput audioOutput]; SpecAna(spectrumInput); AP(audioOutput); end release(AF); release(AP); release(SpecAna);

### Filter Input into Lowpass and Highpass Subbands Using FIR Halfband Decimator

Create a halfband decimator for data sampled at 44.1 kHz. Use a minimum-order design with a transition width of 2 kHz and a stopband attenuation of 60 dB.

hfirhalfbanddecim = dsp.FIRHalfbandDecimator(... 'Specification',... 'Transition width and stopband attenuation',... 'TransitionWidth',2000,... 'StopbandAttenuation',60,... 'SampleRate',44.1e3);

Filter a two-channel input into low and highpass subbands.

x = randn(1024,2); [ylow,yhigh] = hfirhalfbanddecim(x);

## More About

### Halfband Filters

The ideal lowpass halfband filter is given by

$$h(n)=\frac{1}{2\pi}{\displaystyle {\int}_{-\pi /2}^{\pi /2}{e}^{j\omega n}}d\omega =\frac{\mathrm{sin}({\scriptscriptstyle \frac{\pi}{2}}n)}{\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(n)=\frac{1}{2\pi}{\displaystyle {\int}_{-\pi}^{-\pi /2}{e}^{j\omega n}}d\omega +\frac{1}{2\pi}{\displaystyle {\int}_{\pi /2}^{\pi}{e}^{j\omega n}}d\omega .$$

Evaluating the preceding integral gives the following impulse response

$$g(n)=\frac{\mathrm{sin}(\pi n)}{\pi n}-\frac{\mathrm{sin}({\scriptscriptstyle \frac{\pi}{2}}n)}{\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.

`dsp.FIRHalfbandDecimator`

uses a causal FIR
approximation to the ideal halfband response, which is based on minimizing the $${\ell}^{\infty}$$ norm of the error (minimax). See Algorithms for more details.

## Algorithms

### Halfband Equiripple Design

`dsp.FIRHalfbandDecimator`

uses a minimax FIR
design to design a fullband linear phase filter with the desired specifications. The
fullband filter is upsampled so that the even-indexed samples of the filter are
replaced with zeros. The upsampling of the filter produces a halfband filter.
Finally, the filter tap corresponding to the group delay of the filter in samples is
set equal to 1/2. This yields a causal linear-phase FIR filter approximation to the
ideal halfband filter defined in Halfband Filters. See [1] for a description of this filter design method using the Remez exchange
algorithm.

### Polyphase Implementation with Halfband Filters

`dsp.FIRHalfbandDecimator`

uses an efficient
polyphase implementation for halfband filters when you filter the input signal. The
chief advantage of the polyphase implementation is that you can downsample the
signal prior to filtering. This allows you to filter at the lower sampling
rate.

Splitting a filter’s impulse response, *h(n)*, into two polyphase
components results in an even polyphase component with
*z*-transform

$${H}_{0}(z)={\displaystyle \sum _{n}h}(2n){z}^{-n}.$$

and an odd polyphase component with *z*-transform

$${H}_{1}(z)={\displaystyle \sum _{n}h}(2n+1){z}^{-n}.$$

The *z*-transform of the filter can be written in terms of the
even and odd polyphase components as

$$H(z)={H}_{0}({z}^{2})+{z}^{-1}{H}_{1}({z}^{2}).$$

Graphically, you can represent filtering and input followed by downsampling by two with the following figure

Using the multirate noble identity for downsampling, you can move the downsampling operation before filtering. This allows you to filter at the lower rate.

For a halfband filter, the only nonzero coefficient in the even polyphase
component is the coefficient corresponding to
*z ^{0}*. Implementing the halfband
filter as a causal FIR filter shifts the nonzero coefficient to approximately

*z*where

^{-N/4}*N*is the number of filter taps. This process is illustrated in the following figure.

The top plot shows a halfband filter of order 52. The bottom plot shows the even polyphase component. Both of these filters are noncausal. Delaying the even polyphase component by 13 samples creates a causal FIR filter.

To efficiently implement the halfband decimator, `dsp.FIRHalfbandDecimator`

replaces the delay block and downsampling
operator with a commutator switch. This is illustrated in the following figure where
one polyphase component is replaced by a gain and delay.

The commutator switch takes input samples from a single branch and supplies every other sample to one of the two polyphase components for filtering. This halves the sampling rate of the input signal. Which polyphase component reduces to a simple delay depends on whether the half order of the filter is even or odd. This is because the delay required to make the even polyphase component causal can be odd or even depending on the filter half order. You can see this by inspecting the polyphase components of the following filters.

filterspec = 'Filter order and stopband attenuation' ; halfOrderEven = dsp.FIRHalfbandDecimator('Specification',filterspec,... 'FilterOrder',64,'StopbandAttenuation',80); halfOrderOdd = dsp.FIRHalfbandDecimator('Specification',filterspec,... 'FilterOrder', 54,'StopbandAttenuation',80); polyphase(halfOrderEven) polyphase(halfOrderOdd)

To summarize, `dsp.FIRHalfbandDecimator`

decimates the input prior to filtering and filters the even and odd polyphase components of the input separately with the even and odd polyphase components of the filter.

exploits the fact that one filter polyphase component is a simple delay for a halfband filter.

## References

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

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

See System Objects in MATLAB Code Generation (MATLAB Coder).

This object supports code generation for ARM^{®}
Cortex^{®}-M and ARM
Cortex-A processors.

### Fixed-Point Conversion

Design and simulate fixed-point systems using Fixed-Point Designer™.

## See Also

### Functions

### Objects

`dsp.FIRHalfbandInterpolator`

|`dsp.IIRHalfbandDecimator`

|`dsp.DyadicAnalysisFilterBank`

|`dsp.Channelizer`

### Blocks

**Introduced in R2014b**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)