Main Content

filterAnalyzer

Analyze filters with the Filter Analyzer app

Since R2024a

Description

The filterAnalyzer object analyzes responses of input filters using the Filter Analyzer app.

Creation

Description

filterAnalyzer opens the Filter Analyzer app.

example

filterAnalyzer(filt1,...,filtn) plots the responses of the specified filters in the Filter Analyzer app.

  • If Filter Analyzer is not open, this syntax opens the app and plots the responses.

  • If Filter Analyzer is open, this syntax plots the responses in a new display in the app.

filterAnalyzer(filt1,...,filtn,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify filter names, sample rates, or analysis options.

filterAnalyzer(filename) opens a Filter Analyzer session stored in the MAT-file called filename. If Filter Analyzer is already open, this syntax replaces the current app session with the new session.

filterAnalyzer(filename,"append") appends the filters stored in the MAT-file called filename to the current Filter Analyzer session. If Filter Analyzer is not open, this syntax is equivalent to the previous syntax.

[fa,dispnums] = filterAnalyzer(___) returns a handle object for the Filter Analyzer and the numbers corresponding to the newly added displays.

You can also obtain the handle fa by typing fa = getFilterAnalyzerHandle at the command line.

Input Arguments

expand all

Input filter, specified as coefficient matrices, a cell array, a digitalFilter object, or a filter System 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.

Example: hd = design(fdesign.lowpass,"butter",SystemObject=true) specifies a lowpass Butterworth filter System object.

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.

Filter System Objects

If you have DSP System Toolbox™, you can use Filter Analyzer to analyze these filter System objects.

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

Session file name, specified as a character vector or string scalar.

Example: 'lowpassdesigns.mat'

Example: "C:\MyFolder\myfilters.mat"

Data Types: char | string

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: filterAnalyzer(Analysis="impulse",OverlayAnalysis="step")

Analysis type, specified as one of these:

  • Frequency-domain analyses:

    • "magnitude" — Magnitude response

    • "phase" — Phase response

    • "groupdelay" — Group delay response

    • "phasedelay" — Phase delay response

    • "magestimate" — Magnitude response estimate

    • "noisepsd" — Noise power spectral density (PSD)

  • Time-domain analyses:

    • "impulse" — Impulse response

    • "step" — Step response

  • Other analyses:

    • "polezero" — Pole-zero plot

    • "info" — Filter information

    • "coefficients" — Filter coefficients

For more information, see Analysis.

Analysis options, specified as a filterAnalysisOptions object. For more information about available options, see filterAnalysisOptions.

Note

You can also specify analysis options as name-value arguments when calling filterAnalyzer. However, you cannot mix formats.

Example: filterAnalysisOptions("phase") specifies that the display show filter phase responses.

Arithmetic type of filter System objects, specified as one of "double", "single", or "fixed". If you do not specify this argument, and the filter System objects are in an unlocked state, Filter Analyzer assumes the filters are double precision.

Data Types: char | string

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

Overlaid analysis, specified as a string.

  • If Analysis is set to a frequency-domain analysis, then OverlayAnalysis must be also a frequency-domain analysis.

  • If Analysis is set to a time-domain analysis, then OverlayAnalysis must be also a time-domain analysis.

  • Analysis and OverlayAnalysis must be set to different values.

  • This argument is not supported if Analysis is set to "polezero", "info", or "coefficients".

For more information, see Analysis.

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

expand all

Filter Analyzer app handle, returned as a filterAnalyzer object. To obtain fa for the current Filter Analyzer instance, enter getFilterAnalyzerHandle in the command line.

Identification numbers of newly added displays, returned as an integer or a vector of integers. If no displays are added, this argument is an empty array.

Object Functions

addDisplaysAdd new analysis displays to Filter Analyzer app
addFiltersAdd new filters to Filter Analyzer app
clearLegendStringsClear alternative legend strings for filters in Filter Analyzer app
closeClose the Filter Analyzer app
deleteDisplaysDelete displays from Filter Analyzer app
deleteFiltersDelete filters from Filter Analyzer app
duplicateDisplaysDuplicate displays in Filter Analyzer app
getAnalysisOptionsGet analysis options of displays in Filter Analyzer app
newSessionClear Filter Analyzer app session and start a new one
renameFiltersUpdate filter names in Filter Analyzer app
replaceFiltersReplace existing filters with new filters in Filter Analyzer app
saveSessionSave Filter Analyzer app session
setAnalysisOptionsSet analysis options of displays in Filter Analyzer app
setLegendStringsDefine alternative legend strings for filters in Filter Analyzer app
showFiltersShow filters in Filter Analyzer app
showLegendToggle display legends in Filter Analyzer app
showSpecificationMaskToggle filter specification mask of displays in Filter Analyzer app
showUserDefinedMaskSpecify and toggle user-defined spectral mask in Filter Analyzer app displays
zoomZoom into region of interest in Filter Analyzer app displays

Examples

collapse all

Design two filters. Analyze their magnitude and phase responses using the Filter Analyzer app.

d1 = designfilt("lowpassfir", ...
    PassbandFrequency=0.45,StopbandFrequency=0.55);
d2 = designfilt("highpassfir", ...
    StopbandFrequency=0.35,PassbandFrequency=0.45);

filterAnalyzer(d1,d2,FilterNames=["LP" "HP"], ...
    Analysis="magnitude",OverlayAnalysis="phase")

Design a tenth-order elliptic bandpass filter with 5 dB of passband ripple and 60 dB of stopband attenuation. Specify passband edge frequencies of 0.2π rad/sample and 0.45π rad/sample. Express the design as a cascade of fourth-order transfer functions.

[z,p,k] = ellip(5,5,60,[0.2 0.45]);
[bb,aa] = zp2ctf(z,p,k,SectionOrder=4);

Design a finite impulse response bandpass filter with 5 dB of passband ripple and asymmetric stopbands for use with signals sampled at 2 kHz.

  • At lower frequencies, the stopband has 80 dB of attenuation and the transition region ranges from 500 Hz to 600 Hz.

  • At higher frequencies, the stopband has 40 dB of attenuation and the transition region ranges from 750 Hz to 900 Hz.

dfir = designfilt("bandpassfir", ...
    SampleRate=2e3,PassbandRipple=5, ...
    StopbandFrequency1=500,PassbandFrequency1=600, ...
    StopbandAttenuation1=80, ...
    PassbandFrequency2=750,StopbandFrequency2=900, ...
    StopbandAttenuation2=40);

Start a Filter Analyzer session to analyze the filters. Import the filters. On the Analyzer tab, click Import Filter.

  • To import the elliptic filter, select Filter Coefficients. Enter bb as the Numerator and aa as the Denominator. Choose Ellip for the Filter Name and leave the Sample Rate as Normalized. Click Import.

  • To import the FIR filter, select Filter Objects, select dfir, and click Import and Close.

Alternatively, open Filter Analyzer by using the command-line interface. By default, the app displays magnitude responses. Only one of the filters has a sample rate, so the app displays the responses using normalized frequencies.

fa = filterAnalyzer(bb,aa,dfir,FilterNames=["ellip" "dfir"]);

Add a display and use it to plot the magnitude responses and the phase responses of the filters.

  • On the Analyzer tab, click New Display.

  • Expand the Analysis gallery so the Overlay Analysis section is visible and click Phase.

  • Add the filters by clicking the eye icons on the Filters table.

Alternatively, use the filterAnalysisOptions, addDisplays, and showFilters functions.

opts = filterAnalysisOptions(OverlayAnalysis="phase");
addDisplays(fa,AnalysisOptions=opts)
showFilters(fa,true,FilterNames=["ellip" "dfir"])

Add another display and show the cumulative magnitude responses of the cascaded transfer functions that specify the elliptic filter.

  • Click New Display to add the display and click the eye icon for the elliptic filter.

  • On the Display Options tab, click CTF View ▼ and select Cumulative.

Alternatively, use the command-line interface.

addDisplays(fa,CTFAnalysisMode="cumulative")

showFilters(fa,true,FilterNames="ellip")

Add one more display and show the filter specification mask for the FIR filter.

  • On the Analyzer tab, click New Display and click the eye icon for the FIR filter. The app displays the frequencies in units of Hz.

  • For a digitalFilter object, the app shows the specification mask by default. To remove the mask, on the Display Options tab, click Mask ▼ and deselect Specification.

Alternatively, use the command-line interface.

addDisplays(fa)

showFilters(fa,true,FilterNames="dfir")

Create two lowpass halfband decimation filters. The design method in the first filter is set to "Equiripple" and in the second filter is set to "Kaiser".

Specify the filter order to be 52. Specify the transition width in normalized frequency units.

filterspec = "Filter order and transition width";
Order = 52;
TW = 0.1859;
firhalfbanddecimEqui = dsp.FIRHalfbandDecimator(...
    NormalizedFrequency=true,...
    Specification=filterspec,...
    FilterOrder=Order,...
    TransitionWidth=TW,...
    DesignMethod="Equiripple");
firhalfbanddecimKaiser = dsp.FIRHalfbandDecimator(...
    NormalizedFrequency=true,......
    Specification=filterspec,...
    FilterOrder=Order,...
    TransitionWidth=TW,...
    DesignMethod="Kaiser");

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

hfvt = filterAnalyzer(firhalfbanddecimEqui,firhalfbanddecimKaiser,...
    Analysis="impulse");
setLegendStrings(hfvt,["Equiripple","Kaiser"])

Plot the magnitude and phase response.

If the filter specifications are tight, say a very high filter order with a very narrow transition width, the filter designed using the "Kaiser" method converges more effectively.

hvftMag = filterAnalyzer(firhalfbanddecimEqui,firhalfbanddecimKaiser,...
    Analysis="magnitude");

setLegendStrings(hvftMag,["Equiripple","Kaiser"])
hvftPhase = filterAnalyzer(firhalfbanddecimEqui,firhalfbanddecimKaiser,...
    Analysis="phase");

setLegendStrings(hvftPhase,["Equiripple","Kaiser"])

Version History

Introduced in R2024a