Detailed instructions for use are in the User's Guide.
[. . . ] Filter Design ToolboxTM 4 User's Guide
How to Contact The MathWorks
Web Newsgroup www. mathworks. com/contact_TS. html Technical Support
www. mathworks. com comp. soft-sys. matlab suggest@mathworks. com bugs@mathworks. com doc@mathworks. com service@mathworks. com info@mathworks. com
Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information
508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. Filter Design ToolboxTM User's Guide © COPYRIGHT 20002010 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. [. . . ] Your sampling frequency must correspond to the units you select. For example, when you select Normalized (0 to 1), Fs defaults to one. But if you choose one of the frequency options, enter the sampling frequency in your selected units. If you have the sampling frequency defined in your workspace as a variable, enter the variable name for the sampling frequency.
4 Click Import to import the filter.
FDATool checks your workspace for the specified filter. It imports the filter if it finds it, displaying the magnitude response for the filter in the analysis area. If it cannot find the filter it returns an FDATool Error dialog box. Note If, during any FDATool session, you switch to quantization mode and create a fixed-point filter, FDATool remains in quantization mode. If you import a double-precision filter, FDATool automatically quantizes your imported filter applying the most recent quantization parameters. When you check the current filter information for your imported filter, it will indicate that the filter is Source: imported (quantized) even though you did not import a quantized filter.
To Export Quantized Filters
To save your filter design, FDATool lets you export the quantized filter to your MATLAB workspace (or you can save the current session in FDATool). When you choose to save the quantized filter by exporting it, you select one of these options: · Export to your MATLAB workspace · Export to a text file · Export to a MAT-file
4-52
Importing and Exporting Quantized Filters
Example -- Export Coefficients or Objects to the Workspace
You can save the filter as filter coefficients variables or as a dfilt filter object variable. To save the filter to the MATLAB workspace:
1 Select Export from the File menu. 2 Select Workspace from the Export To list. 3 Select Coefficients from the Export As list to save the filter coefficients
or select Objects to save the filter in a filter object.
4 For coefficients, assign variable names using the Numerator and
Denominator options under Variable Names. For objects, assign the variable name in the Discrete Filter option. If you have variables with the same names in your workspace and you want to overwrite them, select the Overwrite Variables box.
5 Click the OK button
If you try to export the filter to a variable name that exists in your workspace, and you did not select Overwrite existing variables, FDATool stops the export operation and returns a warning that the variable you specified as the quantized filter name already exists in the workspace. To continue to export the filter to the existing variable, click OK to dismiss the warning dialog box, select the Overwrite existing variables check box and click OK or Apply.
Getting Filter Coefficients After Exporting
To extract the filter coefficients from your quantized filter after you export the filter to MATLAB, use the celldisp function in MATLAB. For example, create a quantized filter in FDATool and export the filter as Hq. To extract the filter coefficients for Hq, use
celldisp(Hq. referencecoefficients)
which returns the cell array containing the filter reference coefficients, or
celldisp(Hq. quantizedcoefficients
to return the quantized coefficients.
4-53
4
Using FDATool with Filter Design ToolboxTM Software
Example -- Exporting as a Text File
To save your quantized filter as a text file, follow these steps:
1 Select Export from the File menu. 3 Click OK to export the filter and close the dialog box. Click Apply to export
the filter without closing the Export dialog box. Clicking Apply lets you export your quantized filter to more than one name without leaving the Export dialog box. The Export Filter Coefficients to Text-file dialog box appears. [. . . ] You can verify that the gain we get here is consistent with the gain of the filter previously. Now you can also check that the filter h is set up properly to work with integers:
info(h) Discrete-Time FIR Filter (real) ------------------------------Filter Structure Filter Length Stable Linear Phase : Direct-Form FIR : 101 : Yes : Yes (Type 1)
6-16
Using the set2int Method
Arithmetic Numerator Input Filter Internals Output Product Round Mode Overflow Mode
: fixed : s18, 0 -> [-131072 131072) : s12, 0 -> [-2048 2048) : Full Precision : s31, 0 -> [-1073741824 1073741824) (auto determined) : s29, 0 -> [-268435456 268435456) (auto determined) : No rounding : No overflow
Accumulator: s31, 0 -> [-1073741824 1073741824) (auto determined)
Here you can see that all fractional lengths are now set to zero, so this filter is set up properly for working with integers.
Reinterpreting the Output
You can compare the output to the double-precision floating-point reference output, and verify that the computation done by the filter h is done in full precision.
yint = filter(h, xsc); norm(yd - double(yint)) ans = 0
You can then truncate the output to only 16 bits:
yout = fi(yint, true, 16); stem(n(yidx), [xscext, double(yout(yidx)')]); axis([850 950 -2. 5e8 2. 5e8]); legend('input', 'output');
6-17
6
Using Integers and FIR Filters with Filter Design Toolbox
Once again, the plot shows that the input and output are at different scales. In order to scale the output so that the signals can be compared more easily in a plot, you will need to weigh the MSBs appropriately. You can compute the new fraction length using the gain of the filter when the coefficients were integer numbers:
WL = yout. WordLength; FL = yout. FractionLength + log2(g); yf2 = fi(zeros(size(yout)), true, WL, FL); yf2. bin = yout. bin; stem(n(idx)', [xscext, double(yf2(yidx)')]); axis([800 950 -2e3 2e3]); legend('input', 'rescaled output');
6-18
Using the set2int Method
This final plot shows the filtered data re-scaled to match the input scale.
6-19
6
Using Integers and FIR Filters with Filter Design Toolbox
6-20
A
Bibliography
· "Advanced Filters" on page A-1 · "Adaptive Filters" on page A-2 · "Multirate Filters" on page A-2 · "Frequency Transformations" on page A-3 · "Fixed Point Filters" on page A-3
Advanced Filters
[1] Antoniou, A. , Digital Filters: Analysis, Design, and Applications, Second Edition, McGraw-Hill, Inc. , 1993. [. . . ]