Vous êtes sur la page 1sur 15

Introduction to DSP using MATLAB Script & Filter Design Tool

Lab 1 Tutor: Dr Alison Carrington a.l.carrington@staffs.ac.uk http://www.fcet.staffs.ac.uk/alg1/

Digital Signal Processing(CE00063-3) Lab 1

Page 1/15

Lab Learning Outcomes


This lab will introduce you to MATLAB as a tool for designing and evaluating digital filters, prior to implementing them in hardware. The GUI Filter Design and Analysis (FDA) tool will be introduced as a rapid convenient method for digital filters design and analysis.

Lab Preparations
Simply read through the lab instructions and follow them carefully.

Required Hand-ins
Your opinions about the lab and the lab material. Too easy? Too difficult? Suggestions on possible changes.

Digital Signal Processing(CE00063-3) Lab 1

Page 2/15

Lab 1.a Consider the filter described by the following coefficients: y[n] = -5*x[n] + 2*x[n-1] - 5*x[n-2] + 2*x[n-3] Sketch the filter transfer function using Matlab (Sampling frequency = 16 KHz) You may use the following Matlab code if you wish to do so. clear close all

coeff=[-5 2 -5 2 ]; % Filter coefficients FS= 16000; % Sampling freq F=[0:FS/2/255:FS/2]; % Create a freq sweep signal coeff1=[coeff zeros(1,512-length(coeff))]; % Pad the coefficients with zeros

hdb=20*log10(abs(fft(coeff1))+10^-5); hdb=hdb-max(hdb);

% Returns the frequency response % Set the max gain value to zero db

plot(F(2:255),hdb(2:255)); % Plot the response title('frequency response, magnitude in dB') xlabel('Frequency in Hz') ylabel('Magnitude Response') grid

From your simulation results fill in the following: Filter type Filter order Filter Operation Filter Cutoff freq : ______________ : ______________ : ______________ : ______________ (LPF, BPF, HPF, etc.) (FIR, IIR)

Part of the signal processing tool box is a GUI based filter design and analysis tool (FDA). In the next section you will learn how to you use the FDA to design a filter from design specification, display the filter response, and alter the design by tweaking the poles and zeros of the filter.
Digital Signal Processing(CE00063-3) Lab 1

Page 3/15

Lab 1.b

Digital Signal Processing(CE00063-3) Lab 1

Page 4/15

Lab 1.b Open FDA Tool To open the Filter Design and Analysis Tool (FDA Tool), type fdatool

The Filter Design and Analysis Tool opens with the Design Filter panel displayed.

Digital Signal Processing(CE00063-3) Lab 1

Page 5/15

Choose a Response Type You can choose from several response types: Lowpass Raised cosine Highpass Bandpass Bandstop Differentiator Multiband Hilbert transformer Arbitrary magnitude Select the radio button next to Bandpass in the Response Type region of the GUI.

Choose a Filter Design Method You can use the default filter design method for the response type that youve selected, or you can select a filter design method from the available FIR and IIR methods listed in the GUI. To select the Remez algorithm to compute FIR filter coefficients, select the FIR radio button and choose Equiripple from the list of methods.

Digital Signal Processing(CE00063-3) Lab 1

Page 6/15

Set the Filter Design Specifications The filter design specifications that you can set vary according to response type and design method. For example, to design a Bandpass filter, you can enter Filter Order Options Bandpass Filter Frequency Specifications Bandpass Filter Magnitude Specifications The display region illustrates filter specifications when you select Filter Specifications from the Analysis menu or when you click the Filter Specifications toolbar button. You can also view the filter specifications on the Magnitude plot of a designed filter by selecting Design Mask from the View menu.

Digital Signal Processing(CE00063-3) Lab 1

Page 7/15

Set the Filter Order Select the Minimum order radio button.

Set the Filter Options The available options depend on the selected filter design method. Only the FIR Equiripple and FIR Window design methods have settable options. For FIR Equiripple, the option is a Density Factor.

Set the Density factor to 16.

Set the Bandpass Filter Frequency Specifications For a bandpass filter, you can set Units of frequency: -Hz -kHz -MHz -Normalized (0 to 1) Sampling frequency Passband frequencies Stopband frequencies

Digital Signal Processing(CE00063-3) Lab 1

Page 8/15

You specify the passband with two frequencies. The first frequency determines the lower edge of the passband, and the second frequency determines the upper edge of the passband. Similarly, you specify the stopband with two frequencies. The first frequency determines the upper edge of the first stopband, and the second frequency determines the lower edge of the second stopband. Keep the units in Hz (default). Set the sampling frequency (Fs) to 2000 Hz. Set the end of the first stopband (Fstop1) to 200 Hz. Set the beginning of the passband (Fpass1) to 300 Hz. Set the end of the passband (Fpass2) to 700 Hz. Set the beginning of the second stopband (Fstop2) to 800 Hz.

Set the Bandpass Filter Magnitude Specifications For a bandpass filter, you can specify the following magnitude response characteristics: Units for the magnitude response (dB or linear) Passband ripple Stopband attenuation

Keep Units in dB (default). Set the passband ripple (Apass) to 0.1 dB.
Digital Signal Processing(CE00063-3) Lab 1

Page 9/15

Set the stopband attenuation for both stopbands (Astop1, Astop2) to 75 dB.

Compute the Filter Coefficients Now that youve specified the filter design, click the Design Filter button to compute the filter coefficients. Notice that the Design Filter button is disabled once youve computed the coefficients for your filter design. This button is enabled again once you make any changes to the filter specifications. Note that you can undo actions, one at a time, by selecting Undo from the Edit menu or by clicking the Undo toolbar button. To redo previously undone actions, select Redo from the Edit menu or click the Redo toolbar button.

Analyse the Filter View the following filter response characteristics in the display region or in a separate window. Magnitude response Phase response Magnitude and Phase responses Group delay response Phase delay response Impulse response Step response
Digital Signal Processing(CE00063-3) Lab 1 10/15 Page

Pole-zero plot Zero-phase responseavailable from the y-axis context menu in a Magnitude or Magnitude and Phase response plot.

You can display two responses in the same plot by selecting Overlay Analysis from the Analysis menu and selecting an available response. A second y-axis is added to the right side of the response plot. (Note that not all responses can be overlaid on each other.) You can also display the filter coefficients and detailed filter information in this region. For all the analysis methods, except zero-phase response, you can access them from the Analysis menu, the Analysis Parameters dialog box from the context menu, or by using the toolbar buttons. For zero-phase, right-click on the y-axis of the plot and select Zero-phase from the context menu.

View the filters magnitude response by selecting the Magnitude Response button on the toolbar.

Digital Signal Processing(CE00063-3) Lab 1 11/15

Page

Using Data Markers Click on the response to add plot data markers that display information about particular points on the response.

To move a data marker, grab its black square at the corner of the marker. Dragging the marker with your mouse changes the Frequency and Magnitude values. To change the properties of a data marker, right-click on the marker to display the properties menu: AlignmentChange the position of the marker. Font SizeChange the font size. MovableAllow the marker to be moved on the response. InterpolationSelect Nearest to force the marker to snap to nearest point along the plotted curve. Select Linear to interpolate between points along the plotted curve. Track ModeRestrict the marker to be movable in the x, y, or xy direction. DeleteDelete the selected marker. Delete allDelete all markers.

Change the Sampling Frequency Right-click in any filter response plot and select Sampling Frequency from the context menu.
Digital Signal Processing(CE00063-3) Lab 1 12/15

Page

To change the filter name, type the new name in Filter name. (In fvtool, if you have multiple filters, select the desired filter and then enter the new name.) To change the sampling frequency, select the desired unit from Units and enter the sampling frequency in Fs. (For each filter in fvtool, you can specify a different sampling frequency or you can apply the sampling frequency to all filters). To save the displayed parameters as the default values to use when FDATool or FVTool is opened, press Save as default. To restore the MATLAB defined default values, click Restore original defaults.

Display the Filter Response in FVTool To display the filter response characteristics in a separate window, select Filter Visualization Tool from the View menu or click the Full View Analysis button: This launches the Filter Visualization Tool (fvtool).

Edit the Filter Using the Pole/Zero Editor You can edit a designed or imported filters coefficients by moving, deleting, or adding poles and/or zeros using the Pole/Zero Editor panel. Click the Pole/Zero Editor button in the sidebar or select Pole/Zero Editor from the Edit menu to display the following panel. Poles are shown using x symbols and zeros are shown using o symbols.
Digital Signal Processing(CE00063-3) Lab 1

Page 13/15

Plot mode buttons. Plot mode buttons are located to the left of the pole/zero plot. Select one of the buttons to change the mode of the pole/zero plot. The following plot parameters and controls are located to the left of the pole/zero plot and below the plot mode buttons. Filter gainfactor to compensate for the filters pole(s) and zero(s) gains Coordinatesunits (Polar or Rectangular) of the selected pole or zero Magnitudeif polar coordinates is selected, magnitude of the selected pole or zero Angleif polar coordinates is selected, angle of selected pole(s) or zero(s) Realif rectangular coordinates is selected, real component of selected pole(s) or zero(s) Imaginaryif rectangular coordinates is selected, imaginary component of selected pole or zero Sectionfor multisection filters, number of the current section Conjugatecreates a corresponding conjugate pole or zero or automatically selects the conjugate pole or zero if it already exists. Auto updateimmediately updates the displayed magnitude response when poles or zeros are added, moved, or deleted.

Digital Signal Processing(CE00063-3) Lab 1

Page 14/15

The Pole-zero Editor on the Edit menu has items for selecting multiple poles/zeros, for inverting and mirroring poles/zeros, and for deleting, scaling and rotating poles/zeros.

These items are enabled only when one or more poles/zeros are selected. Move one of the zeros on the vertical axis. This should produce the following result:

The selected zero pair is shown in green. When you select one of the zeros from a conjugate pair, the Conjugate check box and the conjugate are automatically selected. The Magnitude Response plot updates immediately because Auto update is active.

Digital Signal Processing(CE00063-3) Lab 1

Page 15/15

Vous aimerez peut-être aussi