Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.

Slides:



Advertisements
Similar presentations
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Advertisements

Introduction to Matlab
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Getting Started MATLAB fundamentals Dr. Umakant Dwivedi 15/10/2009.
Introduction to MATLAB
Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Matlab intro The Environment
Digital Image Processing Lecture3: Introduction to MATLAB.
MATLAB Fundamentals.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
How to Use MATLAB A Brief Introduction. 2 What can MATLAB do? Matrix Operations Symbolic Computations Simulations Programming 2D/3D Visualization.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB Lecture 18.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to MATLAB
Computer Application in Engineering Design
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATLAB How to use (using M-files) Double click this icon
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files)
Introduction to MATLAB
INTRODUCTION TO MATLAB
How to Use MATLAB A Brief Introduction.
Presentation transcript:

Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab

Copyright 2001 OCG 2 What Is MATLAB?  MATLAB is an interactive program for scientific and engineering numeric calculation.  It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation.  Typical uses include:  Math and computation  Algorithm development  Modeling, simulation, and prototyping  Scientific and engineering graphics

Copyright 2001 OCG 3 Command Window  Command Window is used to enter variables and run functions and M-files.  Navigation within MATLAB is done using regular UNIX commands  cd (change directory)  pwd (show the path)  ls (list contents of directory)  whos (list of the variable stored in the memory)  In latest version, most of this is also available using a graphical interface

Copyright 2001 OCG 4 Command Window Getting help from the command window help (show the help document for a given function) By the way you can use this help only if you know the name of the function to be used. If you do not know it, just use the windows help, which is much more easy and complete. Here you can find also several examples. P.S. If you want to have an help for your own functions, you can write it at the beginning of the function as : % your own help. After this statement, the matlab file will start.

Copyright 2001 OCG 5 Variables  MATLAB does not require any type declarations!  Real scalar:>> x=1  Complex scalar:>> x=1+2i  Row vector:>> x=[1 2 3]  Column vector:>> x=[1; 2; 3]  2x2 Matrix:>> x=[1 2; 3 4] You can define global variables by putting in front the variable the statement global.

Copyright 2001 OCG 6 Complex numbers  Some useful operations on complex numbers:  Complex scalar >> x = 3+4j  Real part of x >> real(x) ->3  Imaginary part of x >> imag(x) ->4  Magnitude of x >> abs(x) ->5  Angle of x >> angle(x) ->  Complex conjugate of x >> conj(x) ->3 - 4i

Copyright 2001 OCG 7 Generating vectors >> x=[a:step:b]  Generate a vector that takes on the values a to b in increments of step >> x=linspace(a,b,n)  generates a row vector x of n points linearly spaced between a and b >> x=logspace(a,b,20)  generates a logarithmically spaced vector x of n points between 10^a and 10^b.

Copyright 2001 OCG 8 Generating matrices  Matrix building functions: >> A=zeros(m,n)  returns an m-by-n matrix of zeros >> A=ones(m,n)  returns an m-by-n matrix of 1s >> A=eye(m,n)  returns an m-by-n matrix with 1's on the diagonal and 0's elsewhere

Copyright 2001 OCG 9 Generating random matrices >> A=rand(m,n)  returns an m-by-n matrix of random numbers whose elements are uniformly distributed in the interval (0,1) >> A=randn(m,n)  returns an m-by-n matrix of random numbers whose elements are normally distributed with mean 0 and variance 1 >> A=randint(m,n,range)  generates an m-by-n integer matrix. The entries are uniformly distributed and independently chosen from the range:  [0, range-1] if range is a positive integer  [range+1, 0] if range is a negative integer

Copyright 2001 OCG 10 Accessing matrix elements  Elements of a matrix are accessed by specifying the row and column >> A=[1 2 3; 4 5 6; 7 8 9]; >> x=A(1,3)  Returns the element in the first row and third column >> y=A(2,:)  Returns the entire second row [4 5 6]  “:” means “take all the entries in the column” >> B=A(1:2,1:3)  Returns a submatrix of A consisting of rows 1 and 2 and all three columns [1 2 3; 4 5 6]

Copyright 2001 OCG 11 Arithmetic matrix operation  The basic arithmetic operations on matrices are:  + addition  - subtraction  * multiplication  / division  ^ power  ’ conjugate transpose  This operation are to be meant in the “matrix sense” MATRIX-wise operation

Copyright 2001 OCG 12 element-by-element operations  MATLAB provides element-by-element operations by prepending a ‘.’ before the operator .* multiplication ./ division .^ power .’ transpose (unconjugated)  BE CAREFUL when operating on matrix: the meaning of the two operations.* and * are completely different element-wise operation

Copyright 2001 OCG 13 Relational operations  MATLAB defines the following relational operations:  < less than  <= less than or equal to  > greater than  >= greater than or equal to  == equal to  ~= not equal to

Copyright 2001 OCG 14 Logical operations  MATLAB defines the following logical operations:  & and  | or  ~ not

Copyright 2001 OCG 15 Math functions  The following functions operate element-wise, also when applied to a matrix: sincostan asinacosatan sinhcoshtanh explog(natural log)log10 abssqrtsign

Copyright 2001 OCG 16 M-files  MATLAB is an interpretive language  M-files are text files containing MATLAB scripts  Scripts are sequences of commands typed by an editor  The instructions are executed by typing the file name in the command window at the MATLAB prompt  All the variables used in the m-file are placed in MATLAB’s workspace that contains all the variables defined in the MATLAB session

Copyright 2001 OCG 17 M-files Debug  In Matlab you can debug your m-file, like in other programming languages  To do it, you need to open your matlab file from the window command.  Afterwards, you can operate exactly like for other languages and you can use usual command as: step in step out break point etc. etc

Copyright 2001 OCG 18 Flow control  If statements if expression statements else statements end  Example If n<0 a=a-1; else a=a+1; end

Copyright 2001 OCG 19 Flow control  For  Repeats a group of statements a fixed, predetermined number of times. a=0; for n = 1:10 a=a+1; end

Copyright 2001 OCG 20 Function in Matlab To simplify your matlab file structure, you can use functions. An example of how to use Matlab functions is the following: Main Matlab Program SegEqRx = SegEqNew + 1*SegRx(DimC*TTaps+1:LRx-DimC*TTaps); clear SegEqNew; clear SegEqOld; [SAMPLE_CENTRAL, BIT_DETECTED] = =syncronizer(SegEqRx,PNSEQ_VECTOR,NS_BIT,NBIT_PNSEQ); … Function declaration: function [ SAMPLE_CENTRAL, BIT_DETECTED] =syncro(SIGNAL,PNSEQ_VECTOR,NS_BIT,NBIT_PNSEQ); Main of the function

Copyright 2001 OCG 21 Creating a plot >> plot(x,y)  produces a graph of y versus x, where x and y are two vectors x=linspace(0,2*pi,100); plot(x,sin(x));

Copyright 2001 OCG 22 Line styles and colors  It is possible to specify color, line styles, and markers when you plot your data using the plot command plot(x,y,'color_style_marker')  color_style_marker is a string containing from one to four characters constructed from a color, a line style, and a marker type:  Color strings: 'c', 'm', 'y', 'r', 'g', 'b', 'w', and 'k'. These correspond to cyan, magenta, yellow, red, green, blue, white, and black  Linestyle strings are '-' for solid, '--' for dashed, ':' for dotted, '-.' for dash-dot, and 'none' for no line  The marker types are '+', 'o', '*' and 'x'

Copyright 2001 OCG 23 Axis lables and titles  xlabel('string')  labels the x-axis of the current axes  ylabel('string')  labels the y-axis of the current axes  Title(‘string’)  add a title to a graph at the MATLAB command prompt or from an M-file

Copyright 2001 OCG 24 The figure function  MATLAB directs graphics output to a figure window  Graphics functions automatically create new figure windows if none currently exist >>figure  creates a new window and makes it the current figure >>figure(h)  make an existing figure current by passing its handle (the number indicated in the window title bar), as an argument to figure >>clf  Clear current figure window

Copyright 2001 OCG 25 Adding plots  Setting hold to on, MATLAB doesn’t remove the existing graph and adds the new data to the current graph x=linspace(0,2*pi,100); plot(x,sin(x)); hold on; plot(x,cos(x)); xlabel('x'); ylabel('Sine of x');

Copyright 2001 OCG 26 Adding plots With more graphics functionalities: x=linspace(0,2*pi,100); plot(x,sin(x),’-ob’); hold on; grid on; plot(x,cos(x),’->r’); xlabel('x'); ylabel('Sine of x'); legend('sin(x)','cos(x)',3)

Copyright 2001 OCG 27 Basic plotting commands  Plot  Graph 2-D data with linear scales for both axes  Loglog  Graph with logarithmic scales for both axes  Semilogx  Graph with a logarithmic scale for the x-axis and a linear scale for the y-axis  Semilogy  Graph with a logarithmic scale for the y-axis and a linear scale for the x-axis

Copyright 2001 OCG 28 Specialized plots  bar(x,Y)  draws a bar for each element in Y at locations specified in x, where x is a monotonically increasing vector defining the x-axis intervals for the vertical bars >> bar((1:1:10),(1:1:10))

Copyright 2001 OCG 29 Specialized plots  Stem  displays data as lines (stems) terminated with a marker symbol at each data value x=linspace(0,2*pi,10); stem(x,sin(x));

Copyright 2001 OCG 30 Specialized plots  Stairs  Stairstep plots are useful for drawing time-history plots of digitally sampled data systems x=linspace(0,2*pi,20); stairs(x,sin(x));