Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
55 views

LAB4 - Structure Programming and 2nd Order Systemorig

This document provides instructions for a laboratory experiment using MATLAB to analyze second-order systems. It includes: 1. Learning outcomes which are to create a program to plot the step response of a system and use structured programming. 2. Materials which are a laptop, MATLAB software, and printer. 3. MATLAB commands covered which include if/else statements, switch statements, while and for loops, and nested structures. 4. Hands-on exercises are provided to practice each command by analyzing different systems. 5. Instructions to design an experiment to analyze an unknown system using the commands covered. Programs should be commented and plots of responses included. 6. A rubric is given to
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

LAB4 - Structure Programming and 2nd Order Systemorig

This document provides instructions for a laboratory experiment using MATLAB to analyze second-order systems. It includes: 1. Learning outcomes which are to create a program to plot the step response of a system and use structured programming. 2. Materials which are a laptop, MATLAB software, and printer. 3. MATLAB commands covered which include if/else statements, switch statements, while and for loops, and nested structures. 4. Hands-on exercises are provided to practice each command by analyzing different systems. 5. Instructions to design an experiment to analyze an unknown system using the commands covered. Programs should be commented and plots of responses included. 6. A rubric is given to
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

CENTRAL PHILIPPINE UNIVERSITY

COLLEGE OF ENGINEERING

SECOND-ORDER SYSTEMS
ECE 4101 SIGNALS, SPECTRA, AND SIGNAL PROCESSING
LABORATORY NO. 4

Gelvie Lagos | ECE 4101 | September 18, 2017


LEARNING OUTCOMES
At the end of the laboratory the student will be able to:

a. create a program to plot and identify the step response of the system
b. use structured programming in solving complex engineering problems.

MATERIALS AND EQUIPMENTS


1. A laptop or a personal computer
2. MATLAB 2012 or later installed
3. Printer

MATLAB COMMANDS AND SYNTAX


Decisions
Decision making structures require that the programmer specify one
or more conditions to be evaluated or tested by the program, along with a
statement or statements to be executed if the condition is Determined to
be true, and optionally, other statements to be executed if the condition is
determined to be false.
Following is the general form of a typical decision making structure
found in most of the programming languages:

IF END STATEMENT
An if ... end statement consists of an if statement and a boolean expression followed by one or more
statements. It is delimited by the end statement.
Syntax FLOW DIAGRAM
The syntax of an if statement in MATLAB is:
if <expression>
% statement(s) will execute if the boolean expression is true
<statements>
end
If the expression evaluates to true, then the block of code inside the if
statement will be executed. If the expression evaluates to false, then
the first set of code after the end statement will be executed.

PAGE 1
IF ELSE END STATEMENT
An if statement can be followed by an optional else statement, which executes when the expression is false.
Syntax: FLOW DIAGRAM
The syntax of an if...else statement in MATLAB is:
if <expression>
% statement(s) will execute if the boolean expression is true
<statement(s)>
else
<statement(s)>
% statement(s) will execute if the boolean expression is false
end

If the Boolean expression evaluates to true, then the if block of code will
be executed, otherwise else block of code will be executed.

IFELSEIFELSEIFELSEEND STATEMENTS
An if statement can be followed by an (or more) optional elseif...
and an else statement, which is very useful to test various condition.

When using if... elseif...else statements, there are few points to keep in mind:
An if can have zero or one else's and it must come after any elseif's.
An if can have zero to many elseif's and they must come before the else.
Once an else if succeeds, none of the remaining elseif's or else's will be tested.

Syntax:
if <expression 1>
% Executes when the expression 1 is true
<statement(s)>
elseif <expression 2>
% Executes when the boolean expression 2 is true
<statement(s)>
elseif <expression 3>
% Executes when the boolean expression 3 is true
<statement(s)>
else
% executes when the none of the above condition is true
<statement(s)>
end
PAGE 2
NESTED IF STATEMENTS
It is always legal in MATLAB to nest if-else statements which means you can use one if or elseif statement inside
another if or elseif statement(s).
Syntax:
The syntax for a nested if statement is as follows:
if <expression 1>
% Executes when the boolean expression 1 is true
if <expression 2>
% Executes when the boolean expression 2 is true
end
end

Switch statement
A switch block conditionally executes one set of statements from several choices. Each choice is covered by a
case statement.

An evaluated switch_expression is a scalar or string.

An evaluated case_expression is a scalar, a string or a cell array of scalars or strings.

The switch block tests each case until one of the cases is true. A case is true when:
For numbers, eq(case_expression,switch_expression).
For strings, strcmp(case_expression,switch_expression).
For objects that support the eq function, eq(case_expression,switch_expression).
For a cell array case_expression, at least one of the elements of the cell array matches
switch_expression , as defined above for numbers, strings and objects.

When a case is true, MATLAB executes the corresponding statements and then exits the switch block.
The otherwise block is optional and executes only when no case is true.
Syntax:
switch <switch_expression>
case <case_expression>
<statements>
case <case_expression>
<statements>
...
otherwise
<statements>
end
PAGE 3
NESTED SWITCH STATEMENTS
The syntax for a nested switch statement is as follows:
switch(ch1)
case 'A'
fprintf('This A is part of outer switch');
switch(ch2)
case 'A'
fprintf('This A is part of inner switch' );
case 'B'
fprintf('This B is part of inner switch' );
end
case 'B'
fprintf('This B is part of outer switch' );
end

PAGE 4
PAGE 5
THE SECOND ORDER SYSTEM

PAGE 6
THE SECOND ORDER RESPONSE AS A FUNCTION OF THE DAMPING RATIO

PAGE 7
HANDS-ON EXERCISES
a. IF END STATEMENT

b. IF-ELSE-END STATEMENT

c. IF-ELSEIF-END STAEMENT

PAGE 8
d. NESTED IF-ELSE STATEMENT

e. SWITCH STATEMENT

PAGE 9
f. NESTED SWITCH STATEMENT

g. WHILE LOOP

h. FOR LOOP

PAGE 10
i. NESTED FOR LOOP

j. BREAK

DESIGN AN EXPERIMENT
1. Create a program using structured programming to input the transfer function of the
system, plot the pole-zero diagram, identify and plot the step-response of the system.
Also, calculate the Rise time, Settling Time, Peak Time, damping ratio, and natural
frequency of oscillation of the system. Test the program using different types of system.

2.
.

PAGE 11
FORMAT
A. PROBLEM STATEMENT
State the problem you want to solve using MATLAB.

B. PROCEDURES
Make a detailed procedures supported with pictures (screenshots) of your work for each of the problem.

C. PROGRAMS
Create a program easy to understand and put a comment on each line if possible.

D. RESULTS (PLOTS)
The result should be the plots of each signal.

E. CONCLUSION AND LEARNING EXPERIENCES


In your conclusion you should write all the learning experiences that you acquired during and/or after the
experiment.

F. RUBRIC
You will be graded based on the rubric shown below. Attach the rubric after your conclusion.

Rubric

Ability to
Conduct 1 2 3 4 scores
Experiment
Hands-On The student did The student did The student did The student perform
Exercises not perform three not perform two not perform one all the hands-on
(4) activities given by activities given by activity given by exercises given to
the teacher. the teacher. the teacher. them.
Lacks the Demonstrates Demonstrates Demonstrates very
appropriate good knowledge sound good knowledge
knowledge of of the lab knowledge of of the lab
the lab procedures lab procedures procedures
Procedures procedures Will ask peers for Will discuss with Gladly helps other
(1) Often requires help with peers to solve students to follow
help from the problems in lab problems in procedures
teacher to even procedures procedures thoroughly
complete basic Works to follow Carefully follows Carefully follows
procedures each step before each step each step before
moving on to the moving on to next
next step step
TOTAL

PAGE 12
Ability to
Design an 1 2 3 4 Scores
Experiment
The student did If the problem is
Problem not perform written in the
Statement three activities form of a
given by the question with a
(1)
teacher. word COMPLEX.
a. Procedure steps
must be
numbered
b. Procedure steps
must
Procedure be in the correct
the procedure If only one of the If only two of the If only three of order
is a step-by- requirements requirements the requirements c. Procedure steps
step have been have been have been must
explanation of completed. completed. completed. include instructions
how to on what to
perform the measure and
experiment. where to record the
data.
(2)
d. Procedure steps
must
be written in
complete
sentences.
If only one of the If only two of the If only three of a. Easy to follow and
requirements requirements the requirements understand
Programming
have been have been have been b. Comment were
Skills
completed. completed. completed. written on each
(2) lines.
c. The code was free
of errors
d. New commands
were utilized.
If only one of the If only two of the If only three of a. The output was
requirements requirements the requirements labeled completely
have been have been have been b. Colors and markers
Results completed. completed. completed. were utilized.
(3) c. Presentable and
organize output
Conclusion If only one of the If only two of the If only three of The student were able
requirements requirements the requirements to demonstrate the all
(1)
have been have been have been the learning outcomes
demonstrated. demonstrated. demonstrated.
TOTAL

PAGE 13

You might also like