-seminar 1 for digital signal processing

Slides:



Advertisements
Similar presentations
-seminar 1 for digital signal processing
Advertisements

Introduction to Matlab
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to 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.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
1 M ATLAB Short Course. History of Calculator 2 3 Introduction to Matlab Matlab is short for Matrix Laboratory Matlab is also a programming language.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Introduction to MATLAB
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Getting Started with MATLAB (part 3) 1. Algebra, 2. Trig 3. The keyword ans 4. Clean up and suppress output: finalizing the software’s presentation 1.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
MATLAB Lecture Two Tuesday 5 July Chapter 3.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Linear Algebra Review.
Arithmetic Operations
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
응용 전산 및 실습 MATLAB – Chapter 3 행렬연산
ECE 1304 Introduction to Electrical and Computer Engineering
Built-in MATLAB Functions Chapter 3
Matrices and Arrays.
INTRODUCTION TO BASIC MATLAB
Seminar 1 for DCSP Using Matlab.
MATLAB DENC 2533 ECADD LAB 9.
Part 1 Chapter 2 MATLAB Fundamentals
MATH 493 Introduction to MATLAB
Introduction to MATLAB
Introduction to MATLAB [Vectors and Matrices] Lab 2
Introduction to MATLAB
Introduction to Matlab
Part 1 Chapter 2 MATLAB Fundamentals
Experiment No. (1) - an introduction to MATLAB
CS 111 Introduction to Computing in Engineering and Science
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Matlab Basics Tutorial
EECS Introduction to Computing for the Physical Sciences
Fourier Transforms of Discrete Signals By Dr. Varsha Shah
Presentation transcript:

-seminar 1 for digital signal processing Using Matlab -seminar 1 for digital signal processing

Matlab as calculator 1. basic arithmetic operator + - * / ^ () e.g. 2+3/4*5 = 3^2*4 = 3-4/4-2 = 2 extended arithmetic - accidental error 1/0 = -1/0 = 0/0 = 1/Inf = we know 1/(1/x) = x, then try 1/(1/0) = ? complex number 1+i , -1+3*i

Numbers and formats 1. Different kind of numbers Integer: e.g. 123, -218 Real : e.g. 1.234, - 10.9 complex : e.g. 3.21-3.4*i (i = sqrt(-1)). Inf : Infinity (dividing by 0) NaN: Not a number (0/0) e: notation for very large or small number, e.g. -1.34e+03 = ? , 1.34e-05 = ?

Numbers and formats 2. Calculation: 15 significant figures The 'format' tells how matlab prints numbers. Type 'help format' in command window for full list e.g. pi = ?? usually 3.1416 format long pi = ?? format short e format short If want to switch back to default format, type: format

Numbers and formats 3. finite accuracy consequences Matlab limit accuracy (enough for most cases): 64 bits, store number as large as 2*10^308, as small as 2*10^(-308) Store any number 15 significant figures: e.g. 1.23456789023456 (14 figures, can handle) 1.23456789023456789012 (20 digits, truncated to 15 figures) round off cannnot be avoid. e.g. what is sin (pi) = ? try sin(pi) = ??-slight round-off error, take it as zero as long as small like 10^(-15).

Variables 1. combination of letter and number, case sensitive e.g. a , x1, z2453, A, t = 2+3-9, 2*t-2 Not allowed: Net-c, 2p, %x, @sign 2. special names: eps (= 2^(-54)), pi --> avoid using 3. complex numbers : i, j = sqrt(-1), unless you change them

Suppressing output (don't want to show output) hidden: x = -13; (semi-colon).

Build-in function sin, cos, tan, sec = 1/sin, cosec = 1/cos, cotan e.g. work out the coordinate of a point on a circle of radius 5 centred at origin, having an elevation 30 degree = pi/6 radians. 2. inverse trig function e.g. asin, acos, atan--> answer returned in radians, so asin(1) = pi/2 3. exponential exp : exp(x) = e^x logarithm: log: log to base e/ log10 to base 10 square root: sqrt(). e.g. x = 9; sqrt(x), exp(x), log(sqrt(x)), log10(x^2+6)

vectors 1. row vectors a = [1 2 3] or a = [1, 2, 3] e.g. V = [1 3 sqrt(5)], what is length(V) - space vitally important : e.g. v2 = [3+ 4 5], v3 = [3 +4 5]; - add vector of the same length: e.g. V + v3, v4 = 3*v3, v5 = 2*V-3*v4, v6 = v+v2??? wrong! since dimension must agree build a row vector from existing ones: e.g. w = [1 2 3], z = [8, 9], cd = [2*z -w], sort(cd) (ascending order) look at value of particular entries: e.g. w(2) = ? - set w(3) = 100, then w = ??

Vectors 2. column vector e.g. c = [1; 3; sqrt(5)] or c2 = [3 return 4 return 5] c3 = 2*c-5*c2 3. column notation : a shortcut for producing row vectors e.g. 1:100 3:7 5:0.1:6 1:-1 --> [] 0.32:0.1:0.6 -0.4:-0.3:-2

vector operation 1. scalar product: u*v = sum (ui*vi) u = [u1, ..., un]; v = [v1;...; vn] e.g. u = [10 -11 12], v = [20; -21; -22]; prod = u*v e.g. w = [2 1 3]; z = [7; 6; 5]; check: v*w, u*w', u*u', v'*z - norm of a vector: ||u|| = sqrt(sum(ui)) compute norm: sqrt(u*u') or norm(u)

vector operation 2. dot product-vector of the same length times with each other u.v = [u1v1,...,unvn] e.g. u.*w, u.*v', u.*z, u'.*v ex.: Tabulate y = x*sin(pi*x) for x = 0, 0.25, ... , 1 ans: x = 0:.25:1; y = x.*sin(pi*x);

Vector operations 3. dot divison of array-element by element division e.g. a = 1:5, b = 6:10, check a./b = , a./a = , c = -2:2, a./c, a.*b-24, ans./c - ex: limit sin(pi*x)/x, as x-->0 - ans: x = [.1 .01. .001 .0001], sin(pi*x)./x, format long , ans - pi - e.g. 1/x (wrong!), 1./x (correct) 4. dot power of array (.^) sqare all element of a vector e.g. u.*u, u.^2, u.^4, u.*w.^(-2)

Entering matrices Defining a matrix in ML is simple: just list its entries between [ ]. Use semicolons to separate rows. A= [1 2 3; 4 5 6; 7 8 9] A = 1 2 3 4 5 6 7 8 9

Addressing matrix elements A(2, 3) a single matrix element A(2:3, 1:2) a portion of the matrix ans = 4 5 7 8

Manipulating matrices - 1 You can sum matrices of same size A= [1 2; 4 5]; B = A’; C = 0.5 * (A + B) C = 1 3 3 5 NB: The apostrophe (‘) indicates transpose operation, i.e. A’ is the transpose of A.

Manipulating matrices - 2 You can multiply a matrix by a scalar A= [1 2; 4 5]; k = pi; B = k*A B = 3.1416 6.2832 12.5664 15.7080 All the matrix elements get multiplied by k.

Manipulating matrices - 3 Matrix can be multiplied together (provided ...) A= rand(5,2), B = rand(2, 5), C = A * B Likewise you can take powers of a (square) matrix, S_1 = rand(5,5), S_3 = S^3 NB: The function rand(n,m) returns an nxm matrix of random numbers uniformly distributed between 0 and 1.

Manipulating matrices - 4 Matrices can be multiplied ‘element-by-element’ using the dot notation for multiplication A = [1 2; 3 4], B = [10 20; 30 40], C = A .* B C = 10 40 90 160 Likewise we have a dot-notation for powers, e.g. D = A.^5

Useful matrices All matrices below are nxm A = zeros(n,m) all zeros A = ones(n,m) all ones A = rand(n,m) uniformely distributed [0,1] A = randn(n, m) normally distributed (mean=0, SD=1)

Plotting Use plot(x, y) to plot vector y vs. the vector x. NB: x and y should have the same size Example t = 0:0.001:0.6; x = sin(2*pi*50*t)+sin(2*pi*120*t); y = x + 2*randn(size(t)); plot(1000*t(1:50),y(1:50)) title('Signal Corrupted with Zero-Mean Random Noise') xlabel('time (milliseconds)')

Plotting power spectra Y = fft(y,512); Pyy = Y.* conj(Y) / 512; f = 1000*(0:256)/512; plot(f,Pyy(1:257)) title('Frequency content of y') xlabel('frequency (Hz)')

Scripts Scripts have no input or output arguments. They're useful for automating series of ML commands. Scripts operate on existing data in the workspace, or they can create new data on which to operate. To create a script: File->New->M-file Invoke a script by typing its name from the prompt.

Functions Functions are M-files that accept input arguments and return output arguments. They operate on variables within their own workspace. See an example below function y = average(x) % AVERAGE Mean of vector elements. % AVERAGE(X), where X is a vector, is the mean of vector elements. [m,n] = size(x); if (~((m == 1) | (n == 1)) | (m == 1 & n == 1)) error('Input must be a vector') end y = sum(x)/length(x); % Actual computation

Exercise: build a DTMF (touch-tone) dialing pad Freq (Hz) 1209 1336 1477 1633 697 1 2 3 A 770 4 5 6 B 852 7 8 9 C 941 * # D NB: Get info about function ‘sound’