introduction to matlab ii
DESCRIPTION
Introduction to Matlab II. EE 2303 Lab. Basic Matlab Review. Data file input/output string, char, double, struct Types of variables load, save directory/workspace data file movement Navigation/workspace commands clear – clears workspace of all variables - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/1.jpg)
Introduction to Matlab IIIntroduction to Matlab II
EE 2303 Lab
![Page 2: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/2.jpg)
Basic Matlab Review
Data file input/output string, char, double, struct Types of
variables load, save directory/workspace data file
movement
Navigation/workspace commands clear – clears workspace of all variables close all – close all figure-windows Up-arrow – scroll through recently used command
![Page 3: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/3.jpg)
Basic Matlab Review Fundamentals of matrix computing
[ ], Brackets are used to form vectors and matrices
{ }, Curly braces are used in cell array assignment
( ), ParenthesesEnclose arguments of functionsEnclose subscripts of vectors and matricesIndicate precedence in arithmetic
expressions
![Page 4: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/4.jpg)
Basic Matlab Review Plotting functions
plot(), stem() 1-dimensional graphingmesh(), imagesc() 2-dimensional
visualization
![Page 5: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/5.jpg)
Creating Arrays cell(M,N) create M-by-N cell array of
empty matrices Individual cells can be any matlab data type Enables matrices with mixed elements
e.g.
![Page 6: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/6.jpg)
Creating Arrays zeros(M,N) create M-by-N zeros matrix
ones(M,N) create M-by-N ones matrix
![Page 7: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/7.jpg)
User Interface Commands
More user-friendly Looks slicker Principal UI commands
uigetfile() – retrieve files questdlg() – input logical buttons inputdlg()– input values
![Page 8: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/8.jpg)
uigetfile() Retrieves file via browser windowEx: [audio_input, pathname] = uigetfile('*.wav', 'Please select a wav-file');
![Page 9: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/9.jpg)
inputdlg() Parameter input dialog outputs cell arrayEx: lpdlg = inputdlg({'Enter cutoff frequency(in Hz)'},'Low Pass Filter Parameters',1,{'1000'});
![Page 10: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/10.jpg)
questdlg() Asks question – Yes-No-Cancel by defaultEx: isdlg = questdlg('Would you like to listen to your input signal?', 'Input sound');
![Page 11: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/11.jpg)
guide GUI Design Environment
Alter .fig files
Design self-contained gui’s
![Page 12: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/12.jpg)
Debug Mode Used for scripts
![Page 13: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/13.jpg)
Complex NumbersFor a complex signal x of size N…
real() -- outputs real components imag() – outputs imaginary components abs() – yields magnitude angle() – yields phase of signal
By default, i and j are both set to sqrt(-1)
Z = x + j*y can also be written:
Z = (x,y) essentially a 2d matrix
![Page 14: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/14.jpg)
Discrete Fourier Transform
Used to find frequency response of digital signals Discrete signal input DFT discrete
frequency response Matrix form of DFT:
eWNknjkn
N
/2
1
0
N
n
kn
NWnxkX
![Page 15: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/15.jpg)
FFT Example
Create an example signal:
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)')
![Page 16: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/16.jpg)
FFT Example
Now find the frequency response using the DFT
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)')
![Page 17: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/17.jpg)
Lab Exercise The goal of this lab
is to expand your Matlab repertoire through: Debugging a faulty
script Creating a user
interface script Creating an audio-
Input script
![Page 18: Introduction to Matlab II](https://reader035.vdocuments.mx/reader035/viewer/2022062217/56815862550346895dc5bf49/html5/thumbnails/18.jpg)
Approximating RealityApproximating RealityEE 2303 Lab
References:
Oppenheim, Schafer. Discrete-Time Signal Processing. 2nd Edition, 1999, Prentice-Hall.
Mathworks Home Page: www.mathworks.com