Main Content

How to Filter Data at the Command Line

Simple Passband Filter

Use idfilt to apply passband and other custom filters to a time-domain or a frequency-domain iddata object.

In general, you can specify any custom filter. Use this syntax to filter an iddata object data using the filter called filter:

fdata = idfilt(data,filter)

In the simplest case, you can specify a passband filter for time-domain data using the following syntax:

fdata = idfilt(data,[wl wh])

In this case, w1 and wh represent the low and high frequencies of the passband, respectively.

You can specify several passbands, as follows:

filter=[[w1l,w1h];[ w2l,w2h]; ....;[wnl,wnh]]

The filter is an n-by-2 matrix, where each row defines a passband in radians per second.

To define a stopband between ws1 and ws2, use

filter = [0 ws1; ws2 Nyqf]

where, Nyqf is the Nyquist frequency.

For time-domain data, the passband filtering is cascaded Butterworth filters of specified order. The default filter order is 5. The Butterworth filter is the same as butter in the Signal Processing Toolbox™ product. For frequency-domain data, select the indicated portions of the data to perform passband filtering.

Defining a Custom Filter

Use idfilt to apply passband and other custom filters to a time-domain or a frequency-domain iddata object.

In general, you can specify any custom filter. Use this syntax to filter an iddata object data using the filter called filter:

fdata = idfilt(data,filter)

You can define a general single-input/single-output (SISO) system for filtering time-domain or frequency-domain data. For frequency-domain only, you can specify the (nonparametric) frequency response of the filter.

You use this syntax to filter an iddata object data using a custom filter specified by filter:

fdata = idfilt(data,filter)

filter can be also any of the following:

filter = idm
filter = {num,den}
filter = {A,B,C,D}

idm is a SISO identified linear model or LTI object. For more information about LTI objects, see the Control System Toolbox™ documentation.

{num,den} defines the filter as a transfer function as a cell array of numerator and denominator filter coefficients.

{A,B,C,D} is a cell array of SISO state-space matrices.

Specifically for frequency-domain data, you specify the frequency response of the filter:

filter = Wf

Here, Wf is a vector of real or complex values that define the filter frequency response, where the inputs and outputs of data at frequency data.Frequency(kf) are multiplied by Wf(kf). Wf is a column vector with the length equal to the number of frequencies in data.

When data contains several experiments, Wf is a cell array with the length equal to the number of experiments in data.

Causal and Noncausal Filters

For time-domain data, the filtering is causal by default. Causal filters typically introduce a phase shift in the results. To use a noncausal zero-phase filter (corresponding to filtfilt in the Signal Processing Toolbox product), specify a third argument in idfilt:

fdata = idfilt(data,filter,'noncausal')

For frequency-domain data, the signals are multiplied by the frequency response of the filter. With the filters defined as passband filters, this calculation gives ideal, zero-phase filtering (“brick wall filters”). Frequencies that have been assigned zero weight by the filter (outside the passband or via frequency response) are removed.

When you apply idfilt to an idfrd data object, the data is first converted to a frequency-domain iddata object (see Transforming Between Frequency-Domain and Frequency-Response Data). The result is an iddata object.

Related Topics