4 views

Uploaded by dctrino

dfgdfgdgd

save

You are on page 1of 23

Brady Laska

SYSC 4405

Carleton University

September 13, 2007

SYSC 4405

An Introduction to Matlab for DSP

Overview

1 2 3 4 5

Matlab background Basic Matlab DSP functions Coding for speed Demos

SYSC 4405

An Introduction to Matlab for DSP

Mac.octave. Linux) from http://www. student editions $ + toolboxes $ Use GNU Octave → Compatible syntax → Free download (Windows.Accessing Matlab Labs on campus Purchase it → commercial editions $$$.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 modiﬁcation) SYSC 4405 An Introduction to Matlab for DSP .

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

GUI creation) SYSC 4405 An Introduction to Matlab for DSP .Matlab is A programming language An interactive numerical computation environment An interactive development environment A programming library and API A graphics system (for plotting.

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

’ are optional Interfaces with other languages (C. FORTRAN. Java) Object Oriented → classes.Matlab the programming language Other language aspects Case sensitive Dynamically typed Interpreted (mostly) Whitespace and terminating ‘. operator overloading SYSC 4405 An Introduction to Matlab for DSP .

Navigating The Matlab prompt supports common Linux and Windows shell commands pwd cd newdirectory ls/dir !command current directory path change directory lists ﬁles in current directory executes command in the system shell example: >>!grep fft *.m SYSC 4405 An Introduction to Matlab for DSP .

history list variables and sizes prints usage and documentation scans documentation for key and prints matches Cleaning up clear x clc.clf clear variable x. or use clear all clears the console and current ﬁgure respectively SYSC 4405 An Introduction to Matlab for DSP .Housekeeping When you’re lost who.whos help commandname lookfor key Tab completion.

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

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.conj.angle.imag.cart2pol.pol2cart SYSC 4405 An Introduction to Matlab for DSP .abs.Complex numbers Built-in complex number suppport √ Keywords i.

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

SYSC 4405 An Introduction to Matlab for DSP . 1] matrix with x along the diagonal Note that ones(1E6) will attempt to create a 106 × 106 matrix. not a 106 × 1 vector.N) eye(N) randn(M.N) zeros(M.N) rand(M.Common matrix creation commands ones(M.N) diag(x) matrix of ones matrix of zeros N × N identity matrix matrix of zero-mean unit variance Gaussian random numbers. aka white noise matrix of uniform random numbers on [0.

Subsets deﬁned by logical matrix or index set. vector. SYSC 4405 An Introduction to Matlab for DSP . Elements in a matrix can be accessed using subscripts or linear indices. clever indexing allows functions to be applied to a select subset of your data.Matrix Indexing Most functions can operate on either scalar. or matrix. Functions sub2ind and ind2sub are used to convert back and forth.

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

Sets created using find(Boolean statement ).Indexing methods Index set A matrix of linear indices in the range 1:prod(size(A)). setxor. intersect. Index sets can be combined using set operations: union. Expression is evaluated at the indices in the set. setdiff. SYSC 4405 An Introduction to Matlab for DSP . unique.

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

Working with transfer functions Matlab has many functions for analyzing and constructing ﬁlters and transfer functions. roots poly zplane residuez fdatool fvtool ﬁnd 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 ﬁlter design and analysis tool ﬁlter visualization tool SYSC 4405 An Introduction to Matlab for DSP .

x) conv buffer windows xcorr FIR and IIR ﬁltering FIR ﬁltering using the FFT discrete convolution (polynomial multiplication) divide a signal into (possibly overlapping) frames hanning. bartlett auto and cross-correlation SYSC 4405 An Introduction to Matlab for DSP . blackman kaiser. hamming.A.x) fftfilt(B.Other useful DSP functions filter(B.

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

Proﬁle Use profile on.zeros to intialize vectors/matrices.Coding for speed As usual. toc to time code execution. Pre-allocate Use ones. don’t sacriﬁce readability and clarity for speed. Very important. write your function in C or FORTRAN with Mex interfaces. SYSC 4405 An Introduction to Matlab for DSP . especially for big matrices. profile report and tic. Mex functions If you really need speed.

SYSC 4405 An Introduction to Matlab for DSP . modulate it using a carrier sinusoid.Demos Example AM Modulation Create a baseband signal. Example Noise removal Identify signal components. remove noise to recover signal.

Roth and A.edu/courses/ csci1430/MatlabDemo. SYSC 4405 An Introduction to Matlab for DSP . S.brown. Online at: http: //www.html. “Matlab: A Fast Paced Introduction”. Online at: http://www. “Introduction to Matlab (Demo)”. Venkataraman.edu/∼pnveme/Matlab Course/DEFAULT.References P.HTM. Balan.cs.rit.

- An Introduction to Digital Image Processing With MatlabUploaded byitssiraj
- 2006-09 0974423998 Signals and Systems with MATLAB Computing and Simulink Modeling 3rd EdUploaded bychrisnino
- DSP Project 01Uploaded bykhairuznimo
- Design and Implementation of IIR FilterUploaded bySaurabh Shukla
- digfiltUploaded byNeamt Catalin
- Digital Signal Processing Using MATLABUploaded by오유택
- Matlab Tutorial for DSPUploaded byilgimdemirel
- 5469-0546-Digital Signal Processing Computer Based Approach Sanjit K MitraUploaded byvasu10
- Signals and Systems Using MatlabUploaded byaxeans
- Digital Signal Processing - Computer Based Approach - Solution ManualUploaded byjrodri34
- Real-Time Digital Signal ProcessingUploaded byHyungjoon Lim
- matlab faint cheatsheetUploaded byJodie Edwards
- DSP based ProjectsUploaded bysetsindia3735
- Digital Signal Processing Using MATLABUploaded byTurtogtokh Tumenjargal
- Lecture Note 2007Uploaded byJean Marie Vianney
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- MATLAB_session_1.pptUploaded byndsram
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- Mini ProjectUploaded byFaiz محمد فايز
- computations. It provides capabilities for the numerical.txtUploaded byRAUL
- decided to wait until the 4.0.x release series before making the .txtUploaded byRAUL
- decided to wait until the 4.0.x release series before making the .txtUploaded byRAUL