Main Content

addFilters

Add new filters to Filter Analyzer app

Since R2024a

Description

example

addFilters(fa,filt1,...,filtn) imports the specified filters to the Filter Analyzer app fa and plots their responses in the active display. If there is no active display, Filter Analyzer adds a new display and plots the filters on it.

addFilters(___,Name=Value) specifies additional options using name-value arguments.

dispnum = addFilters(___) returns the identification number corresponding to a newly added display. If there is already a display, Filter Analyzer returns an empty array.

Examples

collapse all

Design a lowpass filter and show it in the Filter Analyzer app.

d1 = designfilt("lowpassfir", ...
    PassbandFrequency=0.45,StopbandFrequency=0.55);
fa = filterAnalyzer(d1,FilterNames="LP1");

Add another lowpass filter to the display.

d2 = designfilt("lowpassfir", ...
    PassbandFrequency=0.25,StopbandFrequency=0.35);
addFilters(fa,d2,FilterNames="LP2");

Input Arguments

collapse all

Filter Analyzer app handle, specified as a filterAnalyzer object.

Input filter, specified as coefficient matrices, a cell array, or a digitalFilter object.

For more information, see Import Filter.

Example: b = [1 3 3 1]/6 and a = [3 0 1 0]/3 together specify a third-order lowpass Butterworth filter with a normalized 3-dB frequency of 0.5π rad/sample.

Example: sos2ctf([2 4 2 6 0 2; 3 3 0 6 0 0]) specifies a third-order lowpass Butterworth filter with a normalized 3-dB frequency of 0.5π rad/sample.

Example: d = designfilt("lowpassiir",FilterOrder=3,HalfPowerFrequency=0.5) specifies a third-order lowpass Butterworth filter with a normalized 3-dB frequency of 0.5π rad/sample.

Filter Coefficients

You can use Filter Analyzer to analyze filters specified as numerator and denominator coefficients. If you specify the coefficients as the K-row matrices

B=[b11b12b1,m+1b21b22b2,m+1bK1bK2bK,m+1],A=[a11a12a1,n+1a21a22a2,n+1aK1aK2aK,n+1],

Signal Analyzer assumes you have specified the filter as a sequence of K cascaded transfer functions (CTF) such that the full transfer function of the filter is

H(z)=b11+b12z1++b1,m+1zma11+a12z1++a1,n+1zn×b21+b22z1++b2,m+1zma21+a22z1++a2,n+1zn××bK1+bK2z1++bK,m+1zmaK1+aK2z1++aK,n+1zn,

where m ≥ 0 is the numerator order of the filter and n ≥ 0 is the denominator order.

  • If K = 1, then B and A are row vectors that specify the transfer function of an IIR filter.

  • If you specify both B and A as column vectors, Filter Analyzer assumes they represent the transfer function of an IIR filter.

  • If B is a scalar, Filter Analyzer assumes you specified the filter as a cascade of all-pole IIR filters with each section having a scaling gain equal to B.

  • If A is a scalar, Filter Analyzer assumes you specified the filter as a cascade of FIR filters with each section having a scaling gain equal to 1/A.

Note

  • To convert second-order section matrices to cascaded transfer functions, use the sos2ctf function.

  • To convert a zero-pole-gain filter representation to cascaded transfer functions, use the zp2ctf function.

Coefficients and Gain

If you have a scaling gain separate from the coefficient values, you can enter it in Filter Analyzer using the Import Filter dialog box. At the command line, you can specify the coefficients and gain as a cell array of the form {B,A,g}, where B and A are as previously defined.

The gain can be a scalar overall gain or a vector of section gains.

  • If the gain is a scalar, Filter Analyzer applies the value uniformly to all the cascade filter sections.

  • If the gain is a vector, it must have one more element than the number of filter sections in the cascade. Filter Analyzer applies a scale value to each of the filter sections and applies the last value uniformly to all the filter sections.

If you specify the coefficient matrices and gain vector as

B=[b11b12b1,m+1b21b22b2,m+1bK1bK2bK,m+1],A=[a11a12a1,n+1a21a22a2,n+1aK1aK2aK,n+1],g=[g1g2gKg0],

Signal Analyzer uses the transfer function

H(z)=g0(g1b11+b12z1++b1,m+1zma11+a12z1++a1,n+1zn×g2b21+b22z1++b2,m+1zma21+a22z1++a2,n+1zn××gKbK1+bK2z1++bK,m+1zmaK1+aK2z1++aK,n+1zn).

digitalFilter Objects

You can use Filter Analyzer to analyze digitalFilter objects. Use designfilt to generate or edit digital filters based on frequency-response specifications.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | cell
Complex Number Support: Yes

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: FilterNames=["LP" "HP"],SampleRates=[150 3e3]

Displays to plot filters, specified as a vector of display numbers. If you do not specify this argument, Filter Analyzer uses the active display. Use display identification numbers to target displays when using other Filter Analyzer functions. Identification numbers appear above the plotting area of the app, on the tabs that correspond to the different displays.

Example: [1 4]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Filter names, specified as a string vector. Filter names are the names that identify the different filters in the app Filters table. If you do not specify this argument:

  • If filters are specified as numerator and denominator coefficients, Filter Analyzer uses num_den as filter names, where num is the variable that specifies the numerator coefficients of a filter and den is the variable that specifies the corresponding denominator coefficients.

  • If filters are specified as cell arrays or objects, Filter Analyzer uses as filter names the variables that specify each cell array or object.

  • Otherwise, Filter Analyzer uses names consisting of Filter_ plus a number: Filter_1, Filter_2, and so on.

Filter names in Filter Analyzer must be unique. If a name already exists, the app appends a suffix number to the name. The Filters table shows the names that already exist in the app session.

Example: ["LPbutter" "LPelliptic"]

Data Types: char | string

Filter sample rates, specified as a scalar or vector of values specified in Hz.

  • If SampleRates is a scalar, the specified value applies to all filters.

  • If SampleRates is a vector, it must have a number of elements equal to the number of filters.

This argument does not apply if one or more filters are objects with a sample rate.

Example: [150 3e3]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Display identification number. If more than one display is added, dispnum is a vector. If Filter Analyzer uses the current display, dispnum is an empty array.

Version History

Introduced in R2024a