Class #15: Experiment Introduction to Matlab

Similar documents
Lab 1 Intro to MATLAB and FreeMat

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

ARRAY VARIABLES (ROW VECTORS)

EE 301 Signals & Systems I MATLAB Tutorial with Questions

1 Introduction to Matlab

Dr Richard Greenaway

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

MATH STUDENT BOOK. 12th Grade Unit 4

Math 144 Activity #2 Right Triangle Trig and the Unit Circle

A Guide to Using Some Basic MATLAB Functions

Dr Richard Greenaway

AMS 27L LAB #2 Winter 2009

Introduction to MATLAB

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Chapter 1: An Overview of MATLAB

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

EGR 111 Introduction to MATLAB

Matlab Introduction. Scalar Variables and Arithmetic Operators

Chapter 2. MATLAB Fundamentals

ENGR 253 LAB #1 - MATLAB Introduction

MATLAB TUTORIAL WORKSHEET

Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Introduction to Engineering gii

Math 2250 MATLAB TUTORIAL Fall 2005

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

Introduction to MATLAB

Introduction to PartSim and Matlab

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

PART 1 PROGRAMMING WITH MATHLAB

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

University of Alberta

John's Tutorial on Everyday Mathcad (Version 9/2/09) Mathcad is not the specialist's ultimate mathematical simulator

1. Register an account on: using your Oxford address

George Mason University Signals and Systems I Spring 2016

EE 216 Experiment 1. MATLAB Structure and Use

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Introduction to MATLAB

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

Welcome. Please Sign-In

Reference and Style Guide for Microsoft Excel

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

Finding MATLAB on CAEDM Computers

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

Matlab Programming Introduction 1 2

MAT 275 Laboratory 1 Introduction to MATLAB

8.4 Graphs of Sine and Cosine Functions Additional Material to Assist in Graphing Trig Functions

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

To start using Matlab, you only need be concerned with the command window for now.

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Laboratory 1 Introduction to MATLAB for Signals and Systems

Using PSpice to Simulate Transmission Lines K. A. Connor Summer 2000 Fields and Waves I

EEE161 Applied Electromagnetics Laboratory 1

Basics of Computational Geometry

Chapter 1 Introduction to MATLAB

ECE 3793 Matlab Project 1

Basic stuff -- assignments, arithmetic and functions

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Lab. Manual. Practical Special Topics (Matlab Programming) (EngE416) Prepared By Dr. Emad Saeid

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

A very brief Matlab introduction

Computer Data Analysis and Use of Excel

The Very Basics of the R Interpreter

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Physics 251 Laboratory Introduction to Spreadsheets

Introduction to Matlab

LAB 2: DATA FILTERING AND NOISE REDUCTION

LAB 1 General MATLAB Information 1

AMS 27L LAB #1 Winter 2009

How to learn MATLAB? Some predefined variables

Introduction to Scientific Computing with Matlab

: Find the values of the six trigonometric functions for θ. Special Right Triangles:

Foundations of Math II

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Lab1: Use of Word and Excel

MATH STUDENT BOOK. 12th Grade Unit 7

Teaching Manual Math 2131

McTutorial: A MATLAB Tutorial

VBScript: Math Functions

ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems

LAB 2: DATA FILTERING AND NOISE REDUCTION

EE 301 Lab 1 Introduction to MATLAB

Finding, Starting and Using Matlab

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel.

CW High School. Advanced Math A. 1.1 I can make connections between the algebraic equation or description for a function, its name, and its graph.

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

To see what directory your work is stored in, and the directory in which Matlab will look for files, type

Introduction to Matlab

Transcription:

Class #15: Experiment Introduction to Matlab Purpose: The objective of this experiment is to begin to use Matlab in our analysis of signals, circuits, etc. Background: Before doing this experiment, students should be able to Analyze simple circuits consisting of combinations of resistors, especially voltage dividers. Do a transient (time dependent) simulation of circuits using LTspice Determine and validate mathematical expressions for steady-state sine and cosine voltage and current waves including amplitude, frequency and phase. Use the mathematical expressions that describe experimental and simulated voltage and current signals to validate and understand the relationships between voltage and current for inductors and capacitors. Determine complex impedance for R, L and C Analyze RC and RL circuits using phasor analysis and approaches applicable to standard voltage dividers. Convert phasor voltages and currents back to time dependent forms. Review the background for the previous experiments. Learning Outcomes: Students will be able to Perform basic mathematical operations with Matlab Plot basic functions (e.g. sinusoidal, exponential, polynomials) using Matlab Plot experimental or simulated data with Matlab Resources Required: LTspice Matlab with activation for RPI students Helpful links for this experiment can be found on the course website under Class #15. Pre-Lab Required Reading: Before beginning the lab, at least one team member must read over and be generally acquainted with this document and the other required reading materials. Hand-Drawn Circuit Diagrams: Before beginning the lab, hand-drawn circuit diagrams must be prepared for all circuits either to be analyzed using LTspice or physically built and characterized using Analog Discovery. Due: At the beginning of Class #17 K. A. Connor, - 1 - Revised: 22 October 2017

Part A Starting Matlab and Using Basic Math Operations Background To prepare for the following experiments, review the material in the videos listed under Class #15 and under Matlab in the course website Experiment We begin with a series of simple operations listed in the table below. Perform each operation and fill in the remaining cells in the table. Note that some operations work as written while others must follow Matlab syntax. Note that the last two rows are left blank for you to try other operations you can think of. Operation Example Answer Sum 333 + 614+ 218 Difference 333-292 Multiplication 333 292 Division 333/29 Raising to a Power 3 55 Roots 419 Round round (456.79) Defining a Variable y 67 Operating on Variable y What is π? Sines & Cosines sin( pi / 3) ln Function ln( 4) Natural Number e e Inverse Tangent tan 1 1 Table A-1 Getting Help The easiest way to get help with some operation in Matlab is to type help. For example, to learn about the use of the tangent function, type help tan and you will see something like what follows. Note that this immediately tells us that trig functions assume arguments in radians, not degrees. >> help tan tan Tangent of argument in radians. tan(x) is the tangent of the elements of X. See also atan, tand, atan2. Overloaded methods: codistributed/tan Reference page in Help browser doc tan If you do not know the exact term that Matlab uses, you can first search online for something like tangent in Matlab and you can click on the question mark symbol at the top of the Matlab screen and browse or search. K. A. Connor, - 2 - Revised: 22 October 2017

Summary Many Matlab operations look the same as we usually see them in mathematical expressions, but others must follow specific syntax. Also, some constants are known and their symbols reserved, but others must be calculated. Part B What Can Matlab Do? Before we learn how Matlab can do many useful things for us, we want to get a sense of what it can do by running some demos. There are some good demos that are no longer available from Matlab (in the version we are using 2015). Go to the course website and click on Matlab. Then select the link to Demos. Select xpsound.m and save it to your m-file directory. This is called Visualizing Sound. Briefly play with this demo without annoying nearby students. You might want to use earbuds to hear better. Another interesting demo is called penny.m or Viewing a Penny. When you type the word penny in the command line, pictures will begin to appear. You can cycle from one to the next by hitting any key. Note the great resolution that is possible from scanned info. This demo is discussed further at http://blogs.mathworks.com/cleve/2014/03/17/higherresolution-penny/. Figure B-1 You can also reach some other examples through Matlab Help, as shown in Figure B-2 below. Figure B-2 Scan through the remainder of the examples and try a few more out. What were the ones you enjoyed the most? Which ones look like they would be most useful for you as an electrical or computer engineer? Be sure to ask questions if you have any problems or are just curious about what the demos is actually doing. We may or may not know the answer because the range of Matlab applications is so broad. K. A. Connor, - 3 - Revised: 22 October 2017

Part C Vectors and Arrays Recall that when we obtain data from measurements or simulation, we produce arrays of numbers. For example, columns can be time, voltage, current, voltage difference and the number of rows can be huge (many thousands). The Mat in Matlab stands for Matrix, so it is ideally suited to work with the arrays of numbers we produce. Experiment There are many ways to define a one-dimensional array, also known as a vector. Define the vector R = (0,1,2,3,4,5,6,7,8,9,10) with the following command: >> R=[0 1 2 3 4 5 6 7 8 9 10] Matlab will immediately tell you what it thinks you told it to do. If you do not want to see it repeat everything, put a semi-colon at the end of the line. You now have an array of 11 numbers called R. Do the following operations on R. Note that if Matlab thinks you did something wrong, it will give you an error message. Pay close attention to the error messages. Operation on R sum(r) mean(r) median(r) min(r) max(r) S=5R V=R+S T=R 2 Result Table C-1 We can also define arrays of numbers. Try the following and see what Matlab thinks you told it to do. >> U=[0 1 2;3 4 5;6 7 8] Helpful hint. Matlab has a great feature where you can repeat or modify previous commands without retyping them. Use the up arrow to cycle through all of the previous commands. Once you find the one you are looking for, you can modify it and use it again. If you know the beginning of the command, type the first letter or two and it will only find commands that start with what you typed. Try this and see what happens. Much of the work we will do will involve plotting function of some variable. Variables are best written in a uniform array with lots of terms in it. To do this, we need a way to write such arrays easily. For example, to have an array of 101 time values from 0s to 1s, we can write the following: >> t=[0:.01:1]; If we want 1001 values from 0ms to 3ms (three periods of a 1kHz sine wave), we can write: >> t=1e-3*[0:.001:1]; Note that we have multiplied each term by 0.001 written in scientific notation. Again, it is important to make sure that Matlab understands what we are asking it to do. You can check one of the elements in the array and see if it is correct by typing t(22) for example, which should give you the 22 nd time element. Summary K. A. Connor, - 4 - Revised: 22 October 2017

We have now seen how arrays of numbers are written and operated on, at least somewhat, in Matlab. For each of the operations above, be sure you understand what is being done. Part D Plotting Next, we want to try to plot some standard functions. We will use the time array you just defined. 10 using a frequency f = 1kHz. There are no Greek letters in Matlab, so we will use w for omega and Th for theta. All parameters have to be defined before they are used anywhere else. First we will define the function V cos t >> f=1e3; >> w=2*pi*f; >> Th=0; Next, we will do the function. >> V=10*sin(w*t+Th); And plot V (y axis) vs t (x axis). >> plot(t,v); The plot you will produce will look rather boring, with no grid or labels. Ask help to show you how to fix that. Once it gives you the info you need, add grid lines, x and y labels, a title, change the color of the cosine wave and its thickness make it as interesting as you can. >> help plot Do each of the plots shown below. For the plots involving exponentials, you will need a value for the time constant τ. Assume that it is equal to the period of the cosine wave. Again we need to use something to represent τ = tau. >> tau=1/f; For the current (4 th case) assume its amplitude is equal to the voltage so that they both are the same size on the plot. Do at least two cases with ϑ I = ±π/2. You should try others to see how the phase affects the signal. Save all plots and fully annotate them in your report. For the 5 th entry in the table, you decide what to plot. Function Vo cos(ωt+ϑ) Vo e -t/τ Vo e -t/τ cos(ωt+ϑ) Vo cos(ωt+ϑv) & Io cos(ωt+ϑi) Plotted? Table D-1 Part E Scripts Since most of the things we do with Matlab are repeated over and over, it is a good idea to write scripts (m-files) to save them for the future. For any of the plots you just completed, create such a script. To open the script editor, go to the file menu and select New then Script. An example script that plots a simple polynomial function is shown below. Note that lots of comments are included (lines that start with %) to help understand what the script does. Invariably, you will forget the next time you need to use it, so add lots of comments. You will have to choose a place to save your scripts for this course. Once you have the directory selected, then save your script with a name K. A. Connor, - 5 - Revised: 22 October 2017

you can remember easily. Also, Matlab is case sensitive, so you will have to type the name correctly or it will not know what you mean. Once you save your script, you should see it listed in the current folder window. Aside: What information is being provided by the various windows usually opened by Matlab? Example Script % Plotting the Function 1-x^2 % K. A. Connor 22 October 2015 % The x array is chosen so that the function will go from 1 to zero x=[0:.001:1]; % The function (note the.^2 to square each element in the vector) y=1-x.^2; z=x.^2; % Plotting plot(x,y,x,z); grid; xlabel('x'); ylabel('functions of x'); title('plotting Example'); legend('1-x^2','x^2','location','west');% Note that the dot is not necessary here axis([0 1 0 1]); Add another function to the Script In your script, add a calculation of the cube of x, x 3, and plot that function with the others. Add a description to the legend for the new function. Part F Task Checklist The following list summaries the tasks from Parts A, B, C, D and E Fill in the table of mathematical operations Try out a few demos Define arrays and fill in the table of array operations Complete the plots in the plotting table. Write at least one script and then run it. K. A. Connor, - 6 - Revised: 22 October 2017