| Filter Design Toolbox™ | ![]() |
[h,w] = freqrespest(hd,L)
[h,w] = freqrespest(hd,L,param1,value1,param2,
value2,...)
freqrespest(hd,L,opts)
[h,w] = freqrespest(hd,L) estimates the frequency response of filter hd by filtering a set of input data and then forming the ratio between output data and input data. The test input data comprises sinusoids with uniformly distributed random frequencies.
Use this filter-based technique for judging the performance of fixed-point filters. Because you can compare a filtering-based frequency response estimate for a fixed-point filter to the response of a similar filter that uses quantized coefficients, but applies floating-point arithmetic internally. This comparison determines whether the fixed-point filter performance closely matches the floating-point, 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.
Refer to example 2 for one way to plot h with w.
[h,w] = freqrespest(hd,L,param1,value1,param2,
value2,...) 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 string
input arguments in single quotation marks. The following table provides
valid parameters for [h, w].
Parameter Name | Default Value | Description |
|---|---|---|
NFFT | 512 | Number of FFT points to use. |
NormalizedFrequency | true | Indicates whether to use normalized frequency or linear frequency. Values are true (use normalized frequency), or false (use linear frequency). When you specify false, you must supply the sampling frequency Fs. |
Fs | normalized | Specifies the sampling frequency when NormalizedFrequency is false. No default value. You must set NormalizedFrequency to false before setting a value for Fs. |
SpectrumRange | half | Specifies whether to use the whole spectrum or half. half is the default, and the valid values are half and whole. |
CenterDC | false | Specifies whether to set the center of the spectrum to the DC value in the output plot. If you select true, both the negative and positive values appear in the plot. If you select false DC appears at the origin of the axes. |
freqrespest(hd,L,opts) uses an object opts to specify the optional input parameters instead of directly specifying PV pairs as input arguments. Create opts with
opts = freqrespopts(hd);
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
freqrespest can also compute the frequency response of double-precision floating filters that cannot be converted to transfer-function form without introducing significant round off errors which affect the freqz frequency response computation. Examples of these kinds of filters include state-space or lattice filters, in particular high-order filters.
These examples demonstrate some uses for freqrespest.
Example 1
Start by estimating the frequency response of a fixed-point 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 fixed-point 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 state-space filters as well. This example estimates the frequency response of a state-space 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
![]() | firtype | freqrespopts | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |