Music 320 lab 1
October 6, 2000

Introduction to matlab

  1. reasons for learning matlab
     a. "really great graphing calculator"
     b. demonstrate freqz
	> freqz(fir1(256,0.6))
     c. encourages exploration
  2. invoking matlab
     a. from the command line
     b. ~/matlab/startup.m and /dspfirst path
  3. demonstration of interpreter
     a. > help help
	> help cos
	> help toeplitz
	> help fft
     b. basic numerical computation: 
	> 2 + 3
     c. trickier computation 
	> 8 * 7 / 4 + 3
     d. precedence 
	> 8 * 7 / (4 + 3)
     e. variables: 
	> x = 3 * 2.01
	> who
     f. ans variable
     g. vectors and matrices
	> x=[1:10]
	> x = [1 3 7 15]
	> y=[1:0.1:10]
	> z=[1:3;4:6;7:9]
     h. matrix vs. pointwise operations: .*, ./, .^
	> z*z
  4. demonstration of scripting (via emacs or whatever)
     a. invoking scripts from matlab
     b. % as comments
     c. ; to suppress output
  5. useful functions
     a. plotting: plot, subplot, figure, hold, stem, axis, title
     b. math: e=exp(1), pi, sin, cos, atan, sqrt
	> cos(pi)
	> cos(0:0.1:pi)
     c. sound: wavread, wavwrite, auread, auwrite, sound(y,fsamp)
     d. signal processing: filter, firfilt, conv, freqz, fft, remez, 
	  fir1, specgram, various window functions
	  > z=firfilt(fir1(256,0.05),y)
	  > specgram(z)
     e. complex: j, real, imag, abs, angle, zprint, zcat, zvect
	> real(j) % locate a complex number in cartesian form
	> imag(j)
	> abs(j)  % locate a complex number in polar form; see help abs
	> angle(j)
	> zprint(j) % convenient graphing tools
	> zvect(j)
	> zcat([1 j 1+j])
  6. example: demonstrate Euler's identity
     a. a real sinusoid can be decomposed into two complex sinusoids
        > figure(1)
	> subplot(2,1,1)
	> x=[0:0.1:2*pi];
	> plot(x,cos(x))
	> subplot(2,1,2)
	> plot(x,(e^(j.*x)+e^(-j.*x))/2)
	> figure(2)
	> subplot(2,1,1)
	> fft(cos(x))
	> subplot(2,1,2)
	> fft((e^(j.*x)+e^(-j.*x))/2)       
  7. user-defined functions
     a. example from final project
     b. vectors instead of loops....
  8. DSP First appendix B as a short Matlab manual
  9. > exit