+ All Categories
Home > Documents > DSP Lab 1 MatlabTutorial

DSP Lab 1 MatlabTutorial

Date post: 13-Apr-2018
Category:
Upload: drhmsa1994
View: 244 times
Download: 0 times
Share this document with a friend

of 15

Transcript
  • 7/27/2019 DSP Lab 1 MatlabTutorial

    1/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 1/15

    Introduction to DSP using MATLAB Script &Filter Design Tool

    Lab 1

    Tutor: Dr Alison [email protected]

    http://www.fcet.staffs.ac.uk/alg1/

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    2/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 2/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 andAnalysis (FDA) tool will be introduced as a rapid convenient method for digitalfilters 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.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    3/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 3/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.

    clearclose all

    coeff=[-5 2 -5 2 ]; % Filter coeff icientsFS= 16000; % Sampling freq

    F=[0:FS/2/255:FS/2]; % Create a freq sweep signalcoeff1=[coeff zeros(1,512-length(coeff))]; % Pad the coeff icients with zeros

    hdb=20*log10(abs(ff t(coeff1))+10^-5); % Returns the frequency responsehdb=hdb-max(hdb); % Set the max gain value to zero db

    plot(F(2:255),hdb(2:255)); % Plot the responsetitle('frequency response, magnitude in dB')xlabel('Frequency in Hz')

    ylabel('Magnitude Response')grid

    From your simulation results fill in the following:

    Filter type : ______________ (FIR, IIR)

    Filter order : ______________

    Filter Operation : ______________ (LPF, BPF, HPF, etc.)

    Filter Cutoff freq : ______________

    Part of the signal processing tool box is a GUI based filter design and analysistool (FDA). In the next section you will learn how to you use the FDA to design afilter from design specification, display the filter response, and alter the design bytweaking the poles and zeros of the filter.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    4/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 4/15

    Lab 1.b

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    5/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 5/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.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    6/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 6/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 theGUI.

    Choose a Filter Design Method

    You can use the default filter design method for the response type that youveselected, or you can select a filter design method from the available FIR and IIRmethods listed in the GUI.

    To select the Remez algorithmto compute FIR filter coefficients, select the FIR

    radio button and choose Equiripple from the list of methods.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    7/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 7/15

    Set the Filter Design Specifications

    The filter design specifications that you can set vary according to response typeand 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 FilterSpecifications from the Analysis menu or when you click the FilterSpecifications toolbar button.

    You can also view the filter specifications on the Magnitude plot of a designedfilter by selecting Design Mask from the View menu.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    8/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 8/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 FIREquiripple and FIR Window design methods have settable options. For FIREquiripple, the option is a Density Factor.

    Set theDensity 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

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    9/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 9/15

    You specify the passband with two frequencies. The first frequency determinesthe lower edge of the passband, and the second frequency determines the upperedge of the passband.

    Similarly, you specify the stopband with two frequencies. The first frequencydetermines 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 responsecharacteristics:

    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.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    10/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page10/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 tocompute the filter coefficients.

    Notice that the Design Filter button is disabled once youve computed thecoefficients for your filter design. This button is enabled again once you makeany changes to the filter specifications.

    Note that you can undo actions, one at a time, by selecting Undofrom the Editmenu or by clicking the Undotoolbar button. To redo previously undone actions,select Redofrom the Editmenu or click the Redotoolbar button.

    Analyse the Filter

    View the following filter response characteristics in the display region or in aseparate window.

    Magnitude response Phase response Magnitude and Phase responses Group delay response Phase delay response Impulse response Step response

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    11/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page11/15

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

    You can display two responses in the same plot by selecting Overlay Analysisfrom the Analysis menu and selecting an available response. A second y-axis isadded to the right side of the response plot. (Note that not all responses can beoverlaid on each other.)

    You can also display the filter coefficients and detailed filter information in thisregion.

    For all the analysis methods, except zero-phase response, you can access themfrom the Analysis menu, the Analysis Parameters dialog box from the contextmenu, or by using the toolbar buttons. For zero-phase, right-click on the y-axis ofthe plot and select Zero-phase from the context menu.

    View the filters magnitude response by selecting the Magnitude Responsebutton on the toolbar.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    12/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page12/15

    Using Data Markers

    Click on the response to add plot data markers that display information aboutparticular 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 Magnitudevalues.

    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 nearestpoint along the plotted curve. Select Linear to interpolate between pointsalong the plotted curve.

    Track ModeRestrict the marker to be movable in the x, y, or xydirection.

    DeleteDelete the selected marker.

    Delete allDelete all markers.

    Change the Sampling Frequency

    Right-click in any filter response plot and select Sampling Frequency fromthe context menu.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    13/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 13/15

    To change the filter name, type the new name in Filter name. (In fvtool, if you havemultiple filters, select the desired filter and then enter the new name.)

    To change the sampling frequency, select the desired unit from Units and enter thesampling frequency in Fs. (For each filter in fvtool, you can specify a different samplingfrequency or you can apply the sampling frequency to all filters).

    To save the displayed parameters as the default values to use when FDATool orFVTool 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 FilterVisualization 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 addingpoles 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 Editmenu to display the following panel.

    Poles are shown using x symbols and zeros are shown using o symbols.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    14/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 14/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/zeroplot 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 selectedpole or zero

    Sectionfor multisection filters, number of the current section Conjugatecreates a corresponding conjugate pole or zero or automatically selectsthe conjugate pole or zero if it already exists. Auto updateimmediately updates the displayed magnitude response when poles or

    zeros are added, moved, or deleted.

  • 7/27/2019 DSP Lab 1 MatlabTutorial

    15/15

    Digital Signal Processing(CE00063-3)

    Lab 1 Page 15/15

    The Pole-zero Editor on the Edit menu has items for selecting multiple poles/zeros, forinverting 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.


Recommended