Frequency response estimate via filtering
[h,w] = freqrespest(H,L)
[h,w] = freqrespest(H,L,param1,value1,param2,value2,...)
[h,w] = freqrespest(H,L,opts)
freqrespest(H,...)
[h,w] = freqrespest(H,L)
estimates
the frequency response of a dfilt
object
or a filter System object™. A set of input data is filtered and
then forming the ratio between output data and input data. The test
input data comprises sinusoids with uniformly distributed random frequencies.
Use this technique for comparing the performance of fixedpoint filters to that of another filter type. You can, for example, compare fixed—point frequency response estimate to that of a similar filter that uses quantized coefficients, but applies floatingpoint arithmetic internally. Such comparison determines whether the fixedpoint filter performance closely matches the floatingpoint, quantized coefficients version of the filter.
L
is the number of trials to use to compute
the estimate. If you do not specify this value, L
defaults
to 10. More trials generates a more accurate estimate of the response,
but require more time to compute the estimate.
h
is the estimate of the complex frequency
response. w
contains the vector of frequencies
at which h
is estimated.
[h,w] = freqrespest(H,L,param1,value1,param2,value2,...)
accepts H
as
either a dfilt
object or a filter System object.
This approach uses parameter value (PV) pairs as input arguments to
specify optional parameters for the test. These parameters are the
valid PV pairs. Enter the parameter names as input arguments in single
quotation marks. The following table provides valid parameters for [h,
w]
.
Parameter Name  Default Value  Description 


 Number of FFT points to use. 

 Indicate whether to use normalized frequency or linear
frequency. Values are 

 Specify the sampling frequency when 

 Specify the spectrum range to be used as 

 Specify whether to set the center of the spectrum to
the DC value in the output plot. If you select 
Arithmetic (only for filter System objects)  ARITH  Analyze the filter System object, based on the arithmetic
specified in the ARITH input. ARITH can
be set to double , single , or fixed .
The analysis tool assumes a doubleprecision filter when the arithmetic
input is not specified and the filter System object is in an unlocked
state. 
If H
is a filter System object, freqrespest
requires
knowledge of the input data type. Analysis cannot be performed if
the input data type is not available. If you do not specify the Arithmetic
parameter,
i.e., use the syntax [h,w] = freqrespest(H)
, then
the following rules apply for this method:
The System object state is Unlocked
— freqrespest
performs
double precision analysis.
The System object state is Locked
— freqrespest
performs
analysis based on the locked input data type.
When you do specify the Arithmetic
parameter,
i.e., use the syntax [h,w] = freqrespest(H,'Arithmetic',
ARITH)
, review the following rules for this method. Which
rule applies depends on the value you set for the Arithmetic
parameter.
Value  System Object State  Rule 

ARITH = 'double'  Unlocked  freqrespest performs doubleprecision analysis. 
Locked  freqrespest performs doubleprecision analysis.  
ARITH = ‘single'  Unlocked  freqrespest performs singleprecision analysis. 
Locked  freqrespest performs singleprecision analysis.  
ARITH = ‘fixed'  Unlocked  freqrespest produces an error because the
fixedpoint input data type is unknown. 
Locked  If the input data type is double or single, then freqrespest produces
an error because the fixedpoint input data type is unknown.  
When the input data is of fixedpoint type, freqrespest performs
analysis based on the locked input data type. 
The following Filter System objects are supported by this analysis function:
Regardless of whether H
is a dfilt
object or a filter System object, [h,w] = freqrespest(H,L,opts)
uses an object, opts
,
to specify the optional input parameters. This specification is not
done directly by specifying PV pairs as input arguments. Create opts
with
opts = freqrespopts(H);
Because opts
is an object, you use set
to change the parameter values in opts
before
you use it with freqrespest
. For example, you could
specify a new sample rate with
set(opts,'fs',48e3); % Same as opts.fs=48e3
Regardless of whether H
is a dfilt
object or a filter System object, freqrespest(H,...)
with no output argument
launches FVTool.
freqrespest
can also compute the frequency
response of doubleprecision floating filters. Such filters cannot
be converted to transferfunction form without introducing significant
round off errors which affect the freqz
frequency
response computation. Examples of these kinds of filters include statespace
or lattice filters, especially if they are highorder filters.
These examples demonstrate some uses for freqrespest
.
Example 1
Start by estimating the frequency response of a fixedpoint
FIR filter that has filter internals set to full precision
.
hd = design(fdesign.lowpass(.4,.5,1,60),'equiripple'); hd.arithmetic = 'fixed'; [h,w] = freqrespest(hd); % This should be about the same as freqz.
Continuing with filter hd
, change the value
of the filterinternals
property to specifyprecision
and
then specify the word lengths and precision (the fraction lengths)
applied to the output from internal addition and multiplication operations.
After you set the word and fraction lengths, use freqrespest
to
compute the frequency response estimate for the fixedpoint filter.
hd.filterinternals = 'specifyprecision'; hd.outputwordlength=16; hd.outputfraclength=15; hd.productwordlength=16; hd.productfraclength=15; hd.accumwordlength=16; hd.accumfraclength=15; [h,w] = freqrespest(hd,2); [h2,w2] = freqz(hd,512); plot(w/pi,20*log10(abs([h,h2]))) legend('Frequency response estimated by filtering',... 'Freq. response computed by quantizing coefficients only'); xlabel('Normalized Frequency (\times\pi rad/sample)') ylabel('Magnitude (dB)')
Example 2
freqrespest
works with statespace filters
as well. This example estimates the frequency response of a statespace
filter.
fs = 315000; wp = [320 3800]/(fs/2); ws = [50 19000]/(fs/2); rp=0.15; rs=60; [n,wn]=cheb1ord(wp,ws,rp,rs); [a,b,c,d] = cheby1(n,rp,wn); hd = dfilt.statespace(a,b,c,d); % Compare the following to freqz(hd,8192) freqrespest(hd,1,'nfft',8192);
dfilt
 freqrespopts
 freqz
 limitcycle
 noisepsd
 scale