Main Content

freqrespest

Frequency response estimate via filtering

Description

example

[h,w] = freqrespest(sysobj) computes the frequency response estimate of the input filter System object™. The function estimates by running input data made up from sinusoids with uniformly distributed random frequencies through the filter and forming the ratio between output data and input data.

The freqrespest function computes the frequency response estimate of the input filter object that is close to the frequency response obtained by using only the quantized coefficients as long as:

  • No overflow occurs when performing the fixed-point filtering

  • There isn't significant quantization happening in the fixed-point additions and multiplications

freqrespest can be used as a diagnostic tool for fixed-point implementations. If freqrespest differs significantly from freqz (which only takes into account the quantization of the coefficients), it is an indication that at least one of the two conditions might be true.

[h,w] = freqrespest(sysobj,L) computes the frequency response estimate of the filter object by specifying L number of trials.

[h,w] = freqrespest(sysobj,L,Name=Value) uses the Name-Value pairs as input arguments to specify optional parameters for the test.

[h,w] = freqrespest(sysobj,L,opts) uses an options object to specify the optional input parameters in lieu of specifying name-value pairs.

[h,w] = freqrespest(sysobj,Arithmetic=arithType) analyzes the filter System object based on the arithmetic specified in the arithType input.

freqrespest(sysobj,___) with no output argument launches FVTool and shows the magnitude response estimate of the filter object.

Examples

collapse all

Estimate the frequency response of a fixed-point FIR filter.

firFilt = design(fdesign.lowpass(.4,.5,1,60),"equiripple",Systemobject=true);
dataIn = fi(randn(16,15),1,16,15);
dataOut = firFilt(dataIn); %#ok
[h,w] = freqrespest(firFilt); %#ok % This should be about the same as freqz.
release(firFilt);

Continuing with the filter object firFilt, change the FullPrecisionOverride property to false 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 the freqrespest function to compute the frequency response estimate for the fixed-point filter.

firFilt.FullPrecisionOverride = false;
firFilt.ProductDataType = "Custom";
firFilt.CustomProductDataType = numerictype(1,16,15);
firFilt.AccumulatorDataType = "Custom";
firFilt.CustomAccumulatorDataType = numerictype(1,16,15);
firFilt.OutputDataType = "Same as accumulator";
dataOut = firFilt(dataIn);
[h,w] = freqrespest(firFilt,2);
[h2,w2] = freqz(firFilt,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)')

Figure contains an axes object. The axes object with xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 2 objects of type line. These objects represent Frequency response estimated by filtering, Freq. response computed by quantizing coefficients only.

Input Arguments

collapse all

Number of trials used to compute the estimate, specified as a positive integer. If you do not specify this value, L defaults to 10. More the number of trials, the greater is the accuracy in the estimate of the response. However, when L is large, the function requires more time to compute the estimate.

Data Types: single | double

Options object to specify the optional input parameters in lieu of specifying name-value pairs.

Create the opts object using the freqrespopts function.

opts = freqrespopts(sysobj);

Because opts is an object, you use the set function to change the property 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

Analyze the filter System object, based on the arithmetic specified in the arithType input. arithType can be set to 'double', 'single', or 'fixed'. The analysis tool assumes a double-precision filter when the arithmetic input is not specified and the filter System object is in an unlocked state.

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 arithType parameter, that is, use the syntax [h,w] = freqrespest(sysobj), then these rules apply.

  • The System object state is Unlockedfreqrespest performs double precision analysis.

  • The System object state is Lockedfreqrespest performs analysis based on the locked input data type.

When you do specify the arithType parameter, that is, use the syntax [h,w] = freqrespest(sysobj,'Arithmetic',arithType), the following rules apply:

ValueSystem Object StateRule
arithType = 'double'Unlockedfreqrespest performs double-precision analysis.
Lockedfreqrespest performs double-precision analysis.
arithType = 'single'Unlockedfreqrespest performs single-precision analysis.
Lockedfreqrespest performs single-precision analysis.
arithType = 'fixed'Unlockedfreqrespest produces an error because the fixed-point input data type is unknown.
LockedIf the input data type is double or single, then freqrespest produces an error because the fixed-point input data type is unknown.
When the input data is of fixed-point type, freqrespest performs analysis based on the locked input data type.

Name-Value Arguments

Specify optional pairs of arguments as Name1=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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: firFilt = design(fdesign.lowpass(.4,.5,1,60),'equiripple',Systemobject=true); [h,w] = freqrespest(firFilt,10,NFFT=1024);

Number of FFT points used in computing the frequency response estimate, specified as a positive integer. This value determines the length of the frequency response vector h and the length of the frequency vector w. When not specified, NFFT defaults to 512.

Data Types: single | double

Indicate whether to use normalized frequency or linear frequency, specified as either:

  • true –– Use normalized frequency. When not specified, the function defaults to true.

  • false –– Use linear frequency. When you specify false, you must supply the sampling frequency Fs.

Sampling frequency to be specified when NormalizedFrequency is set to false. No default value. You must set NormalizedFrequency to false before setting a value for Fs.

Data Types: single | double

Spectrum range to be used while computing the frequency response estimate, specified as either:

  • half

  • whole

Specify 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.

Output Arguments

collapse all

Estimate of the complex frequency response, returned as a vector. The length of the vector equals the NFFT value. By default, this vector is of length 512.

Data Types: double
Complex Number Support: Yes

Frequencies at which the complex frequency response h is estimated, returned as a vector. The length of the vector equals the NFFT value. By default, this vector is of length 512.

Data Types: double

Version History

Introduced in R2011a

expand all

See Also

Functions