dsp lab manual - concordia universityusers.encs.concordia.ca/~weiping/elec442-f12... · lab 1:...

43
Conc Discrete-T C Dr cordia University Time Signal Process Lab Manual (ELEC442) Course Instructor: r. Wei-Ping Zhu Fall 2012 ing

Upload: vunga

Post on 12-Mar-2018

225 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Concordia University

Discrete-Time Signal Processing

Course Instructor:

Dr. Wei

Concordia University

Time Signal Processing

Lab Manual

(ELEC442)

Course Instructor:

Dr. Wei-Ping Zhu

Fall 2012

Time Signal Processing

Page 2: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Lab 1: Linear Constant

Coefficient Difference

Equations (LCCDE)

Objective

In this experiment, you will learn how to use MATLAB to generate the output of the LTI

systems that are represented using Linear Constant Coefficient Difference Equation (LCCDE).

Introduction

Linear Constant Coefficient Difference Equation (LCCDE) is the equation that describes the

relationship between the input and the output of a discrete time system. It describes the operation

of the system in the time domain and provides a method for computing the response of a

system�[�], to an arbitrary input �[�]. An Nth-order linear constant coefficient difference

equation is expressed as

���[� − �]�

�= � ���[� − �]

� �

���� = � ���[� − �]�

� �−���[� − �]

with the initial conditions ��– 1� = ��, ��– 2� = ��, … ��–�� = �� and the coefficients

���� ≠ 0� and �� as constants that define the system. The relation in the equation above is a

general linear relation between�[�], the input, and�[�], the output of the discrete time system.

We also say that � is the degree of the system. An example is the difference equation

Page 3: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

�[�] − 2�[� − 1] = �[�] where � (the order of the discrete difference equation) here is 1. Thus, it is a first-order

difference equation.

If the difference equation has one or more terms � that are nonzero for � > 0, the difference

equation is said to be recursive. On the other hand, if all of the coefficients �, � > 0 are equal

to zero, the difference equation is said to be non-recursive [1] [2].

LTI System as a Filter

A discrete time LTI system that has been designed to achieve a particular purpose or perform a

given function, such as frequency selection or attenuation, is called a Filter. The LTI systems can

be classified into finite impulse response (FIR) filters and infinite impulse response (IIR) filters

according to their impulse responses.

The Impulse Response

The impulse response is the output of a discrete time LTI system when the input is an impulse

signal#[�]. We call the output,�[�], as ℎ[�]when the input �[�] is #[�]. This is shown in

Figure 1.

Figure 1. An LTI system can be classified, according to its impulse response, into an FIR or IIR system.

Page 4: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Finite Impulse Response (FIR) Systems

If the impulse response of a linear time invariant system is of finite duration, the system is said to

be a finite impulse response (FIR) system. It is also called a non-recursive system because the

output samples can be computed using only the current and previous input samples. An FIR filter

can be represented by the difference equation

�[�] = � ���[� −�]�

� �

The output of an FIR system, also, can be computed using the convolution operation

�[�] = �[�] ∗ ℎ[�] = � ℎ[�]�[� − �] &

'&= � ℎ[�]�[� − �] �

which is equivalent to the difference equation in this case by noting �� as ℎ�.

Infinite impulse response (IIR) systems

If the impulse response of a linear time invariant system is of infinite duration, the system is said

to be an infinite impulse response (IIR) system. It is also called a recursive system because it

produces output samples based on the current and possibly previous input samples and the

previous values of its own output. It should be noted that if the impulse response is absolutely

summable, the filter will be stable. An IIR filter can be represented by the difference equation

���� = � ���[� − �]�

� �−���[� − �]

or more generally, by the convolution theorem.

Page 5: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Solution of an LCCDE Using MATLAB

The filter command in MATLAB can be used to compute the response of LTI systems that

are represented using LCCDE. The filter command has the following syntax

y=filter(b,a,x)

where( is the input signal vector, ) = [��, ��, ��, … , ��] and * = [��, ��, ��, … , ��] are row

vectors representing the coefficients of the LCCDE respectively. + is the output sequence. Read

more about the filter function in MATLAB help.

It should be noted that the output signal generated from filter command has same length as

the input signal while using the regular convolution of the input by the impulse response causes

an increase in the length of the output signal.

Example 1. Find the impulse response for a causal LTI system whose input x[n] and output y[n] are

related by the difference equation

�[�] − 12 �[� − 1] = �[�] Solution:

This is a recursive equation, and the system is causal LTI. So the initial rest condition can be

applied (�[�] = 0 for all � ≤ −1). The input signal is �[�] = #[�], so we can compute �[�] for

� ≥ 0 as follows

�[0] = �[0] + 12�[−1] = 1�[1] = �[1] + 12�[0] = 12�[2] = �[2] + 12�[1] = /120

��[3] = �[3] + 12�[2] = /120

2

and so on.

Thus, the solution can be written as

Page 6: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

�[�] = ℎ[�] = /1203 4[�]

The impulse response ℎ[�]is of infinite duration, so the system is infinite impulse response

(IIR).

Pre-lab

Question 1. Consider a causal LTI system whose input �[�] and output �[�] are related by

the following LCCDE

�[�] = 14�[� − 1] + �[�] (a) Determine the impulse responseℎ[�]. (b) Determine �[�] for �[�] = 4[�] − 4[� − 10]. Question 2. Look up in the MATLAB help about the filter command description, and

determine how you can define the vectors ) and *.

Note: You may need the following MATLAB commands to answer the lab problems. So it is

recommended to read MATLAB help about them.

Elementary Matrices and Matrix Manipulation: i, ones, pi, rand, randn, zeros.

Two-Dimensional Graphics: axis, grid, legend, plot, stem, title,

xlabel, ylabel.

Elementary Functions: cos, sin, exp, imag, real.

Data Analysis: sum

Page 7: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Lab problems

Create script files for each question. Include your name and ID as comments in the script files.

For each question, submit as part of the written lab report, the script file and any required plots. It

is suggested to save the script file under meaningful name, such as LAB1_P_1.m.

Problem 1. Use 0 ≤ � ≤ 50 to answer the following parts.

(a) Use MATLAB conv (convolution) command to find the output �[�] for question1-

part (b) in the Prelab section.

(b) Use MATLAB filter command to find the output �[�] for question1-part (b) in

the Prelab section.

Note: plot the input signal and the output signal in the same figure for each part. Adjust the title,

xlabel and ylabel accordingly.

(c) Explain any differences between using conv and filter commands.

Problem 2. Use filter command to answer to this problem. Consider an LTI system

whose input �[�] and output �[�] are related by the following LCCDE

�[�] = 12�[� − 1] − 14�[� − 2] + �[�] + 2�[� − 1] + �[� − 3] (a) Determine and plot the impulse response of the system over 0 ≤ � ≤ 100, and determine

the stability of LTI system from ℎ[�]. (Hint: An LTI system with impulse response ℎ[�] is stable if and only if ℎ[�] is absolutely summable)

(b) Determine and plot the output �[�] over 0 ≤ � ≤ 200, if the input to this system is

�[�] = [15 + 3 cos�0.2;�� − 15 sin�0.7;��]4[�] Note: Plot the input signal and the output signal in the same figure for each part. Adjust the title,

xlabel and ylabel accordingly.

Problem 3. A digital differentiator is given by

Page 8: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

�[�] = �[�] − �[� − 1] which computes a backward first-order difference of the input sequence. Implement this

differentiator on the following sequences, plot the results and give your comments on the output

results

(a) �[�] = 5�4[�] − 4[� − 30]�, (rectangle pulse)

(b) �[�] = ��4[�] − 4[� − 20]� + �40 − ���4[� − 20] − 4[� − 40]�, (triangle pulse)

(c) �[�] = 15 sin ?@3�AB �4[�] − 4[� − 100]�, (sinusoidal pulse)

Note: plot the input signal and the output signal in the same figure for each part. Adjust the title,

xlabel and ylabel accordingly.

Problem 4. A common example of a digital signal processing application is the removal of

the noise component from a signal corrupted by additive noise. Let �[�] be the signal

corrupted by a random noise C[�] resulting in the noisy signal�D[�] = �[�] + C[�]. The objective is to operate on �D[�] to generate a signal �E[�] which is a reasonable

approximation to �[�]. To this end, a simple approach is to generate an output sample by

averaging a number of input samples around the sample at instant�. For example, a

three-point moving average filter is given by

�[�] = 14 ��[� − 1] + 2�[�] + �[� + 1]� Given the following system

Where �[�] is given by the following MATLAB code

%%==========================

Number_of_samples=200;

Time_length=20;

Page 9: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Ts=Time_length/(Number_of_samples-1);

n=0:Ts:Time_length;

%real signal, non-periodic

xn= ((0.9).^n).* cos(2*pi.*n);

%%==========================

• LTI system-1 is given by

�[�] − 14 �[� − 1] = �[�] • C[�] is a Gaussian noise with zero mean and 0.2 standard deviation.

• LTI system-2 is given by

�[�] = �[�] − 14 �[� − 1] (a) Determine and plot each of the following signals �[�], �[�], C[�], �D[�], F[�], �E[�], make

sure that you plot all signal in the same figure using subplot command and adjust the title,

xlabel and ylabel accordingly.

(b) Calculate the mean square error (MSE) between �[�] and �E[�] and the ratio of the MSE

to the squared size of �[�]. Note: If we have an original signal �[�] and a recovered signal �E[�], both of length N, the mean

square error is calculated as

GHI = ���[�] − �E[�]���'�

3 �

Also, the squared size of the �[�] (energy) is calculated as

H = ���[�]���

3 �

Page 10: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Lab 2: The Z-Transform

Objectives

• To see how Z-transform can be used to answer questions concerning stability, causality

and convergence

• To see how Z-transform can be used to determine system output

• To study the use of Z-transform in the systems design process

• To see how Z-transform is used in the analysis for frequency response

Pre-Lab Signal Acquisition

Prior to coming to the lab, you should acquire a real-life signal of some sort. Recall that signal is

a stream of data. The data in your stream may be real or complex. The stream should be single

channel and one dimensional. It should of course be a digital signal.

Possible ways to acquire a signal can be

• Running an experiment at work/home and capturing the results of the experiment on the

computer

• Running a software experiment on the computer

• Investigation of sources on the computers at Concordia (like images and sounds)

• Getting signals from the internet

• Any other way you want

During the lab period, you must place at least 1000 samples of your signal in the directory

designated by the TA and hand in a write-up to the lab TA that:

• Describes the signal that you acquired and how you acquired it.

• Describes why it is an interesting/important signal (This will likely be the most

interesting part, so do not be afraid to indulge in a very good description).

Page 11: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

• State the sampling rate and the unit of the samples (for example, if the signal is the output

of a stereo amplifier to a speaker, the unit might be volts) If you cannot say what unit it

is, then explain it as best you understand it.

• The file containing your signal should be ASCII readable format (text). It should be such

that it can be loaded into MATLAB using the “load” command. This means that the file

can take one of the two following formats:

1- The number representing each sample is placed on a new line. Thus, there is only one

number on each line (column vector).

2- The numbers representing the samples are all on the same line each separated by one

or more spaces. This file contains one line (row vector).

Z-Transform

Laplace transform can be considered to be a generalization of the Fourier Transform (FT) in the

continuous-time domain. Similarly, in the discrete-time domain, Z-transform is a generalization

of the discrete-time Fourier Transform (DTFT). Z-transform plays an important role in both

analysis and design of discrete-time systems. It provides another domain in which signals and

systems can be investigated.

The two–sided or bilateral Z-transform can be written as the following summation

J�K� = � �[�]K'3&

3 '&

or notationally as J�K� = L{�[�]}. Two important properties of Z-transform are apparent from

its definition. First, this transform is linear. Its second property enables the treatment of shifted

sequences, i.e.

�[�] ⇔ J�K� ⇒ �[� − �] ⇔ K'J�K� Z-transform has many other valuable properties that make it a powerful analysis tool. One of the

most important properties is the equivalence of convolution of two sequences and the

multiplication of Z-transform in the transform domain, i.e.

Page 12: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

�[�] ⋇ �[�] ⇔ J�K�R�K� where ⋇ denotes the convolution operation in time domain.

By expressing the complex variable K in the polar form as K = STUV, Z-transform has an

interpretation in terms of Fourier transform. With K so expressed, the Z-transform becomes

J�STUV� = � �[�]�STUV�'3&

3 '&= � �[�]S'3T'UV�&

3 '&

If S = 1, i.e. |K| = 1, the Z-transform is equivalent to the DTFT of the sequence �[�]. In this experiment, we motivate the use of Z-transform by the role it plays in both design and

analysis of discrete-time systems.

Problem 1. The focus in this problem is on demonstrating how the Z-transform answers

questions concerning causality, stability and convergence. Consider the second-order system

transfer function

X�K� = 1 − 1.7K'�1 − 2.05K'� + K'� and an input sequence specified by

J�K� = 11 − 0.9K'�

The input sequence is taken to have a region of convergence (ROC) given by|K| > 0.9.

1. Derive theoretically the inverse z-transform of X�K� associated with the different regions of

convergence. Indicate all relevant steps. On a polar plot, indicate the pole and zero

locations of the second-order system as well as the corresponding ROCs. Discuss the

causality and stability for each ROC. Does the Fourier Transform X�K = TZ[� exist for

each ROC?

2. Theoretically, calculate the convolution of the input sequence corresponding to J�K� with the stable sequence(s) corresponding toX�K�. Show all relevant analytical

calculations. Does the Fourier Transform exist for all ROC ofX�K�J�K�?

Page 13: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Generate the convolution of the input sequence for J�K� with the stable sequence(s)

corresponding to X�K� using the MATLAB routine conv. Consider an input sequence and

impulse response of length � = 10 samples and length � = 250 samples. These results

are to be compared with the analytical expression you derived in Part 2. From the

analytical expression(s) of Part 2, generate two sequences of lengths N = 19 and N =

499 samples. Plot your results using the stem routine. Label each convolution sequence

accordingly. Do the numerical convolution results agree with the theoretical expression? Why or

why not?

Problem 2. Knowledge of the impulse response of a system is very important in digital signal

processing. In this problem, you will find the system transfer function of an unknown system by

determining the system impulse response.

1. Find the impulse response of the unknown system defined by the function func_8.

This can be done by using an impulse as the input to func_8. Use the MATLAB

command “stem” to show the results. (You should be given func_8 as an m-file)

a. Generate an N-point sample input (take N=32 for this experiment).

�[�] = #[�] = \1, � = 00, 0 < � ≤ � − 1̂

b. Determine the output of the unknown system defined by func_8.

2. Do the following:

a. Define x�[n] = 2δ[n − 3] as in (1) using 100 samples.

b. Find the output ��[�] = a[��[�]] with a as the system defined by func_8.

c. Using the convolution routine conv in MATLAB, evaluate ��[�] as

��[�] = ��[�] ⋇ ℎ[�]3. Is the system a LTI? Is this system stable? Explain why.

4. If ais LTI and given that its impulse response is exponential, find the transfer

function. Why must the system be LTI so that its transfer function can be

determined? Is it necessary that it is also stable?

Page 14: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Recall that the frequency response of a system is equivalent to evaluating the transfer function

X�K� of that system on the unit circle, i.e. let K = TUV

X�TUV� = X�K�^|b cde

Using this methodology, it is possible to sketch the frequency response of the system that is

related to its poles and zeros. Here we will only consider the magnitude response, while

phase response can be considered in a similar way and is left as an exercise. Let X�K� be

written in its factorized form

X�K� = f�K − ����K − ���… �K − ����K − ����K − ���… �K − ���

Then, the magnitude response can be written as

|X�K�| = |f|g�TUV − ���gg�TUV − ���g… g�TUV − ���g|�TUV − ���||�TUV − ���|… |�TUV − ���|

A geometrical interpretation can be formed by evaluating the magnitude response of an

arbitrary term�TUV −Kh�. The point TUV lies on the unit circle at an angle of [as in Figure

2. The location of Kh = |Kh|TUi is also shown in the figure. The quantity of interest is the

magnitude of the difference between these two vectors as shown in Figure 2.

Figure 2: Geometric interpretation of the contribution of the magnitude

response due to a single root at an arbitrary frequency.

Page 15: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

It is evident that as the vector TUV rotates from 0 to 2; in a counter-clock-wise

direction, the magnitude of the difference vector �TUV −Kh� also varies. The implication

of the geometric representation is that we can evaluate the magnitude response due to the

root Kh as the length of this difference vector at different frequencies in the range [0, 2;]. In Figure 2, atω = 0, the magnitude of the difference vector is some finite value. As ω

starts to increase, this value starts decreasing and is minimum whenω = θ, the angle of

the rootzm. If we continue to increaseω, the difference magnitude again starts to

increase untilω = 2π at which point everything is repeated again.

From this geometrical interpretation, the idea of periodicity of DTFT is evident. That is,

if we continue to rotate TUV around the unit circle beyond2;, the magnitude �gTUV −Khg�

starts to repeat. Each such revolution of the magnitude around the unit circle

corresponds to a single period which leads to the idea of periodicity of the DTFT.

The example of Figure 2 illustrates how the graphical representation can be generalized

to represent any arbitrary system function. The magnitude response can be represented as the

product of individual difference vectors for the zeros divided by the product of difference

vectors for the poles at each frequency.

At this time, several useful observations relating the magnitude response and pole/zero locations

can be made. Zeros close to the unit circle cause the DTFT magnitude dip in the region near the

zeros and the minimum value of the dip occurs at the angle of the zero. If the zero is on

the unit circle, the DTFT magnitude is zero for that frequency (angle of zero). Similarly,

the poles close to the unit circle force a peak in the magnitude response at frequencies close to

the angle of the poles. With these observations in mind, we are able to generate a rule for

sketching the magnitude response of X�K�. As we move around the unit circle the

magnitude peaks when we pass close to a pole and dips when we pass near a zero. The

sharpness of the peaks and valleys depend on the closeness of the poles and zeros on the

unit circle. Poles and zeros far from the unit circle do not affect the magnitude response

significantly.

Page 16: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Problem 3.

1. Given an all-pole filter (IIR) transfer function

X�K� = 11 − 0.5K'� + 0.2K'� − 0.1K'2 + 0.007K'o + 0.14K'A + 0.15K'p

(a) Find its magnitude response using the MATLAB routine freqz. From the

magnitude response what can be said about the pole locations?

(b) From the magnitude response, try to sketch the pole/zero plot.

(c) Using zplane routine, plot the true pole/zero locations.

2. Repeat (1) for the all-zero (FIR) filter transfer function given by H�z� X�K� = 1 + 1.9K'� + 0.8K'� − 0.8K'2 − 0.7K'o

3. Repeat (1) for the following transfer function (use a value of s = 0.8)

X�K� = 1 − 2 cos[� K'� + K'�1 − 2s cos[� K'� + K'� ,[� = ;/4

Based on part (3) above, answer the following questions.

• What visible clues in the magnitude response of the given transfer function

provide information about the pole/zero locations?

• How are these clues affected by the poles and zeros away from the unit circle?

• How does s affect the pole locations? What values can s take such that the system

is stable?

• Based on your sketch of the magnitude response from the pole/zero plot, what can

you say about the system function of this filter (What does this system do)?

Problem 4. In this discussion, the effect of pole locations on the output of a discrete-time

system is considered. The effect that the poles have on system dampening behavior is

investigated by examining a simple system.

1. Using MATLAB, implement and test a two pole oscillator. An oscillator can be

understood as a system that continues to generate an output between prescribed

limits once it has been started, i.e. a marginally stable system. The sampling rate is

1200Hz with the resonant or center frequency of the system taken to be 35Hz. The

output of the oscillator is to be a sequence of real numbers. A two pole oscillator

Page 17: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

has a complex-conjugate pair of poles that ensure a real system. The output of this

two pole oscillator contains a sinusoid of frequency 35 Hz. Design notes should

include a polar plot of the pole locations with sampling rate and resonant frequency

appropriately indicated on the plot. The difference equation of the oscillator should

be included with the initial conditions required to initiate oscillation. Can any input

to the oscillator be used to start the system oscillating with bounded amplitude?

What if a unit step of finite amplitude is used as the initial excitation? (Would the

output of the oscillator have a bounded output?) Generate and plot 32 samples of

the oscillator output. The time axis should be properly scaled in seconds.

Hint: Examine the input-output relationship in the z-domain.

2. The output of the oscillator is to be dampened. Explain what must be done in

order to dampen the output. Note that dampening and attenuation are

different. Choose an example where the output of the system is dampened and

plot the output of the system for 256 samples.

Page 18: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Lab 3: The DFT and the

Sampling Theorem

Objectives

The principle objectives of this experiment are

• To introduce the DFT as a signal analysis tool and LTI filters as signal restoration

tools (this lab involves designing filters based on analysis using the DFT and other tools)

• To study the effects of different sampling rates

• To understand the issues involved in sampling of a continuous-time signal

• To be able to use the filter design tools provided by MATLAB

• To have an introduction to multirate filtering

Spectrum of a Signal

In chapter 2 of Oppenheim and Schaefer [1], we learned how to express a signal in the frequency

domain using the Fourier Transform for Discrete Signals. The transform takes the

following form

J�TUV� = � �[�]T'UV3&

3 '&

This is a transform that must be done on pencil and paper. In class, we learned of the Discrete

Fourier Transform (DFT) which is similar to the above but can be done on a digital computer.

The DFT is normally defined as

J��� = � �[�]u�3�'�

3 �

Page 19: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

for � = 0, … , � − 1, where u� ≜ T'Uwxy

In class, we learned some of the differences between the Discrete-Time Fourier Transform

(DTFT) and the DFT. We also learned that Fast Fourier Transform (FFT) is a method of

evaluating the DFT that is computationally more efficient. MATLAB command fft will

evaluate the DFT using an efficient FFT algorithm.

Problem 1. Look in the folder “Data_for_Lab3” and look at the READ ME file. Read

this file carefully. It will tell you the names of several signals, names of the

corresponding corrupted signals and a short description of each of the signals. Now, take

the spectrum of each of the signals and their corruption. Plot the signals in the time

domain and provide sketches of them in the frequency domain. Describe qualitatively

what you see in the plots.

Objective Quality Measurement

The corrupted signals are degraded versions of the originals. We would like to quantify how

much corruption has taken place. A common measure of degradation is Mean Squared Error

(MSE). If we have a signal x[n] and the same signal corrupted by some way called xz{||}~�[n], each of length N, then the following is the MSE

GHI = 1����[�] − ���EE���[�]���

3 �

Problem 2. Write a MATLAB code to determine the MSE for each of the signal pairs

that you read about in the README file and obtain the MSE’s. Give these results in your

write-up.

Signal Restoration

“Signal Restoration” usually refers to the enhancement or improvement of signals that have been

degraded in some way.

15

Page 20: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Problem 3. For each of the two signal pairs given, try to recover the signal by designing

an LTI filter using MATLAB tools as discussed in the class. Your LTI filter will take the

corrupted signal as input. The output should be as close to the original signal as possible.

Use MSE as a quality measure for this task and state the MSE that you were able to obtain

with your filter. Give the details of your approach in designing the filter and the designed

filer itself. Use the following

• Limit your filter to an FIR filter of length 20.

• Design your system using an FIR filter of length 50.

• Design your system using an IIR filter of order 20.

• Design your system using an IIR filter of order 50.

• Design your system using any kind of processing you like (not necessarily LTI). Your

only restriction is that the only input is the corrupted signal.

NOTE: the MSE values that you obtained will be used to grade this lab. Be sure to give all your

MSE values.

Sampling Issues

Signals bearing information may be available in either analog or discrete forms. An analog signal

is one in which both the amplitude and time vary continuously in the prescribed intervals,

respectively. Speech signals or the electrical activity of the brain (EEG) are examples of such

signals. Conversely, a discrete signal takes on digital values of the amplitude and time. Examples

of which are computer data and telegraph signals.

A discrete signal can always be generated from an analog signal by the Analog to Digital (A/D)

conversion. The operations involved in such a conversion are anti-alias filtering, sampling and

quantization, as depicted in Figure 3.

Figure 3: Analog to Digital Conversion.

Page 21: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

The key operation involved in the (A/D) process is sampling and is provided by what is known

as the Sampling Theorem. It is this topic that we will explore in this section.

In the ideal sampling operation, only exact values of the continuous signal at uniformly spaced

discrete intervals (�a�, where a� denotes the sampling period) are retained. A sampled signal can

be generated by using a method referred to as sampling by modulation as shown in Figure 4.

The modulator scheme uses a train of impulses as the carrier, ���� ���� = � #�� − �a��

&

3 '&

The sampled signal ����� (where the subscript “s” refers to sampled) can now be represented as

����� = �������� = ���� � #�� − �a��&

3 '&

Taking the Fourier Transform (DTFT) of ����� we obtain

J���� = ℱ ����� � #�� − �a��&

3 '&�

= 12; ℱ[����] ∗ ℱ � � #�� − �a��&

3 '&�

= 12; J��� ∗ �� � #�� − ����&

3 '&

with ∗ denoting the convolution operator and �� = �@�� is the sampling frequency. By further

manipulations, we obtain

J���� = 1a� J��� ∗ � #�� − ����&

3 '&= 1a� � J�� − ����

&

3 '&

The above analysis demonstrates how the spectrum in ideal sampling can be achieved. It also

shows that the FT of the sampled signal is periodic in frequency domain with period ��.

Page 22: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 4: Ideal Sampling by Modulation.

Sampling Theorem

In this section, one version of the sampling theorem is discussed in which aliasing is avoided

when all frequency components of a continuous-time signal are band-limited to ����. From the

FT of the ideally sampled signal ����, it is evident that as the sampling period a� is decreased

(�� increases), all replicas of J��� move farther apart (see Figure 5 the middle). On the other

hand, if a� increases (�� decreases), the replicas of J��� move closer together. As a� is

continually increased, a point will be reached where the replicas will begin to overlap as shown

in Figure 5 bottom. This overlap of the frequency spectrum is known as aliasing or folding. The

maximum sampling period (equivalent to minimum sampling frequency) at which there is no

aliasing is attained when

�� = 2���� �S�� = ��2; = 2����

Page 23: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 5: Fourier Transform of continuous time and the sampled signal.

where ���� or ���� is the highest frequency component in ����. In the communications

literature, ���� or ���� is called the Nyquist frequency and �� = 2���� or �� = 2���� is

called the Nyquist rate.

Assuming ideal sampling, the ideal low-pass reconstruction can be stated as follows.

Let ���� denote a continuous-time signal with Fourier Transform J��� such that

J��� = 0��S���� < |�| i.e. the Nyquist bandwidth of ���� is equal to ����.

Then ���� can be expressed (reconstructed) exactly in terms of its samples ���a�� as

���� = � ���a�� �sin������ − �a�������� − �a�� �&

3 '&

where the sampling period a� must meet the Nyquist criterion as

2;a� = �� = 2;�� > 2����

Page 24: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Reconstruction

The lowpass version of the sampling theorem provides insight into the way a discrete-time signal

can be reconstructed back into a continuous-time form. We note that in the above continuous-

time signal representation, the discrete-time samples implied by

����� = � (�����#�� − �a��&

3 '&

are convolved with an ideal lowpass filter specified by its impulse response

ℎ���������� = sin�0.5����0.5���

In practice, the conversion of a sampled signal to a continuous-time form, referred to as the

digital to analog (D/A) operation, involves two parts, namely a hold operation followed by

lowpass filtering.

The most common form of hold operation is the zero-order hold or sample and hold. The

impulse response for the sample and hold device is given by

ℎ������� = �1, 0 ≤ � < a�0, ��ℎTS���T^ The operation of the sample and hold is illustrated in Figure 6. Note that the lowpass filter

operation which follows the sample and hold removes the higher order spectral components of

the spectrum which are the replicas of the baseband signal spectrum.

Page 25: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 6: Reconstruction of a continuous time signal.

Problem 1. Consider a sinusoidal signal

���� = sin ��� where �� = 10;S�C/�T�.

1. Using a sampling rate 20 times the Nyquist rate, simulate the continuous-time signal

����. Using the MATLAB plot routine, generate the graph over the time interval

0 ≤ � ≤ 1 seconds. Ensure that the graph has proper time scale.

2. Sample ���� at the Nyquist rate and overlay the resulting sequence on the above graph

using the MATLAB stem routine. See also hold and axis routines to do this.

[The sampled sequence �[�] above can be generated by using the functions exp2_pl,

which has been generated for this experiment. For example, given the sampling rate �� and

the length of the time interval a� = 1 seconds, the sampled sequence �[�] can be generated

as [t,x]=exp2_pl(fs,T

f) where t is a time vector representing the sampling instants

and x is the sampled sequence �[�]]. Problem 2. The signal of interest is

���� = 12 sin�14;�� + 13 sin�18;�� + 15 sin�24;�� + 17 sin�30;�� 1. Theoretically calculate the two-sided FT of ����.

Page 26: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

2. Sample ���� on the interval 0 ≤ � ≤ 20 at 20 times the Nyquist rate. Evaluate its two-

sided spectrum using discrete Fourier Transform (DFT). The details of this will be

discussed in the future experiments. Here, we are only concerned with using the

transform to derive the spectrum.

The DFT is performed in MATLAB by using the routine fft. The output of the transform,

which we denote by J is a complex sequence of length N samples representing the phase and

magnitude information contained in the spectrum. The important point to note here is that the

samples of the DFT spectrum are spaced in normalized frequency by

[ = 2;�� ��S� = 0, 1, … ,� − 1

This means that the spectral width (frequency separation) of each DFT sample is

2;� S�C/�T� in normalized frequency, implying that a sinusoid with normalized frequency [� = V

��/� will

appear in the DFT spectrum at the ��� DFT sample (bin) if [ ≤ [� < [ �. Normalized

frequency can be changed to the absolute scale frequency by multiplying it by the sampling rate

to obtain a scheme for the signal DTFT.

[Use the MATLAB function named, exp2_p2 that has been written to give the required

sequence directly, e.g. [F,Y]=exp2_p2(fs,T

f) where Y is the DFT of ���� sampled at the

rate �� over the interval 0 ≤ � ≤ a� and F is the vector containing frequency spacing of the

spectrum in Y].

3. Plot the two-sided spectrum evaluated in (2) using the MATLAB stem routine.

4. Repeat 2 and 3 with the following sampling frequencies:

a. 3/2 time the Nyquist rate

b. 5/6 times the Nyquist rate

c. 13/30 times the Nyquist rate

Plot all graphs with the same axes.

Page 27: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Question 1. Explain the differences in signals spectra in case of meeting Nyquist criterion

(no aliasing) and violating it (having aliasing). Why the resulting frequency components

exist in the observed locations? What are these frequency locations? (Use the frequency

folding or aliasing around � = ��/2)

Question 2. Given that the sampling rate for ���� is fixed to be 20Hz, how would it be

possible to ensure that the spectrum of the sampled signal �[�] for the frequencies

0 ≤ � ≤ 10 is a true representation. Draw a block diagram of the procedure to meet such

an objective.

Page 28: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Lab 4: Multirate Digital

Signal Processing

Objective

In this lab experiment, you will learn how to use MATLAB to implement sampling rate

conversion and multirate signal processing systems.

Introduction

A multirate Digital Signal Processing (DSP) system is characterized by the use of multiple

sampling rates in its realization. That is, signal samples at various points in the systems may not

correspond to the same physical sampling frequency. Some applications of multi-rate processing

include

• Sampling rate conversion between different digital audio standards

• Digital anti-aliasing filtering (used in commercial CD players)

• Sub-band coding of speech and video signals

In some applications, the need for multi-rate processing comes naturally from the problem

definition (e.g. sampling rate conversion). In other applications, multi-rate processing is used to

achieve improved performance of a DSP function (e.g. lower binary rate in speech compression).

In our previous experiments, we have assumed that all signals in a given system have the same

sampling rate. We have interpreted the time index � as an indicator of the physical time�a,

where a is the sampling interval. In many practical applications of DSP, one is faced with the

problem of changing the sampling rate of a signal, either increasing it or decreasing it by some

ratio. For example, in telecommunication systems that transmit and receive different types of

Page 29: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

signals (e.g. speech, video, etc.), there is a requirement to process the various signals at different

rates commensurate with the corresponding bandwidths of the signals. The process of converting

a signal from a given rate to a different rate is called sampling rate conversion. In turn, systems

that employ multiple sampling rates in the processing of digital signals are called multirate

digital signal processing systems.

Fundamental Multirate Operations

The two basic operations in a multirate system are decreasing and increasing the sampling rate of

a signal. The former is called decimation or down-sampling. The latter is called interpolation or

up-sampling.

Downsampling and Decimation

Downsampling can be considered as the discrete-time counterpart of sampling. Whereas in

sampling we start with a continuous-time signal ����and convert it to a sequence of

samples�[�], in downsampling we start with a discrete-time signal �[�] and convert it to

another discrete-time signal�¡[�], which consists of subsamples of�[�]. Thus, the formal

definition of M-fold downsampling is

�¡[�] = �[G�] where G is a positive integer. The block diagram representation of the downsampler is shown in

Figure 7.

Figure 7: Down-sampler by integer factor M.

Where the output sequence �¡[�] is sampled at sampling rate equal to �1/G�th of the sampling

rate of input sequence�[�]. The downsampler can be implemented by keeping all the input

samples that have indices equal to an integer multiple of G.

Page 30: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Example 1. Downsampling by integer factor 2, G = 2.

Figure 8: Down-sampling by integer factor G = 2.

Note that the samples corresponding to � = 1, 3, 5, 7, 9 are lost by downsampling.

The frequency domain relation between the input �[�] and the output �¡[�] of a downsampler is

given by

R¡�TUV� = 1G�J�

h �/TU?V'�@h� B0

as we see, the output discrete Fourier transform R¡�TUV� can be viewed as G copies of the

periodic discrete Fourier transform of J�TUV� frequency scaled by factor G and shifted by

Page 31: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

integer multiple of 2;. For more detail about how the frequency domain relation between

R¡�TUV� and J�TUV� is derived read section 4.6 from [1].

Since downsampling operation, like sampling, leads to potential aliasing, it is desirable to

precede the downsampler with an anti-aliasing filter. Unlike sampling, here the input signal is

already in discrete time, so we use a digital anti-aliasing filter. The anti-aliasing filter, also

called the decimation filter, should approximate an ideal low-pass filter with cut-off

frequency;/G, as shown in Figure 9. The combination of the lowpass filter followed by a

downsampler is called decimation.

Figure 9: A general decimation system, lowpass filter has gain equal to 1 and cut-off frequency ;/G

combined with down-sampler by integer factor M.

Upsampling and Interpolation

Upsampling is another operation on a discrete-time signal that yields a discrete-time signal. It is

related to reconstruction of a discrete-time signal, similar to interpolation that yields a

continuous-time signal. However, the relation is less obvious than in the case of sampling and

decimation. The mathematical definition of L-fold upsampling, where L is a positive integer, is

�£[�] = ��[�/¤], � = 0,±¤,±2¤0,otherwise ̂The block diagram representation of an upsampler with upsampling factor of ¤ is shown in

Figure 10.

Page 32: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 10: Upsampler by integer factor L.

Upsampling (expanding) is an information-preserving operation, i.e. all samples of �[�] are

present in the expanded signal�£[�]. The samples of the upsampled signal appear at a rate faster

than that of the original signal by a factor¤. That means �[�] can always be recovered

from�£[�] and no loss of information or aliasing happens.

Example 2. Up-sampling by integer factor ¤ = 2

Page 33: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 11: Up-sampling by integer factor ¤ = 2.

The frequency-domain relation between the input �[�] and the output �£[�] of the upsampler is

given by

R£�TUV� = J�TUV«� As we see, the shape of the discrete-time Fourier transform (DTFT) of the output signal

R£�TUV�is constructed by scaling (compressing) the frequency axis by factor¤. It is actually a

copy of the input spectrumJ�TUV� being repeated ¤ times in the range[ ∈ [−;, ;]. Thus, it

should be noted that the shape of the discrete-time Fourier transform of the input signal J�TUV� is preserved confirming our conclusion that upsampling does not lead to aliasing. For more

Page 34: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

details about how the frequency domain relation between R¡�TUV� and J�TUV� is derived, refer

to section 4.6 from [1] [2].

Upsampling does not result in aliasing, but it yields undesired replicas of the signal's spectrum in

the range[ ∈ [−;, ;]. These replicas can be eliminated by a digital lowpass filter with cutoff

frequency [� = ;/¤ and gain equal to ¤ following the upsampler, as shown in Figure 12.

Figure 12 Interpolation, up-sampler with integer factor L combined with low-pass filter.

The combination of upsampler followed by lowpass filtering is called interpolation and the

lowpass filter is called an interpolation filter or an anti-imaging filter. Whereas downsampling

may or may not be preceded by a decimation filter, upsampler is almost always followed by an

interpolation filter, because without such a filter, the upsampled signal has little use.

It should be noted that the upsampler and downsampler operations are linear but time-varying

(not time-invariant) discrete-time systems. The upsampler and the downsampler building blocks

shown in Figure 7 and Figure 10 are often involved in multirate signal processing.

Sampling Rate Conversion

A common use of multirate signal processing is for sampling rate conversion. Suppose we are

given a digital signal �[�] sampled at interval a� and we wish to obtain from it a signal

�[�]sampled at interval a�. The techniques of decimation and interpolation enable this

operation, provided the ratio a�/a�is a rational number say¤/G. We distinguish now between

two possibilities:

Page 35: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

1) a� > a�, meaning that the sampling rate should be increased. This is always possible

without aliasing.

2) a� < a�, meaning that the sampling rate should be decreased. This is possible without

aliasing only if �[�] is band limited to a frequency range not higher than ±;�a�/a��. If �[�] does not fulfill this condition, a part of its frequency contents must be eliminated

before decimation to avoid aliasing.

Sampling-rate conversion can be accomplished by upsampling by factor¤ followed by lowpass

filtering and down-sampling by factor G as it is observed in Figure 13. The lowpass filter

performs both interpolation of the upsampled signal and anti-aliasing. If the sampling rate is to

be increased, then we have ¤ > G. The lowpass filter should then have a cutoff frequency;/¤.

If the sampling rate is to be decreased, then we have ¤ < G. The lowpass filter should then

have a cutoff frequency ;/G. In this case, the filter will eliminate a part of the signal's frequency

contents if its original bandwidth is higher than ;�¤/G�. Thus, the sampling-rate conversion

filter should always have a cutoff frequency ;/max{¤,G}. This configuration is shown in

Figure 13.

Figure 13: System for changing the sampling rate by a non-integer factor with

combined interpolation and decimation filters.

Linear filtering with decimation, interpolation, and sampling-rate conversion allows potential

computational savings. However, it is not always obvious how to take advantage of this potential

saving. “Polyphase filters” is a name given to certain realizations of multirate filtering operations

which facilitate computational savings in both software and hardware implementations. It should

be noted that polyphase implementations are useful for FIR filters, but not for IIR ones [1].

Page 36: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Pre-lab

Question 1. The discrete-time Fourier transform for signals��[�], ��[�] and �2[�] is shown

in Figure 14 (a), (b) and (c) respectively. Use ��[�] as input to the systems (a), (b), (c),

(d) and (e) shown in Figure 15 and plot the discrete Fourier transform of the outputs �[�] (and F[�] if exist) over the range −2; ≤ [ ≤ 2;. Repeat this for ��[�] and �2[�].

(a)

(b)

(c)

Figure 14: Discrete Fourier transform of signals��[�], ��[�] and �2[�].

ω ;2 −;2

1

−2; 2; ;

gJ1�TZω�g

−; 0

ω ;4 −;4

1

−2; 2; ;

gJ2�TZω�g

−; 0

ω ;8 −;8

1

−2; 2; ;

gJ3�TZω�g

−;

Page 37: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 15: Down-sampler, decimation system, up-sampler, interpolation system and a rate-conversion system.

Question 2. Consider the analysis-synthesis system shown in Figure 16. The lowpass filter

ℎ«[�] and the highpass filter ℎ¯[�] are identical in the analyzer and synthesizer parts.

The Fourier transforms of ℎ«[�] and ℎ¯[�] are related byX¯�TUV� = X«�TU�V @��. Write a general expression for R�TUV� in term of J�TUV�,X«�TUV� and X¯�TUV�.

Figure 16: An analysis-synthesis system.

Page 38: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Note: The following MATLAB commands you may need to answer the lab problems. It is

recommended to read MATLAB help about them.

Elementary Matrices and Matrix Manipulation: i, ones, pi, zeros, ones.

Two-Dimensional Graphics: axis, grid, legend, plot, subplot, stem,

title, xlabel, ylabel.

Elementary Functions: cos, sin, exp, imag, real, sinc, fir2, fir1, freqz

Multirate Signal Processing: decimate, downsample, interp, upsample

Page 39: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Lab problems

Create a script file for each question and include your name and ID as comments in the script

file. Submit as part of the lab report the script file and any required plots. It is suggested to save

the script files under meaningful names such as LAB4_P_1.m.

Problem 1.

(a) Write a MATLAB script to generate the signals��[�], ��[�] and �2[�] that have the

discrete Fourier transform shown in Figure 14 (a), (b) and (c) respectively. Make sure that

each signal has length of 1025 samples. Plot the resulting discrete Fourier transform over

the range −1 ≤ � ≤ 1 as shown in Figure 17.

Hint: You can use either sinc or fir2 MATLAB commands to solve the problem.

Figure 17: The magnitude of the discrete Fourier transform of ��[�], ��[�] and �2[�] in MATLAB.

Page 40: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

(b) Write a MATLAB function that returns coefficients (impulse response) of a general FIR

lowpass filter. The function must accept as input the number of coefficients, gain and

cutoff frequency. For example

function [h_n]=My_Lowpass_Filter(Num_Coeff,Gain_val,cutoff_freq)

Based on the above, do the following.

(1) Design a lowpass FIR filter having 128 coefficients, gain equal to 1 and a cutoff

frequency ofωz = π/3.

(2) Design a lowpass FIR filter having 128 coefficients, gain equal to 3 and a cutoff

frequency ofωz = π/3.

Plot the magnitude and the phase of the designed filters over the range −2; ≤ [ ≤ 2; on the

same figure. Adjust the title, xlabel and ylabel accordingly.

Hint: You can use the function fir1 command.

(c) Use ��[�] of part (a) as the input to the systems (a), (b), (c), (d), and (e) shown in Figure

15 and write a MATLAB script to generate the output �[�] (and F[�] if exists) for each

system. Plot the discrete Fourier transform of the input signal ��[�] and the output

signal�[�] (and F[�] if exists) on same figure using “subplot” command for each system.

Adjust the title, xlabel and ylabel for each figure accordingly.

Hint: You may find it useful to plot discrete Fourier transform over the range −4; ≤ [ ≤4;. The discrete Fourier transform of the output signals for each system shown in Figure 15

using ��[�] as the input signal are shown in Figure 18.

(d) Repeat part c for ��[�] and �2[�].

Page 41: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

Figure 18: The magnitude of the discrete Fourier transform of the input signal ��[�] and the output signals �[�] of

the five systems shown in Figure 15 plotted over the range −4; ≤ [ ≤ 4; generated using MATLAB.

Problem 2. In this problem, you will implement the system shown in Figure 16. Let �[�] =����a��, where the continuous time signal ����� is given by

����� = °[cos�Ω��� + cos�Ω��� + cos�Ω2�� + cos�Ωo��] withΩ� = 1.2; × 102S�C/�T�, Ω� = 2.4; × 102S�C/�T�, Ω2 = 3.6; × 102S�C/�T�, Ωo = 4.8; × 102S�C/�T� and the sampling frequency is�� = 1/a� = 6 × 102XK.

Write a MATLAB code to

Page 42: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

(a) Compute �[�] = ����a�� for 0 ≤ � ≤ 6000, and to compute the discrete Fourier

transform J�TUV� for −2; ≤ [ ≤ 2;. Plot �[�] over the range 0 ≤ � ≤ 200 and plot

gJ�TUV�g over the range−2; ≤ [ ≤ 2; using the “subplot” command.

(b)

I. Design a lowpass filterℎ«[�], FIR filter having 129 coefficients, gain equal to 1 and a

cutoff frequency ofωz = π/2.

II. Design a highpass filterℎ¯[�], FIR filter such that the Fourier transforms of ℎ«[�]and

ℎ¯[�] are related byX¯�TUV� = X«�TU�V @��. III. Plot the magnitude of both X«�TUV�and X¯�TUV� over the range−2; ≤ [ ≤ 2;.

Adjust the title, xlabel and ylabel accordingly and use the “subplot” command.

(c)

I. Compute and plot the magnitude of´«�TUV� and ´¯�TUV� over the range −4; ≤[ ≤ 4; on the same figure using the “subplot” command.

II. Compute and plot the magnitude of µ«�TUV� and µ̄ �TUV� over the range −4; ≤ [ ≤4; on the same figure using the “subplot” command.

III. Compute and plot the magnitude of R«�TUV� and R̄ �TUV� over the range −2; ≤[ ≤ 2; on the same figure using the “subplot” command.

IV. Plot the magnitude of J�TUV�and R�TUV� over the range −2; ≤ [ ≤ 2; on the

same figure using the “subplot” command.

(d) Determine whether the aliasing phenomenon occurred or not in the above system

implementation and discuss its impacts on the output single�[�].

Page 43: DSP Lab Manual - Concordia Universityusers.encs.concordia.ca/~weiping/ELEC442-F12... · Lab 1: Linear Constant Coefficient Difference Equations (LCCDE) Objective In this experiment,

References

[1] A. Oppenheim and R. Schafer, Discrete-Time Signal Processing, 2nd ed. Englewood Cliffs,

NJ: Prentice-Hall, 1989.

[2] Signals and Systems, 2nd ed. , A.V. Oppenheim and A.S Willsky, Prentice-Hall, ISBN 0-13-

814757-4, 1997.