Docsity

MATLAB Lab Practice: An Introduction to Matrix Operations and Signal Generation, Exercises of Signals and Systems

Partial preview of the text

Download MATLAB Lab Practice: An Introduction to Matrix Operations and Signal Generation and more Exercises Signals and Systems in PDF only on Docsity!

LAB PRACTICE # 01

AN INTRODUCTION TO MATLAB

EXERCISE#

v=[1 2;3 4] v= 1 2 3 4 (a) v(2) ans = 3 w=[2 3;5 6] w = 2 3 5 6 (b) sum=v+w sum = 3 5 8 10 (c) diff=v-w diff = -1 - -2 -

(d) vw=[v w] vw = 1 2 2 3 3 4 5 6 (e) vw(2:6) ans = 3 2 4 2 5 (f) v' ans = 1 3 2 4

w=[3 2 1;5 4 3;8 7 6] w = 3 2 1 5 4 3 8 7 6 (c)[v;w] ans = 3 2 1 5 4 3 7 6 8 3 2 1 5 4 3 8 7 6 (d) v*z ans = 18 24 30 42 54 66 87 108 129

v' ans = 3 5 7 2 4 6 1 3 8 (e) [z;v'] ans = 1 2 3 4 5 6 7 8 9 3 5 7 2 4 6 1 3 8 (f) z+v' ans = 4 7 10 6 9 12 8 11 17

z=[444 333;222 666] z = 444 333 222 666 (e) Mz(1:2) Error using * Inner matrix dimensions must agree. v=[222 444;777 333] v = 222 444 777 333 (f) v(3:4)M ans = 209457 381951 (g) M(1,1) ans = 222 (h) M(1:2,1:2) ans = 222 444 333 555

(I)M(:,1)

ans = 222 333 (J)M(2,:) ans = 333 555

(3) det() Description: det(X) returns the determinant of the square matrix X. If X contains only integer entries, the result d is also an integer. det(m) ans =

(4)Linspace () Description: The linspace function generates linearly spaced vectors. It is similar to the colon operator ":", but gives direct control over the number of points. y = linspace(a,b) generates a row vector y of 100 points linearly spaced between and including a and b. y = linspace(a,b,n) generates a row vector y of n points linearly spaced between and including a and b.

y = linspace(2,3); y = linspace(2,3); y = linspace(2,3) y = Columns 1 through 12

 - 2.0000 2.0101 2.0202 2.0303 2.0404 2.0505 2.0606 2.0707 2. 
  • 2.0909 2.1010 2.
    • Columns 13 through
      • 2.1212 2.1313 2.1414 2.1515 2.1616 2.1717 2.1818 2.1919 2.
  • 2.2121 2.2222 2.
    • Columns 25 through
      • 2.2424 2.2525 2.2626 2.2727 2.2828 2.2929 2.3030 2.3131 2.
  • 2.3333 2.3434 2.
    • Columns 37 through
      • 2.3636 2.3737 2.3838 2.3939 2.4040 2.4141 2.4242 2.4343 2.
  • 2.4545 2.4646 2.
    • Columns 49 through
      • 2.4848 2.4949 2.5051 2.5152 2.5253 2.5354 2.5455 2.5556 2.
  • 2.5758 2.5859 2.
    • Columns 61 through
      • 2.6061 2.6162 2.6263 2.6364 2.6465 2.6566 2.6667 2.6768 2.
  • 2.6970 2.7071 2.
    • Columns 73 through
      • 2.7273 2.7374 2.7475 2.7576 2.7677 2.7778 2.7879 2.7980 2.
  • 2.8182 2.8283 2.
    • Columns 85 through
      • 2.8485 2.8586 2.8687 2.8788 2.8889 2.8990 2.9091 2.9192 2.
  • 2.9394 2.9495 2.

Columns 25 through 36 0.0091 0.0110 0.0133 0.0160 0.0193 0.0233 0.0281 0.0339 0. 0.0494 0.0596 0. Columns 37 through 48 0.0869 0.1048 0.1265 0.1526 0.1842 0.2223 0.2683 0.3237 0. 0.4715 0.5690 0. Columns 49 through 50 0.8286 1. EXERCISE#

Q1)

t=linspace(0,20,100) yc=cos(t) plot(t,y)

Q2)

t=linspace(0,20,100) yc=cos(t) plot(t,yc,'r') hold on ys=sin(t) plot(t,ys) legend('yc','ys')

Q3)

t=linspace(0,20,100) yc=cos(t) subplot(311) plot(t,yc,'r') legend('yc') hold on ys=sin(t) subplot(312) plot(t,ys) legen

Q4)

(i)>> help whos whos List current variables, long form. whos is a long form of WHO. It lists all the variables in the current workspace, together with information about their size, bytes, class, etc. (ii)>> help pwd pwd Show (print) current working directory. pwd displays the current working directory. S = pwd returns the current directory in the string S. (iii)>>help hold hold Hold current graph hold ON holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph. hold OFF returns to the default mode whereby PLOT commands erase the previous plots and reset all axis properties before drawing new plots. hold, by itself, toggles the hold state. hold does not affect axis autoranging properties.

LAB PRACTICE#

SIGNAL GENERATION AND PLOTTING

PROGRAMS

A= f0=4pi w=pi/ t=0:0.001: y=asawtooth(f0*t+w) plot(t,y);

A= f0=10pi w=5pi t=0:0.001: sq=Asquare(f0t+w) plot(t,sq) axis([0 1 -2 2])

A= f0=pi/ w=pi/ n=-10:1: x=Asquare(f0n+w) stem(n,x)

EXERCISE# (A) fo=10pi w=5pi A= n=-10:1: x=Asawtooth((fon+w)/2) stem(n,x) (B) (i) a= w=20pi Q=pi/ t=0:0.001: x=acos(wt+Q) plot(t,x) (B) (ii) a= w=20pi Q=pi/ t=0:0.001: x=asin(wt+Q) plot(t,x)

(D) t=0:0.001: z=2.exp(-t).cos(2.5pit).(t>0.2) plot(t,z) (E) n=0:0.001: y=60.exp(-6n).sin(20pin) plot(n,y)

EXERCISE# (A) (i) n=0:0.001: Un=1(n>=0) x=Un.n stem(n,x) (A) (ii) n=-100:1: x=1.(n==0) stem(n,x) (A) (iii) n=-5:0.5: x=(n-2).((n-2)>0) R=2.*x stem(n,R) grid on