algorithm - sharif university of technologyce.sharif.ir/~kalantari/projects/taships/digital signal...

Click here to load reader

Upload: voxuyen

Post on 30-Jan-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

20

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 MATLABs command line, or you can go through start -> toolboxes -> more -> signal processing -> window design and analysis tool. Youll 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) Conrm 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 .

2. Filter Design & Analysis Tool

Run fdatool from MATLABs command line, or you can Click 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 Sinc Lowpass Filter may seem unfamiliar (Probably you only know that its 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, its time to decide whether you need a FIR filter or an IIR one. You can specify your choice by choosing an option in Design Method section.

If you select IIR filter, then you 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 and a 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 Order will 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 Filters Using 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 MATLABs 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 will appeare:

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.

AlgorithmDesign 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 SpecificationsIn 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:

And for IRR mode, different structures are:

Explain each of the above structures and compare them with each other.

2. Comment on Design method of MATLAB. For example:

Comment the approach they use. Explain Design methods which is used in Filterbuilder toolbox separately.

3. Designing filters:

Lowpass:

I) Design a Lowpass filter with the following specification:

Design your filter with Direct Forms FIR structure. Check all design method, which is available in the toolbox for all of following questions.

II) Show the designed filter using View Filter Response.

III) Show the step response and impulse response of filter and comment on the shape of response in time domain.

IV) Show the pole/zero plots and comment on the places of zeros and poles according to the structure and design methods.

V) Now find the minimum order required to create above filter. After that, change the order of filter (in order mode) into half of minimum order required. Comment on differences and malfunction of this new filter.

Bandstop:

I) Design a Bandstop filter with the following specification:

Design your filter with Direct Form II Transposed SOS structure. Check all the design methods (attention: you have been told these methods in question 2) which are available in the toolbox for all of following questions.

II) Show the designed filter using View Filter Response.

III) Show the step response and impulse response of filter and comment on the shape of response in time domain.

IV) Show the pole/zero plots and comment on the places of zeros and poles according to the structure and design methods.

V) Comment on round off noise power spectrum.

VI) Now find the minimum order required to create the above filter. After that, change the order of filter (in order mode) into half of the minimum order required. Comment on differences and malfunctions of this new filter.

Differentiator:

I) Design a Differentiator filter with:

You can choose any structure and design method that you want.

II) Show the phase response and group delay and pole/zero plot.

Comment on the pictures according to the function of specified filter.

Hint: Differentiating input signal in time domain is equal to multiply signal with in frequency domain:

Hilbert:

I) Use Hilbert design and design a filter with Transition equal to 0.5.

II) Comment on step and impulse response of the filter and places of zero and poles.

III) What is the application of this filter?

Arbitrary:

I) Design a filter with the next specification:

Pulse shape:

I) Design a pulse shape filter with Rolloff factor 0.3 and sample per symbol 5.

II) What is the function of Rolloff factor and sample per symbol? Change the Rolloff factor to 0.7 and do the same.

III) Comment on impulse and step response of this filter.

IV) Do the same with Gaussian pulse shape. Instead of Rolloff factor, use BT = 0.4 and comment on function of BT. What is the characteristic of the Gaussian filter?

V) What is the function of Sample per symbol in this design approach? Change the sample per symbol, show the changes in the filter, and describe your answer.

Hint: Gaussian filter:

Raise cosine filter due to Rolloff factor:

Nyquist Design:

I) Design a Nyquist filter with Band = 5 and Transition width = 0.5 which is a minimum phase filter.

II) Show the pole/zero plot of this filter and comment on the places of zeros and poles.

III) What is the function of Band in this design approach?

HalfBand design:

I) Design a Halfband filter use MATLAB default parameters.

II) What is the function of Stopband shape and Stopband decay? Set them linear and 100 respectively.

III) Show the results of part I and II and comment on differences that have been made in impulse response and pole\zero plot.

Cascaded Integrator-Comb filter:

I) Design a Cascaded Integrator-Comb filter. Use following characteristic:

II) Change the differential delay to values 2 and 5 and show the results.

III) Comment on the pole/zero plot and differential delay function, and explain the application of this filter.

Design a CIC compensating filter:

I) Design a CIC compensating filter with defulat parameters of MATLAB. Show the results of pole\zero plot, Group delay and phase delay.

II) Now, change phase constraints to Minimum and do the same.

III) Change the phase constraints to Maximum and do the same.

IV) Compare the result of each part and the relation between figures and the place of poles and zeros.

Octave filter:

I) Design an Octave Band pass filter, change the Band per Octave from one to six, and show the results.

II) Input Fs is set to be 48000. What is the reason? What are an Octave filter and its function?

III) What is the Center Frequency? Describe the mean of Band per Octave.

Peak/Notch filter:

I) Design a Notch filter with Center Frequency = 0.8 and Bandwith = 0.1. What is the function of Bandwith? (for setting Bandwith you must change Frequency Constraints)

II) Change Magnitude constraints to Passband ripple and stopband attenuation. Explain the changes.

III) Comment on the structure of pole/zero plot of Notch filter.

IV) Now set the quality Factor to be 1 and 4 and explain the changes.

V) Design a Peak filter as stated in part I and show the figures of pole/zero plot.

Comb Design:

I) Design a Notch filter with Comb design and show the result.

II) Do the same for peak filter. Bandwith and quality selection is on your own.(change the quality factor to observe its application)

III) What is the usage of this filter?

Fractional Delay Filter:

I) Design a Fractional Delay filter with Fraction delay 0.3. Show the results.

II) What is the effect of Fractional delay on the filter and what is the usage of filter?

4. Design an Allpass filter choosing one of the above methods. Write the equation; specify the numerator and denominator coefficients.

5. Let . if U is the input signal to the Allpath filter that you create in part 4, plot the output signal.

4. Audio Processing Using SPtool

SPtool consists of 3 sections: 1-Signals, 2-Filters, 3-Spectra. In signal section you can view your signal in both time and frequency domains, its phase and also its group delay, and you can obtain any other important information about your signal as well. In filters part you have to first load the filter, which you have designed before with the FDAtool, and then you can view the filter and get other specifications such as impulse response, step response, poles & zeros, phase & magnitude, and finally Group delay from the filter part. If the designed filter meets your requirements you can then apply it to your specified signal and see the result by the last part which is Spectra.

Exercise 4:

For the purpose of this assignment you have to load the audio file Audio01.mp3 and bring it to the SPtool as your input signal and apply different filters to your signal, specially the ones you have designed in the FDAtool. At last, you should study the results and plot them as a function of time.

The End