# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# dsp.FIRHalfbandDecimator System object

Halfband decimator

## Description

`dsp.FIRHalfbandDecimator` 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. This object supports fixed-point operations and ARM Cortex code generation.

To filter and downsample your data:

1. Define and set up your halfband decimator. See Construction.

2. Call `step` to filter the input signal according to the properties of `dsp.FIRHalfbandDecimator`. The input signal can be a real- or complex-valued column vector or 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.

### Note

Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`firhalfbanddecim = dsp.FIRHalfbandDecimator` returns a halfband decimator, `firhalfbanddecim`, with the default settings. Calling `step` with the default property settings 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.

`firhalfbanddecim = dsp.FIRHalfbandDecimator(Name,Value)` returns a halfband decimator, with additional properties specified by one or more `Name,Value` pair arguments. `Name` is the property name and `Value` is the corresponding value. `Name` must appear inside single quotes (' '). You can specify several name-value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

## Properties

expand all

Filter design parameters, specified as a character vector. Valid options are `'Transition width and stopband attenuation'` (default), ```'Filter order and stopband attenuation'```, or ```'Filter order and transition width'```. The filter design has only two degrees of freedom so you can only specify two of the following: filter order, transition width, or stopband attenuation. Setting a filter design specification without additionally specifying values for the design parameters results in default values for the specifications.

Filter order, specified as the comma-separated pair of `'FilterOrder'` and an even positive integer. Specifying a filter order is only valid when the value of `'Specification'` is ```'Filter order and stopband attenuation'``` or ```'Filter order and transition width'```.

Stopband attenuation in dB, specified as the comma-separated pair of `'StopbandAttenuation'` and a positive real scalar. Specifying the stopband attenuation is only valid when the value of `'Specification'` is ```'Filter order and stopband attenuation'``` or ```'Transition width and stopband attenuation'```.

Transition width in Hz, specified as the comma-separated pair of `'TransitionWidth'` and a positive real scalar. The value of the transition width in Hz must be less than 1/2 the input sample rate. Specifying the transition width is valid only when the value of `'Specification'` is ```'Transition width and stopband attenuation'``` or ```'Filter order and transition width'```.

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

#### Fixed-Point Properties

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.

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

## Methods

 reset Reset internal states of FIR halfband decimator step Filter input with FIR halfband decimator

For additional methods, see Analysis Methods for Filter System Objects.

For a complete list of analysis methods supported for the `dsp.FIRHalfbandDecimator` object, enter `dsp.FIRHalfbandDecimator.helpFilterAnalysis` at the MATLAB® command prompt.

Common to All System Objects
`clone`

Create System object with same property values

`getNumInputs`

Expected number of inputs to a System object

`getNumOutputs`

Expected number of outputs of a System object

`isLocked`

Check locked states of a System object (logical)

`release`

Allow System object property value changes

## Examples

expand all

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') ```

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

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

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); filterspec = 'Filter order and transition width'; Order = 52; TW = 2000; firhalfbanddecim = dsp.FIRHalfbandDecimator(... 'Specification',filterspec,'FilterOrder',Order,... 'TransitionWidth',TW,'SampleRate',afr.SampleRate); firhalfbandinterp = dsp.FIRHalfbandInterpolator(... 'Specification',filterspec,'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); ```

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: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

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); ```

expand all

expand all

## References

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