February 21, 2005 Lecture 10 - By Paul Lin 1 CPET 190 Problem Solving with MATLAB Lecture 10

Slides:



Advertisements
Similar presentations
Math Review with Matlab:
Advertisements

ECE 8443 – Pattern Recognition EE 3512 – Signals: Continuous and Discrete Objectives: Response to a Sinusoidal Input Frequency Analysis of an RC Circuit.
Fundamentals of Electric Circuits Chapter 14 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Quiz Find a positive and negative co-terminal angle with: co-terminal angle with: 2.Find a positive and negative co-terminal angle with: co-terminal.
February 14, 2005 Lecture 9 - By Paul Lin 1 CPET 190 Problem Solving with MATLAB Lecture 9
ITEC113 Algorithms and Programming Techniques
1 Electrical Engineering BA (B), Analog Electronics, Lecture 2 ET065G 6 Credits ET064G 7.5 Credits Muhammad Amir Yousaf.
Alternating Current Circuits
Branches and Loops Selim Aksoy Bilkent University Department of Computer Engineering
Lecture 191 Sinusoids (7.1); Phasors (7.3); Complex Numbers (Appendix) Prof. Phillips April 16, 2003.
Harmonic Analysis Workshop 10. Workshop Supplement Harmonic Analysis March 29, 2005 Inventory # WS10-2 Workshop 10 – Goals Goal: –In this workshop.
Introduction to Frequency Selective Circuits
Chapter 15 – Series & Parallel ac Circuits Lecture 20 by Moeen Ghiyas 19/08/
Alternating-Current Circuits Chapter 22. Section 22.2 AC Circuit Notation.
A Differentiator Circuit.  All of the diagrams use a uA741 op amp. ◦ You are to construct your circuits using an LM 356 op amp.  There is a statement.
Experiment 17 A Differentiator Circuit
Functions. A function is a relation that has exactly one output for each input.
Kent Bertilsson Muhammad Amir Yousaf. DC and AC Circuit analysis  Circuit analysis is the process of finding the voltages across, and the currents through,
Sinusoidal Steady-state Analysis Complex number reviews Phasors and ordinary differential equations Complete response and sinusoidal steady-state response.
Motivation Music as a combination of sounds at different frequencies
Engineering Problem Solving Kuncicky – MatLab Programming G. Polya – How to Solve it.
ELE130 Electrical Engineering 1 Week 5 Module 3 AC (Alternating Current) Circuits.
Do Now 10/26/10 In your notebook, explain how you know a function is a function. Then answer if the following three tables are functions or not. x
Functions and their Graphs. Relations A relation is a mapping of input values with output values. The set of x-values (input values) is called the domain.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Lecture 2 Differential equations
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (4): Control Flow (Chapter 2)
 Voltage can be produced such that, over time, it follows the shape of a sine wave  The magnitude of the voltage continually changes.  Polarity may.
September 13, 2005 Lecture 4 - By P. Lin 1 CPET 190 Lecture 4 Problem Solving with MATLAB
Math – What is a Function? 1. 2 input output function.
Lecture 21 Review: Second order electrical circuits Series RLC circuit Parallel RLC circuit Second order circuit natural response Sinusoidal signals and.
COVERAGE TOPICS 1. AC Fundamentals AC sinusoids AC response (reactance, impedance) Phasors and complex numbers 2. AC Analysis RL, RC, RLC circuit analysis.
MATLAB 及其工程应用 MATLAB and It’s Engineering Application 主讲教师: 胡章芳
Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB
ES97H Biomedical Signal Processing
Lecture 2: Filters.
5-6 Writing Equations from Patterns. Drill # 63 If then find each value: 1.f(0)2.f(1)3. f(-2) 4.g(w)5.g(x + 2)6.3[g(2)]
Domain x Range y Domain x Range y Domain x Range y n n n1234n n n0123n n + 5 PW page 14 questions.
AC SINUSOIDS Lecture 6 (I). SCOPE Explain the difference between AC and DC Express angular measure in both degrees and radians. Compute the peak, peak-peak,
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 4 Monday 06 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
COMPUTE INVERSE KINEMATICS IN A ROBOTIC ARM BY USING FUZZY LOGIC Subject: Robotics Applications Student: Bui Huy Tien Student ID: M961Y204.
1© Manhattan Press (H.K.) Ltd Series combination of resistors, capacitors and inductors Resistor and capacitor in series (RC circuit) Resistor and.
CHAPTER 1: SINUSOIDS AND PHASORS
SYLLABUS AC Fundamentals AC Analysis AC power Three phase circuit
Matlab Programming for Engineers
(4) Filters.
Lesson 15: Bode Plots of Transfer Functions
Ch4 Sinusoidal Steady State Analysis
MECH 373 Instrumentation and Measurements
Computer Application in Engineering Design
Speech Signal Processing
Capacitive AC Circuits
Reference: Croft & Davision, Chapter 6 p.125
COVERAGE TOPICS AC Fundamentals AC Analysis AC power
ECE 1304 Introduction to Electrical and Computer Engineering
Lecture 6 (III): AC RESPONSE
Experiment-5 Phasor Analysis, Gain and Phase Response of a RC Circuit
Chapter 22: AC Circuits Figure (a) Direct current. (b) Alternating current.
Lesson 18: Integral Process Characteristics
Chapter 6 Feedback Circuits
Fundamentals of Electric Circuits Chapter 14
Electric Circuits Fundamentals
AC CIRCUIT ANALYSIS USING PHASORS AND EQUIVALENT IMPEDANCE CONCEPT
Physical Layer Part 1 Lecture -3.
ECE131 BASIC ELECTRICAL & ELECTRONICS ENGG
Chapter 15.
RELATIONS & FUNCTIONS CHAPTER 4.
Unless stated otherwise all AC voltage & current values are rms values
Chapter 10 Analog Systems
Presentation transcript:

February 21, 2005 Lecture 10 - By Paul Lin 1 CPET 190 Problem Solving with MATLAB Lecture 10

February 21, 2005 Lecture 10 - By Paul Lin 2 Lecture 10: MATLAB Program Design & Flow Control - III 10-1 SWITCH Construct 10-2 Problem Solving - MATH Applications 10-3 Problem Solving - Electrical Circuit Applications

February 21, 2005 Lecture 10 - By Paul Lin SWITCH, CASE, WHATEVER SWITCH Construct Another form of flow control or branching Another form of flow control or branching General form General form switch (expression) case exp_1, statement 1-1 statement 1-1 statement 1-2 statement 1-2 **** **** case exp_2, case exp_2, statement 2-1 statement 2-1 statement 2-2 statement 2-2 **** **** case exp_3, case exp_3, statement 3-1 statement 3-1 statement 3-2 statement 3-2 **** ****end

February 21, 2005 Lecture 10 - By Paul Lin SWITCH, CASE, WHATEVER SWITCH Construct Example Example N = input(‘Enter a number - less than 10-: ‘); switch (N) case {1, 3, 5, 7, 9}, disp(‘Odd number is matched’);, disp(‘Odd number is matched’);, case {2, 4, 6, 8, 10}, disp(‘Even number is matched’); disp(‘Even number is matched’); otherwise, otherwise, disp(‘No match is found’); disp(‘No match is found’);end

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - MATH Applications Example 10-1: Evaluating a Function of Two Variables Example 10-1: Evaluating a Function of Two Variables Write a MATLAB program to evaluate a function f(x,y) for any two user-specified values x and y. The function is defined as follows: Write a MATLAB program to evaluate a function f(x,y) for any two user-specified values x and y. The function is defined as follows:

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - MATH Applications Example 10-1: Evaluating a Function of Two Variables Example 10-1: Evaluating a Function of Two Variables Solution: Solution: 1.State the problem 2.Define the inputs and outputs 3.Design the algorithm 4.Translate the algorithm into MATLAB statements 5.Test the program 6.Document the process and solution.

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - MATH Applications Example 10-1: Evaluating a Function of Two Variables (continue) Example 10-1: Evaluating a Function of Two Variables (continue) Solution: Solution: 1.State the problem – as the question 2.Define the inputs and outputs User input two values for X and Y User input two values for X and Y Output is a function value Output is a function value 3.Design the algorithm Read the input X and Y Read the input X and Y Calculate f(x,y), based on the X and Y values Calculate f(x,y), based on the X and Y values Print output Print output

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - MATH Applications Example 10-1: Evaluating a Function of Two Variables (continue) 4.Translate the algorithm into MATLAB statements %func_evs.m% n = true; while n == true x = input('Enter the x coefficient: '); x = input('Enter the x coefficient: '); y = input('Enter the y coefficient: '); y = input('Enter the y coefficient: '); if x >= 0 && y >= 0 f_xy = x + y; f_xy = x + y; elseif x >= 0 && y = 0 && y < 0 f_xy = x + y^2; f_xy = x + y^2; elseif x == 0 && y >= 0 elseif x == 0 && y >= 0 f_xy = x^2 + y; f_xy = x^2 + y; else else f_xy = x^2 + y^2; f_xy = x^2 + y^2; end end fprintf('x = %f, y = %f, f(x,y) = %f\n', x, y, f_xy); fprintf('x = %f, y = %f, f(x,y) = %f\n', x, y, f_xy); disp('Enter Ctrl C one or two times to exit the program'); disp('Enter Ctrl C one or two times to exit the program'); disp(''); disp('');end

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - MATH Applications Example 10-1: Evaluating a Function of Two Variables (continue) Example 10-1: Evaluating a Function of Two Variables (continue) 5.Test the program (x,y)  f(x,y)(x,y)  f(x,y) (2,3) -> f(x,y) = 5(2,3) -> f(x,y) = 5 (2, -3) -> f(x, y) = 11(2, -3) -> f(x, y) = 11 (-2, 3) -> f(x,y) = 7(-2, 3) -> f(x,y) = 7 (-2,-3) -> 13(-2,-3) -> 13 How about x, y => a very large number, and a very small number (accuracy, and computer’s limit) How about x, y => a very large number, and a very small number (accuracy, and computer’s limit)

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-2: Cardioid Microphone Example 10-2: Cardioid Microphone Domain Knowledge on Microphone Pick-up patterns Domain Knowledge on Microphone Pick-up patterns Omni pattern – the most common patternOmni pattern – the most common pattern Cardioid pattern – A directional sound pick-up pattern for use on a stageCardioid pattern – A directional sound pick-up pattern for use on a stage Super Cardioid patternSuper Cardioid pattern Source:

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-2: Cardioid Microphone Example 10-2: Cardioid Microphone Cardioid pattern – A directional sound pick-up pattern for use on a stageCardioid pattern – A directional sound pick-up pattern for use on a stage Gain EquationGain Equation It varies as a function of angle according to the equation It varies as a function of angle according to the equation g is the constant associated with a particular microphone; (value of g?; assume g = 0.5) g is the constant associated with a particular microphone; (value of g?; assume g = 0.5) θ is the angle from the axis of the microphone to the sound source (range of angle?) θ is the angle from the axis of the microphone to the sound source (range of angle?) Questions Questions Calculate gain versus angle andCalculate gain versus angle and prepare a polar plot (what is this?)prepare a polar plot (what is this?)

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-2: Cardioid Microphone - continue Example 10-2: Cardioid Microphone - continue POLAR(THETA, RHO) THETA  theta in Gain equation THETA  theta in Gain equation RHO -> Gain value RHO -> Gain value POLAR Polar coordinate plot.  POLAR(THETA, RHO) makes a plot using polar coordinates of the angle THETA, in radians, versus the radius RHO.  POLAR(THETA,RHO,S) uses the linestyle specified in string S.

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-2: Cardioid Microphone – the Program Example 10-2: Cardioid Microphone – the Program%cardioid_mic.m %Define Variables: % g -- Microphone gain constant % gain - Gain(theta) of the microphone % theta - Angle in radians from % microphone axis % Calculate gain versus angle g = 0.5; theta = 0:pi/20:2*pi; gain = 2*g*(1 +cos(theta)); % Polar plot Gain vs Angle polar(theta, gain, 'r-'); title('\bfGain vs Angle \theta'); Verifying Answrs Verifying Answrs

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-2: Cardioid Microphone – Verifying the answer Example 10-2: Cardioid Microphone – Verifying the answer Verifying Answers: Gain = 2*g*(1+cos(theta)) Verifying Answers: Gain = 2*g*(1+cos(theta)) g = 0.5, theta = 0, gain = 2*0.5*(1+1) = 2g = 0.5, theta = 0, gain = 2*0.5*(1+1) = 2 g = 0.5, theta = 60 degree, gain = 2*0.5*(1 +0.5) = 1.5g = 0.5, theta = 60 degree, gain = 2*0.5*(1 +0.5) = 1.5 Theta = 0, gain = 2 Theta = 60 degree, gain = 2

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-3: Plot the amplitude and frequency response of Low-Pass Filter A simple RC low- pass filter A simple RC low- pass filter Components: Vi, R and C are in series Components: Vi, R and C are in series R = 16 kΩ, C = 1 μF, R = 16 kΩ, C = 1 μF, Xc = 1/(2*pi*f*C) Xc = 1/(2*pi*f*C) Complex number calculation on Amplitude and Phase angle of the Gain = Vo/Vi Complex number calculation on Amplitude and Phase angle of the Gain = Vo/Vi Circuit Equations? Circuit Equations?

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 10-3: Circuit Equations? Example 10-3: Circuit Equations? Xc = -j*1/(2*pi*f*C); Xc = -j*1/(2*pi*f*C); as f ↑, Xc↓ Vo = Vc = Vi/(R –jXc) * (- jXc) Vo = Vc = Vi/(R –jXc) * (- jXc) Gain of response is Vo/Vi = (-jXc)/(R-jXc) Gain of response is Vo/Vi = (-jXc)/(R-jXc) Vo/Vi = 1/(1 + j2πfRC) Frequency range? Frequency range? R*C = 16k * 1 uF = 16 milli-secondsR*C = 16k * 1 uF = 16 milli-seconds F = 1/RC about 60 HzF = 1/RC about 60 Hz Use 0 to 1000 Hz as rangeUse 0 to 1000 Hz as range

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications Example 3: MATLAB Program Example 3: MATLAB Program%rc_lpf.m% R = 1600; % 1600 ohms C = 1E-6; % 1 uF f = 1:2: 1000; % Frequency varies from % 1 to 1000 Hz % Response Av = 1./ (1 + j*2*pi*f*R*C); Av_amp = abs(Av); % amplitude % Phase angle phase = angle(Av) % Plots figure(1), subplot(2,1,1), loglog(f, Av_amp); title('Amplitude Response - Gain'); xlabel('Frequency - Hz'); ylabel('Av = Vo/Vi'); grid on figure(1), subplot(2,1,2), semilogx(f, phase); title('Phase Response'); xlabel('Frequency - Hz'); ylabel('Angle of Av = Vo/Vi in Radians'); grid on

February 21, 2005 Lecture 10 - By Paul Lin Problem Solving - Electrical Circuit Applications

February 21, 2005 Lecture 10 - By Paul Lin 19 Summary SWITCH, CASE, WHATEVER SWITCH, CASE, WHATEVER Problem Solving - MATH Applications Problem Solving - MATH Applications Problem Solving - Electrical Circuit Applications Problem Solving - Electrical Circuit Applications