# dsp.VariableBandwidthFIRFilter

Variable bandwidth FIR filter

## Description

The `dsp.VariableBandwidthFIRFilter`

object filters each channel of the
input using FIR filter implementations. It does so while having the capability of tuning the
bandwidth.

To filter each channel of the input:

Create the

`dsp.VariableBandwidthFIRFilter`

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

### Description

returns
a variable bandwidth FIR filter object which independently filters each channel of the
input over successive calls to the object. The filter cutoff frequency can be tuned during
the filtering operation. The variable bandwidth FIR filter is designed using the window
method.`vbw`

= dsp.VariableBandwidthFIRFilter

returns a variable bandwidth FIR filter with additional properties specified by one or
more `vbw`

= dsp.VariableBandwidthFIRFilter(`Name=Value`

)`Name-Value`

pair arguments. `Name`

is the
property name and `Value`

is the corresponding value. For example,
`FilterOrder=50`

sets the filter order to 50.

## 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.

`FilterOrder`

— FIR filter order

`30`

(default) | even positive integer

FIR filter order, specified as an even positive integer. This property is nontunable.

**Data Types: **`double`

| `single`

`FilterType`

— Type of filter response

`'Lowpass'`

(default) | `'Highpass'`

| `'Bandpass'`

| `'Bandstop'`

Type of filter response, specified as one of these options:

`'Lowpass'`

`'Highpass'`

`'Bandpass'`

`'Bandstop'`

`CutoffFrequency`

— Filter cutoff frequency

`512`

(default) | positive scalar

Filter cutoff frequency, specified as a real positive scalar in Hz or in normalized frequency units* (since R2023a)*.

If you set the
`NormalizedFrequency`

property to:

`false`

–– The value of the cutoff frequency is in Hz. The value must be less than half the`SampleRate`

property value.`true`

–– The value of the cutoff frequency is in normalized frequency units. The value must be a positive scalar less than`1.0`

.

* (since R2023a)*

**Tunable: **Yes

#### Dependencies

To enable this property, set `FilterType`

to
`'Lowpass'`

or `'Highpass'`

.

**Data Types: **`double`

| `single`

`Window`

— Window function

`'Hann'`

(default) | `'Hamming'`

| `'Chebyshev'`

| `'Kaiser'`

Window function used to design the FIR filter, specified as one of these options:

`'Hann'`

`'Hamming'`

`'Chebyshev'`

`'Kaiser'`

`KaiserWindowParameter`

— Kaiser window parameter

`0.5`

(default) | real scalar

Kaiser window parameter, specified as a real scalar.

#### Dependencies

To enable this property, set the `Window`

property to
`'Kaiser'`

.

**Data Types: **`double`

| `single`

`CenterFrequency`

— Center frequency of filter

`11025`

(default) | positive scalar

Center frequency of filter, specified as a real positive scalar in Hz or in normalized frequency units* (since R2023a)*.

If you set the
`NormalizedFrequency`

property to:

`false`

–– The value of the center frequency is in Hz. The value must be less than half the`SampleRate`

property value.`true`

–– The value of the center frequency is in normalized frequency units. The value must be a positive scalar less than`1.0`

.

* (since R2023a)*

**Tunable: **Yes

#### Dependencies

To enable this property, set the `FilterType`

property to
`'Bandpass'`

or `'Bandstop'`

.

**Data Types: **`double`

| `single`

`Bandwidth`

— Filter bandwidth

`7680`

(default) | positive scalar

Filter bandwidth, specified as a real positive scalar in Hz or in normalized frequency units* (since R2023a)*.

If you set the
`NormalizedFrequency`

property to:

`false`

–– The value of the filter bandwidth is in Hz. The value must be less than half the`SampleRate`

property value.`true`

–– The value of the filter bandwidth is in normalized frequency units. The value must be a positive scalar less than`1.0`

.

* (since R2023a)*

**Tunable: **Yes

#### Dependencies

To enable this property, set the `FilterType`

property to
`'Bandpass'`

or `'Bandstop'`

.

**Data Types: **`double`

| `single`

`SidelobeAttenuation`

— Chebyshev window sidelobe attenuation

`60`

(default) | positive scalar

Chebyshev window sidelobe attenuation, specified as a real positive scalar in dB.

#### Dependencies

To enable this property, set the `Window`

property to
`'Chebyshev'`

.

**Data Types: **`double`

| `single`

`NormalizedFrequency`

— Flag to set frequencies in normalized units

`false`

(default) | `true`

*Since R2023a*

Flag to set frequencies in normalized units, specified as one of these values:

`true`

–– The filter cutoff frequency, center frequency, and the filter bandwidth must be in the normalized frequency units and less than`1.0`

.`false`

–– The filter cutoff frequency, center frequency, and the filter bandwidth are in Hz. You can specify the input sample rate through the`SampleRate`

property.

**Data Types: **`logical`

`SampleRate`

— Input sample rate

`44100`

(default) | positive scalar

Input sample rate, specified as a positive scalar in Hz.

#### Dependency

To enable this property, set
`NormalizedFrequency`

to `false`

.* (since R2023a)*

**Data Types: **`double`

| `single`

## Usage

### Syntax

### Description

### Input Arguments

`x`

— Data input

vector | matrix

Data input, specified as a vector or a matrix. This object also accepts variable-size inputs. Once the object is locked, you can change the size of each input channel, but you cannot change the number of channels.

**Data Types: **`double`

| `single`

**Complex Number Support: **Yes

### Output Arguments

`y`

— Filtered output

vector | matrix

Filtered output, returned as a vector or a matrix. The size, data type, and complexity of the output signal matches that of the input signal.

**Data Types: **`double`

| `single`

**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.VariableBandwidthFIRFilter`

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

`fvtool` | Visualize frequency response of DSP filters |

`impz` | Impulse response of discrete-time filter System object |

`info` | Information about filter System object |

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

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

`grpdelay` | Group delay response of discrete-time filter System object |

## Examples

### Filtering Through a Variable Bandwidth Bandpass FIR Filter

Tune the center frequency and the bandwidth of the FIR bandpass filter. Filter a sinusoidal signal through this filter.

Define a bandpass variable bandwidth FIR filter. Specify an input sample rate of 44100 Hz. Initialize a `dsp.TransferFunctionEstimator`

object to estimate the transfer function of the filter from the input and output signals. To visualize the transfer function, initialize a `dsp.ArrayPlot`

object.

Fs = 44100; vbw = dsp.VariableBandwidthFIRFilter(FilterType='Bandpass',... FilterOrder=100,... SampleRate=Fs,... CenterFrequency=1e4,... Bandwidth=4e3); tfe = dsp.TransferFunctionEstimator(FrequencyRange='onesided'); aplot = dsp.ArrayPlot(PlotType='Line',... XOffset=0,... YLimits=[-120 5], ... SampleIncrement=44100/1024,... YLabel='Frequency Response (dB)',... XLabel='Frequency (Hz)',... Title='System Transfer Function');

Generate a sine wave signal with a frame length of 1024. Tune the bandwidth and the center frequency of the filter. Pass the signal through this filter. Estimate the transfer function of the filter using the input and the generated output. Plot the system transfer function using an array plot.

FrameLength = 1024; sine = dsp.SineWave(SamplesPerFrame=FrameLength); for i=1:500 % Generate input x = sine() + randn(FrameLength,1); % Pass input through the filter y = vbw(x); % Transfer function estimation h = tfe(x,y); % Plot transfer function aplot(20*log10(abs(h))) % Tune bandwidth and center frequency of the FIR filter if (i==250) vbw.CenterFrequency = 5000; vbw.Bandwidth = 2000; end end

## Algorithms

### FIR Transformations

All transformations assume a lowpass filter of length 2N+1.

**Lowpass to Lowpass**

Consider an ideal lowpass brickwall filter with normalized cutoff frequency
ω_{c1}. By taking the inverse discrete Fourier transform of
the ideal frequency response, and clipping the resulting sequence to length 2N+1,
the impulse response is:

$$\begin{array}{l}forn=0\\ {h}_{LP}(n)=\frac{{\omega}_{c}}{\pi}.w(0)\\ for\text{1}\le \text{|n|}\le \text{N}\\ {h}_{LP}(n)=\frac{\mathrm{sin}({\omega}_{c}n)}{\pi n}.w(n)\end{array}$$

where w(n) is the window vector. Tune the lowpass filter
coefficients to a new cutoff frequency ω_{c2} as follows:

$$\begin{array}{l}for\text{}n=0\\ {h}_{LP}(n)=\frac{{\omega}_{c2}}{\pi}.\omega (0)\\ for\text{}1\text{}\le \text{}\left|n\right|\text{}\le \text{}N\\ {h}_{LP}(n)=\frac{\mathrm{sin}({\omega}_{c2}n)}{\pi n}.\omega (n)\end{array}$$

You do not need to recompute the window every time you tune the cutoff frequency.

**Lowpass to Highpass**

Assuming a lowpass filter with normalized 6-dB cutoff frequency ω_{c}, you
can obtain a highpass filter with the same cutoff frequency by taking the
complementary of the lowpass frequency response:
H_{HP}(e^{jω}) = 1 −
H_{LP}(e^{jω})

Taking the inverse discrete Fourier transform of the above response, you have the following highpass filter coefficients:

$$\begin{array}{l}for\text{}n=0\\ {h}_{hp}(n)=1-{h}_{LP}(n)\\ for\text{}1\le \text{}\left|n\right|\text{}\le \text{}N\\ {h}_{hp}(n)=-{h}_{LP}(n)\end{array}$$

**Lowpass to Bandpass**

Obtain a bandpass filter centered at frequency ω_{0} by shifting the
lowpass response:

H_{BP}(e^{jω}) = H_{LP}(e^{j(ω–ω0})) + H_{LP}(e^{j(ω–ω0)})

The bandwidth of the resulting bandpass filter is 2ω_{c}, as measured between the two cutoff frequencies of the bandpass filter. The equivalent bandpass filter coefficients are then:

$$\begin{array}{l}{h}_{BP}(n)=({e}^{j{\omega}_{0}n}+{e}^{-j{\omega}_{0}n}){h}_{LP}(n)\\ \text{whichcanbewrittenas:}\\ {h}_{BP}(n)=2\mathrm{cos}({\omega}_{0}n){h}_{LP}(n)\end{array}$$

**Lowpass to Bandstop**

You can transform a lowpass filter to a bandstop filter by combining the highpass and bandpass
transformations. First make the filter bandpass by shifting the lowpass response,
and then invert it to get a bandstop response centered at ω_{0}.

H_{BS}(e^{jω}) = 1 – (H_{LP}(e^{j(ω–ω0)}) + H_{LP}(e^{j(ω+ω0)}))

This yields the following coefficients:

$$\begin{array}{l}for\text{}n=0\\ {h}_{BS}(n)=1-2\mathrm{cos}({\omega}_{0}n){h}_{LP}(n)\\ for\text{}1\le \text{}\left|n\right|\text{}\le \text{}N\\ {h}_{BS}(n)=-2\mathrm{cos}({\omega}_{0}n){h}_{LP}(n)\end{array}$$

**Generalized Transformation**

You can combine these transformations to transform a lowpass filter to a lowpass, highpass, bandpass, or bandstop filter with arbitrary cutoffs.

For example, to transform a lowpass filter with cutoff ω_{c1} to a highpass with cutoff ω_{c2}, you first apply the lowpass-to-lowpass transformation to get a lowpass filter with cutoff ω_{c2}, and then apply the lowpass-to-highpass transformation to get the highpass with cutoff ω_{c2}.

To get a bandpass filter with center frequency ω_{0} and bandwidth β, we
first apply the lowpass-to-lowpass transformation to go from a lowpass with cutoff
ω_{c} to a lowpass with cutoff β/2, and then apply the
lowpass-to-bandpass transformation to get the desired bandpass filter. You can use
the same approach for a bandstop filter.

## References

[1] Jarske, P.,Y. Neuvo, and S. K. Mitra, "A simple approach to the design of linear phase FIR digital filters with variable characteristics." Signal Processing. Vol. 14, Issue 4, June 1988, pp. 313-326.

## 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 also supports SIMD code generation using Intel AVX2 technology when the
input signal has a data type of `single`

or
`double`

.

The SIMD technology significantly improves the performance of the generated code.

## Version History

**Introduced in R2014a**

### R2023a: Support for normalized frequencies

When you set the `NormalizedFrequency`

property to
`true`

, you can specify the filter cutoff frequency, center frequency,
and the filter bandwidth in normalized frequency units (0 to 1).

When you set the `NormalizedFrequency`

property to
`true`

while creating the object, the frequency values are automatically
set to normalized frequency units using the default sample rate of 44100 Hz.

vbFIRFilter = dsp.VariableBandwidthFIRFilter(NormalizedFrequency=true)

vbFIRFilter = dsp.VariableBandwidthFIRFilter with properties: FilterOrder: 30 FilterType: 'Lowpass' CutoffFrequency: 0.0232 Window: 'Hann' NormalizedFrequency: true

When you set the `NormalizedFrequency`

property to
`true`

after you create the object, the frequencies must be manually set
to the normalized frequency values before you run the object
algorithm.

vbFIRFilter = dsp.VariableBandwidthFIRFilter

vbFIRFilter = dsp.VariableBandwidthFIRFilter with properties: FilterOrder: 30 FilterType: 'Lowpass' CutoffFrequency: 512 Window: 'Hann' NormalizedFrequency: false SampleRate: 44100

`NormalizedFrequency`

to
`true`

and manually convert the frequency values in Hz to normalized
values using the input sample rate in Hz. For example, if the input sample rate is 44100 Hz,
the corresponding values in normalized units are computed using these equations.vbFIRFilter.NormalizedFrequency = true; vbFIRFilter.CutoffFrequency = 512/(44100/2)

vbFIRFilter = dsp.VariableBandwidthFIRFilter with properties: FilterOrder: 30 FilterType: 'Lowpass' CutoffFrequency: 0.0232 Window: 'Hann' NormalizedFrequency: true

## See Also

### Functions

### Objects

### Blocks

## 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)