SignalProcessing
FilterFrequencyResponse
determine the response of an FIR or IIR digital filter from taps
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
FilterFrequencyResponse( A, options )
FilterFrequencyResponse( A, B, options )
A
-
1-D rtable or list of numeric values for the coefficients of the numerator of the transfer function.
B
(optional) 1-D rtable or list of numeric values for the coefficients of the denominator of the transfer function. The default is NULL.
fftnormalization: (optional) One of none, symmetric, or full, indicates the normalization to be applied when using the Fast Fourier Transform (FFT). The default is symmetric.
magnitudeplotoptions: (optional) Additional plot options to be passed when creating the plot of the magnitudes. The default is [].
phaseplotoptions: (optional) Additional plot options to be passed when creating the plot of the phases. The default is [].
phaseunit: (optional) Specifies the unit of angle for the phases. The default is Unit(degrees). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of angle.
samplerate: (optional) Positive numeric value for the sampling rate. The default is NULL.
size: (optional) Positive integer larger than 1, which specifies the computed size of the response, magnitudes, and phases Vectors. The default is the smallest power of 2 that is greater than or equal to all of 512, numelems(A), and (if passed) numelems(B).
output: (optional) The type of output. The supported options are:
frequencies: Returns a Vector, of float[8] datatype and length size, containing the frequencies.
magnitudes: Returns a Vector of float[8] datatype and length size containing the magnitudes.
phases: Returns a Vector of float[8] datatype and length size containing the phases.
response: Returns a Vector of complex[8] datatype and length size containing the response. This is the default.
magnitudeplot: Returns a plot of the magnitudes versus the frequencies.
phaseplot: Returns a plot of the phases versus the frequencies.
record: Returns a record with the previous options.
list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order.
The FilterFrequencyResponse command computes the frequency response of the transfer function indicated by the taps stored in one or two rtables/lists of 1-D data.
The A container stores the coefficients of the numerator of the transfer function and, if passed, B stores the coefficients of the denominator. Each of the containers must contain one or more elements.
For the IIR (Infinite Impulse Response) case, the impulse transfer function in terms of the taps is given by the following:
H⁡z=∑k=1m⁡Ak⁢zk−1∑k=1n⁡Bk⁢zk−1
where m=numelems⁡A and n=numelems⁡B. For the FIR (Finite Impulse Response) case:
H⁡z=∑k=1m⁡Ak⁢zk−1
Internally, the taps containers are padded with sufficiently many zeros, if necessary, so that the response will be of length size.
When only numerator taps are passed (FIR case), the response is the Fast Fourier Transform (FFT) of the padded taps container. When denominator taps are also passed (IIR case), the response is the element-wise quotient of the FFTs of the respective padded taps containers. When the taps are all real-valued, the padded length will be 2*size, and then the redundant (due to symmetry) second half of any FFT will be discarded. On the other hand, when one or more taps is complex, the padded length will be just size, and no terms will be discarded.
The magnitudes are first computed as the element-wise absolute values of the response. Then, they are converted to decibels via the transformation ρ↦10⋅log10⁡ρ for the complex case, and ρ↦20⋅log10⁡ρ for the real-case (the extra factor of 2 is due to the symmetry and discarding of the second half of the FFTs).
The phases are first computed as the element-wise angles/arguments of the response. Then, they are "unwrapped" to eliminate big jumps in the phases, and finally, if phaseunit=degrees, converted to angles (a common convention).
When samplerate=NULL, the frequencies Vector F is of size n=size and "normalized", with components defined by the following:
Fk=k−1n
When r=samplerate is not NULL, on the other hand:
Fk=k−1⁢rn
The samplerate option can include a unit, which will be included in the plots. Either of the forms algebraic or Unit(algebraic) is accepted, but the unit must be convertible to a valid unit of frequency.
Maple will attempt to coerce the provided taps to Vectors of complex[8] datatype, and an error will be thrown if this is not possible. For this reason, it is most efficient for the passed taps to use this datatype.
Input rtables cannot have an indexing function, and must use rectangular storage.
The FilterFrequencyResponse command is not thread safe.
with⁡SignalProcessing:
Simple Examples
FilterFrequencyResponse⁡5,−3,7,1,10,size=8
5.+0.⁢I1.89019807578427−3.68139417593046⁢I−1.95710678118655−1.39644660940673⁢I−0.505419324478097+2.05114364039828⁢I2.+I0.530545590325181−0.473982625448804⁢I−0.542893218813452+2.10355339059327⁢I3.08467565836865+3.79347955822245⁢I
F,R,M,P≔FilterFrequencyResponse⁡1,2−3⁢I,4,5,6−7⁢I,samplerate=2.5,size=4,output=frequencies,response,magnitudes,phases
F,R,M,P≔0.0.6250000000000001.250000000000001.87500000000000,0.576470588235294+0.0941176470588235⁢I0.600000000000000−0.800000000000000⁢I0.360000000000000−0.480000000000000⁢I0.0666666666666667+0.133333333333333⁢I,−2.335104639076680.−2.21848749616356−8.26606256887672,9.27260177720030−53.1301023541560−53.130102354156063.4349488229220
Real FIR Filter
First, generate some FIR taps using the GenerateFIRFilterTaps command:
Taps≔GenerateFIRFilterTaps⁡48,0.25,window=Hamming,normalize=false,filtertype=lowpass
Taps≔−0.000766226652048602−0.0008413391496714700.001008607404047670.00127911948879349−0.00166460722830032−0.002177698278995560.002832285591326240.00364406190199566−0.00463129091647615−0.005815925810116530.007225250693016810.00889433259851163−0.0108697711579715−0.01321560393683070.01602294765573570.0194264426666097−0.0236338399613289−0.02898287244730020.03606012258515080.0459783098573302−0.0611288196507035−0.08774012691350400.1486695910602470.4496957394879000.4496957394879000.148669591060247−0.0877401269135040−0.06112881965070350.04597830985733020.0360601225851508−0.0289828724473002−0.02363383996132890.01942644266660970.0160229476557357−0.0132156039368307−0.01086977115797150.008894332598511630.00722525069301681−0.00581592581011653−0.004631290916476150.003644061901995660.00283228559132624−0.00217769827899556−0.001664607228300320.001279119488793490.00100860740404767−0.000841339149671470−0.000766226652048602
Now, display plots of the magnitude and phase of the response:
num_points≔1024
R≔FilterFrequencyResponse⁡Taps,size=num_points,output=record:
Rmagnitudeplot
Rphaseplot
IIR Filter
Here, we will obtain taps for a lowpass digital Chebyshev Type I Filter from the GenerateChebyshev1Taps command:
cutoff_frequency_ratio≔0.4
filter_order≔5
ripple≔29
Taps≔GenerateChebyshev1Taps⁡filter_order,cutoff_frequency_ratio,ripple,filtertype=lowpass
Taps≔0.01452562229512240.07262811147561200.1452562229512240.1452562229512240.07262811147561200.01452562229512241.1.677643285741721.12542851668154−0.885659875792074−1.51371985423053−0.938872158956746
The first half of the Taps Vector are for the numerator, and the second half are for the denominator:
A,B≔ListTools:-Slice⁡Taps,2
A,B≔0.01452562229512240.07262811147561200.1452562229512240.1452562229512240.07262811147561200.0145256222951224,1.1.677643285741721.12542851668154−0.885659875792074−1.51371985423053−0.938872158956746
Now, we plot the magnitudes and phases of the response:
R≔FilterFrequencyResponse⁡A,B,samplerate=5.0⁢Unit⁡Hz,size=num_points,output=record:
Complex FIR Filter
n≔25
Taps≔Vector⁡n,k↦k+I⋅−1k,datatype=complex8
num_points≔2048
R≔FilterFrequencyResponse⁡Taps,samplerate=2.0,size=num_points,phaseunit=radians,output=record:
The SignalProcessing[FilterFrequencyResponse] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
ListTools[Slice]
SignalProcessing[FFT]
SignalProcessing[GenerateChebyshev1Taps]
SignalProcessing[GenerateFIRFilterTaps]
SignalProcessing[Magnitude]
SignalProcessing[Phase]
Download Help Document