Share
Embed
Transcript
17 slides
-
Graphics Basics • XY Plot – plot: Graph 2-D data
with linear scales for both axes – plot3: Graph 3-D data with linear scales for both axes – loglog: Graph with logarithmic scales for both axes – semilogx: Graph with a logarithmic scale for the x-axis and a linear scale for the y-axis – semilogy: Graph with a logarithmic scale for the y-axis and a linear scale for the x-axis – plotyy: Graph with y-tick labels on the left and right side • XY Plot example – x = 0:0.05:5; – y = sin(x.^2); – plot(x,y); – xlabel('Time') – ylabel('Amplitude') Fig 1. XY Plot -
Bar Chart • bar(Y) draws one bar for each element
in Y. – x = -2.9:0.2:2.9; – bar(x,exp(-x.*x)); Fig 2. Bar Chart -
Stem Chart • Plot discrete sequence data • stem(Y) plots
the data sequence, Y, as stems that extend from a baseline along the x-axis. The data values are indicated by circles terminating each stem. • Example – x = 0:0.1:4; – y = sin(x.^2).*exp(-x); – stem(x,y) Fig 3. Stem Chart -
Scatter Plot • scatter(X,Y) displays circles at the locations specified
by the vectors X and Y. This type of graph is also known as a bubble plot. • Example – load count.dat – scatter(count(:,1),count(:,2),'r*') – xlabel('Number of Cars on Street A'); – ylabel('Number of Cars on Street B'); Fig 4. Scatter Plot -
Polar Plot • The polar function accepts polar coordinates, plots
them in a Cartesian plane, and draws the polar grid on the plane. • Example – t = 0:0.01:2*pi; – polar(t,abs(sin(2*t).*cos(2*t))); Fig 5. Polar Plot -
Ezplot • Easy-to-use function plotter • Example – ezplot('sin(x)') –
ezplot('sin(x).^2 + cos(y).^2 = 1') Fig 6. Plot sin(x)^2 + cos(y)^2 = 1 Fig 7. Plot sin(x) -
3D Plot • mesh(X,Y,Z) draws a wireframe mesh with color
determined by Z, so color is proportional to surface height. – z=peaks(25); – mesh(z); • surf(Z) creates a three-dimensional shaded surface from the z omponents in matrix Z. – z=peaks(25); – surf(z); • ezsurf() • ezmesh() Fig 8. Mesh Plot -
Ezplot3 • Easy-to-use 3-D parametric curve plotter • Three dimension
version of ezplot. – ezplot3('t*sin(t)', 'cos(t)', 't', [0,12*pi]) Fig 9. 3D plot -
Tips and Tricks • Use “fx” – Find functions •
Scalar multiplication – .* – ./ • Reading online manuals – http://www.mathworks.com/help/matlab/index.html -
MATLAB FFT for Signal Analyze • Tools: Aglient Toolbox +
Aglient IO Library. • MATLAB + Aglient https://www.mathworks.com/products/instrument/supported/agilent.html Fig 11. Aglient Toolbox for Excel Fig 10. Aglient Toolbox for Word -
MATLAB FFT for Signal Analyze • Use Excel to retrieve
data from the oscilloscope and export CSV file. Table 1. Retrieved Data from the oscilloscope Fig 13. Dialog for Retrieving Data from the Oscilloscope -80.4 mV, 平均電壓 (1) 2.51 V, RMS 電壓 (1) 7.6 V, 峰值對峰值電壓 (1) 2.49 V, 最大電壓 (1) -3.7 V, 最小電壓 (1) 3 us, 上升時間 (1) 3 us, 下降時間 (1) 1.908 ms, 正脈衝寬度 (1) 1.908 ms, 負脈衝寬度 (1) 3.816 ms, 週期 (1) 262.05 Hz, 頻率 (1) 50 %, 占空比 (1) Fig 12. Plot Data from the Oscilloscope Fig 14. Output waveform -
MATLAB FFT for Signal Analyze • Fast Fourier transform •
A common use of Fourier transforms is to find the frequency components of a signal buried in a noisy time domain signal. • http://www.mathworks.com/help /matlab/ref/fft.html • https://www.youtube.com/watch ?v=Ko57FiBVkVY Fig 15. FFT from the Oscilloscope Fig 17. FFT Analyze using MATLAB Fig 16. Import CSV File into MATLAB -
Fig 20. FFT from the Oscilloscope Fig 19. Fourier Expansion
of Square Wave -
Writing MATLAB Program • Call by function name / file
name Fig 22. Play sound using square wave Fig 23. Play sound using sine wave Fig 21. Play single tone