Sunteți pe pagina 1din 18

Fdatool Tutorial

ECE 5580 DSP Implementation

Created on: 02/04/09

Objective: This document describes how to use the application fdatool provided in Matlab. As stated in Matlab: >> help fdatool FDATOOL Filter Design & Analysis Tool. FDATOOL launches the Filter Design & Analysis Tool (FDATool). FDATool is a Graphical User Interface (GUI) that allows you to design or import, and analyze digital FIR and IIR filters. This tutorial will guide you through the process of creating a low-pass equiripple filter. After completing this tutorial, you should be able to design this filter and import the coefficients into the Matlab workspace. This tutorial does not show you how to create other filters, however, once you can design the equiripple low-pass filter, any other filter will be relatively trivial (since fdatool is a GUI). Procedure: 1. Open up Matlab and type fdatool into the workspace and hit enter (figure 1).

Figure 1

2. You will see the window shown in figure 2 below. As you can see this GUI allows you to design many different types of digital filters very easily. We can specify the type of filter and the design type as well as the pass and stop band frequencies. In addition we can specify the attenuation in the pass and stop band to give us the desired filter response (by changing the values on the bottom right corner of the window). After choosing the attenuation we want, fdatool will design a filter of the lowest order, which achieves these attenuations. 3. Select Lowpass and Equiripple as shown on the bottom left of figure 2.

Figure 2

4. For the programs developed in this course, (Implementation of DSP) however, we normally want a filter of a specific order (31, 63, 127, etc), so instead we will specify the order of the filter as has been done in figure 3 below. Note: One may instead indicate the amount of attenuation as shown in figure 2 and then follow the procedure here from step 6 onwards. 5. Specify the order of the filter, the sampling frequency of the system for which the filter is to be used, the upper frequency (where the pass band ends), and the stop frequency (where the stop band starts), as shown in figure 3 below: Note: It may be useful to specify the order as N-1 where N is the number of coefficients that the filter will have. Chosen below is a filter of order 128 -1 = 127, with 128 coefficients.

Figure 3

6. Hit the design filter button to get the filter. As is seen in figure 4 below, the filter has been generated and the response has been plotted.

Figure 4

7. Notice below (figure 5) that the filter has been altered to give a sharper response. The sharper response, however, sacrifices the amount of attenuation in the stop band and causes ripple in the passband.

Figure 5

8. Notice now (figure 6 below) that the filter order has been changed to 63, resulting in about 45 dB less attenuation in the stop band as compared to a filter of order 127 (figure 4). This is just an example, the filter of order 127 will be used for the rest of this tutorial. Rule of Thumb: The higher the order of the filter, the greater the stop band attenuation. The downside, however, is that a higher order filter means more computations.

Figure 6

9. You can view many of the filters aspects using fdatool. For example, the amount of ripple in the pass band or the 3 dB point can be seen by placing markers on the plot (just click on the plot to place a marker; see figure 7 below).

Figure 7

10. We may also view the magnitude and phase response by using the buttons on the toolbar at the top of the page (see figure 8).

Figure 8

11. We may also view the filter coefficients by clicking on the Filter Coefficients button on the top toolbar (see figure 9).

Figure 9

12. To export these coefficients to the Matlab workspace, go to File --> Export (see figure 10).

Figure 10

13. The window shown in figure 11 will pop-up. Make sure workspace and coefficients are selected. Enter the name of the vector to save the coefficients to (coeff chosen in the example of figure 11) and hit export.

Figure 11 14. As seen in figure 12 and 13 below, the coefficients have been placed in the vector coeff and there are 128 coefficients for the filter of order 128 1 = 127:

Figure 12

Figure 13

15. From here the coefficients can be exported into a *.c file for use by the DSP board. 16. In addition to exporting the filter into the Matlab workspace, you may also save the filter within fdatool as well and compare it with other filters you create in fdatool or have imported into fdatool from the Matlab workspace. 17. Change the current Matlab directory to: C:\CD\chapter_11\matlab\figureGeneration 18. Load equalizer.mat into the Matlab workspace (this loads 5 different filters): >> load equalizer.mat >> who Your variables are: filt1 filt2 filt3 filt4 filt5 19. You can view the coefficients of filt1 by entering: >> filt1.tf.num

20. Notice that filt1, filt2, etc are structures and the tf branch contains the vector num, which contains the coefficients of the filter: >> filt1 filt1 = tf: [1x1 struct] ss: [] zpk: [] sos: [] imp: [] step: [] t: [] H: [] G: [] f: [] specs: [1x1 struct] Fs: 10000 type: 'design' lineinfo: [] SPTIdentifier: [1x1 struct] label: 'filt1' >> filt1.tf ans = num: [1x129 double] den: 1 21. Set: >> Fs = 48000 Fs = 48000 22. Now click on File -> Import Filter from Workspace, from the fdatool window to import these filters (Figure 13). 23. Select direct-form fir as shown in figure 14. 24. Fill in the boxes on the bottom of the window just as shown in figure 15.

Figure 13

Figure 14

Figure 15 25. Now click on Store Filter to get the window shown in figure 16 to pop-up.

Figure 16 26. Enter the filter name you want (eg.filt1) and click OK. 27. If you click on Filter Manager now, you will see that your filter is saved for use (figure 17). 28. Repeat steps 24-27 to import and save filters filt2, filt3, filt4, and filt5 as well.

Figure 17

29. Open up Filter Manager again, select all 5 filters, and click on FVTool (figure 18).

Figure 18

30. Notice that all filters have been plotted together for easy comparison. You can do this with any filter you create, simply by just clicking on Store Filter and then using FVTool.

Figure 19

S-ar putea să vă placă și