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.
- 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([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.
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.
Input Arguments
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.
- If L = 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 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 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
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
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:
- 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 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:
- If filters have been specified as numerator and denominator coefficients,Filter Analyzer uses
num_den
as filter names, wherenum
is the variable that specifies the numerator coefficients of a filter andden
is the variable that specifies the corresponding denominator coefficients. - If filters have been specified as cell arrays or objects, Filter Analyzer uses the variables that specify each cell array or object as filter names.
- Otherwise, Filter Analyzer uses names consisting of
Filter_
n
, where_n
_ is a number representing the order in which that filter was added to the Filters table: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: cell
| string
Overlaid analysis, specified as a string scalar or character vector.
- If you set
Analysis
to a frequency-domain analysis, thenOverlayAnalysis
must be also a frequency-domain analysis. - If you set
Analysis
to a time-domain analysis, thenOverlayAnalysis
must be also a time-domain analysis. Analysis
andOverlayAnalysis
must be set to different values.- This argument is not supported if you set
Analysis
to"polezero"
,"info"
, or"coefficients"
.
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.
- If you specify
SampleRates
as a scalar, the value you specify applies to all filters. - If you specify
SampleRates
as a vector, the vector must have the same number of elements as the number of filters.
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.
- If you specify
LegendStrings
, Filter Analyzer appends strings to the default legend strings for all the filters being added. - If you do not specify this argument, Filter Analyzer does not append strings to the default legend strings.
Example: ["LowpassFilter1" "LowpassFilter2"]
Data Types: cell
| string
Output Arguments
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
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. Select
bb
as the Numerator andaa
as the Denominator. SpecifyEllip
for the Filter Name, and leave the Sample Rate asNormalized
. 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
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.
- 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 clear 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
The filterAnalyzer
function supports setting legend strings and sample rates.
- The
LegendStrings
name-value argument enables you to append strings to the default legend strings for all the filters added to Filter Analyzer. - You can specify a sample rate in the
SampleRates
name-value argument even if one or more filters are objects with a sample rate.