You are on page 1of 52

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

SEVENTH SEMESTER

DIGITAL SIGNAL PROCESSING

COMPUTER SIMULATION LAB DEPARTMENT OF ELECTRICAL ENGINEERING

Prepared By:

Checked By:

Approved By:

Engr. Amir Ijaz


Lecturer (Lab) Electrical, FUUAST-Islamabad

Engr. M.Nasim Khan


Senior Lab Engineer Electrical, FUUAST-Islamabad

Dr.Noman Jafri
Dean, FUUAST-Islamabad

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Name: ____________________________________________ Registration No: ____________________________________ Roll No: ___________________________________________ Semester: _________________________________________ Batch: ____________________________________________

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

CONTENTS CONTENTS

Exp No

List of Experiments

1 2 3 4 5 6 7 8 9 10 11 12

Introduction to MATLAB

Basic sequences Basic operations on basic function Discrete Time Fourier Transform Discrete-Time Fourier Transform and Z-transform Rational Z-transform, Inverse Z-transform Frequency response of LTI systems Frequency response for rational system function Frequency response of all-pass system function Term Project Sampling and aliasing, Discrete Fourier Transform IIR and window based FIR filter design

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Software Requirements
S.No. 1 Software Title Matlab Description It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO - 1
Lab Title: INTRODUCTION TO MATLAB. Lab Objective: Familarize with the coding style in MATLAB.
The tasks given in the lab include, 1 2 3 4 Write a program to generate a matrix. Solve linear system of equation. Compute determinent of matrix. Extract matrix from the given matrix.

Tool used: MATLAB Lab Tasks:


Task#1: Write a program to generate a 6x6 matrix A Task#2: Generate a 6x1 matrix z Task#3: Solve linear system of equations Ax=z. Task#4: Compute determinant of matrix A. Task#5: Extract a 4x4 matrix from the 6x6 matrix and 4x1 matrixes from 6x1

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 2
Lab Title: BASIC SEQUENCES. Lab Objective: Generating basic sequences in MATLAB.
The tasks given in the lab include,

.
Generate Generate Generate Generate Generate Generate Generate Generate Tool used: MATLAB Delta (Impulse) Function. Unit Step Function. Unit Ramp Function. Exponential Function sinusoidal function. unit imuplse delay(shift) function. unit step delay(shift) function. unit ramp delay(shift) function.

Lab Description:
is defined by

The Unit Delata(Impulse) function: The unit sample, denoted by S(n),

and plays the same role in discrete-time signal processing that the unit impulse plays in continuous-time signal processing.

The Unit step function: The unit step, denoted by u(n), is defined by

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

and is related to the unit sample by

The Unit Ramp Function:

The Exponential Function: Finally, an exponential sequence is defined


by

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

where a may be a real or complex number. Of particular interest is the exponential sequence that is formed when

The sinusoidal function:

Lab Tasks:
Task#1: Write a Matlab code that generate Delta (Impulse) Function. Task#2: Write a Matlab code that generate Unit Step Function. Task#3: Write a Matlab code that generate Unit Ramp Function. Task#4: Write a Matlab code that generate Exponential Function. Task#5: Write a Matlab code that generate sinusoidal Function. Task#6: Write a Matlab code that generate Unit Impulse delay (shift) function. Task#7: Write a Matlab code that generate Unit Step delay (shift) function. Task#8: Write a Matlab code that generate Unit Ramp delay (shift) function.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 3
Lab Title: BASIC OPERATIONS ON BASIC FUNCTION. Lab Objective: Graphical views of different arithmetic operations on basic functions(impulse,unit step etc)
The tasks given in the lab include,

.
5 6 7 8 Summing unit step and unit ramp function. Subtracting unit step and unit ramp function. Multiplication of the unit step and unit ramp function. Division of unit step and unit ramp function.

Tool used: MATLAB Lab Tasks:

Task#1: Write a Matlab code to sum unit step and unit ramp function that generate
Delta (Impulse) Function.

Task#2: Write a Matlab code to suctract Subtracting unit step and unit ramp
function.

Task#3: Write a Matlab code to multiply unit step and unit ramp function. Task#4: Write a Matlab code to divide unit step and unit ramp function.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 4
Lab Title: DISCRETE TIME FOURIER TRANSFORM. Lab Objective: Evaluating the magnitude and phase response ,real and imaginary plots from the given system function and observe the basic filtering effect.
The tasks given in the lab include, Plot the real and imaginary parts,magnitude and phase spectrum of the system function by using cofficients. Plot the real and imaginary parts,magnitude and phase spectrum of the system function by implementing system function function. Observe the time shifting property of DTFT. Observe the filtering effect by passing the sinusoid through the low pass filter.

Tool used: MATLAB Lab Description:


Eigenfunctions of linear shift-invariant systems are sequences that, when input to the system, pass through with only a change in (complex) amplitude. That is to say, if the input is x(n), the output is y(n) = kx(n), where A, the eigenvalue, generally depends on the input x(n).

Frequency response:

Signals of the form

where w is a constant, are eigenfunctions of LSI systems. This may be shown from the convolution sum:

Thus, the eigenvalue, which we denote by H (elw), is

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Has a frequency-response that is independent of w. This can be seen by writing Hap(ejw) in the form, Note that H(eJw) is, in general, complex-valued and depends on the frequency w of the complex exponential.Thus, it may be written in terms of its real and imaginary parts.

Real and imaginary parts of DTFT:

Magnitude and phase response of DTFT:

The magnitude and phase response of DTFT be,

Where

and

Graphical representations of the frequency response are of great value in the analysis of LSI systems, and plots of the magnitude and phase are commonly used. However, another useful graphical representation is a plot of 20 log1 H(eJ")I versus o. The units on the log magnitude scale are decibels (abbreviated dB). Thus, 0 dB corresponds to a value of 1H(ejW)l = 1,20dB is equivalent to 1H(ejw)l = 10, -20dB is equivalent to IH(ejU)l = 0.1, and so on. It is also useful to note that 6 dB corresponds approximately to I H (eJ")( = 2, and -6 dB is approximately I H(eJW)l = 0.5. One of the advantages of a log magnitude plot is that, because the logarithm expands the scale for small values of (H(ej")(, it is useful in displaying the fine detail of the frequency response near zero. If x[n] be the sequence ,and X(ejw) be its fourier transform then, x[n] ----F----- X(ejw) then, for the time-shifted sequences, a simple transformation of the index of summation in the discrete-time Fourier transform yields x[n-nd] ----F----- e-jwndX(ejw)

Time-shifting property of DTFT:

Critical Evaluation : The following observation are critcal regarding time shifting, Magnitude Response: The magnitude response of e-jwndX(ejw) is the same as that of X(ejw) because magnitude of e-jwnd is unity. Phase Response: The phase response of e-jwndX(ejw) is not same as that of X(ejw)
because the exponential term contribute to the phase .

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Low pass filter is obtained by taking the fourier transform of damped sinusoid i-e;damped sinusoid. W/sinc(Wt) -f- rect(w/2W) Rect is the rectangular function of w with cut-off W.

Low-pass filter:

In frequency domain passing sinusoid to the filter is just the multipication of fourier transform of filter and sinusoidal. Y(ejw) =G(ejw)H(ejw) jw Where G(e ) is the fourier transform of input sinusoid and H(ejw) is the fourier transform of filter.

Passing sinusoid through low-pass filter:

Lab Tasks:
Task#1: Evaluate the DTFT of the given cofficients. Num=[2 1] Den=[1 0.6] Plot real and imaginary parts of fourier spectrum. Also plot the magnitude and phase spectrum. Task#2: Observe the time-shifting property of DTFT.
Plot and compare the magnitude spectrum of the original input with time delayed input. Plot and compare the phase spectrum of the original input with delayed input.

Task#3: Pass a sinusoid through a low-pass filter with a cut-off W=0.25.


Order of filter should be 13 for good results. Vary the w0 of the sinusoid and notice the effect of filtering. The analysis must be done in frequency domain.

Task#4: Given below is the frequency response of the system,

H(ejw) = 1+e-jw 1-e-jw+0.9e-j2w a) Write a MATLAB code that manually implements the above system. b) Compare with the spectrum obtained from freqz command Plot the magnitude and frequency spectrum. Also plot real and imaginary plots

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 5
Lab Title: DISCRETE-TIME FOURIER TRANSFORM AND Z-TRANSFORM
fourier

Lab Objective:

Verification of general properties of DTFT of sequences in

domain and famililarize with Z-transform The tasks given in lab include: Verification of Frequency shifting property Verification of Time reversal property Verification of Convolution property Plotting poles and zeros of transfer function in z-domain.

Tools used:
MATLAB

Frequency Shifting Property: If x[n] be the sequence ,and X(ejw) be its fourier transform then, x[n] ----F----- X(ejw) If the sequence x[n] be multiplied by the exponential term ejw0n then the fourier transform of the resulting sequence be X(ej(w-w0)), ----F----- X(ej(w-w0)) ejw0n (x[n]) Critical Evaluation : The following observation are critcal regarding frequency shifting, Magnitude Response: The magnitude response of X(ej(w-w0)) is only the frequency jw shifted version of X(e ) i-e;shifted at w0.The peak-to-peak magnitude of X(ej(ww0) ) is similar to that of X(ejw). Phase Response: The phase response of X(ej(w-w0)) is also shifted version of jw X(e ). Usage: We can use frequency shifting property of DTFT for converting a low pass filter to high pass Time Reversal Property: If x[n] be the sequence , and X(ejw) be its fourier transform then, x[n] ----F----- X(ejw) then if the sequence is reversed in time i-e;x[-n],then its fourier transform be, x[-n] ----F----- X(e-jw) x[-n] is only the mirror image of x[n]. Critical Evaluation : The following observation are critcal regarding time reversal, Magnitude Response: The magnitude response of X(e-jw) is similar to that of X(ejw) because negative sign in the exponential term contribute only to phase change but not magnitude. Phase Response:

Lab Description:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

The phase response of X(e-jw) is inverted to that of X(ejw) because there is a negative sign in the exponential which contribute to the phase shift of 180o. Convolution Property:

Critical Evaluation : Convolution in time domain is a much tedious operation by flipping the sequence again and again. But convolution in frequency domain is simply the product of fourier transform of input sequence X(ejw) and impulse response H(ejw) . Plotting poles and zeros of transfer function in z-domain: Why we need z-transform? DTFT doesn't converge for all sequences, it I useful to have a generalization of DTFT that covers a broad class of signals In analytical problem the z-transform notation is often more convenient than the DTFT notation Z-tf is equivalent to Laplace transform for continuous time

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

ROC and Fourier transform:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Poles

Roc: ROC of the power series of z-transform consists of all values of z such that this inequality holds Thus if some values of z, say z=z1 is in the ROC then all values of z on the circle defined by |z|=|z1| will also be in the ROC ROC will consist of a ring in the z-plane centered about the origin

and Zeros: If X(z) is rational i.e. X(z)=P(z)/Q(z) Values of z for which X(z)=0 are zeros of X(z) Values of z for which X(z) is infinite are called poles of X(z) Roots of denominator polynomial

Lab Task:
of DTFT 1: Convert a low pass filter to high pass by using Frequency shifting property ejn (hlp[n]) --------Hlp(w- )

2: Verify the time reversal property of DTFT 3: Verify the convolution property of DTFT 4: Plot the pole zero plot of the system given below X(z)= z2 z -3/4z+1/8
2

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 6
Lab Title: RATIONAL Z-TRANSFORM, INVERSE Z-TRANSFORM Lab Objective: Helps in evaluating the higher order Z-transform transfer function The tasks given in lab include: Converting Rational Z-transform to factored Z-transform. Converting factored Z-transform to rational Z-transform Converting Rational Z-transform to partial fraction form. Converting partial fraction form to Z-transform. Evaluating coefficients of the inverse Z-transform. Tools used:
MATLAB

Lab Description:

Example: Let the given transfer function be in the rational form, 2z4+16z3+44z2+56z+32 G(z)= -------------------------------3z4+3z3-15z2+18z-12 It is required to convert it into factored form, so that we can find the poles and zeros mathematically by applying quadretic equation. Matlab command required for converting rational form to factored form be Zp2sos The factored form of G(z) as evaluated by zp2sos be, G(z)=( 0.6667 + 0.4z-1 + 0.5333 z-2) (1.000 + 2.000 z-1 +2.000 z-2) (1.000 + 2.000z-1 -4.000z-2 )(1.000 - 1.000 z-1 + 1.000 z-2) Usage: We can use this technique when the order of transfer function is greater than 3.

Rational Z-transform to factored Z-transform:

It is the inverse of the above case, when the transfer function is given in factored form and it is required to convert in rational form then a single matlab command can serve the purpose. Example: Lets use the above result i-e;transfer function in factored for, G(z)=( 0.6667 + 0.4z-1 + 0.5333 z-2) (1.000 + 2.000 z-1 +2.000 z-2) (1.000 + 2.000z-1 -4.000z-2 )(1.000 - 1.000 z-1 + 1.000 z-2) For building up transfer function in rational form we find the poles and zers of above system simply by using matlab root command or by hand. Or simply we have poles and zeros of the given system we can find the transfer function in factored form. Matlab command that converts poles and zeros of the system in to transfer function is zp2tf .

Factored Z-transform / zeros,poles to rational Z-transform:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Usage: We used this technique typically when we have by some way the poles and zeros of some system, we can extract transfer function from it.

This technique is usually used , while taking the inverse Z-transform and when the order H(z) is high so that it is quite difficult to solve it mathematically. Example: Consider the transfer function in the rational form i-e; 18z3 G(z)= -----------------18z3+3z2-4z-1 We can evaluate the partial fraction form of the above system using matlab command. The partial fraction form be, G(z)= 0.36__ + __0.24__ + _0.4____ (1+0.33 z-1) 1 0.5z-1 1+0.33 z-1 Matlab command that converts rational z-transform in to partial fraction form is residuez. Usage: We use this technique especially for evaluating the inverse Z-transform of higher order transfer function. Partial fraction form to Z-transform: This technique is used when it is required to convert partial fraction expression in to rational Z-transform. Example: Take the partial fraction form of above , The partial fraction form be, G(z)= 0.36__ + __0.24__ + _0.4____ (1+0.33 z-1) 1 0.5z-1 1+0.33 z-1 Matlab command that converts partial fraction form into rational z-transform is residuez

Rational Z-transform to partial fraction form.

For causal sequences ,the z-transform X(z) can be expanded in to a power series in z-1.In series expansion, the coefficients multiplying the term z-n is the nth sample x[n].For a rational X(z) a convenient way to determine the power series is to express the numerator and denominator as polynomial in z-1 and then obtain the power expansion by long division.

Evaluating coefficients of the inverse Z-transform:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Example:

Matlab commands used for evaluating the coefficients of inverse Z-transform be impz and filter Usage: It is used for evaluating the coefficients of inverse Z-transform ,which is mathematically obtained by tediously long division, matlab commands easily help us out.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Lab Task:
Task#1: Express the following z-transform in factored form , plot its poles and
zeros,and then determine its ROCs. 2z4+16z3+44z2+56z+32 G(z)= -------------------------------3z4+3z3-15z2+18z-12

Task#2:Determine the rational z-transform from its zero and pole locations. The

zeros are at z1=0.21, z2=3.14, z3=-0.3+j0.5, z4=-0.3-j0.5; the poles are at p1=0.45, p2=0.67, p3=0.81+j0.72, p4=0.81-j0.72; and the gain constant k is2.2. 18z3 G(z)= -----------------18z3+3z2-4z-1

Task#3:Determine the partial fraction expansion of the z-transform G(z) given by

Task#4:Determine the rational form of z-transform from its partial-fraction


expansion representation, it is the inverse of above question.

Task#5 (a): Determine the first 11 coefficients of the inverse z-transform of the
given equation H(z) using impz function, 1+2.0z-1 H(z)=-----------------------1+0.4z-1-0.12z-2

given equation H(z) using filter(),

Task#5(b): Determine the first 11 coefficients of the inverse z-transform of the


1+2.0z-1 H(z)=-----------------------1+0.4z-1-0.12z-2

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 7
Lab Title: Lab Objective:

FREQUENCY RESPONSE OF LTI SYSTEMS.

Implementing difference equation and know how to evaluate the frequency response of LTI system in Matlab. The tasks given in lab include: Compute the output y[n] of an LTI system expressed in difference equation form and verify the result using dltidemo. Evaluate the impulse response and step response of causal finite-dimensional LTI discrete time system. Compute the output y[n] of an LTI system expressed in difference equation form. Evaluate the magnitude and phase response of moving average filter. Generate the smoothed output y[n] from the niose corrupted x[n]using moving average system.

Tools used:
MATLAB

Lab Description:
LTI system:

Difference Equation: Introduction One of the most important concepts of DSP is to be able to properly represent the input/output relationship to a given LTI system. A linear constantcoefficient difference equation (LCCDE) serves as a way to express just this relationship in a discrete-time system. Writing the sequence of inputs and outputs, which represent the characteristics of the LTI system, as a difference equation help in understanding and manipulating a system.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Definition 1: difference equation An equation that shows the relationship between consecutive values of a sequence and the differences among them. They are often rearranged as a recursive formula so that a systems output can be computed from the input signal and past outputs. Example (1) y[n] +7y[n1] +2y[n2] =x[n] 4x[n1] General Formulas from the Difference Equation : As stated briefly in the definition above, a difference equation is a very useful tool in describing and calculating the output of the system described by the formula for a given sample n. The key property of the difference equation is its ability to help easily find the transform, H(z) , of a system. In the following two subsections, we

will look at the general form of the difference equation and the general conversion to a z-transform directly from the difference equation. Difference Equation: The general form of a linear, constant-coefficient difference equation (LCCDE), is shown below:

From this equation, note that y[nk] represents the outputs and x[nk] represents the inputs. The value of N represents the order of the difference equation and corresponds to the memory of the system being represented. Because this equation relies on past values of the output, in order to compute a numerical solution, certain past outputs, referred to as the initial conditions, must be known. Impulse response of LTI system: Output of an LTI system ("at rest") is completely determined by the input and the response to an impulse.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Step response of LTI systems: Input is the unit function to LTI sytem

Moving-average filter:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

DLTI Demo:

DLTIDemo is a program that illustrates the relationship between the input and output of a discrete-time linear time-invariant (LTI) filter when the input is a sinusoidal signal. The user is allowed to control the parameters of both the input sinusoid and the digital filter. Lab Task:
Task#1: Compute the output y[n] using MATLAB, of an LTI system given by the following system equation y[n]=0.5(x[n] x[n-1]) The input x[n] is given by: x[n]=2.07cos(0.2*pi*n + 0.179*pi) where let n=0:100. Solve it mathematically. Plot the graph of y[n] obtained mathematically and compare it with y1[n] which is obtained by convolving x[n] and h[n]. Evaluate the resulting phase shift using plots. Verify the result by using demo named dltidemo in MATLAB. Task#2: : Evaluate the impulse response and step response of the causal finitedimensional LTI discrete-time system as described by the equation. y[n] +0.7y[n-1]] 0.45y[n-2] - 0.6y[n-3]=0.8x[n] 0.44x[n-1] + 0.36x[n2]+0.02x[n-3] Task#3: Calculate the output y[n] an LTI system given by the following equation, y[n]=-6.76195( x[n] +x[n-2]) + 13.456335x[n-1], The x[n] is causal and is given by, x[n]={cos(0.1n) + cos(0.4n)}u[n]

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Task#4: Evaluate the magnitude and phase response of moving-average filter of length M1=5 and M2=14. The impulse response of moving-average filter is given by, h[n]={ 1/M, 0<=n<=M-1 ; 0 , otherwise}

Task#5 : Write MATLAB code to generate the smoothed output y[n] from the noise corrupted x[n] using the moving average system?

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 8
Lab Title: FREQUENCY RESPONSE FOR RATIONAL SYSTEM FUNCTION. Lab Objective: Evaluating the log-magnitude, phase response and group delay from the given transfer function and verification of the results using PEZ demo in MATLAB.
The tasks given in the lab include, Plot the log-magnitude, phase response and group delay of the single factor of the form (1- reje-jw) where 'r' is the radius and '' is the angle of pole or zero in the z-plane. Plot the log-magnitude, phase response and group delay of the single zero system function H(z). Plot the log-magnitude, phase response and group delay of the single pole system function H(z). Plot the log-magnitude, phase response and group delay of the second order system H(z) Verify the plots of log-magnitude and phase response by PEZ demo in MATLAB.

Tools used: MATLAB Lab Description:


FIR Vs IIR: A linear shift-invariant system with a rational system function
may be written in factored form as follows:

Assuming only first-order poles, with ak l for all k and l, if p > q, H ( z ) may be expanded using a partial fraction expansion as follows:

If the system is causal, the unit sample response is

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

When pq , the partial fraction expansion has the form

and, if the system is causal, the unit sample response becomes

If p = 0, H ( z ) has only zeros,

(I

and h(n) is finite in length with,

These systems are called finite-length impulse response (FIR) filters. If p 0, H(z) is infinite in length, and these systems are called infinite-length impulse response (IIR) filters.

If a stable linear time-invarient system has a rational system function(i-e, if its input and output satifies a difference equation of the form given below,

Frequency response of rational system function:

Then its frequency response has the form,

That is,H(ejw) is a ratio of polynomials in the variable e-jw .To determine the magnitude,phase and group-delay associated with the frequency response of such systems, it is useful to express H(ejw) in terms of poles and zeros of H(z).Such an expression results from substuting z=ejw .We get,

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Log-magnitude: The above equation is written as,

Sometimes it is convenient to consider the magnitude squared ,rather than the magnitude ,of the system function. The magnitude-squared function is,

Where * denote complex conjugate, and for H(ejw) ,

|H(ejw)| is the product of the magnitude of all zeros factors of H(z) evaluated on the unit circle, divided by the product of the magnitude of all the pole factor evaluated on the unit circle. It is common practice to transform these product into a corresponding sum of terms by considering 20log10|H(ejw)| instead of |H(ejw)|. The logarithm of |H(ejw)| be,

The function 20log10|H(ejw)| is referred to as the log-magnitude of H(ejw) and is expressed in decibels(dB).Sometime this quantity is called gain in dB;i-e; Gain in dB=20log10|H(ejw)| Phase-response: The phase response for rational system function has the form,

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

The zeros factors contribute with a plus sign and the pole factor contribute with a minus sign. Group-delay: function is, The corresponding group-delay for a rational system

Where arg[] represents the continous phase

PEZ demo:

PeZdemo allows the user to select the poles and zeros of a system and then change those poles and zero dynamically. The z-plane, Fourier domain and time-domain are all updated simultaneously.

Lab TasKs:
'r' is the radius and '' is the angle angle of pole or zero in the z-plane . This factor is typical of either a pole or zero at a radius r and angle in the z-plane. Plot using MATLAB the given equations as a function of frequency 'w' in radians for r=0.9 and =0, /2 and . Log-magnitude:

Task#1: Examine the properties of a single factor of the form (1- reje-jw) ,where

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

20log10|H(ejw)|=20log10|1- reje-jw| = 10 log10[1 + r2 -2r cos(w - )] Phase: ARG[H(ejw)] =ARG[1- reje-jw]=arctan[rsin(w )/(1- rcos(w ))] Group-delay: Grd[H(ejw)] =Grd[1- reje-jw]=(r2 r cos(w ))/(1+ r2 -2rcos(w )) Verify the result by 'PEZ' demo.

H(z)=( 1- rejz-1)=(z rej)/z Derive and plot the equation for log-magnitude, phase and group-delay as a function of frequency 'w' in radians for r=0.8 and =/4. Verify the result by 'PEZ' demo. H(z)=1/(1-rejz-1) Plot the given equation for log-magnitude, phase and group-delay as a function of frequency 'w' in radians for r=0.8 and =/4. Log-magnitude: 20log10|H(ejw)|=20log10|1/(1- reje-jw)| = -10 log10[1 + r2 -2r cos(w - )] Phase: ARG[H(ejw)] =ARG[1/(1- reje-jw)]= -arctan[rsin(w )/(1- rcos(w ))] Group-delay: Grd[H(ejw)] =Grd[1/(1- reje-jw)]= -(r2 r cos(w ))/(1+ r2 -2rcos(w )) Verify the result by 'PEZ' demo.

Task#2: Consider system function 'H(z)' for a single zero.

Task#3: Consider system function 'H(z)' for a single pole.

Task#4: Consider the second order system,

H(z)=1/(1- rejz-1)( 1- re-jz-1) Plot the given equation for log-magnitude, phase and group-delay as a function of frequency 'w' in radians for r=0.9 and =/4.

Log-magnitude: 20log10|H(ejw)|= -10 log10[1 + r2 -2r cos(w - )] -10 log10[1 + r2 -2r cos(w+ )] Phase: ARG[H(ejw)] = -arctan[rsin(w )/(1- rcos(w ))] -arctan[rsin(w )/(1- rcos(w + ))] Group-delay: Grd[H(ejw)] = -(r2 r cos(w ))/(1+ r2 -2rcos(w )) -(r2 r cos(w ))/(1+ r2 -2rcos(w + )) Verify the result by 'PEZ' demo.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 9
Lab Title: FREQUENCY RESPONSE OF ALL-PASS SYSTEM FUNCTION. Lab Objective: Evaluating the log-magnitude, phase response and group delay from the given all-pass system function and verification of the results using PEZ demo in MATLAB.
The tasks given in the lab include, Plot the pole-zero diagram, log-magnitude, phase response and group delay of the third order IIR system expressed in H(z). 10 Plot the log-magnitude, phase response, group delay and unwrap phase of the second order all-pass system expressed in Hap(ejw). 11 Plot the log-magnitude, phase response and group delay of an all-pass system using the pole-zero plot of an allpass system. 9

Tool used: MATLAB Lab Description:


ALL-PASS SYSTEM: A stable system function of the form,

Has a frequency-response that is independent of w. This can be seen by writing Hap(ejw) in the form,

In the above term e-jw has unity magnitude, and the remaining numerator and denominator factors are complex conjugate of each other and therefore have the same magnitude. Consequently,|Hap(ejw)|=1. A system for which the frequency response magnitude is a constant is called an all-pass system.since the system passess all of the frequency components of its input with constant gain or attenuation.

The most general form for the system function of an all-pass system with a real-valued impulse is a product of factors with complex poles being paired with their conjugates;i-e;

Evaluating transfer function of all-pass from pole zero plot:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Where A is positive and the dks are the real poles ,and the eks the complex poles ,of Hap(z). For causal and stable all-pass system, |dk|<1 and |ek|<1. In terms of our general notation for system functions, all-pass systems M=N=2Mc+Mr poles and zeros. Frequency response of all-pass system can be expressed in terms of the frequency response of first-order all-pass system . Log-magnitude of all-pass system: For a causal all-pass system, each of these terms consist of a single pole inside the unit circle and a zero at the conjugate reciprocal location. The magnitude response of such a term is, as we have shown unity. Thus, the log-magnitude in dB is zero. Phase response of all-pass systems: With a expressed in polar form as a=rej, the phase function for Hap(z) is,

Frequency response of all-pass systems:

Likewise, the phase of a second-order all-pass system with poles z=rej and z=re-j is,

Group-delay of all-pass system: The group-delay of the simple one pole allpass system is the negative derivative of the phase .With a .small amount of algebra,it can be shown that,

Since r<1 for a stable and causal all-pass system. The group delay contributed by a single causal all-pass systemis always posistive. Since, the groupdelay of a higher order all-pass system will be a sum of positive terms. Uses of all-pass system: All-pass system have many uses. They can be used as compensators for phase(or group delay) distortion. They are used in the theory of of minimum-phase systems. They are also useful in transforming frequency-selective lowpass filters into other frequency-selective filters.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Lab Tasks:

Task#1: Consider Third-Order IIR System


H(z)= 0.05634(1 + z-1)(1 1.0166z-1 + z-2) (1 0.683z-1)(1 1.4461z-1 + 0.7957z-2) Plot using Matlab, pole-zero diagram log-magnitude phase of the above system as a function of frequency w in radians. Verify the results by 'PEZ' demo. Task#2: Given below is the frequency response of second-order all-pass system, Hap(ejw)= (e-jw re-j) (e-jw rej) (1-rej e-jw) (1-re-j e-jw) Plot using Matlab, log_magnitude . phase . group delay . Also plot the unwrap phase. of the above all-pass system as a function of frequency 'w' in radians for z=0.9ej/4. Where group-delay for second order all pass system be, 1-r2______ Grd= 1-r2______ + 2 2 1+r -2rcos(w+) 1+r -2rcos(w-) Task#3: :Given below is pole-zero plot for an all-pass system. Using pole-zero diagram evaluate system function for an 'all-pass' system.

Plot using Matlab, log_magnitude . phase . Also plot the unwrap phase. of the above all-pass system as a function of frequency 'w' in radians.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 10
Term Project Encoding and decoding of touch tone signals 1 Introduction:
This lab introduces a practical application where sinusoidal signals are used to transmit information: a touch-tone dialer. Bandpass FIR filters can be used to extract the information encoded in the waveforms.The goal of this lab is to design and implement bandpass FIR filters in MATLAB, and to do the decoding automatically. In the experiments of this lab, you will use firfilt(), or conv(), to implement filters and freqz()to obtain the filters frequency response.1 As a result, you should learn how to characterize a filter by knowing how it reacts to different frequency components in the input.

1.1 Review :
A very important FIR filter is known as the Band-Pass Filter (BPF). For the rest of the lab, you will learn how to design these filters and how to use them to do certain tasks for you. One practical example is the dual tone multiple frequency (DTMF) signals used to dial a telephone. Read the following Background section before coming to the lab to speed up the sign-off process in the lab.

1.2 Background: Telephone Touch Tone Dialing:


Telephone touch-tone2 pads generate dual tone multiple frequency (DTMF) signals to dial a telephone. When any key is pressed, the sinusoids of the corresponding row and column frequencies (in Fig. 1) are generated and summed, hence dual tone. As an example, pressing the 5 key generates a signal containing the sum of the two tones at 770 Hz and 1336 Hz together. The frequencies in Fig. 1 were chosen (by the design engineers) to avoid harmonics. No frequency is an integer multiple of another, the difference between any two frequencies does not equal any of the frequencies, and the sum of any two frequencies does not equal any of the frequencies.3 This makes it easier to detect exactly which tones are present in the dialed signal in the presence of non-linear line distortions.

Figure 1: Extended DTMF encoding table for Touch Tone dialing. When any key is pressed the tones of the corresponding column and row are generated and summed. Keys A-D (in the fourth column) are not

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

implemented on commercial and household telephone sets, but are used in some military and other signaling applications.

1.3 DTMF Decoding :


There are several steps to decoding a DTMF signal: 1. Divide the time signal into short time segments representing individual key presses. 2. Filter the individual segments to extract the possible frequency components. Bandpass filters can be used to isolate the sinusoidal components. 3. Determine which two frequency components are present in each time segment by measuring the size of the output signal from all of the bandpass filters. 4. Determine which key was pressed, 09, AD, *, or # by converting frequency pairs back into key names according to Fig. 1. It is possible to decode DTMF signals using a simple FIR filter bank. The filter bank in Fig. 2 consists of eight bandpass filters which each pass only one of the eight possible DTMF frequencies. The input signal for all the filters is the same DTMF signal.

Figure 2: Filter bank consisting of bandpass filters (BPFs) which pass frequencies corresponding to the eight DTMF component frequencies listed in Fig. 1. The number is each box is the center frequency of the BPF.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Here is how the system should work: When the input to the filter bank is a DTMF signal, the outputs from two of the bandpass filters (BPFs) should be larger than the rest. If we detect (or measure) which two outputs are the large ones, then we know the two corresponding frequencies. These frequencies are then used as row and column pointers to determine the key from the DTMF code. A good measure of the output levels is the peak value at the filter outputs, because when the BPF is working properly it should pass only one sinusoidal signal and the peak value would be the amplitude of the sinusoid passed by the filter. More discussion of the detection problem can be found in Section 4.

2 Pre-Lab :
2.1 Signal Concatenation:
In a previous lab, a very long music signal was created by joining together many sinusoids. When two signals were played one after the other, the composite signal was created by the operation of concatenation.In MATLAB, this can be done by making each signal a row vector, and then using the matrix building notation as follows: xx= [ xx, xxnew]; where xxnew is the sub-signal being appended. The length of the new signal is equal to the sum of the lengths of the two signals xxand xxnew. A third signal could be added later on by concatenating it to xx. 2.1.1 Comment on Efficiency: In MATLAB the concatenation method, xx = [ xx,xxnew], would append the signal vector xxnew to the existing signal xx. However, this becomes an inefficient procedure if the signal length gets to be very large. The reason is that MATLAB must re-allocate the memory space for xx every time a new sub-signal is appended via concatenation. If the length xxwere being extended from 400,000 to 401,000, then a clean section of memory consisting of 401,000 elements would have to be allocated followed by a copy of the existing 400,000 signal elements and finally the append would be done. This is clearly inefficient, but would not be noticed for short signals. An alternative is to pre-allocate storage for the complete signal vector, but this can only be done if the final signal length is known ahead of time. 2.1.2 Encoding from a Table: Explain how the following program uses frequency information stored in a table to generate a long signal via concatenation. Determine the size of the table and all of its entries, and then state the playing order of the frequencies. Determine the total length of the signal played by the soundscfunction. How many samples and how many seconds? ftable = [1;2;3;4;5]*[80,110] fs = 8000;

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

xx = [ ]; disp(---Here we go through the Loop ---) keys = rem(3:12,10) + 1; for ii = 1:length(keys) kk = keys(ii); xx = [xx,zeros(1,400)]; krow = ceil(kk/2); kcol = rem(kk-1,2) + 1; xx = [xx, cos(2*pi*ftable(krow,kcol)*(0:1199)/fs)]; end soundsc(xx,fs);

2.2 Overlay Plotting:


Sometimes it is convenient to overlay information onto an existing MATLAB plot. The MATLAB command hold on will inhibit the figure erase that is usually done just before a new plot. Demonstrate that you can do an overlay by following these instructions: (a) Plot the magnitude response of the 5-point averager, created from HH=freqz(ones(1,5)/5,1,ww) Make sure that the horizontal frequency axis extends from ? to ? +. (b) Use the stemfunction to place vertical markers at the zeros of the frequency response. hold on, stem(2*pi/5*[-2,-1,1,2],0.3*ones(1,4),r.), hold off

3 Warm-up: DTMF Synthesis:


3.1 DTMF Dial Function:
Write a function, dtmfdial.m, to implement a DTMF dialer based on the frequency table defined in Fig. 1. A skeleton of dtmfdial.mis given in Fig. 3. In this warm-up, you must complete the dialing code function xx = dtmfdial(keyNames,fs) %DTMFDIAL Create a signal vector of tones which will dial % a DTMF (Touch Tone) telephone system. %% usage: xx = dtmfdial(keyNames,fs) % keyNames = vector of characters containing valid key names % fs = sampling frequency % xx = signal vector that is the concatenation of DTMF tones. %dtmf.keys = ... [1,2,3,A; 4,5,6,B; 7,8,9,C; *,0,#,D]; dtmf.colTones = ones(4,1)*[1209,1336,1477,1633];

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

dtmf.rowTones = [697;770;852;941]*ones(1,4);

Figure 3: Skeleton of dtmfdial.m, a DTMF phone dialer. Complete this function with additional lines of code.

so that it implements the following: 1. The input to the function is a vector of characters, each one being equal to one of the key names on the telephone. The MATLAB structure called dtmfcontains the key names in the field dtmf.keys which is a 4 4 array that corresponds exactly to the keyboard layout in Fig. 1. 2. The output should be a vector of samples with sampling rate fs = 8000 Hz containing the DTMF tones, one tone pair per key. Remember that each DTMF signal is the sum of a pair of (equal amplitude) sinusoidal signals. The duration of each tone pair should be exactly 0.20 sec., and a silence,about 0.05 sec. long, should separate the DTMF tone pairs. These times can be declared as fixed code in dtmfdial. (You do not need to make them variable in your function.) 3. The frequency information is given as two 44 matrices(dtmf.colTonesand dtmf.rowTones): one contains the column frequencies, the other has the row frequencies. You can translate a key such as the 6 key into the correct location in these 4 4 matrices by using MATLABs findfunction. For example, the key 6 is in row 2 and column 3, so we would generate sinusoids with frequencies equal to dtmf.colTones(2,3)and dtmf.rowTones(2,3). To convert an key name to its corresponding row-column indices, consider the following example: [ii,jj] = find(3==dtmf.keys) Also,consultthe dtmfdial.m. MATLAB codeinSection2.1aboveandmodifyitforthe 44 tablesin

4. You should implement error checking so that an illegitimate key name is rejected. Your function should create the appropriate tone sequence to dial an arbitrary phone number. When played through a telephone handset, the output of your function will be able to dial the phone. You could use specgram to check your work.4

3.2 Simple Bandpass Filter Design:


The L-point averaging filter is a lowpass filter. Its passband width is controlled by L, being inversely proportional to L. It is also possible to create a filter whose passband is centered around some frequency other than zero. One simple way to do this is to define the impulse response of an L-point FIR as: h[n]=cos(wc n) 0nL

where L is the filter length, and wc is the center frequency that defines the frequency location of the passband. For example, we pick 'wc =0.2pi' if we want the peak of the filters passband to be centered at 0.2. Also, it is possible to choose so

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

that the maximum value of the frequency response magnitude will be one. The bandwidth of the bandpass filter is controlled by L; the larger the value of L, the narrower the bandwidth. (a) Generate a bandpass filter that will pass a frequency component at wc=0.2pi . Make the filter length (L) equal to 51. Figure out the value of so that the maximum value of the frequency response magnitude will be one. Make a plot of the frequency response magnitude and phase.Hint: use MATLABs freqz()function to calculate these values. (b) The passband of the BPF filter is defined by the region of the frequency response where |H(ejw)|is close to its maximum value of one. Typically, the passband width is defined as the length of the frequency region where |H(ejw)| is greater than 0.707. Note: you can use MATLABs find function to locate those frequencies where the magnitude satisfies |H(ejw)|? 0.707 (similar to Fig. 4). --MATLAB the demo called phonealso shows the waveforms and spectra generated in a DTMF system.

Figure 4: The frequency response of an FIR bandpass is shown with its passband and stopband regions.

Use the plot of the frequency response for the length-51 bandpass filter from part (a) to determine the passband width. (c) If the sampling rate is fs = 8000 Hz, determine the analog frequency components that will be passed by this bandpass filter. Use the passband width and also the center frequency of the BPF to make this calculation.

4 DTMF Decoding :
A DTMF decoding system needs two pieces: a set of bandpass filters (BPF) to isolate individual frequency components, and a detector to determine whether or not a given component is present. The detector must score each BPF output and determine which two frequencies are most likely to be contained in the DTMF tone. In a practical system where noise and interference are also present, this scoring

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

process is a crucial part of the system design, but we will only work with noise-free signals to understand the basic functionality in the decoding system. To make the whole system work, you will have to write three M-files: dtmfrun, dtmfscore and dtmfdesign. An additional M-file called dtmfcut can be downloaded from the MATLAB Files link. The main M-file should be named dtmfrun.m. It will call dtmfdesign.m, dtmfcut.m, and CD-ROM dtmfscore.m. The following sections discuss how to create or complete these functions.

4.1 Simple Bandpass Filter Design: dtmfdesign.m:


The FIR filters that will be used in the filter bank (Fig. 2) are a simple type constructed with sinusoidal impulse responses, as already shown in the Warm-up. In the section on useful filters, a simple bandpass filter design method is presented in which the impulse response of the FIR filter is simply a finite-length cosine of the form:

where L is the filter length, and fs is the sampling frequency. The constant gives flexibility for scaling the filters gain to meet a constraint such as making the maximum value of the frequency response equal to one. The parameter fb defines the frequency location of the passband, e.g., we pick fb =852 if we want to isolate the 852 Hz component. The bandwidth of the bandpass filter is controlled by L; the larger the value of L, the narrower the bandwidth. function hh = dtmfdesign(fb, L, fs) %DTMFDESIGN % hh = dtmfdesign(fb, L, fs) % returns a matrix (L by length(fb)) where each column contains % the impulse response of a BPF, one for each frequency in fb % fb = vector of center frequencies % L = length of FIR bandpass filters % fs = sampling freq % % Each BPF must be scaled so that its frequency response has a % maximum magnitude equal to one.
Figure 5: Skeleton of the dtmfdesign.mfunction. Complete this function with additional lines of code.

(a) Devise a MATLAB strategy for picking the constant so that the maximum value of the frequency response will be equal to one. Write the one or two lines of MATLAB code that will do this scaling operation in general. There are two approaches here: (a) Mathematical: derive a formula for from the formula for the frequency response of the BPF. Then use MATLAB to evaluate this closed-form expression for . (b)Numerical: let MATLAB measure the peak value of the unscaled frequency response, and then have MATLAB compute to scale the peak to be one. (b) Complete the M-file dtmfdesign.mwhich is described in Fig. 5. This function should produce all eight bandpass filters needed for the DTMF filter bank system. Store the filters in the columns of the matrix hhwhose size is L 8.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

(c) The rest of this section describes how you can exhibit that you have designed a correct set of BPFs. In particular, you should justify how to choose L, the length of the filters. When you have completed your filter design function, you should run the L = 40 and L=80 cases, and then you should determine empirically the minimum length L so that the frequency response will satisfy the specifications on passband width and stopband rejection given in part (f) below. (d) Generate the eight (scaled) bandpass filters with L =40 and fs = 8000. Plot the magnitude of the frequency responses all together on one plot (the range 0 ?w?? is sufficient because |H(ejw)| is symmetric). Indicate the locations of each of the eight DTMF frequencies (697, 770, 852, 941, 1209, 1336, 1477, and 1633 Hz) on this plot to illustrate whether or not the passbands are narrow enough to separate the DTMF frequency components. Hint: use the holdcommand and markers as you did in the warm-up. (e) Repeat the previous part with L = 80 and fs = 8000. The width of the passband is supposed to vary inversely with the filter length L. Explain whether or not that is true by comparing the length 80 and length 40 cases. (f) As help for the previous parts, recall the following definitions: The passband of the BPF filter is defined by the region of w where |H(ejw)| is close to one. Typically, the passband width is defined as the length of the frequency region where | H(ejw)| is greater than 0.707. The stopband of the BPF filter is defined by the region of 'wc' where | H(ejw)| is close to zero. In this case, it is reasonable to define the stopband as the region where | H(ejw)| is less than 0.25. Filter Design Specifications: For each of the eight BPFs, choose L so that only one frequency lies within the passband of the BPF and all other DTMF frequencies lie in the stopband. Use the zoom on command to show the frequency response over the frequency domain where the DTMF frequencies lie. Comment on the selectivity of the bandpass filters, i.e., use the frequency response to explain how the filter passes one component while rejecting the others. Is each filters passband narrow enough so that only one frequency component lies in the passband and the others are in the stopband? Since the same value of L is used for all the filters, which filter drives the problem? In other words, for which center frequency is it hardest to meet the specifications for the chosen value of L?

4.2 A Scoring Function: dtmfscore.m:


The final objective is decodinga process that requires a binary decision on the presence or absence of the individual tones. In order to make the signal detection an automated process, we need a score function that rates the different possibilities. (a) Complete the dtmfscorefunction based on the skeleton given in Fig. 6. The input signal xxto the dtmfscore function must be a short segment from the DTMF signal. The task of breaking up the signal so that each short segment corresponds to one key is done by the function dtmfcut prior to calling dtmfscore. function sc = dtmfscore(xx, hh)

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

%DTMFSCORE % usage: sc = dtmfscore(xx, hh) % returns a score based on the max amplitude of the filtered output % xx = input DTMF tone % hh = impulse response of ONE bandpass filter % % The signal detection is done by filtering xx with a length-L % BPF, hh, and then finding the maximum amplitude of the output. % The score is either 1 or 0. % sc = 1 if max(|y[n]|) is greater than, or equal to, 0.59 % sc = 0 if max(|y[n]|) is less than 0.59 xx = xx*(2/max(abs(xx))); %--Scale the input x[n] to the range [-2,+2]
Figure 6: Skeleton of the dtmfscore.mfunction. Complete this function with additional lines of code.

(b) Use the following rule for scoring: the score equals one when |yi[n]|?0.59;otherwise, it is zero. The signal yi[n] is the output of the i-th BPF.

max

(c) Prior to filtering and scoring, make sure that the input signal x[n] is normalized to the range [-2,+2].With this scaling the two sinusoids that make up x[n] should each have amplitudes of approximately 1.0. Therefore the scoring threshold of 0.59 corresponds to a 59% level for detecting the presence of one sinusoid. (d) The scoring rule above depends on proper scaling of the frequency response of the bandpass filters.Explain why the maximum value of the magnitude for H(ejw) must be equal to one for each filter. Consider the fact that both sinusoids in the DTMF tone will experience a known gain (or attenuation) through the bandpass filter, so the amplitude of the output can be predicted if we control both the frequency response and the amplitude of the input. (e) When debugging your program it might be useful to have a plot command inside the dtmfscore.m function. If you plot the first 200500 points of the filtered output, you should be able to see two cases: either y[n] is a strong sinusoid with an amplitude close to one (when the filter is matched to one of the component frequencies), or y[n] is relatively small when the filter passband and input signal frequency are mismatched.

4.3 DTMF Decode Function: dtmfrun.m :


The DTMF decoding function, dtmfrun must use information from dtmfscore to determine which key was pressed based on an input DTMF tone. The skeleton of this function in Fig. 7 includes the help comments. function keys = dtmfrun(xx,L,fs) %DTMFRUN keys = dtmfrun(xx,L,fs) % returns the list of key names found in xx. % keys = array of characters, i.e., the decoded key names % xx = DTMF waveform % L = filter length % fs = sampling freq % center_freqs = .... %<============================FILL IN THE CODE HERE

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

hh = dtmfdesign( center_freqs,L,fs ); % hh = L by 8 MATRIX of all the filters. Each column contains the % impulse response of one BPF (bandpass filter) %[nstart,nstop] = dtmfcut(xx,fs); %<--Find the beginning and end of tone bursts keys = []; for kk=1:length(nstart) x_seg = xx(nstart(kk):nstop(kk)); %<--Extract one DTMF tone .... %<=========================================FILL IN THE CODE HERE end
Figure 7: Skeleton of dtmfrun.m. Complete the forloop in this function with additional lines of code.

The function dtmfrun works as follows: first, it designs the eight bandpass filters that are needed, then it breaks the input signal down into individual segments. For each segment, it will have to call the user-written dtmfscore function to score the different BPF outputs and then determine the key for that segment. The final output is the list of decoded keys. You must add the logic to decide which key is present. The input signal to the dtmfscorefunction must be a short segment from the DTMF signal. The task of breaking up the signal so that each segment corresponds to one key is done with the dtmfcutfunction which is called from dtmfrun. The score returned from dtmfscore must be either a 1 or a 0 for each frequency. Then the decoding works as follows: If exactly one row frequency and one column frequency are scored as 1s, then an unique key is identified and the decoding is probably successful. In this case, you can determine the key by using the row and column index. It is possible that there might be an error in scoring if too many or too few frequencies are scored as 1s. In this case, you should return an error indicator (perhaps by setting the key equal to -1). There are several ways to write the dtmfrunfunction, but you should avoid excessive use of if statements to test all 16 cases. Hint: use MATLABs logicals (e.g., help find) to implement the tests in a few statements.

4.4 Telephone Numbers :


The functions dtmfdial.m and dtmfrun.m can be used to test the entire DTMF system as shown in Fig. 8. You could also use random digits (e.g., ceil(15.9*rand(1,22)+0.09)) in place of 1:16 in dtmfdial. For the dtmfrunfunction to work correctly, all the M-files must be on the MATLAB path. It >>fs = 8000; %<--use this sampling rate in all functions >>tk = [A,B,C,D,*,#,0,1,2,3,4,5,6,7,8,9]; >>xx = dtmfdial( tk, fs ); >>soundsc(xx, fs) >>L = ... %<--use your value of L >>dtmfrun(xx, L, fs) ans =ABCD*#0123456789 Figure 8: Testing the DTMF system.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

is also essential to have short pauses in between the tone pairs so that dtmfcutcan parse out the individual signal segments. If you are presenting this project in a lab report, demonstrate a working version of your programs by running it on the following phone number: 407*89132#BADC In addition, make a spectrogram of the signal from dtmfdial to illustrate the presence of the dual tones.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 11
Lab Title: SAMPLING AND ALIASING. Objective: In this Matlab lab, you will learn:

Sampling process in time domain. Aliasing effect in time domain Design butterworth low-pass and high-pass filter.

Tool Used: Matlab. Lab Tasks:


Q-1: Write a matlab code to illustrate the sampling process in time domain. Consider the sinusoidal signal of frequency 'f=13 Hz' and phase '=0' . Evaluate the samples from this sinusoid with sampling frequency 'Fs', Fs=10. Fs=20. Fs=28. Deduce from this sampling rate, is aliasing occur or not? Also verify the deduction using Matlab demo 'CON2DIS'. Q-2: Write a matlab code to illustrate the aliasing effect in time domain. Take the samples of sinusoid from above question and reconstruct the continuous-time signal using formula,

Set the appropriate sampling frequency so that aliasing is perfectly removed. Verify the result using Matlab demo 'CON2DIS'.

Q-3: Write a matlab code to design 'Butterworth Lowpass Filter' with following
specifications, Wp(passband edge angular frequency in rad/sec)= 2(1000) Ws(stopband edge aangular frequency in rad/sec)=2 (4000) Rp(maximum passband attenuation in dB)=1 Rs(minimum stopband attenuation in dB)= 40

The following M-files may help for the design of analog butterworth filter. [z,p,k]=buttap(N) [num,den]=butter(N,Wn,'s') [num,den]=butter(N,Wn,'type','s') [N,Wn]=buttord(Wp,Ws,Rp,Rs,'s')

Q-4: Write a matlab code to design 'Butterworth highpass Filter' with following specifications,

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Wp(passband edge angular frequency in rad/sec)= 2 (4000) Ws(stopband edge aangular frequency in rad/sec)= 2(1000) Rp(maximum passband attenuation in dB)=1 Rs(minimum stopband attenuation in dB)=40 The following M-files may help for the design of analog butterworth filter. [z,p,k]=buttap(N) [num,den]=butter(N,Wn,'s') [num,den]=butter(N,Wn,'type','s') [N,Wn]=buttord(Wp,Ws,Rp,Rs,'s') [num,den]=lp2hp(b,a,wo)

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

EXPERIMENT NO 12
Lab Title: IIR AND WINDOW BASED FIR FILTER DESIGN. Lab Objective: Design IIR filters using butterworth,chebyshev(I and II) and elliptic approximation and kaiser window . The tasks given in the lab include,
12 IIR lowpass filter design by butterworth,chebyshev(I and II) and elliptic approximation. 13 IIR bandpass filter design by butterworth,chebyshev(I and II) and elliptic approximation. 14 Window based FIR filter design by kaiser window approximation.

Tool used: MATLAB Lab Description:


Bilinear transformation: The bilinear transformation is a mapping from the s-plane to the z-plane defined by,

Given an analog filler with a system function Ha(s), the digital filter is designed as follows:

The bilinear transformation is a rational function that maps the left-half s-plane inside the unit circle and maps the jC2-axis in a one-to-one manner onto the unit circle. However, the relationship between the jR-axis and the unit circle is highly nonlinear and is given by thefr-equency warpb~g,funcrion

As a result of this warping, the bilinear transformation will only preserve the magnitude response of analog filters that have an ideal response that is piecewise constant. Therefore, the bilinear transformation is generally only used in the design of frequency selective filters. The parameter T, in the bilinear transformation is normally included for historical reasons. However, it does not enter into the design process, because il only scales the jR-axis in the frequency warping function, and this scaling may be done in the specification of the analog filter. Therefore, T, may be set to any value to simplify the design procedure.

IIR Filter design:

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

There are two general approaches used to design IIR digital filters. The most common is to design an analog IIR filter and then map it into an equivalent digital filter because the art of analog filter design is highly advanced. Therefore, it is prudent to consider optimal ways for mapping these filters into the discrete-time domain. Furthermore, because there are powerful design procedures that facilitate the design of analog filters, this approach to IIR filter design is relatively simple. The second approach to design IIR digital filters is to use an algorithmic design procedure, which generally requires the use of a computer to solve a set of linear or nonlinear equations. These methods may be used to design digital filters with arbitrary frequency response characteristics for which no analog filter prototype exists or to design filters when other types of constraints are imposed on the design. In this section, we consider the approach of mapping analog filters into digital filters. Initially, the focus will be on the design of digital low-pass filters from analog lowpass filters. Techniques for transforming these designs into more general frequency selective filters will then be discussed. o Chebyshev filter(I and II): In, a butterworth filter,the magnitude response is monoonic in both the passband and the stopband. Consequently, if the filter specification are in terms of maximum passband and stopband approximation error, the specifications are exceeded towards the low-frequency end of the passband above the stopband cutoff frequency. A more efficients approach, which usually leads to a lower order filter,is to distribute the accuracy of the approximation uniformly over the passband or stopband(or both).This is accomplished by choosing an approximation that has an equiripple behaviour rather than monotonic behaviour.The class of Chebyshev filters has the property that the magnitude of the frequency response is either equiripple in the passband monotonic in the stopband(reffered to as a type I chebyshev filter) or monotonic in the passband and equiripple in the stopband(a type II chebyshev filters).

o Elliptic filters: If we distribute the error unformly across the entire passband or across the entire stopnband, as in the Chebyshev case, we are able to meet the design specification with a lower order filter than if we permit a monotonically increasing error in the passband,as in butterwworth case. We note that in the type I chebyshev and butterworth approximations, the stopband error decreases monotonically with frequency,raising the possibility of further improvements if we distribute the stopband error uniformly across the stopband.It has equiripple in the passband and stopband.

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

FIR filter design: The frequency response of an N th-order causal FIR filter is

and the design of an FIR filter involves finding the coefficients h(n) that result in a frequency response that satisfies a given ser of filter specifications. FIR filters have two important advantages over 1IR filters. First, they are guaranteed to be stable, even after the filter coefficients have been quantized. Second, they may be easily constrained to have (generalized) linear phase. Because FIR filters are generally designed to have linear phase, in the following we consider the design of linear phase FIR filters.

Kaiser developed a family of windows that are defined by,

Kaiseer window:

where a = N/2, and lo(.)is a zeroth-order modified Bessel function of the first kind, which may be easily generated using the power series expansion

The parameter determines the shape of the window and thus controls the trade-off between main-lobe width and side-lobe amplitude. A Kaiser window is nearly optimum in the sense of having the most energy in its main lobe for a given sidelobe amplitude. Table 9-3 illustrates the effect of changing the parameter . There are two empirically derived relationships for the Kaiser window that facilitate the use of these windows to design FIR filters. The first relates the stopband ripple of a low-pass filter, a, = -20 log(6,), to the parameter ,

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

The second relates N to the transition width f and the stopband attenuation s

Note that if s< 21 dB, a rectangular window may be used ( = O), and N = O.9/f.

Lab Tasks:
Task#1 IIR Lowpass Filter Design:

Consider the low-pass discrete-time filter specification, 0.99|H(ejw)| 1.01 , |w|0.4, , 0.6 |w| |H(ejw)| 0.001 Design using MATLAB this low pass filter by butterworth, Chebyshev( I and II), elliptic approximation. Plot the gain response, detailted plot of magnitude in passband and pole-zero plot for each approximation.

Task#2 IIR bandpass Filter Design:

Consider the band-pass discrete time filter specification, 0.99|H(ejw)| 1.01 , 0.45 |w|0.6, jw , 0.75 |w| , 0 |w|0.3 |H(e )| 0.001

Digital Signal Processing

Federal Urdu University of Arts, Science & Technology Islamabad Pakistan

Electrical Engineering

Design using MATLAB this band-pass filter by butterworth, Chebyshev( I and II), elliptic approximation. Plot the gain response, detailted plot of magnitude in passband and pole-zero plot for each approximation The following m-files may help in above two questions, [N,Wn] = buttord(Wp,Ws,Rp,Rs) [N,Wn] = cheb1ord(Wp,Ws,Rp,Rs) [N,Wn] = cheb2ord(Wp,Ws,Rp,Rs) [N,Wn] = ellipord(Wp,Ws,Rp,Rs) [b,a]=butter(N,Wn) [b,a]=cheby1(N,Rp,Wn) [b,a]=cheby2(N,Rs,Wn) [b,a]=ellip(N,Rp,Rs,Wn)

Task#3: Window-Based FIR filter design:

Consider the low-pass specification for the design of Kaiser window 1-s|H(ejw)| 1+ s , |w|0.3 , , 0.4 |w| |H(ejw)| s Where s =0.003162. Plot using MATLAB the gain response of kasier window.

The following M-files may help to design the Kaiser window, [N,Wn,beta,ftype]=kaiserord(fpts,mag,dev) W=Kaiser(N+1,beta) b=fir1(N,Wn,W)

Digital Signal Processing

You might also like