Sharif University of Technology

DSP

Dr. Mashhadi

Computer Assignment 3

Dear All,

This assignment is intended to make you familiar with filter design in MATLAB. Please upload a zip file including your M-files and the word document in the courseware. The name of your zip file should be HW3_xxxxxxxx in which the 8-digit number is your student ID. Choose proper titles for your plots and use separate M-files for each problem. Try to make each part of the problem recognizable by commenting (e.g. %a, %b, etc.). The word document should just contain your answers to the explanatory questions presented in each problem.

Introduction to Signal processing Toolbox in matlab

Signal processing toolbox is a platform in MATLAB which enables you to do a variety of things in the field of signals and systems such as designing filters, observing the effects of poles and zeros on signals, studying how a signal changes when a filter is applied to it, and so many other things which you are going to get familiar with in this assignment.In the attached files there is a complete tutorial which provides you with whatever you need to know or learn regarding signal processing.

Signal processing toolbox has three major parts, which are:

  • Filter design and Analysis tool (FDAtool)
  • Signal processing Tool (SPtool)
  • Window design and analysis tool (WINtool)
  • Since the main goal of this assignment is to help you with getting familiar with Matlab tools in signal processing,and not analyzing your skills in working with mouse and keyboard, the questions in this assignment may seem somehow ambiguous to you. Henceforth, the most key factor for your score is going to be the cogency of your report and its line of reasoning. So please note that you have to include your statements and conclusions in your report. In this assignment, your report is the only thing that could convince us that you have learned some skills.
  • Also please note that the parts that are your official exercise are highlighted. The other parts are just explanatory description.
  1. Window Design Using Wintool

Run Wintool from MATLAB’s command line, or you can go through start->toolboxes ->more->signal processing->window design and analysis tool. You’ll see this window:

Wintool has three panels:

1)Window Viewer displays the time domain and frequency domain representations of the selected window(s). The currently active window is shown in bold font. Three window measurements are shown below the plots.

a)Leakage factor — ratio of power in the side-lobes to the total window power

b)Relative side-lobe attenuation — difference in height from the main-lobe peak to the highest side-lobe peak.

c)Main-lobe width (-3dB) — width of the main-lobe at 3 dB below the main-lobe peak.

2)Window List lists the windows available for display in the Window Viewer. Highlight one or more windows to display them. The Window List buttons are:

a)Add a new window — Adds a default Hamming window with length 64 and symmetric sampling. You can change the information for this window by applying changes made in the Current Window Information panel.

b)Copy window — Copies the selected window(s).

c)Save to workspace — Saves the selected window(s) as vector(s) to the MATLAB workspace. The name of the window in Wintool is used as the vector name.

d)Delete — Removes the selected window(s) from the window list.

3)Current Window Information displays information about the currently active window. The active window name is shown in the Name field. To make another window active, select its name from the Name menu.

Exercise 1:

Use Wintool in MATLAB. Look at the time and frequency domain plots of the following 4 windows: Rectangular, Hann, Hamming, Blackman and Kaiser. Use window length N=11.For each of the windows, do the following:

1)Determine Main Lobe Width (MLW), Relative Side Lobe Attenuation, and Leakage Factor. Note that with the Kaiser window, you have to use a value for β.

2)Confirm the MLW and attenuation with the known theoretical MLW and Ripple values.

3)Can you adjust β value for Kaiser, to get, for example the rectangular window? What about the The Blackman window?

4)Evaluate the performance of the Kaiser window with different lengths and values of β.

  1. Filter Design & Analysis Tool

Run fdatool from MATLAB’s command line, or you canClick on the start button on the bottom left part of the command window. Then follow these steps: Toolboxes → More → Signal Processing → Filter Design & Analysis Tool.

Now we go through designing filters.

You can choose the response type by selecting one of the icons available in Response Type section. Note that there is a list for low pass and high pass filters. Using the last list, you can choose your arbitrary options.

As an exemplification, although ‘Inverse SincLowpass Filter‘ may seem unfamiliar (Probably you only know that it’s a low pass filter!), you can choose it and see its specifications in 3 parts:

1) Filter Specifications

2) Frequency specifications

3) Amplitude specifications

After choosing the Response Type, it’s time to decide whether you need a FIR filter or an IIR one. You can specify your choiceby choosing an option in Design Method section.

If you select IIR filter, thenyou can choose among the filter types available.

After this step, you can check and determine Filter Specifications. As an example, the required steps for an IIR filter anda FIR filter are shown next.

An IIR High pass filter (Chebyshev Type 2) has been selected. In Filter Order section you have two options, by choosing Specify Order you can determine the filter order based on your desire, while Minimum Orderwill design the filter with the lowest possible order. Then, in Frequency Specifications you can change the frequency related parameters visible in Filter Specifications section. Finally, in Magnitude Specifications section you are able to change the remaining parameters i.e. magnitude related parameters.

Now, we study the FIR filter design. Note that in this case, the only obvious difference happens in Options section, where you can choose the window and the parameters related to it. In addition, by clicking on the View button you can see the window.

To finish the filter design, click on Design Filter button below the option section. Now, you can see your filter in Filter specifications window.

Pole/Zero Editor

After finishing filter design, now click on Pole/Zero Editor icon in the left hand side of the Filter Design & Analysis Tool window.

An example regarding an IIR filter is illustrated below:

You can change the location of zeros and poles. Moreover, you can add or delete ones to your structure by using the following tools:

Furthermore, in order to find the exact location of each pole or zero first you choose it then the following section tells you its location.

(In Coordinates you can choose whether you want polar or rectangular coordination.)

Supposedly, if you want to decide based on phase response or both phase and magnitude response, There are three icons in the toolbox which help you.

Set Quantization Parameters

Now click on Set Quantization Parameters icon in the left hand side of the Filter Design & Analysis Tool window.

In this section, you are able to quantize the phase and magnitude response of your filter in three ways:

1-Double- precision floating-point

2-Single- precision floating-point

3-Fixed point

There are various additional settings in fixed point quantization.

Transform Filter

Now click on Transform Filter icon in the left hand side of the Filter Design & Analysis Tool window.

In this part you can transform any type of response to some other types:

First of all choose The Original Filter Type and then Transformed Filter Type. After that, choose one point from original filter to be transformed to another desired point in the new filter. Now click on Transform Filter.

Realize Model

Now click on Realize Model icon in the left hand side of the Filter Design & Analysis Tool window.

Realizing models provides us a precious tool, which is saving designed filters as blocks and using them in Simulink.

Exercise 2:

IIR Filters

1)Design a Butterworth filter of order 15,. Plot magnitude, zero-pole and group delay of the above filter (Fc is the cutoff frequency).

2)Design a Chebyshev Type 1 filter of order 7 and with maximum tolerance of 0.3dB in pass band. Plot magnitude, zero-pole and group delay of the above filter.

3)Design a Chebyshev Type 2 filter of order 7 and with maximum gain of -30dB in stop band. Plot magnitude, zero-pole and group delay of the above filter.

4)Design an Elliptic filter of order 7 and with maximum gain of -30dB in stop band and maximum tolerance of 0.3dB in pass band. Plot magnitude, zero-pole and group delay of the above filter.

5)Compare the results obtained in part 1 to 4. Do the results confirm your expectations?

6)Repeat part 1, but this time, choose this filter to be of minimum order. Now you can assign both Fstop and Fc. As you know you can just choose one of them (stop band or pass band) to be matched exactly by using minimum order filters.

7)Design a Peaking filter. Use both options in IIR designing method and explain the differences (Comb and Single Peak). What is the advantage of this filter?

FIR Filters

8)Design a FIR low pass filter using Kaiser window of minimum order and with maximum gain of -30dB in stop band and maximum tolerance of 0.3dB in pass band. Plot the magnitude and zero-pole of the above filter.

9)Design a FIR high pass filter using Kaiser window of minimum order and with maximum gain of -30dB in stop band and maximum tolerance of 0.3dB in pass band. Plot the magnitude and zero-pole of the above filter.

10)Design a FIR band pass filter using Kaiser window of minimum order and with maximum gain of -30dB in stop band and maximum tolerance of 0.3dB in pass band. Determine Fc2 and Fstop2 to make the response symmetric. Plot the magnitude and zero-pole of the above filter.

Other Options

11)Consider the filter designed in part 1.Now go to pole/zero editor and move poles or zeros (Two of them)and explain the changes in magnitude, phase and group delay.

12)Design a low pass Chebyshev Type 1 filter of order four with maximum tolerance of 0.10875 dB in pass band and . Now use ‘Transform Filter’ option to make that a high pass filter with . Plot magnitude, zero-pole and group delay of the above filter for both cases and compare the results.

3. Designing FiltersUsing FilterBuilder

FilterBuilder presents the option of designing a filter using a GUI dialog box as opposed to the command line instructions.To start working with FilterBuilder, you should open the mentioned toolbox. There are two ways for opening filter design:

First approach: Type FilterBuilder in MATLAB’s prompt window:

Second approach: Use the following address:

Start ---- > Toolboxes ---- > Filter Design HDL Coder ---- > FilterBuilder

After opening FilterBuilder the following box will appear:

There are various types of Filters in the above window. Here we are going to become familiar with all of above filter types and how to use them.

Lowpass Filter: Select the Arbitrary Response and press OK. The following figure will show up:

We are going to give a brief summary about variable options and design parameters:

1.

Save variable as — When you click Apply to apply your changes or OK to close this dialog box, FilterBuilder saves the current filter to your MATLAB workspace as a filter object with the name you enter

2.

View Filter Response — Displays the magnitude response for the current filter specifications and design method by opening the Filter Visualization Tool (fvtool) from Signal Processing Toolbox software. For more information about FVTool, refer to Signal Processing Toolbox documentation.

If you push it, for example the following window willappeare:

3.

The second tab in the Filterbuilder dialog box is shown in the following figure.

The Arithmetic drop down box allows the choice of Double precision, Single precision, or Fixed point. Some of these options may be unavailable depending on the filter parameters.

-Double precision: All filtering operations and coefficients use double-precision, floating-point representations and math.

-Single precision: All filtering operations and coefficients use single-precision floating-point representations and math.

-Fixed point :This string applies selected default values, typically used on many digital processors, for the properties in the fixed-point filter. These properties include coefficient word lengths, fraction lengths, and various operating modes. This setting allows signed fixed data types only.

The following figure shows the Data Types panel, after you select Fixed point for Arithmetic:

4.

The code generation panel contains options for various implementations of the completed filter design. Depending on your installation, you can generate MATLAB, VHDL, and Verilog code from the designed filter. You can also choose to create or update a Simulink model from the designed filter.

5.

This is the most important part of this brief instruction.

Arbitrary Response Design Dialog Box:

Impulse response

Select either FIR or IIR from the drop down list, where FIR is the default impulse response. When you choose an impulse response, the design methods and structures you can use to implement your filter change accordingly.

If you choose FIR the coefficients of your filter will be something like following example:

On the other hand if you choose IIR depending on the structure of your filter, it will be as the following picture if you use direct form II:

Order

Enter the order for FIR filter, or the order of the numerator for the IIR filter.

:

Denominator order

Select the check box and enter the denominator order. This option is enabled only if IIR is selected for Impulse response.

Filter type

This option is available for FIR filters only. Select Single-rate, Decimator, Interpolator, or Sample-rate converter. Your choice determines the type of filter as well as the design methods and structures that are available to implement your filter. By default, FilterBuilder specifies single-rate filters.

  • Selecting Decimator or Interpolator activates the Decimation Factor or the Interpolation Factor options respectively.
  • Selecting Sample-rate converter activates both factors.

When you design either a decimator or interpolator, the resulting filter is a bandpass filter that either decimates or interpolates your input signal.

Decimation Factor

Enter the decimation factor. This option is enabled only if the Filter type is set to Decimator or Sample-rate converter. The default factor value is 2.

Interpolation Factor

Enter the decimation factor. This option is enabled only if the Filter type is set to Interpolator or Sample-rate converter. The default factor value is 2.

If you choose Sample-rate converter filter type, you have both Interpolation and Decimator factor.

Response Specification

Number of Bands

Select the number of bands in the filter. Multiband design is available for both FIR and IIR filters.

Specify response as:

Specify the response as Amplitudes, Magnitudes and phase, or Frequency response.

Frequency units

Specify frequency units as either Normalized, which means normalized by the input sampling frequency, or select from Hz, kHz, MHz, or GHz.

Input Fs

Enter the input sampling frequency in the units specified in the Frequency units drop-down box. This option is enabled when the frequency units are selected.

Algorithm
Design Method

Select the design method for the filter. Different methods are enabled depending on the defining parameters entered in the previous sections.

Structure

Select the structure for the filter, available for the design method selected in the previous box.

Design Options

Window — replace the square brackets with the name of a window function or function handle. For example, "hamming" or "@hamming". If the window function takes parameters other than the length, use a cell array. For example, {‘kaiser',3.5} or {@chebwin,60}

Special cases:

If you use Bandpass filter there are more options:

Filter order mode

Select either Minimum (the default) or Specify from the drop-down box. Selecting Specify enables the Order option (explained in the following descriptions) so you can enter the filter order.

Frequency Specifications
In the Bandpass filter there is some different in Frequency Specifications.
There are many more cases to investigate. This summary is sufficient to answer the following questions but for more information check the Help of the MATLAB:

MATLAB ---- > Help ---- > DSP System Toolbox ---- > Functions ---- > GUIs ---- > FilterBuilder

Exercise 3:

  1. Specify the functions of structures in both FIR and IRR modes.

Note that in FIR mode, different structures are: