filterAnalyzer - Analyze filters with Filter Analyzer app - MATLAB (original) (raw)

Analyze filters with Filter Analyzer app

Since R2024a

Description

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

Creation

Syntax

Description

filterAnalyzer([filt](#mw%5F49d3b6b2-893c-41b7-8b84-889c6cba82b5%5Fsep%5Fmw%5F38e3294f-22f9-4688-8a60-27cc447cff7c)1,...,[filt](#mw%5F49d3b6b2-893c-41b7-8b84-889c6cba82b5%5Fsep%5Fmw%5F38e3294f-22f9-4688-8a60-27cc447cff7c)n) plots the responses of the specified filters in the Filter Analyzer app.

filterAnalyzer([filt](#mw%5F49d3b6b2-893c-41b7-8b84-889c6cba82b5%5Fsep%5Fmw%5F38e3294f-22f9-4688-8a60-27cc447cff7c)1,...,[filt](#mw%5F49d3b6b2-893c-41b7-8b84-889c6cba82b5%5Fsep%5Fmw%5F38e3294f-22f9-4688-8a60-27cc447cff7c)n,[Name=Value](#namevaluepairarguments)) specifies additional options using one or more name-value arguments. For example, you can specify filter names, sample rates, or analysis options.

example

filterAnalyzer([filename](#mw%5F65dc93cf-6feb-40da-80c5-bb1e86e38b4f)) opens aFilter Analyzer session stored in the specified MAT filefilename. If Filter Analyzer is already open, this syntax replaces the current app session with the new session.

filterAnalyzer([filename](#mw%5F65dc93cf-6feb-40da-80c5-bb1e86e38b4f),"append") appends the filters stored in the specified MAT file filename to the current Filter Analyzer session. If Filter Analyzer is not open, this syntax is equivalent to the previous syntax.

[[fa](#mw%5F49d3b6b2-893c-41b7-8b84-889c6cba82b5%5Fsep%5Fmw%5F9fe92715-3fe3-4137-b2bd-19087e343162),[dispnums](#mw%5F49d3b6b2-893c-41b7-8b84-889c6cba82b5%5Fsep%5Fmw%5F0008ca2a-6fc6-4f44-85d8-87915e512603)] = filterAnalyzer(___) returns a handle object for the Filter Analyzer and the numbers corresponding to the newly added displays, using any combination of input arguments from previous syntaxes.

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

example

Input Arguments

expand all

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

For more information, see Import Filter on the Filter Analyzer page..

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_L_-row matrices

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

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

Note

Coefficients and Gain

If you have a scaling gain separate from the coefficient values, you can enter it in Filter Analyzer using the Import Filters 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 defined in the Filter Coefficients section.

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

If you specify the coefficient matrices and gain vector as

Filter Analyzer uses the transfer function

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.

If you also have DSP HDL 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 filename, specified as a character vector or string scalar.

Example: 'lowpassdesigns.mat'

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

Data Types: char | string

Name-Value Arguments

expand all

Specify optional pairs of arguments asName1=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") specifies a step response analysis overlaid on an impulse response analysis.

Analysis type, specified as one of these options:

For more information, see Analysis on the Filter Analyzer page.

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

Note

You can also specify analysis options as name-value arguments when callingfilterAnalyzer. 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 vector of strings or a cell array of character vectors. Filter names are the names that identify the different filters in theFilters table of the Filter Analyzer app. If you do not specify this argument:

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: cell | string

Overlaid analysis, specified as a string scalar or character vector.

For more information, see Analysis on the Filter Analyzer page.

Data Types: char | string

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

When you specify SampleRates, the Filters table shows the specified sample rate.

Example: [150 3e3]

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

Since R2025a

Filter legend strings, specified as a vector of strings or a cell array of character vectors.

By default, Filter Analyzer uses the filter names to set the legend strings.

Example: ["LowpassFilter1" "LowpassFilter2"]

Data Types: cell | string

Output Arguments

expand all

Filter Analyzer app handle, returned as a filterAnalyzer object. To obtain fa for the currentFilter Analyzer instance, entergetFilterAnalyzerHandle 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

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.

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.

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.

Alternatively, use the filterAnalysisOptions object and the 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.

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.

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

expand all

The filterAnalyzer function supports setting legend strings and sample rates.