Sie sind auf Seite 1von 100

CHAPTER I

STARTING WITH MATLAB


Brief introduction to MATLAB

MATLAB (MATrix LABoratory) is an interactive software, developed by Math Works Inc.


MATLAB can be used for math computations, modeling and simulations, data analysis and processing,
visualization and graphics, and algorithm development. It is particularly effective when data format is
vector or matrix.
MATLAB is primarily written in FORTRAN and C. However, MATLAB knows how to interpret
commands, while a compilation of the source code is required by FORTRAN or C.
MATLAB is especially designed for digital signal processing and for complex digital system
modeling and simulation. It is suitable for processing data series, images or multidimensional data fields.
The standard MATLAB program has tools (functions) that can be used to solve common
problems. In addition, MATLAB has optional toolboxes that are collections of specialized programs
designed to solve specific types of problems. Examples include toolboxes for signal processing,
symbolic calculations, and control systems
MATLAB has been developed for several years, as especially as a consequence of its use in the
academic environment as an excellent tool in mathematics, engineering and science. In addition,
MAATLAB has already proven its utility for scientific research and technological development.

The MATLAB Window

Windows commonly used in MATLAB are as follows:

1. Command Window: The Command Window is MATLAB’s main window and opens when
MATLAB is started.

Figure 1-1. The Command Window (default MATLAB window)

1
2. Figure Window: The Figure Window opens automatically when graphics commands are executed,
and contains graphs created by these commands.

Figure 1-2. Example of a Figure Window

3. Editor Window: The Editor Window is used for writing and editing programs. This window is
opened from the File menu. It is used for writing script files and function files.

Figure 1-3. Example of an Editor Window

2
4. Help Window: The Help Window contains help information. This window can be opened from the
Help menu in the toolbar of any MATLAB window. The Help Window is interactive and can be used
to obtain information on any feature of MATLAB.

Figure 1-4. Example of a Help Window

3
Working in the command window

The Command Window is MATLAB’s main window and can be used for executing commands, opening
other windows, running programs written by the user, and managing the software.

Figure 1-5: The Command Window

Notes for working in the Command Window:

• To type a command the cursor must be placed next to the command prompt ( >> ).

• Once a command is typed and the Enter key is pressed, the command is executed. However, only the last
command is executed. Everything executed previously (that might be still displayed) is unchanged.

• Several commands can be typed in the same line. This is done by typing a comma between the commands.
When the Enter key is pressed the commands are executed in order from left to right.

• It is not possible to go back to a previous line that is displayed in the Command Window, make a
correction, and then re-execute the command.

• A previously typed command can be recalled to the command prompt with the up-arrow key ( ). When the
command is displayed at the command prompt, it can be modified if needed and then executed. The down-
arrow key ( ) can be used to move down the list of previously typed commands.

• If a command is too long to fit in one line, it can be continued to the next line by typing three periods …
(called an ellipsis) and pressing the Enter key. The continuation of the command is then typed in the new
line. The command can continue line after line up to a total of 4,096 characters.

The semicolon ( ; ):

When a command is typed in the Command Window and the Enter key is pressed, the command is executed.
Any output that the command generates is displayed in the Command Window. If a semicolon ( ; ) is typed at
the end of a command the output of the command is not displayed. Typing a semicolon is useful when the
result is obvious or known, or when the output is very large.

If several commands are typed in the same line, the output from any of the commands will not be displayed
if a semicolon is typed between the commands instead of a comma.
4
Typing %:

When the symbol % (percent) is typed at the beginning of a line, the line is designated as a comment. This
means that when the Enter key is pressed the line is not executed. The % character followed by text
(comment) can also be typed after a command (in the same line). This has no effect on the execution of the
command.

Usually there is no need for comments in the Command Window. Comments, however, are frequently used
in a program to add descriptions or to explain the programs.

The clc command:

The clc command (type clc and press Enter) clears the Command Window. After working in the Command
Window for a while, the display may become very long. Once the clc command is executed a clear window
is displayed. The command does not change anything that was done before. For example, if some variables
were defined previously (see Section 1.6), they still exist and can be used.

The up-arrow key can also be used to recall commands that were typed before.

ELEMENTARY MATH BUILT-IN F UNCTIONS

Table 1-2: Elementary Math Functions

5
Table 1-3: Trigonometric Functions

Table 1-4: Rounding Functions

DEFINING SCALAR VARIABLES

A variable is a name made of a letter or a combination of several letters (and digits) that is assigned a
numerical value. Once a variable is assigned a numerical value, it can be used in mathematical expressions,
in functions, and in any MAT-LAB statements and commands. A variable is actually a name of a memory
location. When a new variable is defined, MATLAB allocates an appropriate memory space where the
variable’s assignment is stored. When the variable is used the stored data is used. If the variable is assigned
a new value the content of the memory location is replaced.

6
The Assignment Operator

In MATLAB the = sign is called the assignment operator. The assignment opera-tor assigns a value to a
variable

Variable_name = A numerical value, or a computable expression

The left-hand side of the assignment operator can include only one variable name. The right-hand side can be
a number, or a computable expression that can include numbers and/or variables that were previously
assigned numerical values. When the Enter key is pressed the numerical value of the right-hand side is
assigned to the variable, and MATLAB displays the variable and its assigned value in the next two lines.

The following shows how the assignment operator works

Rules About Variable Names

A variable can be named according to the following rules:

• Must begin with a letter.

• Can be up to 63 characters long.

• Can contain letters, digits, and the underscore character.

• Cannot contain punctuation characters (e.g., period, comma, and semicolon).

• MATLAB is case sensitive: it distinguishes between uppercase and lowercase letters. For example, AA,
Aa, aA, and aa are the names of four different variables.

• No spaces are allowed between characters (use the underscore where a space is desired).

• Avoid using the name of a built-in function for a variable (i.e., avoid using cos , sin , exp , sqrt, etc.). Once
a function name is used to define a variable, the function cannot be used.

Predefined Variables and Keywords

There are 20 words, called keywords that are reserved by MATLAB for various purposes and cannot be used
as variable names. These words are:

break case catch classdef continue else elseif end for function global if otherwise parfor

persistent return spmd switch try while

When typed, these words appear in blue. An error message is displayed if the user tries to use a keyword as a
variable name. (The keywords can be displayed by typing the command iskeyword.)
7
A number of frequently used variables are already defined when MATLAB is started. Some of the predefined
variables are:
ans A variable that has the value of the last expression that was not assigned to a specific variable. If the
user does not assign the value of an expression to a variable, MATLAB automatically stores the
result in ans .
pi The number π.
eps The smallest difference between two numbers. Equal to 2^(–52), which is approximately 2.2204e–
016.
inf Used for infinity.
i Defined as , which is: 0 + 1.0000i.
j Same as i.
NaN Stands for Not-a-Number. Used when MATLAB cannot determine a valid numeric value. Example:
0/0.

The predefined variables can be redefined to have any other value. The variables pi, eps , and inf , are
usually not redefined since they are frequently used in many applications. Other predefined variables, such
as i and j , are sometime redefined (commonly in association with loops) when complex numbers are not
involved in the application.

SCRIPT FILES

A script file is a list of MATLAB commands, called a program that is saved in a file. When the script file is
executed (run), MATLAB executes the commands.

Notes About Script Files


• A script file is a sequence of MATLAB commands, also called a program.
• When a script file runs (is executed), MATLAB executes the commands in the order they are written
just as if they were typed in the Command Window.
• When a script file has a command that generates an output (e.g., assignment of a value to a variable
without a semicolon at the end), the output is displayed in the Command Window.
• Using a script file is convenient because it can be edited (corrected or otherwise changed) and
executed many times.
• Script files can be typed and edited in any text editor and then pasted into the MATLAB editor.
• Script files are also called M-files because the extension .m is used when they are saved.
Creating and Saving a Script File

In MATLAB script files are created and edited in the Editor/Debugger Window. This window is
opened from the Command Window. In the File menu, select New , and then select Script . An open
Editor/Debugger Window

8
Figure 1-6: Editor/Debugger Window

Once the window is open, the commands of the script file are typed line by line. MATLAB
automatically numbers a new line every time the Enter key is pressed. The commands can also be typed in
any text editor or word processor program and then copied and pasted in the Editor/Debugger Window. An
example of a short program typed in the Editor/Debugger Window is shown in Figure 1-7. The first few lines
in a script file are typically comments (which are not executed since the first character in the line is %) that
describe the program written in the script file.

Before a script file can be executed it has to be saved. This is done by choosing Save As... from the File
menu, selecting a location and entering a name for the file. When save d, MATLAB adds the extension .m to
the name. The rules for naming a script file follow the rules of naming a variable (must begin with a letter,
can include digits and underscore, no spaces , and up to 63 characters long). The names of user-defined
variables, predefined variables, and MATLAB commands or functions should not be used as names of script
files.
Running (Executing) a Script File

A script file can be executed either directly from the Editor Window by clicking on the Run icon (see
Figure 1-7) or by typing the file name in the Command Window and then pressing the Enter key. For a file
9
to be executed, MATLAB needs to know where the file is saved. The file will be executed if the folder
where the file is saved is the current folder of MATLA B or if the folder is listed in the search path, as
explained next.

Current Folder

The current folder is shown in the “Current Folder” field in the desktop toolbar of the Command Window, as
shown in Figure 1- 8. If an attempt is made to execute a script file by clicking on the Run icon (in the
Editor Window) when the current folder is not the folder where the script file is saved, then the prompt
shown in Figure 1-8

Figure 1-9 will open. The user can then change the current folder to the folder where the script file is saved,
or add it to the search path. Once two or more different current folders are used in a session, it is possible to
switch from one to another in the Current Folder field in the Command Window. The current folder can also
be changed in the Current Folder Window, shown in Figure 1-10, which
can be opened from the Desktop menu. The Current Folder can be changed by choosing the drive and folder
where the file is saved.

10
An alternative simple way to change the current folder is to use the cd command in the Command
Window. To change the current folder to a different drive, type cd, space, and then the name of the directory
followed by a colon : and press the Enter key. For example, to change the current folder to drive F (e.g., the
flashdrive) type cd F:. If the script file is saved in a folder within a drive, the path to that folder has to be
specified. This is done by typing the path as a string in the cd command. For example, cd('F:\Chapter 1') sets
the path to the folder Chapter 1 in drive F. The following example shows how the current folder is changed
to be drive E. Then the script file from Figure 1-7, which was saved in drive E as ProgramExample.m, is
executed by typing the name of the file and pressing the Enter key.

EXAMPLES OF MATLAB APPLICATIONS

Sample Problem 1-1: Trigonometric identity

A trigonometric identity is given by:

Verify that the identity is correct by calculating each side of the equation, substituting x = π/5

11
Solution
The problem is solved by typing the following commands in the Command Window.

Sample Program: Geometry and Trigonometry

12
Sample Problem 1-4: Compounded interest

13
Operations with Matrices and Arrays

Some important terms:

14
15
16
17
Example: Consider the following sum of functions

Approach 1

Approach 2

Approach 3

18
19
SCRIPTS AND FUNCTIONS IN SIGNAL PROCESSING

INPUT SCRIPT TO A FILE

20
21
When executed:

22
23
The fprintf Command

24
25
26
USER DEFINED FUNCTIONS

CREATING A FUNCTION FILE

27
28
The following are examples of function definition lines with different combinations of input
and output arguments.

SIMPLE EXAMPLE OF A USER DEFINED FUNCTION

29
30
THE TWO-DIMENSIONAL PLOTS

31
Example of executing a plot Command

The Figure Window with simple plot

32
33
Example: Plot the given data

34
The Figure Window with a plot of the sales data

The fplot Command

35
PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT

36
EXAMPLE OF PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT

USING THE hold on AND hold off COMMAND

To plot several graphs using the hold on and hold off commands, one graph is plotted first with
the plot command. Then the hold on command is typed. This keeps the figure window with the
first plot open, including its axis properties and formatting any was done. Additional graphs can
be added with plot command that are typed next. Each plot commands creates a graph that is
added to that figure. The hold off command stops this process. It returns MATLAB to the default
mode in which the plot command erases the previous plot and resets the axis properties: The
following is an example of MATLAB command using hold on and hold off

37
PUTTING MULTIPLE PLOTS ON THE S AME PAGE (THE subplot COMMAND)

38
39
Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 1

Name: ______________________ Date Performed: ____________

Course / Year _________________ Date Passed : _______________

I. Title: Familiarization of MATLAB commands through basic mathematical functions


II. Objectives:
At the end of this activity, students will be able to

1. Familiarize on the MATLAB environment


2. Use the built-in MATLAB command.
3. Execute and run saved functions/commands.

III. Procedures: (use the space provided to write your MATLAB commands)

Solve the following problems by writing commands in the Command Window, or by writing a program
in a script file and then executing the file.

40
11. Circuit Applications

12. Resonant Frequency Applications

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”

- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing 41
Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 2

Name: ______________________ Date Performed: ____________

Course / Year _________________ Date Passed : _______________

I. Title: Familiarization of MATLAB Commands Through Array Manipulation


II. Objectives:
At the end of this activity, students will be able to

1. Familiarize on the MATLAB environment


2. Use the built-in MATLAB array commands.
3. Distinguish scalar manipulations from vector manipulations
4. Execute and run saved functions/commands.

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Create a 2x3 matrix A with elements 5, -3, 8 on the first row and 9, 2, 10 on the second row

>> A = [5 -3 8; 9 2 10]

2. Create a 2x3 matrix B with elements 10, 7, 4 on the first row and -11, 15, 1 on the second
row

>> B = [10 7 4; -11 15 1]

3. Subtract matrix B from matrix A

>> A – B

4. Define matrix C that is equal to A + B

>> C=A + B

42
5. Number 8 is subtracted from C. Save your work

>> C – 8

6. In another editor make matrices A & B as follows

>> A = [1 4 2; 5 7 3; 9 1 6; 4 2 8];
>> B = [6 1; 2 5; 7 3];

7. Multiply matrix A by matrix B and assign the result as C

>> C = A*B

8. Do also >>D = B*A. What happens? Why? Place your answer on the answersheet.

9. Multiply matrix A by 5. >> A* 5 and >>> 5*A

10. Create matrices AV = [2 5 1] and BV = [2; 1; 4] and try multiplications AV*BV and
BV*AV. Copy the answer in the worksheet. Why do they differ?

11. Determine the inverse of A = [2 1 4; 4 1 8; 2 -1 3] and assign the inverse as B.

>> A = [2 1 4; 4 1 8; 2 -1 3]
>> B = inv(A)

12. Multiply A*B. What type of matrix is the result? (place your answer in the answersheet)

13. Try also >> A*A^-1. What type of matrix is the result? (place your answer in the
answersheet)

14. Manually get the determinant of A in item 11. Place your calculation in the worksheet.

Compare the result by inputting the commands >> det(A) in MATLAB.

43
15. ARRAY DIVISION: MATLAB has two types of array division which are the right division
and left division. First is the left division(\) which is used to solve matrix equation AX = B.
In this equation X and B are column vectors. This equation can be used by multiplying on
the left both sides the inverse of A.

A-1AX = A-1B
X = A-1B
X = A\B

For the right division(/); to solve matrix equation XC = D. In this equation X and D are row
vectors. This equation can be used by multiplying on the right both sides the inverse of C.

X.CC-1 = DC-1
X = DC-1
X = D/C

To solve the three linear equations

4x – 2y + 6z = 8

2x + 8y + 2z = 4

6x + 10y +3z = 0

a. Solving the form AX = B


>> A = [4 -2 6; 2 8 2; 6 10 3];
>> B = [8; 4; 0];
>> Xa = A\B
>> Xb = inv(A)*B

b. Solving for the row vectors in the form XC = D


>> A = [4 2 6;- 2 8 10; 6 2 3];
>> B = [8; 4; 0];
>> Xa = D/C
>> Xb = D*inv(C)

16. For element-by-element operation, either multiplication(.*), division (.\ , ./) and
exponentiation (.^) is entered in MATLAB by typing a period in front of the arithmetic
operator. Notice the answers of the following in the given matrices A = [2 6 3; 5 8 4; 4 3 1]
and B = [6 -2 1; 4 -2 6; 5 4 -4]
a. >>A .* B
b. >>A * B
c. >> C = A ./ B
d. >> D = A / B
44
e. >> E = A .^ -1
f. >> F = A ^ -1
g. >> G = A .^ B
h. >> H = A ^ B
17. The electrical circuit shown consists of resistors and voltage sources. Determine the current
in each resistor using the mesh current method which is based on Kirchhoff’s voltage law.
Loop 1 on the loop with 20V , loop 3 on the loop with 12V and loop 4 on the loop with 40V
for uniformity.(Write your MATLAB commands in the answersheet.)

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”

- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Signals Spectra and Signal Processing

ACTIVITY 2 (Aswersheet)

Name: _______________________ Date Performed: ___________________

Course / Year _____________ Date Passed : ______________________


45
1. Item 8.
_________________________________________________________________________________
_____________________________________________________________________________
2. Item 10.
_________________________________________________________________________________
_____________________________________________________________________________Item
12.
_______________________________________________________________________________

3. Item 13.
_______________________________________________________________________________
4. Item 14.

5. What do you notice on the results of Xa and Xb in item 15 (a)?


_______________________________________________________________________________
6. What do you notice on the results of Xc and Xd in item 15 (b)?
_________________________________________________________________________________
________________
7. What do you notice on the results of item 16 (a) and 16(b)?
_________________________________________________________________________________
_________________________________________________________________________________
____________________________________
8. What do you notice on the results of item 16 (c) and 16(d)?
_________________________________________________________________________________
_____________________________________________________________________________
9. What do you notice on the results of item 16 (e) and 16(f)?
_________________________________________________________________________________
_____________________________________________________________________________
10. What do you notice on the results of item 16 (g) and 16(h)?
_________________________________________________________________________________
_____________________________________________________________________________

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 3

46
Name: ______________________ Date Performed: ____________

Course / Year _________________ Date Passed : _______________

I. Title: The Script File


II. Objectives:
At the end of this activity, students will be able to

1. Familiarize on the MATLAB script commands


2. Make a script file in MATLAB.
3. Use the input and output commands and implement in script files.

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Create a script file that calculate the distance of a projectile given its initial velocity and the
angle at which it was shot. Use the output commands to display a mix of text and numbers.

2. Voltage Divider

47
48
3. Create a MATLAB script for the conversion of oF to oC and vice versa.

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya

Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 4

Name: ______________________ Date Performed: ____________


49
Course / Year _________________ Date Passed : _______________

I. Title: The User-Defined Functions


II. Objectives:
At the end of this activity, students will be able to

1. Familiarize on the MATLAB user-defined functions


2. Create a user-defined functions.
3. Use the input and output commands and implement in function files.

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Create a function file that calculate the distance of a projectile given its initial velocity and the
angle at which it was shot. Use the output commands to display a mix of text and numbers.

2. Create a user defined function in solving for the base current, collector current, emitter
current, base voltage, collector voltage and emitter voltage of an NPN transistor connected
in a voltage divider bias.

50
3. Create a user-defined function MATLAB file for the conversion of oF to oC and vice versa.

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya

Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 5

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: 2-D and 3-D Plots


II. Objectives:
At the end of this activity, students will be able to

1. Use the plot command, understand its format and will be able to implement using line properties such as
its style, color, its marker type.
2. Use the fplot command and implement in two-dimensional plot.
3. Plot multiple graph in the same plot.
4. Format a plot using label, title, text, legend, axis and grid commands.
5. Plot with special graphics such as the bar plot, stairs plot, pie plot histograms and polar plots.

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Create the plot of sine and cosine functions in a single from o to 2π. Apply marker characteristics to
distinguish from each other. Apply title, x and y label, grid and legend. Use hold on/hold off command.
Write your command in here.

51
2. Do problem number 1 using subplots

3. Create the plot of sine and cosine functions in a single from –π to π. Apply marker characteristics to
distinguish from each other. Apply title, x and y label, grid, legend, axis visibility, axis aspect ratio and
axis limits. Use hold on/hold off command. Write your command in here.

52
4. Plot the function y = 3x3 – 26x + 10, its first and second derivative from the limit -2 to 4. Apply marker
characteristics to distinguish from each other. Apply title, x and y label, grid, legend, axis visibility, axis
aspect ratio and axis limits. Use hold on/hold off command. Write your command in here.

5. Plots with special graphics. The following program shows a bar graph of sales(in Million) from 1988 to
1994 of a certain company. The “ r” indicates red bar.

Year = [1988:1994]
Sales= [8 12 20 22 18 24 27]
Bar(Year, Sales, ‘r’)
xlabel (‘Year’)
ylabel (‘Sales (in Millions)’)

a. Do the problem using horizontal bar and apply title. Command: barh(x,y)
b. Do the problem using stairs plot and apply title. Command: stairs(x,y)
c. Do the problem using stem plot and apply title. Command: stem(x,y)
d. Do the problem using pie chart and apply title. Command: pie(x)
e. Do the problem using histogram and apply title. Command: hist(y)

53
6. A stone is thrown with an initial velocity of 50 m/s at an angle of 30 degrees with the horizontal. Make a
script and plot the y position, its velocity in same plot. Plot also in subplots.

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

CHAPTER II
DISCRETE-TIME SIGNALS AND SYSTEMS

DISCRETE-TIME SIGNALS

54
TYPES OF SEQUENCES

55
56
OPERATIONS ON SEQUENCES

57
58
59
DISCRETE-TIME SINUSOIDS

In the last section we introduced the discrete-time sinusoidal sequence x(n)=


A cos( ω0n + θ0), for all n as one of the basic signals. This signal is very
important in signal theory as a basis for Fourier transform and in system
theory as a basis for steady-state analysis. It can be conveniently related to
the continuous-time sinusoid xa(t)= A cos(Ω0t + θ0) using an operation called
sampling, in which continuous-time sinusoidal values at equally spaced
points t = nTs are assigned to x(n).

60
SOME USEFUL RESULTS

Example of Even-Odd Decomposition

61
Odd – even decomposition of the above example

62
DISCRETE SYSTEMS

LINEAR SYSTEMS

EXAMPLE

Solutions

63
EXAMPLE

Solutions

64
65
CONVOLUTION

The following example is a MATLAB implementation of a convolution.

Example: Given the following two sequences

DIFFERENCE EQUATIONS

66
EXAMPLE

Solutions

67
Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 7

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: Discrete-Time Signals


II. Objectives:
At the end of this activity, students will be able to

1. Generate and plot different discrete-time sequences over an indicated interval


2. Make functions and utilize it in generating plot of discrete time sequences

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Generate the plot for the following sequences

a. x(n)=2δ (n +2) − δ (n − 4) , −5 ≤ n ≤ 5

10
b. x(n) = ∑ (m+ 1)[δ (n−2m)−6(n−2 m−l)], 0 ≤ n ≤ 25.
m=0

c. x (n) = (0.9)n cos (0.2πn + π/3), 0 ≤ n ≤ 20

68
2. Let x(n) = {1, -2,4,6, -5,8,10}. Generate and plot the samples (use the stem function) of the
following.sequences.
a. x1 (n) = 3x(n + 2) + x(n - 4) - 2x(n)

b. x2(n) = 5x(5 + n) + 4x(n + 4) + 3x(n)

c. x3 (n) = x(n + 4)x(n - 1) + x(2 - n) x(n)

d. x4 (n) = 2e0.5" x (n) + cos (0.lπn) x (n + 2), -10 ≤ n ≤ 10

69
5
e. x5 (n) = ∑ nx (n−k )
k=1

3. Combine the output of item 2 using subplot

4. Decompose the sequences in problem 2 parts (a), (b), (c), (d),( e) into their even and odd components. Plot
these components using the stem function.

5. Combine the output of item 4 using subplot

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing 70
Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 8

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: CONVOLUTION
II. Objectives:
At the end of this activity, students will be able to

1. Generate and plot discrete-time sequences using convolution


2. Make functions and utilize it in generating plot of discrete time sequences

III. Procedures: (use the pace provided to write your MATLAB commands)
1. The linear convolution has several properties:

x 1 ( n )∗x 2 ( n )=x 2 ( n )∗x 1 ( n ) Commutative


[ x 1 ( n )∗x 2 ( n ) ]∗x 3 ( n )=x 1 ( n )∗[x 2 ( n )∗x 3 ( n ) ] Associative
x 2 ( n)
x 1 ( n )∗[¿]+ x 3 ( n ) Distributive
¿
¿
x ( n )∗δ ( n−n 0 )=x ( n−n0 ) Identity

a. Analytically prove these properties

b. Using the following three sequences, verify the above properties

u ( n+10 )−u (n−20)


x 1 ( n )=n¿
x 2 ( n ) =cos ( 0.1 πn ) [u ( n )−u ( n−30 ) ]
u ( n+5 )−u(n−10)
n ]
x3 ( n ) =(1.2) ¿

c. Generate the plot for the sequences item b.

71
“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 9

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: DIFFERENCE EQUATION


II. Objectives:
At the end of this activity, students will be able to

1. Generate and plot discrete-time sequences using difference


2. Make functions and utilize it in generating plot of discrete time sequences

III. Procedures: (use the pace provided to write your MATLAB commands)
1. A particular linear and time-invariant system is described by the difference equation

y ( n )−0.5 y ( n−1 )+ 0.25 y ( n−2 )=x ( n ) +2 x 1 ( n−1 ) + x (n−3)


a. Determine the stability of the system
b. Determine and plot the impulse response of the system over 0 ≤ n ≤ 100. Determine the stability
from this impulse response
c. If the input to this system is x ( n )=[ 5+cos ( 0.2 πn ) +4 sin ( 0.6 πn ) u ( n ) ] determine the
response y ( n ) over 0 ≤ n ≤ 200

2. A simple digital differentiator is given by

y ( n )=x ( n )−x (n−1)

Which computes a backward first-order difference of the input sequence. Implement this
differentiator on the following sequences and plot the results. Comment on the appropriateness of
this simple differentiator.
a. x ( n )=5[ u ( n )−u ( n−20 ) ] : a rectangular pulse
b. x ( n )=n [ u ( n )−u ( n−10 ) ] +(20−n)[u ( n−10 )−u ( n−20 ) ] : a triangular pulse
πn
25
c. : a sinusoidal pulse
(¿)[u ( n )−u ( n−100 ) ]
x ( n )=sin ¿

72
“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

CHAPTER III
DISCRETE – TIME FOURIER ANALYSIS

Some Common DTFT Pairs

73
EXAMPLE
Determine the discrete-time Fourier Transform of x(n) = (0.5)n u(n) at 501
equispaced points between (0, π) and plot its magnitude, angle, real and imaginary
parts.

74
THE PROPETIES OF THE DTFT

75
76
THE FREQUENCY DOMAIN REPRESENTATION OF LTI SYSTEM

77
Example

78
FREQUENCY RESPONSE FUNCTION FROM DIFFERENCE EQUATIONS

Example

79
80
CHAPTER IV

81
82
83
Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 10

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: DISCRETE-TIME FOURIER TRANSFORM


II. Objectives:
At the end of this activity, students will be able to

1. Generate and plot discrete-time Fourier transform of different sequences


2. Make functions and utilize it in generating plot of discrete time sequences

III. Procedures: (use the pace provided to write your MATLAB commands)
1. Numerically compute the discrete-time Fourier transform of

x ( n )={1, 2,3 , 4,5 }

at 501 equispaced frequencies between [0, π]

2. Determine the discrete-time Fourier transform and investigate the periodicity of

π
j
0.9 e 3 ) n , 0 ≤ n ≤ 10
x ( n )=¿

Evaluate an plot it at 401 equispaced frequencies over two periods between -2π to 2π. Observe its
periodicity.

84
3. Determine the discrete-time Fourier transform and investigate the conjugate symmetry of its DTFT of

0.9
) n , -10 ≤ n ≤ 10
x ( n )=¿

Evaluate an plot it at 401 equispaced frequencies over two periods between -2π to 2π. Observe its
periodicity

85
“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 11

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: PROPERTIES OF DISCRETE-TIME FOURIER TRANSFORM


II. Objectives:
At the end of this activity, students will be able to

1. Generate and plot discrete-time Fourier transform of different sequences


2. Verify and investigate the different properties of the discrete-time Fourier transform of different sequences

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Verify the linearity property of discrete-time Fourier transform using a real valued finite-duration
sequence x1(n) and x2(n) both are random sequences uniformly distributed between [0,1] over 0 ≤ n ≤ 10

2. Verify the shift property of discrete-time Fourier transform using a real valued finite-duration sequence
x(n) a random sequence uniformly distributed between [0,1] over 0 ≤ n ≤ 10 and y(n) = x(n-2)

86
3. Verify graphically the shift property of the discrete-time Fourier transform using a real valued finite-
duration sequence

π
(¿n/2) , 0 ≤ n ≤ 100
x ( n )=cos ¿
jπn
4
y ( n )=e x (n)

Plot the magnitude and angle of x(n) and y(n) in four separate subplots. Label the plots. Frequencies are
equispaced at 200.

4. Verify the conjugation property Ƒ [ x*(n)] = X*(e-jω) using a complex valued random sequence x(n) with
real and imaginary parts uniformly distributed between [0,1] over -5 ≤ n ≤ 10 at 200 equispaced
frequencies.

5. Verify the symmetry property of real signals say

x(n) = sin(πn/2) , -5 ≤ n ≤ 10

compute the odd and even parts of x(n) and evaluate their discrete-time Fourier transform using
numerical and verify using graphical method. Frequencies are equipaced at 200. Plot the real part of x,
imaginary part of x, transform of the even part of x, and odd part of x in subplots.

87
“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 12

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: FREQUENCY DOMAIN REPRESENTATION OF LTI SYSTEM


II. Objectives:
At the end of this activity, students will be able to

1. Determine the frequency response of DTFT to complex exponential inputs


2. Determine the frequency response of DTFT to sinusoidal sequences
3. Determine the frequency response of DTFT to arbitrary sequences

III. Procedures: (use the pace provided to write your MATLAB commands)

1. An LTI system is specified by the difference equation

n−1
¿ + x (¿ n)
y ( n )=0.5 y ¿
a. Determine H( e jω)
b. Calculate and the plot through MATLAB the steady-state response yss (n) to
n
0.08 π ¿ u(n)
x ( n )=cos ¿

2. A 3rd order lowpass filter is described by the difference equation

88
n
n−3
¿+1.76 y (¿ n−1)
¿+0.0543 x (¿ n−1)+0.0543 x ( n−2 ) +0.0181 x ¿
y ( n ) =0.0181 x ¿
−1.1829 y ( n−2 )+ 0.2781 y (n−3)

Plot the magnitude and the phase response of this filter and verify that this is a lowpass filter through
MATLAB.


3. For each of the following systems determine H( e ) and plot its magnitude and phase using MATLAB

4
1
a. y ( n )= ∑ x (n−m)
5 m=0

b. y ( n )=x ( n )−x ( n−2 )+ 0.95 y ( n−1 )−0.9025 y (n−2)

c. y ( n )=x ( n )−x ( n−1 ) + x ( n−2 ) 0.95 y ( n−1 ) −0.9025 y (n−2)

89
d. y ( n )=x ( n )−1.7678 x ( n−1 ) +1.5625 x ( n−2 ) +1.1314 y ( n−1 ) −0.64 y (n−2)

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 13

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: FREQUENCY RESPONSE OF LTI SYSTEM


II. Objectives:
At the end of this activity, students will be able to

1. Determine the frequency response of DTFT to complex exponential inputs


2. Determine the frequency response of DTFT to sinusoidal sequences
3. Determine the frequency response of DTFT to arbitrary sequences

III. Procedures: (use the pace provided to write your MATLAB commands)

1. Let xa(t) = e-1000 |t| . Determine and plot its Fourier transform.
Sample xa(t) at Fs = 5000 sam/sec to obtain x1(n). Determine and plot X1(ejω)
Sample xa(t) at Fs = 1000 sam/sec to obtain x2(n). Determine and plot X1(ejω)

90
2. An analog signal xa(t) = sin (1000πt) is sampled using the following sampling intervals. In each case, plot
the spectrum of the resulting discrete-time signal

a. Ts = 0.1 ms
b. Ts = 1 ms
c. Ts = 0.01 ms

3. From the samples x1(n) in item 1a, reconstruct xa(t) and comment on the result. Plot the reconstructed
signal using ZOH and FOH interpolations. Comment on the plots.

4. From the samples x2(n) in item 1b, reconstruct xa(t) and comment on the result. Plot the reconstructed
signal using ZOH and FOH interpolations. Comment on the plots.

5. Consider an analog signal xa(t) = cos(20πt), 0 ≤ t ≤ 1. It is sampled at Ts = 0.01, 0.05 and 0.1 sec intervals
to obtain x(n)
a. For each Ts plot x(n)
b. Reconstruct the analog signal ya(t) from the samples x(n) using the sinc interpolation (use ∆t = 0.001)
and determine the frequency in ya (t) from your plot. (Ignore the end effect)
c. Reconstruct the analog signal ya(t) from the samples x(n) using the cubic spline interpolation (use ∆t
= 0.001) and determine the frequency in ya (t) from your plot. (Again, ignore the end effect)
d. Comment on your result.

91
“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

CHAPTER V
THE Z-TRANSFORM

92
Some common z- transform pairs

Example

93
Solutions

MATLAB Verification:

94
Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 14

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________

I. Title: THE Z-TRANSFORM


II. Objectives:
At the end of this activity, students will be able to

1. Determine the z-transform of a system and implement in MATLAB


2. Determine the region of convergence for a given sequence
3. Provide a pole zero plot of a certain system

III. Procedures: (use the pace provided to write your MATLAB commands)
1. Determine the z-transform of the following sequences. Indicate the region of convergence for each
sequence and verify the z-transform expression using MATLAB

95
a. x(n) = {3, 2, 1, -2, -3}

b. x(n) = (0.8)n u(n-2)

c. x(n) = [(0.5)n + ( - 0.8)n ] u(n)

d. x(n) = (n + 1) (3)n u(n)

e. x(n) = (2)n cos (4πn) u(-n)

2. Determiner the z-transform of the following sequences using the z-transform table and the z-
transform properties. Express X(z) as a rational function in z-1. Verify your result using MATLAB.
Indicate the region of convergence in each case and provide a pole-zero plot.

a. x ( n )=2 δ (n−2)+3 u(n−3)


n
0.75¿ sin (0.3 πn) u(n)
b. 0.75 ¿n cos( 0.3 πn)u (n)+ 4 ¿
x (n)=3 ¿

0.9 ¿n u(n−2)
c. πn
x ( n )=n sin ( )
3
u ( n ) +¿

2 n−2
¿ u ( n−1 )
d. 3
x ( n )=n2 ¿

n−3
¿
¿
e. 1 n−2 π
¿ sin ⁡{ ( n−1 ) }u ( n )
4 2
x ( n ) =¿

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

Pamantasan ng Cabuyao
Banay-banay, Cabuyao, Laguna

Signals Spectra and Signal Processing

ACTIVITY 15

Name: _______________________ Date Performed: ___________________

Course / Year _________________ Date Passed : ______________________


96
I. Title: THE Z-TRANSFORM
II. Objectives:
At the end of this activity, students will be able to

1. Determine the z-transform of a system and implement in MATLAB


2. Determine the region of convergence for a given sequence
3. Determine the z-transform of a system given a difference equation

III. Procedures: (use the pace provided to write your MATLAB commands)
1. Determine the results of the following polynomial operations using MATLAB

a. X1(z) = ( 1 – 2z -1+ 3z -2 - 4z -3) ( 4 + 3z -1- 2z -2 + z -3)

b. X2(z) = ( z2 – 2z + 3 + 2z -1 + z -2) ( z 3 - z -3)

c. X3(z) = ( 1 + z -1+ z -2 )3

d. X4(z) = X1(z) X2(z) X3(z)

e. X5(z) = (z -1 - 3z -3 + 2z -5 + 5z -7 - z -9) ( z + 3z2 + 2z3 + 4z4)

2. Solve the following difference equation for y(n) using one-sided z-transform approach

y(n) = 0.81 y(n-2) + x(n) – x(n-1) , n ≥ 0; y(-1) =2, y(-2) =2

x(n) = (0.7)n u(n +1 )

Generate the first 20 of samples of y(n) using MATLAB, compare them with your answer.

“We are all playing in the game called Life. If you want to be MVP in your own event, let God be your coach”
- Engr. Andaya
Prepared by: Engr. Florante M. Andaya Signals, Spectra and Signal Processing

CHAPTER VI
IMPLEMENTATION OF DISCRETE-TIME FILTERS

97
98
99
100

Das könnte Ihnen auch gefallen