Purpose of the lecture

Similar documents
AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

(!' ) "' # "*# "!(!' +,

MATLAB Workshop 14 - Plotting Data in MATLAB

Lab 1. The Fourier Transform

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial VI

Beginner s Matlab Tutorial

How long is the vector? >> length(x) >> d=size(x) % What are the entries in the matrix d?

WEEK #3, Lecture 1: Sparse Systems, MATLAB Graphics

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

Signal Processing First Lab 01: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

TWO-DIMENSIONAL TRANSFORMATION

Cooling and Euler's Method

Introduction to Matlab

Curve Fitting, Loglog Plots, and Semilog Plots 1

Iowa State University Electrical and Computer Engineering. E E 452. Electric Machines and Power Electronic Drives. Laboratory #3 Figures of Merit

Tutorial Program. 1. Basics

Programming in MATLAB

6 Scalar, Stochastic, Discrete Dynamic Systems

A few useful MATLAB functions

Command-induced Tracking Jitter Study I D. Clark November 24, 2009

CD-ROM Appendix E: Matlab

Solving ODEs in Matlab. BP205 M.Tremont

Euler s Method and Functions

Experimental Identification an Interactive Online Course

Numerical Analysis. Professor Donna Calhoun. Fall 2013 Math 465/565. Office : MG241A Office Hours : Wednesday 10:00-12:00 and 1:00-3:00


1 Topic. 2 Scilab. 2.1 What is Scilab?

Appendix 4 Simulation software for neuronal network models

Data Analysis with MATLAB The MathWorks, Inc. 1

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

Programming Languages & Tools

Matlab Practical: Solving Differential Equations

1 Cubic Hermite Spline Interpolation

Introduction to MATLAB Gergely Somlay Application Engineer

Solving Systems of Linear Equations

Simple Programming in MATLAB. Plotting a graph using MATLAB involves three steps:

3.2 LOGARITHMIC FUNCTIONS AND THEIR GRAPHS. Copyright Cengage Learning. All rights reserved.

An Incomplete C++ Primer. University of Wyoming MA 5310

ADVANCED APPLICATIONS OF ELECTRICAL ENGINEERING

Spline Toolbox Release Notes

Designing a Graphical User Interface

SCIENTIFIC COMPUTING AND PROGRAMMING IN THE CLOUD USING OPEN SOURCE PLATFORMS: AN ILLUSTRATION USING WEIGHTED VOTING SYSTEMS

The Algorithms of Speech Recognition, Programming and Simulating in MATLAB

Financial Econometrics MFE MATLAB Introduction. Kevin Sheppard University of Oxford

AC : MATHEMATICAL MODELING AND SIMULATION US- ING LABVIEW AND LABVIEW MATHSCRIPT

Lab 3: Introduction to Data Acquisition Cards

Modeling with Python

B3. Short Time Fourier Transform (STFT)

STATISTICAL DATA ANALYSIS COURSE VIA THE MATLAB WEB SERVER

DAQ in MATLAB HANS-PETTER HALVORSEN,

Gerrit Stols

MATLAB Programming. Problem 1: Sequential

1 Finite difference example: 1D implicit heat equation

Introduction to MATLAB for Data Analysis and Visualization

Product Information CANape Option Simulink XCP Server

An Introduction to Using Simulink

Row Echelon Form and Reduced Row Echelon Form

x y The matrix form, the vector form, and the augmented matrix form, respectively, for the system of equations are

MATLAB: Structures and Cell Arrays

MATLAB LECTURE NOTES. Dr. ADİL YÜCEL. Istanbul Technical University Department of Mechanical Engineering

Programming Exercise 3: Multi-class Classification and Neural Networks

Case study: how to use cutoff conditions in a FRA frequency scan?

(!' ) "' # "*# "!(!' +,

Matrix Indexing in MATLAB

Simple File Input & Output

Using MATLAB to develop standalone graphical user interface (GUI)

Appendix: Tutorial Introduction to MATLAB

Numerical Methods for Differential Equations

ELECTRONICS and CIRCUIT ANALYSIS using MATLAB

Numerical Methods in MATLAB

Building a Simulink model for real-time analysis V Copyright g.tec medical engineering GmbH

PGR Computing Programming Skills

Section 8.2 Solving a System of Equations Using Matrices (Guassian Elimination)

Laboratory 4: Feedback and Compensation

MATERIALS. Multisim screen shots sent to TA.

2+2 Just type and press enter and the answer comes up ans = 4

MATLAB Basics MATLAB numbers and numeric formats

What s New in MATLAB and Simulink

7 Time series analysis

Scientific Programming in Python

Linear Equations ! $ & " % & " 11,750 12,750 13,750% MATHEMATICS LEARNING SERVICE Centre for Learning and Professional Development

Here are some examples of combining elements and the operations used:

5: Magnitude 6: Convert to Polar 7: Convert to Rectangular

FOURIER TRANSFORM BASED SIMPLE CHORD ANALYSIS. UIUC Physics 193 POM

Linear Regression. use waist

Analecta Vol. 8, No. 2 ISSN

Scicos is a Scilab toolbox included in the Scilab package. The Scicos editor can be opened by the scicos command

5 Correlation and Data Exploration

Non-negative Matrix Factorization (NMF) in Semi-supervised Learning Reducing Dimension and Maintaining Meaning

Solution of Linear Systems

Continued Fractions and the Euclidean Algorithm

Introduction. Chapter 1

Lab #9: AC Steady State Analysis

POTENTIAL OF STATE-FEEDBACK CONTROL FOR MACHINE TOOLS DRIVES

Straightening Data in a Scatterplot Selecting a Good Re-Expression Model

Matrix Multiplication

Transcription:

MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course Purpose of the lecture This lecture contains a short introduction to the MATLAB For further details see other sources Later we will apply Matlab to a simple simulation exercise of a communication system In that exercise we study, at the same time as learning MATLAB, different aspects of communication simulations 2 1

MATLAB MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation and visualization You can solve complex numerical problems in a fraction of the time required with a programming language such as Fortran or C. The name MATLAB is derived from MATrix LABoratory 3 MATLAB MATLAB is an expression language the expressions you type are interpreted and evaluated MATLAB statements are usually of the form variable = expression, or simply expression 4 2

MATLAB MATLAB contains several build-in functions Written either using C, or as a form of m-files You can create your own functions (m-files) Most of work is writing functions that are used to execute simulations You can obtain functions (m-files) written by others BUT, AS ALWAYS, Remember to validate all the functions (if not already validated by others) Even build-in functions may contain errors, or are not usable in your problem since every numeric algorithm has its limitations remember to check the function manual 5 MATLAB MATLAB has its core with some basic functions (which can be used to build everything) In addition, it has TOOLBOXes that include buildin functions to support different areas or multiple of areas TOOLBOXes ease and fasten simulations in their areas Naturally, one has to learn how to use functions in TOOLBOXes 6 3

Toolboxes 7 Toolboxes 8 4

Information sources Matlab primer http://ise.stanford.edu/matlab/matlab-primer.pdf Guide to basic properties, very helpful if read and executed simultaneously Mathworks home page http://www.mathworks.com/ Information of all Matlab related products Helps User created m-files from several areas 9 Matrices MATLAB can efficiently use matrices and vectors MATLAB handles vector vector and matrix vector products faster than for loops (if sizes are not too large) Many books and papers where you can find algorithms use matrix notation So, learn to use matrices and vectors efficiently! A hint: always write vectors in the same way Either as a column or row vector Column form is the most common 10 5

M-files You can call m-files in the command line or inside m-files You can use other m-files in your simulations A good practice is to make small, general-usable m-files (if possible) and then apply them in your master simulation m-file The generality allows you to apply the same m-file in many places Build-in m-files are general M-files are called such since they have file type.m 11 M-files M-files can be either script files or function files A script file consists of a sequence of normal MATLAB statements When the m-file is called, the statements are executed Variables in a script file are global and will change the value of variables of the same name in the environment of the current MATLAB session 12 6

Script file example We want to calculate logarithm (base 10) of 10 In command line it is log10(10) (since log is ln) Put this as a variable a=log10(10) Create m-file which calculates logarithm on 100, and puts the result in a variable a, name this as testa.m Execute first a=log10(10) and then testa.m 13 If the result is not a named variable Matlab gives ans Value of variable a changes since script files have global variables 14 7

M-files Function files provide extensibility to MATLAB You can create new functions specific to your problem which will then have the same status as other MATLAB functions Variables in a function file are by default local A variable can, however, be declared global (see help global) Locality means that a value of variable on the command line is not changed even if a function file contains the same variable 15 M-files Inputs to function files may be variables Remember to comment your files you may even create a help part that explains what the function does Commenting helps you and others to remember what the different lines do and what for the different variables are 16 8

Function file example We create a function file that computes a sinusoidal function with a frequency f over an interval 0 - T results values of a sinusoidal and the interval And plots the signal In addition We make a help and comment the file 17 function [y,t]=testb(f,t,n); %[y,t]=testb(f,t,n) plots a sinusoidal with a frequency f [Hz] %over an interval 0 - T [s] and results values of the function y and %corresponding time instants. n+1 is the number of time instants, %the default being 128. % %by Michael Mfilewriter, 2006 %check if n is given or not %if not set it as default if nargin<3, n=127; else n=n-1; %makes sure that we have n+1 time instants end 18 9

%create time scale with n steps t=0:t/n:t; t=t(:); % t(:) makes a column vector %compute values of sinusoideal y=sin(2*pi*f*t); %plot it with t as a x-axis and y as a y-axis plot(t,y) xlabel('time [s]') %creates text for x-label ylabel('sinusoidal') %creates text for y-label 19 [y,t]=testb(1,10,1024); results 20 10

Help If m-files have a help it is called as help m-file E.g., if we call help of testb.m as help testb It results [y,t]=testb(f,t,n) plots a sinusoidal with a frequency f [Hz] over an interval 0 - T [s] and results values of the function y and corresponding time instants. n+1 is the number of time instants, the default being 128. by Michael Mfilewriter, 2006 That is, help results everything commented (by %) in the code before first line without % 21 11