46 views

Original Title: Chap1 ECL301L Lab Manual Pascual

Uploaded by pascionladion

- Pure Maths Unit 1 Paper 1 2013
- Georgia State University Math Placement Practice Test
- 77864266-Getting-Started-With-Matlab-RudraPratap_Parte3.pdf
- Tutorial 2
- yahoo answers
- Graphing Trigonometric Functions
- Mathematics
- Trigonometry
- 5.3 Exercise
- JavaScript Built
- Secret_ECE524.pdf
- AllLessons.pdf
- Oracle Functions
- Jeep 208
- Matlab Chapter 1
- Mathsisinteresting.blogspot.com Search q=Sinc+Function
- 1006.2938
- ch 1 notes Grist Calculus
- SPM Add Maths Formula List Form5
- EN_SIMIT_SCE_V7_Basic_Libray.pdf

You are on page 1of 15

a. Ability to apply knowledge of mathematics and science to solve engineering problems

b. Ability to identify, formulate, and solve engineering problems

c. Ability to use techniques, skills, and modern engineering tools necessary for engineering

practice

a. Compute solutions to numerical problems in engineering using MATLABs interactive

computing environment and functions

b. Construct and manipulate vectors and matrices in MATLAB

1.3 Introduction

The entire digital signal processing (DSP) laboratory course uses MATLAB [1], a widely used technical

computing and visualization software system. Thus, the first couple of chapters in this material have

been dedicated to introducing the students to MATLAB environment, functions and programming. In

particular, this chapter focuses on important mathematical and matrix manipulation functions that we can

immediately employ in MATLABs command window, an interactive computing environment.

To get started, open MATLAB from your program menu or through its shortcut icon.

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 3

Figure 1.1 shows how a typical MATLAB desktop looks like. Note that the desktops appearance varies with

different versions of MATLAB. In this section, we focus on the Command Window, an interactive command

line environment that allows us to enter and execute quick commands or computations just like how we

would use a calculator. The Command Windows prompt is the double greater than or the double right

arrowhead symbol (>>).

2

Suppose we want to compute the following: 1

3

Example 1.1 below shows a command that we may type at the Command Windows prompt, and shows

how MATLAB responds after pressing <Enter> or <Return>.

Example 1.1

>> 1+2/3*pi

ans =

3.0944

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 4

Like most common computing or programming languages, we use the arithmetic operator symbols

(+) for addition, (-) for subtraction, (*) for multiplication and (/) for division. Note that MATLAB assigns the

value of (3.14156) to the reserved symbol pi. Note also that the most recent result of a computation

is stored in a default variable named ans, just like in a typical calculator. We can use ans in our

subsequent computation as shown in Example 1.2.

Most of the time, we want to store the results of our calculations to our own user-defined variable

for future use. Example 1.2 also shows how we can quickly generate and employ user-defined variables

without the need for variable declaration. There are however some rules to keep in mind in creating user-

defined variables. For instance, we cannot create variable names that start with numbers, nor create

variable names that contains special characters such as plus sign (+), dash (-), asterisk (*), dot (.), slash

(/), commercial at (@), or even a space. Moreover, variable names in MATLAB are case- sensitive

(e.g., a variable named var_1 will be different from Var_1.)

Example 1.2

>> 1+2/3*pi

ans =

3.0944

>> ans-2

ans =

1.0944

>> var_1=1+2/3*pi

var_1 =

3.0944

After doing Example 1.2, let us now turn our attention to another windowpane on MATLAB

Desktop called the Workspace window (shown in Fig. 1.2). The Workspace contains all the variables that

we have created so far in the current session of MATLAB. For example, Fig. 1.2 shows the variables ans

and var_1, and their respective values, sizes, number of bytes, and classes. Note that the class double

in MATLAB uses the 64-bit or 8-byte IEEE floating point format.

You may also generate the variable list directly from the Command Window using the command

whos.

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 5

If we want to clear the Command Window, we may invoke the command clc. If we want to

clear variables from the workspace however, we may invoke the command clear.

Exercise 1.1

a.) Execute the sequence of commands in Example 1.2. Then enter the following command:

>> clc

>> whos

QUESTION 1.1:

In the space provided below, write down MATLABs response after the whoscommand. Did clc clear

the variables in the workspace? Why or why not?

>> clc

>> clear ans

>> whos

QUESTION 1.2:

In the space provided below, write down MATLABs response after the whoscommand. Did the

command clear ans clear all the variables in the workspace? Why or why not? If not, write the

command for clearing all the variables in the workspace.

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 6

Another useful windowpane in the MATLAB desktop is the Command History window. The

Command History contains a chronological list of the commands you have executed in the Command

Window, including commands from past sessions in MATLAB. For instance, Fig. 1.3 shows the past

commands that we have executed so far in this Chapter.

To quickly navigate through the past command list directly from the Command Window, use the

up/down arrows keys in your keyboard.

Getting help in MATALB may be done in different ways. For example, if you want to access the

complete product documentation, you may click on the help icon on the MATLAB toolstrip. But if

you want to quickly view a shortened text version of the function documentation in the Command

Window, use the help command as illustrated in Example 1.3 below.

Example 1.3

If we want to view the short text version of the command clc, we may enter the following command in

MATLAB:

clc Clear command window.

clc clears the command window and homes the

cursor.

doc clc

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 7

1.5 Math Operations and Functions

When performing a computation, MATLAB observes certain operator precedence (i.e., the order at

which multiple operations in one command line are performed.) A summary of MATLABs operator

precedence levels is shown in Table 1.1 below. Operators within same priority level are evaluated from

left to right as they appear in a command line.

1 Parenthesis ( )

2 Power (^), Transpose ()

3 Multiplication (*), Division (/)

4 Addition (+), Subtraction (-)

5 Logical Operations such as:

Greater than (>), Less than (<), Equal to (==),

Greater than or equal to (>=), Not Equal to (~=)

Example 1.4

Enter the following command line in MATLAB:

>> 6+12/3*2^(2+1)

ans =

38

The result of the computation (i.e., 38) was obtained by performing operations in the following order:

2.) Next, raise 2 to the power of 3 (obtained from step 1), resulting to 8;

3.) Then, divide 12 by 3, resulting to 4;

4.) Next, multiply 4 (obtained from step 3) by 8 (obtained from step 2), resulting to 32;

5.) Finally add 6 and 32 (obtained from step 4), resulting to 38.

Aside from arithmetic operators, MATLAB also has many mathematical functions available.

Some of the most common elementary math functions are listed below:

Various Sine Function: Other Trigonometric Functions:

sin sine of argument in radians cos - cosine

sind - sine of argument in degrees tan - tangent

sinh - hyperbolic sine sec - secant

asin - inverse sine in radians csc cosecant

asind - inverse sine in degrees cot cotangent

asinh - inverse hyperbolic sine

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 8

(Note: Variations of the other trigonometric

functions are also available, e.g., atan for

inverse tangent.)

Complex Functions:

Exponential Functions: abs - absolute value/magnitude

exp - exponential angle phase angle

log - natural logarithm conj - conjugate

log10 - common logarithm

sqrt - square root

Example 1.5

Suppose we want to compute the following in MATLAB:

x cos(n)

y e 0.1n

z x y

where =2f, f=1/8 and n=3.

We may then enter the following sequence of commands in MATLAB command window, and observe

MATLABs response as shown below:

>> x=cos(2*pi*(1/8)*3)

x =

-0.7071

>> y=exp(-0.1*3)

y =

0.7408

>> z=abs(x*y)

z =

0.5238

Exercise 1.2

a.) Enter the following command in MATLAB command window :

>> 8*3/abs(-(1-4)^2/6*5)*7

QUESTION 1.3:

What is the result of the preceding command? How was the result computed in the preceding

command? (Present an ordered list of operations just as in Example 1.4.)

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 9

b.) Suppose we want to compute x, y and z below:

2p/ T

x ;

Fs

x sin(nx)

y ( )

nx

2n

z y 0.54 0.46cos( )

L1

QUESTION 1.4:

List down your MATLAB commands that computes x, y and z. What are the values of x, y and z?

Throughout the entire DSP laboratory course, we will be dealing with signal representations in the form

of vectors and matrices. For example a digital audio signal would usually be represented as a row or a

column vector, while a digital image would usually be represented as a matrix. Vectors may be thought

of as a special matrix having only a single row or a single column.

To create a row vector of any length in MATLAB, simply type the elements or numbers,

separated by commas or spaces, inside a square bracket [ ]. Similarly, to create a matrix of any size in

MATLAB, type the matrix elements separated by commas or spaces, and with each row separated by

semicolons, inside a square bracket [ ]. Note that the semicolon (;) is a row separator.

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 10

Example 1.6

Suppose we want to create the following vectors and matrices in MATLAB:

1

A 1 2 3 B 0

2

4 3 6

C7 1 0

2 1 8

>> A=[1,2,3]

A =

1 2 3

>> B=[1;0;-2]

B =

1

0

-2

>> C=[4,-3,6;7,-1,0;2,-1,8]

C =

4 -3 6

7 -1 0

2 -1 8

Note that we may also create the column vector [B] by invoking the matrix transpose or single quote ()

operator as shown below:

>> B=[1,0,-2]

B =

1

0

-2

Arithmetic operators (+), (-) and (*) also applies to vectors and matrices provided that proper

dimensions are observed. For example, addition (+) or subtraction (-) operators will only apply to vectors

and matrices that are having same dimensions. Otherwise, unequal dimensions results to a syntax error.

Similarly, multiplication (*) operator only applies between two matrices with equal inner or internal

dimensions. If what we want is an element-wise multiplication, instead of a matrix multiplication, then

we should precede the (*) operator with a dot (.). This is illustrated in the next example below.

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 11

Example 1.7

Let us say we want to add the vectors [A] and [B]T from Example 1.6. The MATLAB command for this is:

>> A+B'

ans =

2 2 1

>> A*B

ans =

-5

>> A*B'

Error using *

Inner matrix dimensions must agree.

>> A.*B'

ans =

1 0 -6

Note from the preceding example that A*B is a matrix multiplication resulting to a scalar because the

outer dimensions of [A]1x3 and [B]3x1 are both equal to 1. The command A*B produced a syntax error

because the inner or interior dimensions of [A]1x3 and [B]T 1x3 are not equal (i.e., 3 1). Finally, the

Some useful matrix or array creation built-in functions, such as ones, zeros, rand and eye,

are available in MATLAB. These commands, together with their brief descriptions, are listed below:

linspace - Generate linearly spaced vectors

ones - Create array of all ones

rand - Uniformly distributed pseudorandom numbers

zeros - Create array of all zeros

Example 1.8

Let us look at the MATLABs response to the following commands:

>> A=ones(2,3)

A =

1 1 1

1 1 1

>> B=eye(3)

B =

1 0 0

0 1 0

0 0 1

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 12

>> C=rand(1,4)

C =

0.8147 0.9058 0.1270 0.9134

>> D=linspace(0,2,5)

D =

0 0.5000 1.0000 1.5000 2.0000

In the preceding example: [A] is a 2-by-3 matrix all elements of which are equal to 1, [B] is a 3-by-3 identity

matrix, C is a 4-element row vector whose elements are random numbers, and [D] is a 5-point vector

whose elements are equally spaced in the range from 0 to 2.

The colon (:) or the range operator is one of the most useful operators in MATLAB that can

generate a vector whose elements are equally spaced, and can be used for array subscripting or a loop

iterator. The general form is (init : inc : final), where init = initial element value, inc = increment or

decrement value, and final = final element value.

Example 1.9

The matrix [D] created in Example 1.8 may likewise be created using the colon operator as shown below:

>> D=0:0.5:2

D =

0 0.5000 1.0000 1.5000 2.0000

>> E=1:5

E =

1 2 3 4 5

>> F=5:-1:1

F =

5 4 3 2 1

Note also from the preceding example that in creating the vector [E] where the element spacing is equal

to 1, we may delete the increment or the middle field from the command. In creating vector [F], note

that a negative value for the increment field is necessary.

Another important matrix manipulation task is extraction through array indexing. Array

indexing allows us to address a certain portion of a huge vector or matrix for extraction or isolation. In

signal processing for example, there are times when we need to perform an operation only to a short

segment of a long audio recording, or only to a small cropped portion of a huge matrix representing a

certain digital image.

To address a particular element of a certain matrix, say [A], specify its row and column number

using the following format:

A(row, col)

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 13

Example 1.10

Let us now try the MATLAB commands shown below:

A =

1 2 3

4 5 0

0 -6 7

>> B=A(2,1)

B =

4

>> C=A(2,:)

C =

4 5 0

>> D=A(1:2,2:3)

D =

2 3

5 0

After the execution of the second command in the preceding example, observe that [B] then contains

the 2nd row, 1st column element of [A]. After the execution of the third command, observe that [C]

then contains the whole 2nd row of [A]. Finally after the execution of the fourth command, check that

[D] contains the 2-by-2 portion of [A] corresponding to elements in rows 1 and 2, which are also in columns

2 and 3.

The final important matrix manipulation task covered in this chapter is matrix concatenation.

Matrix concatenation is the process of joining two or more matrices to make a larger matrix. In MATLAB,

brackets [ ] are used as concatenation operator. In the matrix concatenation task, we form a larger

matrix as we would form an ordinary vector or matrix, but this time with matrix elements being the smaller

matrices themselves to be concatenated.

Example 1.11

Let us now look at the following MATLAB commands:

>> C=[A,B]

C =

1 2 3 4 5 6

>> D=[A,A;B,B]

D =

1 2 3 1 2 3

4 5 6 4 5 6

We first note from the first command line in the preceding example that a semicolon (;) operator may

also be used as a statement separator, and as an output suppressor. Next, we see that [C] is a horizontal

concatenation of [A] and [B]. Finally, [D] is a result of both horizontal and vertical concatenations. That

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 14

is, [D] is the vertical concatenation of [A,A] and [B,B], which are respective horizontal concatenations of

[A] and [B] with themselves.

Exercise 1.3

Write MATLAB commands that create a certain 7-by-7 matrix [A] with the following specifications:

sin(n / 2)

2nd row contains the values of , for n=0, 1, 2,,6

(n / 2)

n

3rd row contains the values 0.7 , for n=0, 1, 2,,6

The lower right 3-by-3 portion of [A] are all zeros

The remaining elements are random numbers generated by rand

QUESTION 1.5:

Present an ordered list of MATLAB commands with brief explanations for the above exercise. Is it

possible to change the order of your commands and still come up with the desired result? Why or why

not? Briefly explain your answer.

The Lab Instructor provides the machine problem for this chapter.

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 15

MATLAB Code/Notes:

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 16

Results and Conclusion:

DSP Lab Manual Ronald M. Pascual & FEU Institute of Technology Page 17

- Pure Maths Unit 1 Paper 1 2013Uploaded byKingBee1123
- Georgia State University Math Placement Practice TestUploaded byJoey Wright
- 77864266-Getting-Started-With-Matlab-RudraPratap_Parte3.pdfUploaded byjulionba
- Tutorial 2Uploaded bySeedy B Fofana
- yahoo answersUploaded byl2kassassisn
- Graphing Trigonometric FunctionsUploaded byChristian Temporado
- MathematicsUploaded byHary Kriz
- TrigonometryUploaded byEdward S. Mzugu
- 5.3 ExerciseUploaded byAvnish Bhasin
- JavaScript BuiltUploaded byRaj Bangalore
- Secret_ECE524.pdfUploaded byKarumon Utsumi
- AllLessons.pdfUploaded bylucthiano
- Oracle FunctionsUploaded byVikram Reddy
- Jeep 208Uploaded bywhatqwerty
- Matlab Chapter 1Uploaded byChathura Priyankara Wijayarathna
- Mathsisinteresting.blogspot.com Search q=Sinc+FunctionUploaded byYogesh Gujar
- 1006.2938Uploaded byJunior Chico
- ch 1 notes Grist CalculusUploaded byjhahab
- SPM Add Maths Formula List Form5Uploaded bySayantani Ghosh
- EN_SIMIT_SCE_V7_Basic_Libray.pdfUploaded byChrisKastanja
- Introduction to MATLABUploaded bySäjidëë KisÅn
- Satii QuizUploaded byTanaka Okada
- 700000637_Topper_8_101_4_3_Mathematics_2012_questions_up201506182058_1434641282_7364.pdfUploaded byShri Ram Yadav
- CSE123_Lecture02_2013.pdfUploaded byHasanMert
- Trig1Uploaded byMarkoKralj
- Common_Math_Errors.pdfUploaded byΔημήτρης Τρίκας
- MATA30_TT2_2012F.pdfUploaded byexamkiller
- Fpseries Prog f313e-18Uploaded byprsantos98
- lec03.pdfUploaded byss_nainamohammed
- 9.2 Trigonometry IIUploaded byl_sieeng

- 05114200 2Uploaded bySAKDA MAPRADITKUL
- 2014.11.27.Debates on LTE-unlicensed and WiFi (KT, SK Telecom, Qualcomm).pdfUploaded byAbdulqader Al-kaboudei
- fly by wire and fly by opticsUploaded byvenkatsahul
- Building IrregularitiesUploaded bykalpanaadhi
- Handling Notes on the Cessna 152Uploaded byc_s_wagon
- 39026413Uploaded byJesse Ramirez
- 300 Project Manager Interview QuestionsUploaded bybhaveshkumar78
- ICU Mechanical Ventilators, Technologicaladvances vs. User Friendliness the Rightpicture is Worth a Thousand Numbers 2009Uploaded byEN BU
- Quality+Control+Manual+2015Uploaded byJasna Maksimova
- EOR Processes.pptUploaded byPurabiBora
- NACTO Urban Bikeway Design GuideUploaded byAiman Zhafri
- Ccece04 Fast CentroidUploaded byHenno Snyman
- What is an Enterprise ArchitectureUploaded byKibrom Haftu
- Mech Vi Non Traditional Machining [10me665] NotesUploaded bynikhil
- Case Study RevisedUploaded byRoel Wills
- beyli1981 (1)Uploaded byIsaac Gabriel Larrea
- Diode Matrix ROM1Uploaded byDeepak Kumbhar
- Module 1 - GasesUploaded byRuth Aquino
- Tl-wr941n_941nd User GuideUploaded byRadomir Panic
- BT Hand Pallet Truck Product and Service brochure.pdfUploaded bytintucinb
- Distance Survey ProblemUploaded bySajid ar
- An Offshore Wind Farm for the South Fork (by Clint Plummer)Uploaded byGordian Raacke
- New Wordpad DocumentUploaded byAsif Khan
- ApplicationUploaded byzaheermech
- Stealth AntennasUploaded byblackbeast8
- UHF RFID102R Integrated Reader by R2000Uploaded byPercy M. Sucari
- Proximate Analysis of CoalUploaded byAngelica Alvizo
- Centrum KlimaUploaded bycentrumklima
- Handan Xinxing Heavy Machinery CoUploaded bysantoshkumarmishra2009
- Tandberg Edge 95 85 75 MxpUploaded byManuel Vasquez Neira