An Introduction to Matlab for DSP

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

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab

Some elements for Matlab programming

An Introduction to MATLAB and the Control Systems toolbox Aravind Parchuri, Darren Hon and Albert Honein

Computational Mathematics

Getting started with MATLAB

Introduction to MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help

An Introduction to MATLAB See Chapter 1 of Gilat

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Lecture 15 MATLAB II: Conditional Statements and Arrays

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

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

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

ECE Lesson Plan - Class 1 Fall, 2001

1 Overview of the standard Matlab syntax

Scientific Computing Lecture Series Introduction to MATLAB Programming

CITS2401 Computer Analysis & Visualisation

Introduction to MATLAB

Eng Marine Production Management. Introduction to Matlab

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Introduction to Matlab

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Introduction to Matlab

Introduction to Matlab

Matlab Primer. Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005

Introduction to MATLAB. Todd Atkins

Introduction to MATLAB

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Getting Started with MATLAB

Getting Started with MATLAB

Introduction to Scientific Computing with Matlab

Introduction to Scientific Computing with Matlab

Introduction to MATLAB

Introduction to MATLAB Programming

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.

Lecturer: Keyvan Dehmamy

Introduction to MATLAB

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

Introduction to MATLAB

Matlab course at. P. Ciuciu 1,2. 1: CEA/NeuroSpin/LNAO 2: IFR49

University of Alberta

An Introduction to MATLAB

Dynamics and Vibrations Mupad tutorial

System Design S.CS301

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

1 Introduction. 2 Useful linear algebra (reprise) Introduction to MATLAB Reading. Spencer and Ware (2008), secs. 1-7, 9-9.3,

Image Processing CS 6640 : An Introduction to MATLAB Basics Bo Wang and Avantika Vardhan

MATH-680: Mathematics of genome analysis Introduction to MATLAB

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

MATLAB for Experimental Research. Fall 2018 Vectors, Matrices, Matrix Operations

FACULTY OF ENGINEERING LAB SHEET INFORMATION THEORY AND ERROR CODING ETM 2126 ETN2126 TRIMESTER 2 (2011/2012)

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS

D. Richard Brown III Associate Professor Worcester Polytechnic Institute Electrical and Computer Engineering Department

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

Chapter 1 Introduction to MATLAB

Introduction to Scientific Computing with Matlab

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

D. Richard Brown III Professor Worcester Polytechnic Institute Electrical and Computer Engineering Department

Handout: Handy Computer Tools

ECE 3793 Matlab Project 1

Introduction to MATLAB

MatLab Just a beginning

A Basic Guide to Using Matlab in Econ 201FS

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

개발과정에서의 MATLAB 과 C 의연동 ( 영상처리분야 )

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

Introduction to Programming Using Java (98-388)

Evolutionary Algorithms. Workgroup 1

ENGR 253 LAB #1 - MATLAB Introduction

MATLAB. Devon Cormack and James Staley

LAB 2 VECTORS AND MATRICES

Introduction to MATLAB programming: Fundamentals

Image Processing Matlab tutorial 2 MATLAB PROGRAMMING

A Brief Introduction to MATLAB Evans Library Research Support Workshops

CS335. Matlab Tutorial. CS335 - Computational Methods in Business and Finance. Fall 2016

Learning from Data Introduction to Matlab

Computational Finance

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Introduction to Matlab

The MATLAB system The MATLAB system consists of five main parts:

How to program with Matlab (PART 1/3)

Introduction to MATLAB Programming

Vector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has.

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

Introduction to MATLAB for Engineers, Third Edition

Lecture 2. Arrays. 1 Introduction

Computational Methods of Scientific Programming

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

2.0 MATLAB Fundamentals

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji

An Introductory Tutorial: Learning R for Quantitative Thinking in the Life Sciences. Scott C Merrill. September 5 th, 2012

Introduction to MATLAB

Matlab Tutorial. CS Scientific Computation. Fall /51

Matlab Tutorial and Exercises for COMP61021

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015

Transcription:

Brady Laska Carleton University September 13, 2007

Overview 1 Matlab background 2 Basic Matlab 3 DSP functions 4 Coding for speed 5 Demos

Accessing Matlab Labs on campus Purchase it commercial editions $$$, student editions $ + toolboxes $ Use GNU Octave Compatible syntax Free download (Windows, Mac, Linux) from http://www.octave.org Octave-forge add-on contains most functions from signal processing toolbox All in-class examples will run in both Matlab and Octave (possibly with modification)

Uses of Matlab in DSP Analyze data import, export, number-crunch, curve fitting Visualize and explore data interactive, easy to transform data, powerful plotting/graphics Implement/prototype/test algorithms vast library of built-in functions, available add-on toolboxes, integration with Simulink easy to map algebra of DSP algorithms to Matlab syntax Simulation, modelling

Matlab is A programming language An interactive numerical computation environment An interactive development environment A programming library and API A graphics system (for plotting, GUI creation)

Matlab the programming language Typical programming constructs Looping: for, while, break Branching: if-elseif-else, switch-case Datatypes Standard datatypes are scalar, vector and matrix of double also: integer, boolean, char, string, structure, cell array Arrays (vector/matrix) are 1-based and automatically re-size

Matlab the programming language Other language aspects Case sensitive Dynamically typed Interpreted (mostly) Whitespace and terminating ; are optional Interfaces with other languages (C, FORTRAN, Java) Object Oriented classes, operator overloading

Navigating The Matlab prompt supports common Linux and Windows shell commands pwd current directory path cd newdirectory change directory ls/dir lists files in current directory!command executes command in the system shell example: >>!grep fft *.m

Housekeeping When you re lost who,whos help commandname lookfor key Tab completion, history Cleaning up list variables and sizes prints usage and documentation scans documentation for key and prints matches clear x clc,clf clear variable x, or use clear all clears the console and current figure respectively

Mathamathical operations Functions All functions that are frequently used in DSP are included and named as you d expect: sin,cos,tan,exp,sinc,log,log10,log2,sqrt,pow,... Arithmetic operators Matrix operators perform the linear-algebra-defined matrix operation (matrix multiplication, exponential). Array operators work element-by-element and are indicated by adding a period before the operator.

Complex numbers Built-in complex number suppport Keywords i,j both equal 1 (watch when using index variables and complex numbers in the same function) example: creating a complex number >>x = 1 + 2j Functions for manipulating complex numbers: real,imag,conj,abs,angle,cart2pol,pol2cart

Vectors Unlike other programming languages, Matlab has two distinct types of 1-dimensional arrays (vectors). Row vectors: >>x = [1,2,3]; Default for range operations such as x = 1:10. Column vectors: >>y = [1;2;3]; Default for signals. Functions such as plot, fft, sum, mean, etc. that take a vector input will evaluate each column of a matrix as a separate signal.

Common matrix creation commands ones(m,n) zeros(m,n) eye(n) randn(m,n) matrix of ones matrix of zeros N N identity matrix matrix of zero-mean unit variance Gaussian random numbers, aka white noise rand(m,n) matrix of uniform random numbers on [0, 1] diag(x) matrix with x along the diagonal Note that ones(1e6) will attempt to create a 10 6 10 6 matrix, not a 10 6 1 vector.

Matrix Indexing Most functions can operate on either scalar, vector, or matrix; clever indexing allows functions to be applied to a select subset of your data. Elements in a matrix can be accessed using subscripts or linear indices. Functions sub2ind and ind2sub are used to convert back and forth. Subsets defined by logical matrix or index set.

Indexing methods Logical matrix A matrix of logical ones and zeros (or boolean datatype in new versions) same size as vector/matrix. Logical matrices can be combined using Boolean algebra and logical operators: ==, =,>,<,&,,xor. Note that &, accept and return matrices while &&, accept and return scalars and are used for control statements. Logical vectors can be collapsed to scalars for control statements using any and all.

Indexing methods Index set A matrix of linear indices in the range 1:prod(size(A)). Expression is evaluated at the indices in the set. Sets created using find(boolean statement). Index sets can be combined using set operations: union, intersect, unique, setxor, setdiff.

Matrix reshaping size(a) A(:) A, A. reshape repmat flipud,fliplr returns the size of the matrix convert any matrix or vector to a column vector conjugate and non-conjugate transpose. Generally use conjugate transpose in DSP. reshapes a matrix, traverses column-wise useful for adding/multiplying a vector to each row/column of a matrix flips the vector/matrix

Working with transfer functions Matlab has many functions for analyzing and constructing filters and transfer functions. roots poly zplane residuez fdatool fvtool find the zeros of a polynomial construct a polynomial from a set of roots plot poles and zeros on the complex plane z-transform partial fraction expansion filter design and analysis tool filter visualization tool

Other useful DSP functions filter(b,a,x) fftfilt(b,x) conv buffer windows xcorr FIR and IIR filtering FIR filtering using the FFT discrete convolution (polynomial multiplication) divide a signal into (possibly overlapping) frames hanning, hamming, blackman kaiser, bartlett auto and cross-correlation

Vectorizing Definition Vectorization: replacing loops with calls to vector functions. Matlab used to be entirely interpreted and loops were very slow. Matlab now has JIT acceleration so code using loops with built-in functions can be as fast as vectorizing. Vectoring can still make your code faster, more readable, and more amenable to parallelization. Code says what you want to do, not how to do it. Vectorization makes extensive use of index sets and logical matrices.

Coding for speed As usual, don t sacrifice readability and clarity for speed. Pre-allocate Use ones,zeros to intialize vectors/matrices. Very important, especially for big matrices. Profile Use profile on, profile report and tic, toc to time code execution. Mex functions If you really need speed, write your function in C or FORTRAN with Mex interfaces.

Demos Example AM Modulation Create a baseband signal, modulate it using a carrier sinusoid. Example Noise removal Identify signal components, remove noise to recover signal.

References P. Venkataraman, Matlab: A Fast Paced Introduction, Online at: http: //www.rit.edu/ pnveme/matlab Course/DEFAULT.HTM. S. Roth and A. Balan, Introduction to Matlab (Demo), Online at: http://www.cs.brown.edu/courses/ csci1430/matlabdemo.html.