Sei sulla pagina 1di 87

Department of Electronics

Engineering

Department of Electronics Engineering

STUDENT MANUAL
Semester-VI
Digital Signal Processing & Processors
Laboratory

i
Department of Electronics
Engineering

Institute Vision, Mission & Quality Policy

Vision
To foster and permeate higher and quality education with value added engineering,
technology programs, providing all facilities in terms of technology and platforms for all
round development with societal awareness and nurture the youth with international
competencies and exemplary level of employability even under highly competitive
environment so that they are innovative adaptable and capable of handling problems faced
by our country and world at large.

Mission
The Institution is committed to mobilize the resources and equip itself with men and
materials of excellence thereby ensuring that the Institution becomes pivotal center of
service to Industry, academia, and society with the latest technology. RAIT engages
different platforms such as technology enhancing Student Technical Societies, Cultural
platforms, Sports excellence centers, Entrepreneurial Development Center and Societal
Interaction Cell. To develop the college to become an autonomous Institution & deemed
university at the earliest with facilities for advanced research and development programs
on par with international standards. To invite international and reputed national
Institutions and Universities to collaborate with our institution on the issues of common
interest of teaching and learning sophistication.

Quality Policy
Our Quality Policy
It is our earnest endeavour to produce high quality engineering professionals who are
innovative and inspiring, thought and action leaders, competent to solve
problems faced by society, nation and world at large by striving towards very high
standards in learning, teaching and training methodologies.
Our Motto: If it is not of quality, it is NOT RAIT!
Dr. Vijay D. Patil
President, RAES
Department of Electronics
Engineering

Department Vision & Mission

Vision
The department envisions that the students of the branch become engineers of
professional character equipped with a strong theoretical and experimental
foundation required for critical thinking, practical engineering skills to face the recent
research and industrial challenges in the field, the ability to work in a team dignity,
and all the qualities that help them accomplish their goals with a zeal for social
awareness.

Mission
Our mission is to facilitate the development of well rounded, educated,
productive, society–focused, creative, adaptive, motivated and ethical individuals
who are well versed in technology and in social and environmental issues.

To create an academic environment of high quality through an outcome based


interactive learning teaching model.

Provide outstanding education & research training to students to enable them to


have productive careers in industry and academia.

To inculcate leadership and entrepreneurship qualities in the students and to make


them ready for the challenges of competitive professional life.

To foster and encourage collaborative research activities and to develop the


excitement of research with intellectual stimulation of diverse campus community
and with other various leading industries and research institutions.
Department of Electronics &
Telecommunication Engineering
Index

Sr. No. Contents Page No.


1. List of Experiments 1

2. Experiment Plan and Course Outcomes 2

3. Study and Evaluation Scheme 4

4. Experiment No. 1 5

5. Experiment No. 2 19

6. Experiment No. 3 22

7. Experiment No. 4 26

8. Experiment No. 5 31

9. Experiment No. 6 35

10. Experiment No. 7 47

11. Experiment No. 8 52

12. Experiment No. 9 57

13. Experiment No. 10 61

14 Experiment No. 11 68

15 Experiment No. 12 73

ii
Department of Electronics &
Telecommunication Engineering
List of Experiments

Sr. No. Experiments Name


1 Introduction to MATLAB and Familiarization with MATLAB software

2 To develop elementary signal function modules (m-files) for unit sample, unit step,
exponential and unit ramp sequences
3 Generation of signals . a) Sinusoidal Signals
b) Exponential Signals
c) Square Wave
4 Computation of Discrete Fourier Transform :To compute N point DFT of a given
sequence and to plot magnitude and phase spectrum.

5 To compute circular convolution using DFT/IDFT

6 a)To convert a Analog Filter to Digital Filter using


i) Impulse Invariant Transformation
ii) Bilinear Transformation
b) To implement a IIR Digital Lowpass Butterworth filter using Bilinear Transformation.
7 To implement a IIR Digital Lowpass Chebhyshev filter using Bilinear Transformation.

8 To implement a FIR Filter using Windowing Techniques

9 To Generate a signal and quantize it to specified number of bits and calculate the
quantization error.

10 Signal Generation using TMS3206713

11 Design of Digital High Pass Butterworth IIR Filter.

12 Design of Digital Band Pass Butterworth IIR Filter.

Experiment Plan & Course Outcome


1
Department of Electronics &
Telecommunication Engineering
Course Outcomes:

CO1 Introduction to MATLAB, familiarisation with various commands and functions of


MATLAB.
CO2 Students will be able to understand DFT and its computation.

CO3 Students will be able to understand the designing of IIR filter.

CO4 Student will be able to understand the FIR filter.

CO5 Student will be able to understand the effect of hardware limitation.

CO6 Student will be able to understand the use and application of DSP processors.

Module Week Course


Experiments Name
No. No. Outcome
1 W1 Introduction to MATLAB and Familiarization with MATLAB CO1
software
2 W2 To develop elementary signal function modules (m-files) for CO1
unit sample, unit step, exponential and unit ramp sequences
3 W3 Generation of signals a) Sinusoidal Signals CO1
b) Exponential Signals
c) Square Wave
4 W4 Computation of Discrete Fourier Transform :To compute N CO1
point DFT of a given sequence and to plot magnitude and phase
spectrum.
5 W5 To compute circular convolution using DFT/IDFT CO2

6 W6 a)To convert a Analog Filter to Digital Filter using CO2


i) Impulse Invariant Transformation
ii) Bilinear Transformation
b) To implement a IIR Digital Lowpass Butterworth filter using
Bilinear Transformation.
7 W7 To implement a IIR Digital Lowpass Chebyshev filter using CO3
Bilinear Transformation.
8 W8 To implement a FIR Filter using Windowing Techniques CO4

9 W9 To Generate a signal and quantize it to specified number of bits CO5


and calculate the quantization error.

10 W10 Signal Generation using TMS3206713 CO6

11 W11 Design of Digital High Pass Butterworth IIR Filter. CO3

12 W12 Design of Digital Band Pass Butterworth IIR Filter. CO3

2
Department of Electronics &
Telecommunication Engineering

Study and Evaluation Scheme


Course
Course Name Teaching Scheme Credits Assigned
Code

3
Department of Electronics &
Telecommunication Engineering
EXL602 Digital Signal Theory Practical Tutorial Theory Practical Tutorial Total
Processing &
Processors
Laboratory -- 02 -- -- 01 -- 01

Course Code Course Name Examination Scheme


EXL602 Digital Signal Term Work Practical & Oral Total
Processing &
Processors 25 25 50
Laboratory

Term Work:

1. Term work assessment must be based on the overall performance of the student with
every experiment graded from time to time. The grades should be converted into marks as
per the Credit and Grading System manual and should be added and averaged.
2. The final certification and acceptance of term work ensures satisfactory performance of
laboratory work and minimum passing marks in term work.

Practical & Oral:

1. Oral exam will be based on the entire syllabus of DSP & P.

4
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No :1

Introduction to MATLAB and


Familiarization with MATLAB software

Experiment No. 1
1. Aim: Introduction to MATLAB and Familiarization with MATLAB software.
2. What will you learn by performing this experiment?

 To understand the concepts and Basics of MATLAB


 To understand the applications of MATLAB

5
Department of Electronics &
Telecommunication Engineering
 To understand in built functions and user defined functions in MATLAB

3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:

Introduction

Millions of engineers and scientists worldwide use MATLAB® to analyze and design the systems
and products transforming our world. MATLAB is in automobile active safety systems,
interplanetary spacecraft, health monitoring devices, smart power grids, and LTE cellular
networks. It is used for machine learning, signal processing, image processing, computer vision,
communications, computational finance, control design, robotics, and much more.

The MATLAB platform is optimized for solving engineering and scientific problems. The
matrix-based MATLAB language is the world's most natural way to express computational
mathematics. Built-in graphics make it easy to visualize and gain insights from data. A vast
library of pre-built toolboxes lets you get started right away with algorithms essential to your
domain. The desktop environment invites experimentation, exploration, and discovery. These
MATLAB tools and capabilities are all rigorously tested and designed to work together.

MATLAB helps you take your ideas beyond the desktop. You can run your analyses on larger
data sets, and scale up to clusters and clouds. MATLAB code can be integrated with other
languages, enabling you to deploy algorithms and applications within web, enterprise, and
production systems.

Key Features

High-level language for scientific and engineering computing

Desktop environment tuned for iterative exploration, design, and problem-solving

Graphics for visualizing data and tools for creating custom plots

Apps for curve fitting, data classification, signal analysis, control system tuning, and
many other tasks

Add-on toolboxes for a wide range of engineering and scientific applications

Tools for building applications with custom user interfaces

Interfaces to C/C++, Java®, .NET, Python, SQL, Hadoop, and Microsoft® Excel®

Royalty-free deployment options for sharing MATLAB programs with end users

Description

6
Department of Electronics &
Telecommunication Engineering
MATLAB is a high-performance language for technical computing. It integrates computation,
visualization, and programming environment. Furthermore, MATLAB is a modern programming
language environment: it has sophisticated data structures, contains built-in editing and
debugging tools, and supports object-oriented programming. These factors make MATLAB an
excellent tool for teaching and research.

MATLAB has many advantages compared to conventional computer languages (e.g., C,


FORTRAN) for solving technical problems. MATLAB is an interactive system whose basic data
element is an array that does not require dimensioning. The software package has been
commercially available since 1984 and is now considered as a standard tool at most universities
and industries worldwide. It has powerful built-in routines that enable a very wide variety of
computations. It also has easy to use graphics commands that make the visualization of results
immediately available. Specific applications are collected in packages referred to as toolbox.
There are toolboxes for signal processing, symbolic computation, control theory, simulation,
optimization, and several other fields of applied science and engineering.

Starting MATLAB After logging into your account, you can enter MATLAB by double-clicking
on the MATLAB shortcut icon (MATLAB 7.0.4) on your Windows desktop. When you start
MATLAB, a special window called the MATLAB desktop appears. The desktop is a window that
contains other windows. The major tools within or accessible from the desktop are:

• The Command Window

• The Command History

• The Workspace

• The Current Directory

• The Help Browser

• The Start button

When MATLAB is started for the first time, the screen looks like the one that shown in the
Figure 1. Command prompt window is shown in Fig 2.This illustration also shows the default
configuration of the MATLAB desktop. You can customize the arrangement of tools and
documents to suit your needs. Now, we are interested in doing some simple calculations. We will
assume that you have sufficient understanding of your computer under which MATLAB is being
run.

7
Department of Electronics &
Telecommunication Engineering

Figure 1. MATLAB window

Using MATLAB as a calculator As an example of a simple interactive calculation, just type the
expression you want to evaluate. Let’s start at the very beginning. For example, let’s suppose you
want to calculate the expression,

1 + 2 × 3.

You type it at the prompt command (>>) as follows,

>> 1+2*3 ans = 7 You will have noticed that if you do not specify an output variable, MATLAB
uses a default variable ans, short for answer, to store the results of the current calculation. Note
that the variable ans is created (or overwritten, if it is already existed). To avoid this, you may
assign a value to a variable or output argument name.

8
Department of Electronics &
Telecommunication Engineering

Figure 2 : Command prompt window

For example, >> x = 1+2*3 x = 7 will result in x being given the value 1 + 2 × 3 = 7. This
variable name can always be used to refer to the results of the previous computations. Therefore,
computing 4x will result in

>> 4*x

ans = 28.0000

Quitting MATLAB To end your MATLAB session, type quit in the Command Window, or select
File −→ Exit MATLAB in the desktop main menu.

Creating MATLAB variables MATLAB variables are created with an assignment statement. The
syntax of variable assignment is

variable name = a value (or an expression)

For example, >> x = expression where expression is a combination of numerical values,


mathematical operators, variables, and function calls.

On other words, expression can involve:

• manual entry

• built-in functions

• user-defined functions

9
Department of Electronics &
Telecommunication Engineering
Error messages If we enter an expression incorrectly, MATLAB will return an error message. For
example, in the following, we left out the multiplication sign, *, in the following expression

>> x = 10;

>> 5x

??? 5x

Error: Unexpected MATLAB expression.

Managing the workspace The contents of the workspace persist between the executions of
separate commands. Therefore, it is possible for the results of one problem to have an effect on
the next one. To avoid this possibility, it is a good idea to issue a clear command at the start of
each new independent calculation.

>> clear

The command clear or clear all removes all variables from the workspace. This frees up system
memory. In order to display a list of the variables currently in the memory, type

>> who while,

whos will give more details which include size, space allocation, and class of the variables.

Getting help To view the online documentation, select MATLAB Help from Help menu or
MATLAB Help directly in the Command Window. The preferred method is to use the Help
Browser.

The Help Browser can be started by selecting the ? icon from the desktop toolbar. On the other
hand, information about any command is available by typing >> help Command

Another way to get help is to use the look for command.

The look for command differs from the help command. The help command searches for an exact
function name match, while the look for command searches the quick summary information in
each function for a match. For example, suppose that we were looking for a function to take the
inverse of a matrix. Since MATLAB does not have a function named inverse, the command help
inverse will produce nothing.

Editor/Debugger : Editor/Debugger is used to create and debug M-files, which are programs to
run MATLAB functions. The Editor/Debugger provides a graphical

10
Department of Electronics &
Telecommunication Engineering
user interface for text editing, as well as for M-file debugging. To create or edit an M-file use
File > New or File > Open, or use the edit function.
c) General Commands in MATLAB
The important commands/ functions in MATLAB are as given below :

 clc (Remove items from workspace, freeing up system memory) :


clears all input and output from the Command Window display, giving "clean screen."
After using clc, the scroll bar cannot be used to see the history of functions, but still the
up arrow can be used to recall statements from the command history.
 close (Remove specified figure):
close deletes the current figure or the specified figure(s). It optionally returns the status of
the close operation.
 xlabel, ylabel, zlabel (Label x-, y-, and z-axis) :
Each axes graphics object can have one label for the x-, y-, and z-axis. The label appears
beneath its respective axis in a two-dimensional plot and to the side or beneath the axis in
a three-dimensional plot.
xlabel('string') labels the x-axis of the current axes.

ylabel(...) and zlabel(...) label the y-axis and z-axis, respectively, of the current axes.

 title( Add title to current axes) :


Each axes graphics object can have one title. The title is located at the top and in the
center of the axes.
title('string') outputs the string at the top and in the center of the current axes.

 Figure (create figure graphics object) :


figure creates figure graphics objects. Figure object are the individual windows on the
screen in which MATLAB displays graphical output.
 subplot (Create axes in tiled positions):
subplot divides the current figure into rectangular panes that are numbered row wise.
Each pane contains an axes object. Subsequent plots are output to the current pane.

h = subplot(m,n,p) or subplot(mnp) breaks the figure window into an m-by-n matrix of


small axes, selects the pth axes object for the current plot, and returns the axes handle.
The axes are counted along the top row of the figure window, then the second row, etc.
For example,

11
Department of Electronics &
Telecommunication Engineering
subplot(2,1,1), plot(income)

subplot(2,1,2), plot(outgo) plots income on the top half of the window and outgo on the
bottom half.

 stem (Plot discrete sequence data) :


A two-dimensional stem plot displays data as lines extending from a baseline along the x-
axis. A circle (the default) or other marker whose y-position represents the data value
terminates each stem.
stem(Y) Plots the data sequence Y as stems that extend from equally spaced and
automatically generated values along the x-axis. When Y is a matrix, stem plots all
elements in a row against the same x value.

stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the
same size. Additionally, X can be a row or a column vector and Y a matrix with length(X)
rows.

 bar(Plot bar graph (vertical and horizontal)) :


A bar graph displays the values in a vector or matrix as horizontal or vertical bars.
bar(Y) draws one bar for each element in Y. If Y is a matrix, bar groups the bars
produced by the elements in each row. The x-axis scale ranges from 1 up to length(Y)
when Y is a vector, and 1 to size(Y,1), which is the number of rows, when Y is a matrix.
barh(...) and h = barh(...) create horizontal bars. Y determines the bar length. The vector x
is a vector defining the y-axis intervals for horizontal bars.

 plot ( 2-D line plot) :


plot(Y) Plots the columns of Y versus their index if Y is a real number. If Y is complex,
plot(Y) is equivalent to plot(real(Y),imag(Y)). In all other uses of plot, the imaginary
component is ignored.
plot(X1,Y1,...) Plots all lines defined by Xn versus Yn pairs. If only Xn or Yn is a
matrix, the vector is plotted versus the rows or columns of the matrix, depending on
whether the vector's row or column dimension matches the matrix. If Xn is a scalar and
Yn is a vector, disconnected line objects are created and plotted as discrete points
vertically at Xn.

12
Department of Electronics &
Telecommunication Engineering
 input (Request user input) : The response to the input prompt can be any MATLAB
expression, which is evaluated using the variables in the current workspace.
user_entry = input('prompt') Displays prompt as a prompt on the screen, waits for

input from the keyboard, and returns the value entered in user_entry. user_entry =

input('prompt', 's') returns the entered string as a text variable rather than as a variable

name or numerical value.

 zeros (Create array of all zeros) :

B = zeros(n) Returns an n-by-n matrix of zeros. An error message appears if n is not a


scalar.

 ones (Create array of all ones) :

Y = ones(n) Rreturns an n-by-n matrix of 1s. An error message appears if n is not a scalar.

 exp (Exponential) :

Y = exp(X) The exp function is an elementary function that operates element-wise on


arrays. Its domain includes complex numbers.

Y = exp(X) returns the exponential for each element of X.

 disp (Display text or array) :

disp(X) Displays an array, without printing the array name. If X contains a text string,
the string is displayed. Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable. Note that disp does not
display empty arrays.

 conv (Convolution and polynomial multiplication) :

w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same


operation as multiplying the polynomials whose coefficients are the elements of u and v.

13
Department of Electronics &
Telecommunication Engineering
 xcorr (Cross-correlation) :

c = xcorr(x,y) returns the cross-correlation sequence in a length 2*N-1 vector, where x


and y are length N vectors (N>1). If x and y are not the same length, the shorter vector is
zero-padded to the length of the longer vector.

 filter (1-D digital filter) :

y = filter(b,a,X) filters the data in vector X with the filter described by numerator
coefficient vector b and denominator coefficient vector a. If a(1) is not equal to 1, filter
normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error.

 poly (Polynomial with specified roots) :

r = roots(p) which returns a column vector whose elements are the roots of the
polynomial specified by the coefficients row vector p. For vectors, roots and poly are
inverse functions of each other, up to ordering, scaling, and round off error.

 tf(Convert unconstrained MPC controller to linear transfer function) :

sys=tf(MPCobj) The tf function computes the transfer function of the linear controller
ss(MPCobj) as an LTI system in tf form corresponding to the MPC controller when the
constraints are not active. The purpose is to use the linear equivalent control in Control
System Toolbox for sensitivity and other linear analysis.

 freqz (Frequency response of filter ) :


[h,w] = freqz(ha) returns the frequency response vector h and the corresponding
frequency vector w for the adaptive filter ha. When ha is a vector of adaptive filters, freqz
returns the matrix h. Each column of h corresponds to one filter in the vector ha.

 abs (Absolute value and complex magnitude) :

abs(X) returns an array Y such that each element of Y is the absolute value of the
corresponding element of X.

 fft (Discrete Fourier transform) :

14
Department of Electronics &
Telecommunication Engineering
Y = fft(X) Y = fft(X) returns the discrete Fourier transform (DFT) of vector X,
computed with a fast Fourier transform (FFT) algorithm.

 mod (Modulus after division) :

M = mod(X,Y) returns X - n.*Y where n = floor(X./Y). If Y is not an integer and the


quotient X./Y is within round off error of an integer, then n is that integer. The inputs X
and Y must be real arrays of the same size, or real scalars.

 sqrt (Square root) :

B = sqrt(X) returns the square root of each element of the array X. For the elements of

X that are negative or complex, sqrt(X) produces complex results.

 ceil (Round toward infinity) :

B = ceil(A) rounds the elements of A to the nearest integers greater than or equal to A.
For complex A, the imaginary and real parts are rounded independently.

d)Signal Processing commands used in MATLAB

 fir1(Window-based finite impulse response filter design) :

b = fir1(n,Wn) returns row vector b containing the n+1 coefficients of an order n lowpass
FIR filter. This is a Hamming-window based, linear-phase filter with normalized cutoff
frequency Wn. The output filter coefficients, b, are ordered in descending powers of z.

 buttord (Butterworth filter order and cutoff frequency) :

[n,Wn] = buttord(Wp,Ws,Rp,Rs) returns the lowest order, n, of the digital Butterworth


filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in
the stopband. The scalar (or vector) of corresponding cutoff frequencies, Wn, is also
returned. Use the output arguments n and Wn in butter.

 fliplr (Flip matrix left to right) :

15
Department of Electronics &
Telecommunication Engineering
B = fliplr(A) returns A with columns flipped in the left-right direction, that is, about a
vertical axis.If A is a row vector, then fliplr(A) returns a vector of the same length with the
order of its elements reversed. If A is a column vector, then fliplr(A) simply returns A.

 min ( Smallest elements in array) :

C = min(A) returns the smallest elements along different dimensions of an array. If A is


a vector, min(A) returns the smallest element in A.If A is a matrix, min(A) treats the
columns of A as vectors, returning a row vector containing the minimum element from
each column. If A is a multidimensional array, min operates along the first nonsingleton
dimension.

 max ( Largest elements in array) :

C = max(A) returns the largest elements along different dimensions of an array.If A is a


vector, max(A) returns the largest element in A.If A is a matrix, max(A) treats the columns
of A as vectors, returning a row vector containing the maximum element from each
column. If A is a multidimensional array, max(A) treats the values along the first non-
singleton dimension as vectors, returning the maximum value of each vector.

 find (Find indices and values of nonzero elements) :

ind = find(X) locates all nonzero elements of array X, and returns the linear indices of
those elements in vector ind. If X is a row vector, then ind is a row vector; otherwise, ind is
a column vector. If X contains no nonzero elements or is an empty array, then ind is an
empty array.

 residuez (z-transform partial-fraction expansion ) :

residuez converts a discrete time system, expressed as the ratio of two polynomials, to
partial fraction expansion, or residue, form. It also converts the partial fraction expansion
back to the original polynomial coefficients.

[r,p,k] = residuez(b,a) finds the residues, poles, and direct terms of a partial fraction
expansion of the ratio of two polynomials, b(z) and a(z). Vectors b and a specify the

16
Department of Electronics &
Telecommunication Engineering
coefficients of the polynomials of the discrete-time system b(z)/a(z) in descending powers
of z.

 angle (Phase angle) :

P = angle(Z) returns the phase angles, in radians, for each element of complex array Z.
The angles lie between + π and – π.

 log (Natural logarithm ) :

Y = log(X) returns the natural logarithm of the elements of X. For complex or negative z,
where z = x +y*i , the complex logarithm is returned.

5. Conclusion :

6. QUIZ / Viva Questions:

1. Which MATLAB command generates the solution to the system of equations AX=B?

a. X = A/B c. X = sum(A.*B)

b. X = inv(A)*B d. X = B*A'

2. . Given the following matrices, show the results generated by these MATLAB command
A.*I

1. I = eye(2)

2. A = [1 2; 2 3]

3. What value does the variable q contain after the MATLAB code below executes?
x = 7;
if x <= 3
q = 0;
elseif x > 10
q = 5;
else
q = 2.5;
end

a. 2.5
b. 5
c. 0

17
Department of Electronics &
Telecommunication Engineering
d. 7
e. Nothing is possible

4. The command shown below will produce what text note on the current figure?

Y = 2;
text(2,2,'Y^2');

7. References:

a. Rudra Pratap ., "Getting started with MATLAB ", 4th Edition, Pearson Education.

b. Amos Gilat., "MATLAB An Introduction with Applications ", 4th Edition,WILEY

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

18
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No : 2

To develop elementary signal function


modules (m-files) for unit sample, unit
step, exponential and unit ramp
sequences

Experiment No. 2
1. Aim: To develop elementary signal function modules (m-files) for unit sample, unit step,
exponential and unit ramp sequences
2. What will you learn by performing this experiment?
 To generate unit step , ramp and impulse signals

19
Department of Electronics &
Telecommunication Engineering
 To understand the use of MATLAB commands.

3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:
Unit Sample ( impulse) Function
δ(n) = 1, n = 0
= 0, n ≠ 0
In sequence form δ(n) ={ 1 0 0 0 …..}
Unit step sequence:

u(n) = 1, n ≥ 0

= 0, n < 0

In sequence form u(n) ={ 1 1 1 1 …..}


Unit ramp sequence:

r(n) = n, n ≥ 0

= 0, n < 0

In sequence form u(n) ={ 1 2 3 4 5 …..}


Real-valued exponential sequence:

x(n) = an, a is a real number

5. Design Problem : Write a program in MATLAB to generate Unit step , ramp and
impulse signal. Label the outputs appropriately

6. Signal Processing commands used in the program:

 Zeros( )

 Ones( )

 Xlabel ( )

 Ylabel ( )

20
Department of Electronics &
Telecommunication Engineering
 Title( )

 Subplot ( )

 Input( )
7. Algorithm/ Program:
Write a program in MATLAB to generate Unit step , ramp and impulse signal. Label the
outputs appropriately
8. Simulation Result:

9. Conclusion and Discussion:

10. QUIZ / Viva Questions:

1.What is d/dt of u(t) ?


2.What is the relation between unit , step and ramp signals.
3.What is even and odd signal?
4.What do you mean by time scaling ?
11. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
Pearson Education.

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

d. S Salivahanan, A Vallavaraj., "Digital Signal Processing", Tata Mcgraw Hill publication.

21
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No : 3

Generation of Signals

a) Sinusoidal Signal

b) Square Wave

c) Exponential Wave

Experiment No. 3
1. Aim: To generate signals a) Sinusoidal signal b) Square wave c) Exponential signal
2. What will you learn by performing this experiment?
 To generate different types of signals as per the specifications
 To understand the use of MATLAB commands.

22
Department of Electronics &
Telecommunication Engineering
 To understand how to use MATLAB commands for generating Continuous and
Discrete signals.

3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:

Description
Y = sin(X) returns the sine of the elements of X. The sin function operates element-wise on
arrays. The function accepts both real and complex inputs. For real values of X in the interval [-
Inf, Inf], sin returns real values in the interval [-1 ,1]. For complex values of X, sin returns
complex values. All angles are in radians.

Example :

 Plot Sine Function

Plot the sine function over the domain .

x = -pi:0.01:pi;

stem(x,sin(x)), grid on

 Square wave
Description:

x = square(t,duty)

x = square(t) generates a square wave with period 2π for the elements of time
vector t. square(t) is similar to sin(t), but creates a square wave with peaks of ±1 instead of a sine
wave.
x = square(t,duty) generates a square wave with specified duty cycle, duty, which is a number
between 0 and 100. The duty cycle is the percent of the period in which the signal is positive.

Example :
Generate Square Waves
Create a vector of 100 equally spaced numbers from to . Generate a square wave with a
period of .
t = linspace(0,3*pi)';
x = square(t);
stem(t/pi,x)
grid on

23
Department of Electronics &
Telecommunication Engineering

 Exponential Sequence

Example :
n=input('Enter the duration of the signal N = ');
a=input ('Enter the scaling factor a = ');
t=0:.1:n-1;
y=exp(a*t);

plot(t,y);
%stem(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Exponential Signal');
5. Design Problem : Write a program in MATLAB to generate Sinusoidal signal, Square
wave , and Exponential Signal. Label the outputs appropriately.

6. Signal Processing commands used in the program:

 y=exp(a*t);

 square(t,duty)

 linspace(0,3*pi)';

 plot(x,sin(x)),

 Xlabel ( )

 Ylabel ( )

 Title( )

 Subplot ( )

 Input( )

 Stem( )
7. Algorithm/ Program:
Write the program based on the examples mentioned above
8. Simulation Results:

24
Department of Electronics &
Telecommunication Engineering
9. Conclusion and Discussion:

This experiments enables us to generate signals like Sine ,Square and exponential. We
also infer that Using plot function continuous signal can be generated
10. QUIZ / Viva Questions:

1. What is the significance of plot function in MATLAB?


2. What does the stem command in MATLAB do ?
3. What is the meaning of Linspace?
4. Explain the command subplot ( ).
11. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
Pearson Education.

25
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No : 4

Computation of Discrete Fourier


Transform

Experiment No. 4
1. Aim: To compute N point DFT of a given sequence and to plot magnitude and phase
spectrum..

26
Department of Electronics &
Telecommunication Engineering
2. What will you learn by performing this experiment?

 To compute DFT of a given sequence


 To plot the magnitude and phase spectrum

3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:

DFT stands for Discrete Fourier Transform ."FFT algorithms are so commonly employed to
compute DFTs that the term 'FFT' is often used to mean 'DFT' in colloquial settings. Formally,
there is a clear distinction: 'DFT' refers to a mathematical transformation or function, regardless
of how it is computed, whereas 'FFT' refers to a specific family of algorithms for computing
DFTs."

The Fourier Transform of the original signal is:

We take N samples from x(t), and those samples can be denoted as x[0], x[1],...,x[n],...,x[N−1].

Since we could think each sample x[n] as an impulse which has an area of x[n]:

So, X(jω) becomes

Since there are only a finite number of input data, the DFT treats the data as if it were period, and
evaluates the equation for the fundamental frequency:

27
Department of Electronics &
Telecommunication Engineering
Therefore, the Discrete Fourier Transform of the sequence x[n] can be defined as:

The equation can be written in matrix form:

Where

So, our final DFT equation can be defined like this:

The inverse of it:

5. Design Problem : Compute DFT of the sequence {2,1,4,3}.Plot the magnitude and phase
response.
6. Signal Processing commands used in the program:
28
Department of Electronics &
Telecommunication Engineering
 Input ( )

 abs( )

 angle( )

 stem( )
7. Algorithm:

 Get the input sequence from the specifications


 Identify the no. of samples.
 N and K will vary from 0 to N-1
 Calculate the twiddle factor
 Multiply twiddle factor with x(n)
 Using abs( ) and angle ( ) functions in MATLAB plot the magnitude and phase
response.
 Label the graphs appropriately.

8. Program:

Write the Program to compute DFT of given sequence using the design steps and
algorithm for reference

9. Simulation Result:

10. Conclusion and Discussion:

1) The DFT of the given sequence is calculated.

2) Magnitude and phase response for the sequence is observed from the plot

3) Angle ( ) and abs( ) functions are the functions in MATLAB to plot the magnitude and

phase response.

11. QUIZ / Viva Questions:

1. What is the real part of the N point DFT XR(k) of a complex valued sequence x(n)?

2. The computation of XR(k) for a complex valued x(n) of N points requires:

29
Department of Electronics &
Telecommunication Engineering
3.Which of the following is true regarding the number of computations required to
compute DFT at any one value of ‘k’?
a) 4N-2 real multiplications and 4N real additions
b) 4N real multiplications and 4N-4 real additions
c) 4N-2 real multiplications and 4N+2 real additions
d) 4N real multiplications and 4N-2 real additions

4.Divide-and-conquer approach is based on the decomposition of an N-point DFT into

Successively smaller DFTs. This basic approach leads to FFT algorithms.


a)True
b) False

5. If N=LM, then what is the value of WNmqL?


a) WMmq
b) WLmq
c) WNmq
d) None of the mentioned

12. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
Pearson Education.

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

30
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No. :5

Circular Convolution using DFT/IDFT

Experiment No. 5
1. Aim: To compute Circular convolution of two finite length sequences using DFT/IDFT.
2. What will you learn by performing this experiment?

 To compute circular convolution of given sequences


 To understand the significance of circular convolution

3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:

Circular Convolution x[n] and h[n] are two finite sequences of length N with DFTs denoted by
X[k] and H[k], respectivel. Let us form the product W[k] = X[k]H[k], and determine the
sequence w[n] of length N for which thethe DFT is W[k].

31
Department of Electronics &
Telecommunication Engineering
First, extend x[n] and h[n] to periodic sequences with period N, x h ˜[n] and [n], respectively. ˜
Then, the periodic convolution of x h ˜[n] and [n] corresponds to multiplication of the correspond
ing periodic sequences of Fourier series coefficients

The periodic sequence for which the DFS coefficients are corresponds to the
periodic extension of the finite length sequence w[n] with period N. We can recover w[n] by

extracting one period of

This operation is called circular convolution and denoted

5. Design Problem : Generate the elementary signals Unit step , ramp and impulse signal.
Label the outputs appropriately
6.Signal Processing commands used in the program:

 length ( )

 subplot( )

 fft( )

 ifft( )
7. Algorithm/ Program:

32
Department of Electronics &
Telecommunication Engineering
Write the Program to compute circular convolution of given sequences using the design
steps and algorithm for reference.

Algorithm:

 Find the length of the first sequence x[n]=x_length


 Find the length of the first sequence h[n]=h_length

 Take the circular convolution order as N


 If x_length < N, pad enough number of zeros to x[n], so that the number of
samples in the modified x[n]=N

 If h_length < N ,pad enough number of zeros to h[n], so that the number of
samples in the modified h[n]=N
 Take DFT for modified x[n]=x(k)
 Take DFT for modified h[n]=H(k)
 Compute Y(K)=X(K)*H(K)
 Compute y(n)=IDFT(Y(k))
 Verify if y[n]=conv(x,h)

Program:

8. Result:

9. Conclusion and Discussion:

10. QUIZ / Viva Questions:

1. What is the circular convolution of the sequences x1(n)={2,1,2,1} and x2(n)={1,2,3,4},


find using the DFT and IDFT concepts?
a) {16,16,14,14}
b) {14,16,14,16}
c) {14,14,16,16}
d) None of the mentioned

2. What is the difference between linear and circular convolution.

3. What is the role of function fft( ) in MATLAB?

33
Department of Electronics &
Telecommunication Engineering
11. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
a. Pearson Education.

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

DSP & P

Experiment No : 6a

34
Department of Electronics &
Telecommunication Engineering

To Convert Analog filter to Digital filter

Experiment No. 6a
1. Aim: To convert a Analog Filter to Digital Filter using
i) Impulse Invariant Transformation (IIT)
ii) Bilinear Transformation(BLT)
.
2. What will you learn by performing this experiment?

 Mapping of poles in IIT and BLT


 Advantages of BLT over IIT

3. Software Required: MATLAB (version 12),Signal Processing toolbox

35
Department of Electronics &
Telecommunication Engineering
4. Theory:

The continuous-time system's impulse response, , is sampled with sampling period to


produce the discrete-time system's impulse response, .

Thus, the frequency responses of the two systems are related by

If the continuous time filter is approximately band-limited (i.e.


when ), then the frequency response of the discrete-time system will be
approximately the continuous-time system's frequency response for frequencies below π radians
per sample (below the Nyquist frequency 1/(2T) Hz):

for

Comparison to the bilinear transform

Note that aliasing will occur, including aliasing below the Nyquist frequency to the extent that
the continuous-time filter's response is nonzero above that frequency. The bilinear
transform is an alternative to impulse invariance that uses a different mapping that maps the
continuous-time system's frequency response, out to infinite frequency, into the range of
frequencies up to the Nyquist frequency in the discrete-time case, as opposed to mapping
frequencies linearly with circular overlap as impulse invariance does

Effect on poles in system function


If the continuous poles at , the system function can be written in partial fraction
expansion as

Thus, using the inverse Laplace transform, the impulse response is

The corresponding discrete-time system's impulse response is then defined as the following

36
Department of Electronics &
Telecommunication Engineering

Performing a z-transform on the discrete-time impulse response produces the following discrete-
time system function

Thus the poles from the continuous-time system function are translated to poles at z = e skT. The
zeros, if any, are not so simply mapped.
The bilinear transform (also known as Tustin's method) is used in digital signal
processing and discrete-time control theory to transform continuous-time system representations
to discrete-time and vice versa.
The bilinear transform is a special case of a conformal mapping (namely, the Möbius
transformation), often used to convert a transfer function of a linear, time-invariant(LTI)
filter in the continuous-time domain (often called an analog filter) to a transfer function
of a linear, shift-invariant filter in the discrete-time domain (often called a digital filter although
there are analog filters constructed with switched capacitors that are discrete-time filters). It
maps positions on the axis, , in the s-plane to the unit circle, , in the z-
plane. Other bilinear transforms can be used to warp the frequency response of any discrete-time
linear system (for example to approximate the non-linear frequency resolution of the human
auditory system) and are implementable in the discrete domain by replacing a system's unit

delays with first order all-pass filters.


The transform preserves stability and maps every point of the frequency response of the
continuous-time filter, to a corresponding point in the frequency response of the
discrete-time filter, although to a somewhat different frequency, as shown in
the Frequency warping section below. This means that for every feature that one sees in the
frequency response of the analog filter, there is a corresponding feature, with identical gain and
phase shift, in the frequency response of the digital filter but, perhaps, at a somewhat different
frequency. This is barely noticeable at low frequencies but is quite evident at frequencies close to
the Nyquist frequency.
The bilinear transform is a first-order approximation of the natural logarithm function that is an
exact mapping of the z-plane to the s-plane. When the Laplace transform is performed on a
discrete-time signal (with each element of the discrete-time sequence attached to a
correspondingly delayed unit impulse), the result is precisely the Z transform of the discrete-time
sequence with the substitution of

37
Department of Electronics &
Telecommunication Engineering

where is the numerical integration step size of the trapezoidal rule used in the bilinear
transform derivation;[1] or, in other words, the sampling period. The above bilinear approximation
can be solved for or a similar approximation for can be performed.
The inverse of this mapping (and its first-order bilinear approximation) is

The bilinear transform essentially uses this first order approximation and substitutes into the
continuous-time transfer function,

That is

5. Design Problem : Convert a Analog filter with a transfer function H(s)= s+3/(s+1)(s+2)
to Digital filter.
6. Signal Processing commands used in the program:

 [num, denz] = bilinear(num,den,fs)

 [num, denz] = impinvar(num,den,fs)

38
Department of Electronics &
Telecommunication Engineering
 Grid on

 Pzmap ( )

 angle( )
7. Algorithm/ Program:

Write the Program to convert analog filter to a digital filter using IIT and BLT using the
design steps and algorithm for reference

Algorithm:

 Get the numerator coefficients


 Get the denominator coefficients.
 Get the sampling frequency
 Using ‘bilinear’ and ‘impinvar’ function in MATLAB find transfer function
 Plot pole zero plot using MATLAB function.
Program:

8. Results

9. Conclusion and Discussion:

10. QUIZ / Viva Questions:

1.Which of the following rule is used in the bilinear transformation?


a) Simpson’s rule
b) Backward difference
c) Forward difference
d) Trapezoidal rule

2.If s=σ+jΩ and z=rejω, then what is the condition on σ if r<1?


a) σ > 0
b) σ < 0
c) σ > 1
d) σ <

3.What do you mean by many to one mapping in IIT?

39
Department of Electronics &
Telecommunication Engineering
4.What do you mean by frequency warping?

11. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson
Education.

b. Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
Pearson Education.

c. S Salivahanan, A Vallavaraj., "Digital Signal Processing", Tata Mcgraw Hill


publication .

d. Samuel D Stearns ., "Digital Signal Processing with examples in MATLAB: ",CRC


press .

DSP & P
40
Department of Electronics &
Telecommunication Engineering

Experiment No : 6b

To implement a IIR Digital Lowpass


Butterworth filter using Bilinear
Transformation.

Experiment No. 6b
1. Aim: To implement a IIR Digital Lowpass Butterworth filter using Bilinear
Transformation.
.
2. What will you learn by performing this experiment?
 To implement digital low pass filter according to given specifications.
 To understand the response of the butterworth filter.
3. Software Required: MATLAB (version 12),Signal Processing toolbox
4. Theory:
The Butterworth filter is a type of signal processing filter designed to have as flat a
frequency response as possible in the passband. It is also referred to as a maximally flat
41
Department of Electronics &
Telecommunication Engineering
magnitude filter. It was first described in 1930 by the British engineer and physicist Stephen
Butterworth in his paper entitled "On the Theory of Filter Amplifiers".
Analog Low-Pass Filter Prototypes
To design an IIR digital low-pass filter from an analog low-pass filter, we must first know how to
design an analog low-pass filter. Historically, most analog filter approximation methods were
developed for the design of passive systems having a gain less than or equal to 1. Therefore, a
typical set of specifications for these filters is as shown in Fig. (a), with the passband
specifications having the form

Fig 1. Filter Specifications

Another convention that is commonly used is to describe the passband and stopband constraints
in terms of the parameters ε and A as illustrated in Fig. . Two auxiliary parameters of interest are
the discriminator factor,

and the selectivity factor

The three most commonly used analog low-pass filters are the Butterworth, Chebyshev, and
elliptic filters. These filters are described below.
Butterworth Filter
A low-pass Butterworth filter is an all-pole filter with a squared magnitude response given by

42
Department of Electronics &
Telecommunication Engineering

The parameter N is the order of the filter (number of poles in the system function), and Q,. is the
3-dB cutoff frequency. The magnitude of the frequency response may also be written as

where

The frequency response of the Butterworth filter decreases monotonically with increasing Ω ,
and as the filter order increases, the transition band becomes narrower. These properties are
illustrated in Fig. which shows magnitude response for Butterworth filters of orders N = 2 , 4 ,
8 , and 12. Because

from the magnitude-squared function, we may write

Fig 2. Magnitude of Frequency response for Butterworth filters of orders N=2,4,8

Therefore, the poles of G,(s) are located at 2N equally spaced points around a circle of radius
Q,.,

43
Department of Electronics &
Telecommunication Engineering

and are symmetrically located about the jR-axis shows these pole positions for N = 6 and N =
7.
The system function, H,(s), is then formed from the N roots of H a(s)Ha(-s) that lie in the left-
half s-plane. Butterworth filter with Ωc= 1 , the system function has the form

5. Design Problem : Implement a digital low pass butterworth filter for the following
specifications
0.707 ≤ H(ejw) ≤ 1.0 for 0 ≤ ω ≤ 0.3 π
H(ejw) ≤ 0.2 for 0.75π ≤ ω ≤ 0.3 π

Design Steps in design of Low pass filter using Bilinear transformation :


The steps involved in designing Butterworth filter are as follows:
1. From the specifications infer passband gain Ap and stop band gain As.
2. For the given passband edge frequency and stop band edge frequency calculate analog
frequencies.
Ωp = 2/T tan (ωp/2)

3. Determine the order of the filter N required to meet the specifications using the design
formula.

N ≥ ½ log10(1/As2-1/1/Ap2-1)/log(Ωs/Ωp)

4. Set the 3-dB cutoff frequency, Ωc to any value in the range

Ωc=Ωp/[1/Ap2-1)]1/2N
5. Find poles pk= e j∏(N+1+2k/2N) from k=0 to N-1
6. Using above poles find normalized transfer function
H(s)=1/(s-p0)(s-p1)------
7. Substitute s= s/ Ωc in H(s) to get analog filter transfer function.
8.The system transfer function H(z)is determined by using formula for bilinear
transformation. S =2/T*(1-z-1)/(1+ z-1)

44
Department of Electronics &
Telecommunication Engineering
6. Signal Processing commands used in the program:

 [N, Cf] = buttord(fp,fs,Ap,As,’s’)

 [Bn,An] = butter(N,1,’S’)

 bilinear(B,A,1/T)

 freqz( )

 abs( )
angle( )
7. Algorithm/ Program:

Write the Program to implement Lowpass filter using the design steps and algorithm for
reference.

8. Algorithm:

1. Get the passband and stopband gain from the specifications


2. Identify the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter using ‘ buttord ’ function
5. Find the filter coefficients, using ‘butter’ function
6. Use bilinear transformation by using ‘bilinear ‘ command in MATLAB.
7. Plot the magnitude and phase response

9. Simulation Result:

10. Conclusion and Discussion:

11. QUIZ / Viva Questions:

1. Differentiate between IIR and FIR filters ?


2. What are the advantages of digital filters over analog filters ?
3. Why bilinear transformation is preferred over impulse invariant transformation?
4. What do you mean by frequency warping?

8. References:

45
Department of Electronics &
Telecommunication Engineering
1. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.
2. Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
Pearson Education.
3. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.
4. Sanjit K Mitra., "Digital Signal Processing"

DSP & P

Experiment No : 7

46
Department of Electronics &
Telecommunication Engineering

To implement a IIR Digital Lowpass


Chebyshev filter using Bilinear
Transformation.

Experiment No. 7
1. Aim: To implement a IIR Digital Lowpass Chebyshev filter using Bilinear
Transformation.
.
2. What will you learn by performing this experiment?
 To implement digital low pass filter according to given specifications.
 To understand the response of the Chebyshev filter.
3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:
Chebyshev Filters
Chebyshev filters are defined in terms of the Chebyshev polynomials:

47
Department of Electronics &
Telecommunication Engineering

----------------------- …… 1
These polynomials may be generated recursively as follows,

with To(x) = 1 and Tl(x) = x. The following properties of the Chebyshev polynomials follow
from Eq. 1
1 . For lxl≤1 the polynomials are bounded by 1 in magnitude, . lTN(x)l≤1and oscillate between
±1.
For lxl > I , the polynomials increase monotonically with x.
2. TN(l) = 1 for all N.
3. TN (0) =± l for N even, and TN (0) = 0 for N odd.
4. All of the roots of TN(x) are in the interval - 1 ≤ x ≤1.
There are two types of Chebyshev filters. A type I Chebyshev filter is all-pole with an equiripple
passband and a monotonically decreasing stopband. The magnitude of the frequency response is

where N is the order of the filter, Ωp is the


passband cutoff frequency, and ε is a
parameter that controls the passband ripple
amplitude. Because varies
between 0 and 1 for oscillates between 1 and As the order of the filter
increases, the number of oscillations (ripples) in the passband increases, and the transition width
between the passband and stopband becomes narrower. Examples are given in Fig. for N = 5,6.
The system function of a type I Chebyshev filter has

e form

48
Department of Electronics &
Telecommunication Engineering

where
if N is even, and Ha(Ω) = 1 if N is odd. Given the passband and stopband cutofffrequencies,
Ωp, and Ωs, and the passband and stopband ripples, δs , and δp , (or the parameters ε and A),

5. Design Problem : Implement a digital low pass chebyshwv filter for the following
specifications
0.8 ≤ H(ejw) ≤ 1.0 for 0 ≤ ω ≤ 0.2 π
H(ejw) ≤ 0.2 for 0.6π ≤ ω ≤ π

6. Design Steps in design of Low pass Chebyshev filter using Bilinear transformation :
The steps involved in designing Butterworth filter are as follows:

 Find the values for the selectivity factor, k, and the discrimination factor, d.
 Determine the filter order using the formula

 From the rational function

where
construct the system function Ha(s) by taking the N poles of Ga(s) that lie in the left-half
s-plane.

 The system transfer function H(z)is determined by using formula for bilinear
transformation. S =2/T*(1-z-1)/(1+ z-1)
7. Signal Processing commands used in the program:

 [N, Cf] = cheb10rd(fp,fs,Ap,As,’s’)

 [Bn,An] = cheby(N,1,’S’)

 bilinear(B,A,1/T)

 freqz( )

49
Department of Electronics &
Telecommunication Engineering
 abs( )

 angle( )
8. Algorithm/ Program:

Write the Program to implement Chebyshev Lowpass filter using the design steps and
algorithm for reference

Algorithm:

 Get the passband and stopband gain from the specifications


 Identify the passband and stopband edge frequencies
 Get the sampling frequency
 Calculate the order of the filter using ‘ cheb1ord ’ function
 Find the filter coefficients, using ‘cheby1’ function
 Use bilinear transformation by using ‘bilinear ‘command in MATLAB.
 Plot the magnitude and phase response

Program:
9. Simulation Result:

10. Conclusion and Discussion:

11. QUIZ / Viva Questions:

1.What are the types of Chebyshev filters ?

2. The Chebyshev-I filter is equi-ripple in pass band and monotonic in the stop band.
a) True
b) False

3. What is the number of minima’s present in the pass band of magnitude frequency
response of a low pass Chebyshev-I filter of order 4?
a) 1
b) 2

50
Department of Electronics &
Telecommunication Engineering
c) 3
d) 4

4. The poles of HN(s).HN(-s) are found to lie on:


a) Circle
b) Parabola
c) Hyperbola
d) Ellipse

12. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. .Oppenheim A., Schafer R., Buck J., "Discrete Time Signal Processing", 2nd Edition,
Pearson Education.

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

DSP & P

Experiment No : 8

51
Department of Electronics &
Telecommunication Engineering

To implement a FIR filter using


Windowing Techniques.

Experiment No. 8
1. Aim: To implement a FIR Lowpass filter using :
a)Rectangular Window
b)Hamming Window
c)Hanning Window
d)Blackmann Window and plot the magnitude and phase response using MATLAB.
.
2. What will you learn by performing this experiment?
 To implement digital low pass FIR filter according to given specifications.
 Effect of windowing techniques on the output response.
3. Software Required: MATLAB (version 12),Signal Processing toolbox
4. Theory: The frequency response of an N th-order causal FIR filter is

52
Department of Electronics &
Telecommunication Engineering

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.
Linear Phase FIR Design Using Windows
Let hd(n) be the unit sample response of an ideal frequency selective filter with linear phase,

Because hd(n) will generally be infinite in length, it is necessary to find an FIR approximation to
Hd(ejw). With the window design method, the filter is designed by windowing the unit sample
response,

where w(n) is a finite-length window that is equal to zero outside the interval 0 ≤ n ≤ N and is
symmetric about its midpoint:

The effect of the window on the frequency response may be seen from the complex convolution
theorem,

Ideally, the main-lobe width should be narrow, and the side-lobe amplitude should be small.
However, for a fixed-length window, these cannot be minimized independently. Some general
properties of windows are as follows:
1. As the length N of the window increases, the width of the main lobe decreases, which results
in a decrease in the transition width between passbands and stopbands. This relationship is given
approximately by

where A f is the transition width, and c is a parameter that depends on the window.
2. The peak side-lobe amplitude of the window is determined by the shape of the window, and it
is essentially independent of the window length.

53
Department of Electronics &
Telecommunication Engineering
3. If the window shape is changed to decrease the side-lobe amplitude, the width of the main
lobe will generally increase. Listed in Table are the side-lobe amplitudes of several windows
along with the approximate transition width and stopband attenuation that results when the given
window is used to design an N th-order low-pass filter.
Table of Some Common Windows

The Peak Side-Lobe Amplitude of Some Common Windows and the Approximate

Transition Width and Stopband Attenuation of an Nth-Order Low-Pass Filter

Designed Using the Given Window.

5. Design Problem : Implement a digital FIR filter for the following specifications
Hd(ω ) = e-jωτ for ω ≤ ωc
= 0 otherwise
The length of the filter should be 7 and ωc = 1rad/sample. use rectangular window.

6. Design Steps in design of FIR filter using Rectangular Window :


 Start with desired amplitude response with zero phase.
 Apply inverse DTFT to recover acausal, symmetric and possibility infinitely long
impulse response h (nT )
 Truncate h (nT ) d to finite extent by multiplying it by an appropriate
window function and form h (nT ) nc .
54
Department of Electronics &
Telecommunication Engineering
 Delay h (nT ) nc to make it casual.
7. Signal Processing commands used in the program:

 w = blackman(n)
 w = boxcar(n)
 w = hamming(n)
 w = hanning(n)
 freqz( )
 abs( )
 angle( )
8. Algorithm/ Program:

Write the Program to implement FIR Lowpass filter using the design steps and algorithm
for reference

9. Algorithm:

 Get the order of the filter


 Get the cut off frequency
 use ‘ fir1 ’& ‘rectangular’ function to compute the filter coefficient
 use window functions as per the requirements
 Plot the magnitude and phase response
 Do the above steps for all windows .
Program:

10. Simulation Result ( show results for all windows)

11. Conclusion and Discussion:

12. QUIZ / Viva Questions:


1. What is the difference equation of the FIR filter of length M, input x(n) and
output y(n)?

2. What condition should the unit sample response of a FIR filter satisfy to have
a linear phase?

55
Department of Electronics &
Telecommunication Engineering
3. Which of the following is not suitable either as low pass or a high pass filter?
a) h(n) symmetric and M odd
b) h(n) symmetric and M even
c) h(n) anti-symmetric and M odd
d) h(n) anti-symmetric and M even

4. What is the Fourier transform of the rectangular window of length M-1?

5. The width of each side lobes decreases with an increase in M.


a) True
b) False

13. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. S. Salivahanan, A Vallavaraj., "Digital Signal Processing", Tata Mcgraw Hill publication.

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

DSP & P

Experiment No. :9

To Generate a signal and quantize it to


specified number of bits and calculate the
56
Department of Electronics &
Telecommunication Engineering

Quantization error

Experiment No. 9
1. Aim: To Generate a signal and quantize it to specified number of bits and calculate the
quantization error.
2. What will you learn by performing this experiment?

 To understand the meaning of quantization


 To calculate quantization error

3. Software Required: MATLAB (version 12),Signal Processing toolbox

4. Theory:

Quantization (rounding)
In practice the sampling process also involves "quantization" in which the signal being
sampled is assigned a discrete value so it can be used inside a computer.

57
Department of Electronics &
Telecommunication Engineering

The quantization process is often modeled as a "quantization noise" being added to a


signal. In the diagram below the quantization noise is labeled "e[n]."

When a signal is digitized, quantization errors occur. This will be demonstrated below
where the input signal, x, is rounded to one of 8 quantization levels.

58
Department of Electronics &
Telecommunication Engineering
In this diagram the sampled (but not yet quantized) signal is in blue (i.e., x[n]), the sampled
and quantized signal (i.e., xq[n]), and the quantization error (i.e., e[n]) is shown in green.

SQNR given by quantization by rounding is:


SQNRdB = 10log10(SQNR) = 1.76 + 6.02b where "b" is the number of bits.

5. Design Problem : Generate a sinusoidal signal , quantize the signal to 4 bits ,and
calculate the quantization error .
6.Signal Processing commands used in the program:

 fprintf ( )

 switch

 case

 floor( )
Algorithm/ Program:
Write the Program in MATLAB using algorithm for reference.

Algorithm:

 Generate sinusoidal signal , sawtooth signal and random signal .


 Restrict the signals between - 1 and + 1.
 Quaantize the signal to b bits.
 Calculate the quantization error.

Program
7. Simulation Result ( show results for all windows)

8. Conclusion and Discussion:

9. QUIZ / Viva Questions:

1. Finite word length effects refer to the quantization effects that are inherent in any
digital implementation of the system, either in hardware or software.
a) True
b) False

59
Department of Electronics &
Telecommunication Engineering
2. . Which of the following are called as finite word length effects?
a) Parameters of the system must be represented with finite precision
b) Computations are truncated to fit in the limited precision constraints
c) Whether the computations are performed in fixed point or floating point arithmetic
d) All of the mentioned

3.What do you mean by truncation and rounding?

10. References:

1. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson
Education.

2. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

DSP & P

Experiment No. :10

Signal Generation using DSP


60
Department of Electronics &
Telecommunication Engineering

Experiment No. 10
1. Aim: Signal Generation Using TMS320C6713 Processor.

2. What will you learn by performing this experiment?


 To compute circular convolution of given sequences
 To understand the significance of circular convolution

3. Software Required: Code Composer Studio

4. Hardware Required : TMS320C6713 processor

5. Theory:

This note describes a digital signal processor (DSP) based waveform generator, which can
generate a sine wave, up to 24 kHz, a square wave, up to 5 kHz, and a triangular wave, up to 12
kHz. A DSP starter kit with Code Composer Studio has been used in the design of a waveform
generator. The waveform generators can also produce periodic arbitrary waveforms and
amplitude modulated signals. Two synchronized signals can be obtained by using the waveform

61
Department of Electronics &
Telecommunication Engineering
generator too. The spectral components of the signals generated are found comparable with a
commercially available signal generator. 1.Launch CCS by double-clicking on its desktop icon.
Create a new project file MLF.pjt by selecting Project ⇒ New and typing MLF as the project
name, as shown in Fig. 3.5. Set Target to TMS320C67XX before clicking on Finish. The new
project file will be saved in the folder, C ⇒ CCStudio v3.1 ⇒ My projects ⇒ MLF. The .pjt file
stores project information on build options, source filenames, and dependencies. The names of
the files used by a project are displayed in the project view window which by default appears at
the left-hand side of the code composer window.

Fig 1: Project Creation

2.For write your C code go to, File ⇒ New ⇒ Source File. Write your C program in this source
file and then go to, File ⇒ Save. And save it in your project directory MLF (make sure it has a .c
extension).

3.For connecting the kit to DSK go to Debug --Connect. And check that the symbol in the
bottom left-hand corner of the CCS window indicates connection to the DSK.

62
Department of Electronics &
Telecommunication Engineering

Fig 2: Adding Files to project

4. Add required support files to project by first going to, Project ⇒ Add Files to Project

a) Add the source file MLF.c to the project. MLF.c is the top level C source file containing the
definition of function main(). This source file is stored in the folder MLF and must be added to
the project if it is to be used to generate the executable file MLF.out. Select, Project ⇒ Add Files
to Project. And look for files of type C Source Files ( * .c, * .ccc). Open, or double-click on,
MLF.c. It should appear in the Project View window in the Source folder. b)Secondly add .lib file
to our project by going in, C6000 ⇒ dsk6713 ⇒ lib ⇒ dsk6713bsl.lib. Then add this file to our
project. (DSK board support library functions-useful for interfacing to the codec, DIP switches,
and LED’s). c) Also add the header files dsk6713.h in the Project. d) The GEL file dsk6713.gel is
added automatically when you create the project. It initializes the C6713 DSK invoking the
board support library to use the PLL to set the CPU clock to 225 MHz (otherwise the C6713 runs
at 50 MHz by default). Any of the files (except the library files) listed in the project view
window can be displayed (and edited) by double-clicking on their name in the project view
window. If you have not added header in your project then they are added to the project

5. Setting Compiler Options :

63
Department of Electronics &
Telecommunication Engineering
Select, Project ⇒ Build options and click on the Compiler tab. Set the following options, as
shown in Fig. 3.7, 3.8, and 3.9. In the Basic category set Target Version to C671x (−mv6710). In
the advanced category set memory models to Far ( memmodel:data=far). In the preprocessor
category set PreDefine symbol to CHIP-6713 and include search path to, C ⇒ CCStudio v3.1 ⇒
C6000 ⇒ dsk6713 ⇒ include and click on OK.

Fig 3: Basic compiler settings

6. First go to, File ⇒ New ⇒ DSP/BIOS Configuration. Then a dialog box will appears, select
the dsk6713.cbd template and click OK. The CBD files shown in dialog box are called seed CDB
files. CDB files are used to configure a great many objects. To make life easier TI provides a
seed files with all boards it ships. Now save your CDB file by, File ⇒ Save As and give it some
name suppose xyz. Rightclick the project icon in the project explorer and go to, Project ⇒ Add
files, then select xyz.cbd file and add it in the project. Click the + sign to source in the Project

64
Department of Electronics &
Telecommunication Engineering
Window to make sure your .c files were added successfully. Also click the + sign next to
DSP/BIOS config to make sure the .CDB file is displayed. The DSP/BIOS configuration tool
creates and modifies a system files called configuration database (.CBD). The graphical user
interface simplifies system design by • Automatically including the appropriate runtime support
libraries. • Automatically handles interrupts vectors and system reset. • Handles system memory
configuration (builds CMD file).

When you add a CDB file to your project, CCS automatically add the C and assembly files in
the project.

Fig 4 : DSP/BIOS configuration

7.For building the project select, Project ⇒ Rebuild All as shown in Fig. 3.11. Or press the
toolbar button with the three downward arrows. This creates an executable file MLF.out that can
be loaded into the C6713 processor and run. Note that the commands for compiling, assembling,
and linking are performed with the Build option. A log file cc-build-Debug.log is created that
shows the files that are compiled and assembled, along with the compiler options selected. It also
lists the support functions that are used. The building process causes all the dependent files to be
included (in case one forgets to scan for all the file dependencies). You should see a number of
diagnostic messages, culminating in the message “Build Complete, 0 Errors, 0 Warnings, 0
Remarks ” appear in an output window in the bottom left-hand side of the CCS window. It is
possible that a warning about the Stack Size will have appeared. This can be ignored or can be
suppressed by unchecking the Warn About Output Sections option in the Advanced category of
Linker Build Options. Alternatively, it can be eliminated by setting the Stack Size option in the
Advanced category of Linker Build Options to a suitable value.

65
Department of Electronics &
Telecommunication Engineering
8.If successful, load the .out file to the DSK: as shown in Fig. 3.11 by selecting, File ⇒ Load
Program browse the Debug directory and select the MLF.out file. Then finally Run it by clicking,
Debug ⇒ Run or F5 or the run button

Fig 5 : Building and loading programs in DSP

6. Program:

7. Simulation Results :

8. Conclusion:

9. QUIZ / Viva Questions:

1. Why most of the DSPs use Harvard architecture?


a) they provide greater bandwidth

66
Department of Electronics &
Telecommunication Engineering
b) they provide more predictable bandwidth
c) none of the mentioned
d) both of the mentioned

2.Which of the two architecture saves memory?


a) Harvard
b) Von Neumann
c) none of the mentioned
d) both of the mentioned

3.What is the advantage of DSP processors over Microprocessors.

4.What are the real time applications

10. References:

1.B Venkataramani , M Bhaskar ., "Digital Signal Processors: Architecture programming


and Applications ",Mc Graw Hill .

67
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No. :11

Digital High Pass Butterworth IIR Filter.

Experiment No. 11
1. Aim: To design Digital High Pass Butterworth IIR Filters.

2. What will you learn by performing this experiment?


 To implement digital high pass IIR filter according to given specifications.
3. Software Required: MATLAB (version 12),Signal Processing toolbox
4. Theory:
There are basically four types of frequency selective filters viz i)Lowpass filter ii)
Highpass filter iii)Bandpass filter iv)Bandstop filter
We know the design of Low pass filter. This lowpass filter can be considered as a
prototype filter can be considered as a prototype filter and its system function can be

68
Department of Electronics &
Telecommunication Engineering
obtained. Then if a Highpass, Bandpass or Bandstop filter is to be designed it can be
accomplished by using Frequency Transformation.
Frequency Transformation are of two types:
i) Analog Frequency Transformation
ii) Digital Frequency Transformation
In analog frequency transformation the analog system function Ha(s) of the prototype
filter is converted into another analog system function of the desired filter. Then by using
any of the mapping techniques it is converted into the digital System function. Whereas
in case of Digital frequency transformation the analog prototype filter is first transformed
to the digital domain , to have a system function H(z). Then by using Frequency
Transformation, it can be converted into desired digital filter.
Analog Frequency Transformation

Digital Frequency Transformation

69
Department of Electronics &
Telecommunication Engineering

5. Design Problem : Design a Butterworth digital High pass IIR Filter by using Bilinear
Transformation by taking T=0.5 sec to satisfy the following specifications.
0.707 ≤ |H(ejw)| ≤ 1.0 ; for 0.65π ≤ w ≤ π
|H(ejw)| ≤ 0.2 ; for 0 ≤ w ≤ 0.45π

Design Steps in design of IIR Butterworth Filter :

 Designing IIR digital filter involves the design of equivalent analog filter & then
converting analog filter to digital filter.
 First analog Butterworth IIR filter transfer function is determined using the
specifications.
 Then, analog transfer function is converted to a digital filter transfer function using,
Bilinear transformation
 Find order of the filter,
 Obtain cut-off frequency,
 With the order of the filter, obtain the transfer function H(s), by substituting s by S/Ω
 Convert analog transfer function Ha(s) to digital function H(z), using either impulse
invariance method or bilinear transformation method.

6. Signal Processing commands used in the program:

70
Department of Electronics &
Telecommunication Engineering
 Buttord()
 Butter()
 freqz( )
7. Algorithm/ Program:

Write the Program to implement IIR Highpass filter using the design steps and algorithm
for reference

Algorithm:

Design Steps of Butterworth Filter


 Convert the filter specifications to their equivalents in the lowpass prototype frequency.
 From Ap determine the ripple factor 
 From As determine the filter order , N
 Determine the left hand poles, using the equations given.
 Construct the lowpass prototype filter transfer function.
 Use the frequency transformation to convert the LP prototype filter to the given
specifications.
Program:

8. Simulation Result:

9. Conclusion and Discussion

10. QUIZ / Viva Questions:


1. Mention any two techniques for digitizing the transfer function of an analog filter.
2. What is Warping effect

3. What is bilinear transformation?

4. List the features that make an analog to digital mapping for IIR filter design coefficient.

5. Give the equation for the order of N and cut-off frequency Ωc of butter worth filter.

11. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. S Salivahanan, A Vallavaraj., "Digital Signal Processing", Tata Mcgraw Hill publication.


71
Department of Electronics &
Telecommunication Engineering
c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

72
Department of Electronics &
Telecommunication Engineering

DSP & P

Experiment No. :12

Digital Band Pass Butterworth IIR Filter.

Experiment No. 12
1. Aim: To design Digital Band Pass Butterworth IIR Filters :

73
Department of Electronics &
Telecommunication Engineering
2. What will you learn by performing this experiment?
 To implement digital high pass IIR filter according to given specifications.
3. Software Required: MATLAB (version 12),Signal Processing toolbox
4. Theory:
There are basically four types of frequency selective filters viz i)Lowpass filter ii) Highpass
filter iii)Bandpass filter iv)Bandstop filter
We know the design of Low pass filter. This lowpass filter can be considered as a prototype
filter can be considered as a prototype filter and its system function can be obtained. Then if
a Highpass, Bandpass or Bandstop filter is to be designed it can be accomplished by using
Frequency Transformation.
Frequency Transformation are of two types:
iii) Analog Frequency Transformation
iv) Digital Frequency Transformation
In analog frequency transformation the analog system function Ha(s) of the prototype
filter is converted into another analog system function of the desired filter. Then by
using any of the mapping techniques it is converted into the digital System function.
Whereas in case of Digital frequency transformation the analog prototype filter is first
transformed to the digital domain , to have a system function H(z). Then by using
Frequency Transformation, it can be converted into desired digital filter.

Analog Frequency Transformation

Digital Frequency Transformation

74
Department of Electronics &
Telecommunication Engineering

5. Design Problem : Using Bilinear Transformation design a digital Bandpass Butterworth


filter for following specifications.
Ap=2 dB in the pass band 800Hz ≤ f ≤ 1000Hz
As=20 dB in the stop band 0 ≤ f ≤ 400Hz and 2000 ≤ f ≤ ∞.
Design Steps of Butterworth Filter
 Convert the filter specifications to their equivalents in the lowpass prototype
frequency.
 From Ap determine the ripple factor 
 From As determine the filter order , N
 Determine the left hand poles, using the equations given.
 Construct the lowpass prototype filter transfer function.
 Use the frequency transformation to convert the LP prototype filter to the given
specifications.
6. Signal Processing commands used in the program:

 Buttord()

 Butter()

 freqz( )

75
Department of Electronics &
Telecommunication Engineering
 abs()

 angle()
7. Algorithm/ Program:

Write the Program to implement IIR Bandpass filter using the design steps and algorithm
for reference.

Algorithm:

Design Steps of Butterworth Filter


 Convert the filter specifications to their equivalents in the lowpass prototype
frequency.
 From Ap determine the ripple factor 
 From As determine the filter order , N
 Determine the left hand poles, using the equations given.
 Construct the lowpass prototype filter transfer function.
 Use the frequency transformation to convert the LP prototype filter to the given
specifications.
Program:

8. Simulation Result ( show results for all windows)

9. Conclusion and Discussion:

1. The digital Bandpass filter is designed from analog filter.

2. The frequency response, magnitude and phase response is obtained.

10. QUIZ / Viva Questions:


1. Mention any two techniques for digitizing the transfer function of an analog filter.
2. What is the region between origin and the pass band frequency in the magnitude
frequency response of a low pass filter?

3. What is the value of pass band ripple in dB?

4. The low pass, high pass, band pass and band stop filters can be designed by applying a
specific transformation to a normalized low pass filter.

76
Department of Electronics &
Telecommunication Engineering
a) True
b) False

5. What is the pass band gain of a low pass filter with 1- δP as the pass band attenuation?

6. What is the cutoff frequency of a normalized filter?

7. What is bilinear transformation?

8. Give the equation for the order of N and cut-off frequency Ωc of butter worth filter.

11. References:

a. Proakis J., Manolakis D., "Digital Signal Processing", 4th Edition, Pearson Education.

b. S Salivahanan, A Vallavaraj., "Digital Signal Processing", Tata Mcgraw Hill publication.

c. Babu R., "Digital Signal Processing", 4th Edition, Scitech Publications.

APPENDIX

Examples on Matrices

77
Department of Electronics &
Telecommunication Engineering
1. Creating vectors

(a) Generate the following vectors:

A = [1 0 4 5 3 9 0 2]

a = [4 5 0 2 0 0 7 1]

Be aware that MATLAB are case sensitive. Vector A and a have different values.

(b) Generate the following vectors:

B = [A a]

C = [a, A]

Concatenation is the process of joining small matrices to make bigger ones. In fact,you made
your first matrix by concatenating its individual elements. The pair of square brackets, [ ], is the
concatenation operator.

(c) Generate the following vectors using function zeros and ones:

D = [0 0 0 . . . 0] with fifty 0’s.

E = [1 1 1 . . . 1] with a hundred 1’s.

(d) Generate the following vectors using the colon operator

F = [1 2 3 4 . . . 30]

G = [25 22 19 16 13 10 7 4 1]

H = [0 0.2 0.4 0.6 . . . 2.0]

The colon, :, is one of MATLAB’s most important operators.

2. Operate with the vectors

V1 = [1 2 3 4 5 6 7 8 9 0]

V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9]

78
Department of Electronics &
Telecommunication Engineering
V3 = [4 4 4 4 3 3 2 2 2 1]

(a) Calculate, respectively, the sum of all the elements in vectors V1, V2, and V3.

(b) How to get the value of the fifth element of each vector?

What happens if we execute the command V1(0) and V1(11)?

Remember :if a vector has N elements, their subscripts are from 1 to N.

(c) Generate a new vector V4 from V2, which is composed of the first five elements of V2.

Generate a new vector V5 from V2, which is composed of the last five elements of V2.

(d) Derive a new vector V6 from V2, with its 6th element omitted.

Derive a new vector V7 from V2, with its 7th element changed to 1.4.

Derive a new vector V8 from V2, whose elements are the 1st, 3rd, 5th, 7th, and 9th

elements of V2

(e) What are the results of

9-V1

V1*5

V1+V2

V1-V3

V1.*V2

V1*V2

V1.^2

V1.^V3

V1^V3

79
Department of Electronics &
Telecommunication Engineering
V1 == V3

V1>6

V1>V3

V3-(V1>2)

(V1>2) & (V1<6)

(V1>2) | (V1<6)

any(V1)

all(V1)

3. Using MATLAB help system, click on Help -> MATLAB help or type helpdesk to open the
help files. For description of a single function or command,

type

help command_name on the command line, or use ’search’ in the help window.

For example, type

help plot

on the command line.

4. Flow control

What are the results of these sets of commands?

(a) A = zeros(1,5);

for n = 1:4

for m = 1:3

A = A + n*m;

80
Department of Electronics &
Telecommunication Engineering
end

end

(b) B = [1 0];

if (all(B))

B = B + 1;

elseif (any(B))

B = B + 2;

else

B = B + 3;

end

(c) C = 7:2:22

num = 0;

while (all( C>0))

C = C - 3;

num = num + 1;

end

num

81
Department of Electronics &
Telecommunication Engineering
(b) Situations under which loops can be avoided. Does the set of commands:

for i = 1:20

H(i) = i * 5;

end

have the same result as:

H = 1:20;

H = H*5;

Does the set of commands:

for n = 1:100000

x(n) = sin(n*pi/10);

end

have the same result as:

n = 1:100000;

x = sin(n*pi/10);

5. Compare a script and a function

(a) Write a script: In the main menu of MATLAB, select

file -> new -> M-file

A new window will pop up. Input the following commands:

x = 1:5;

y = 6:10;

82
Department of Electronics &
Telecommunication Engineering
g = x+y;

and then save the file as myscript.m under the default path MATLAB/work

(b) Write a function: Create a new m file following the procedure of above. Type in the

commands:

function g = myfunction(x,y)

g = x + y;

and then save it as myfunction.m

(c) Compare their usage

(1) run the commands one by one:

myscript

z = myscript

(error?)

83

Potrebbero piacerti anche