Introduction to Matlab. Useful links
-
Upload
elaine-perry -
Category
Documents
-
view
239 -
download
0
description
Transcript of Introduction to Matlab. Useful links
![Page 1: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/1.jpg)
Introduction to Matlab
![Page 2: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/2.jpg)
Useful links• http://mirlab.org/jang/books/matlabProgramming4beginner/slide/
• http://www.mathworks.com/
![Page 3: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/3.jpg)
Basic Settings• Create new file : New Script• Create new function : New -> Function
![Page 4: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/4.jpg)
Basic Operation• Don’t need to do variable declaration, but the first word of the
variable must be English.
• Comments and multiple lines comments :
• Help : search for command usageex : help mean
![Page 5: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/5.jpg)
Basic Matrix Operation
![Page 6: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/6.jpg)
Basic Matrix Operation
![Page 7: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/7.jpg)
Basic Function• y = mean(x) calculate the mean of x• y = abs(x) calculate the absolute value of x• y = exp(x) calculate e^x• y = sin(x) sine value of x• y = cos(x) cosine value of x• y = min(x) minimum value of x• y = max(x) maximum value of x• y = sum(x) summation of x
![Page 8: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/8.jpg)
Useful wave generation function
clear all;t=0:0.01:4;y1=square(2*pi*t);y2=square(2*pi*t,30);subplot(2,1,1),plot(t,y1);axis([-inf, inf, -1.2, 1.2]);subplot(2,1,2),plot(t,y2);axis([-inf, inf, -1.2, 1.2]);
![Page 9: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/9.jpg)
For, While, If else
![Page 10: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/10.jpg)
User-defined Function• save a function as a .m file, and call the function from the main.m• function [output variable] = name_of_function(input variable)ex :function [x , y] = two_vectors(r1,r2,t1,t2)d2r = pi/180;th1 = t1*d2r; th2 = t2*d2r;x = r1.*cos(th1)+r2.*cos(th2);y = r1.*sin(th1)+r2.* sin(th2);
% main.m
clear all;rr1 = 3;rr2 = 4;tt1 = 20;tt2 = 50;[xx , yy ] = two_vectors (rr1,rr2,tt1,tt2);
![Page 11: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/11.jpg)
Plot
![Page 12: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/12.jpg)
Plot
![Page 13: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/13.jpg)
FFT
![Page 14: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/14.jpg)
IFFT
![Page 15: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/15.jpg)
Audio signal read and write• Read : [x , fs] = wavread('C:\WINDOWS\Media\test_music.wav'); x : signal vectorfs : sampling frequency• Write:wavwrite(x,fs,wavfile);
![Page 16: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/16.jpg)
Audio signal transmit and receive• Transmit:1. sound(x,fs);2. wavplay(x,fs);• Receive :1.
x = audiorecorder(fs,16,1);recordblocking(x,sec); % records ‘sec’ secondsx_array = getaudiodata(x);
2.x = wavrecord(array_length,fs) %how many data
![Page 17: Introduction to Matlab. Useful links](https://reader034.fdocuments.net/reader034/viewer/2022050806/5a4d1b247f8b9ab05999673d/html5/thumbnails/17.jpg)
Easy quiz • Please create x(t) = 0.8sin(240t)+0.6cos(560t), 0<t<1.5 , where the
sampling frequency is 4000Hz. Plot the FFT of this signal.(50%)
• Please create a triangle pulse like this, where x axis = -1 : 0.01 : 1 (50%)