% Matlab programs for Chapter 1 % Date: 2/25/04 % File: Chap01.m % Name: Feng-Li Lian (fengli@ntu.edu.tw) echo on clear all; close all; %%% scalar 3*5 a = 3 b = 5 a*b c = a*b d = a^b pause whos pause %%% matrix A = [ 1 2 3 4 ] pause B = [ 5 6 7; 8 9 10 ] pause C = [ 5 6 7 8 9 10 ]; pause D = [ 2 2 3 3 ]; pause A * B C = A * B; A*D A.*D pause %%% DT exponential signals C = 5; a = 0.8; n = -10:10; m = -10:2:10; pause x1 = C*a.^n; pause a = -0.8; x2 = C*a.^n; pause %%% figure plot(x1) pause plot(x1,'.') plot(x1,'o') pause stem(x1) pause plot(n,x1,'o') stem(n,x1) pause title('Title is HERE') xlabel('X lable is HERE'); ylabel('Y lable is HERE'); text( 2, 30, 'Here is (2,30)'); pause stem(n,x1, 'or' ); hold on; stem(n,x2, 'xb' ) axis([ -15 15 -60 60 ]) hold off; pause subplot(2,1,1); %subplot(211) stem(n,x1,'or') subplot(2,1,2); stem(n,x2,'xb') pause subplot(2,2,1); %subplot(211) stem(n,x1,'or') subplot(2,2,4); stem(n,x2,'xb') pause %%% DT sinusodal signals n = -15:15; x1 = cos(0*n); x2 = cos(pi*n/8); x3 = cos(pi*n/4); x4 = cos(pi*n/2); x5 = cos(pi*n); x6 = cos(3*pi*n/2); x7 = cos(7*pi*n/4); x8 = cos(15*pi*n/8); x9 = cos(2*pi*n); %%% figure close subplot(3,3,1); stem(n,x1,'or'); axis([-15 15 -1 1]); subplot(3,3,2); stem(n,x2,'or'); axis([-15 15 -1 1]); subplot(3,3,3); stem(n,x3,'or'); axis([-15 15 -1 1]); n = -15:15; x = zeros(9,length(n)); w = [ 0 pi/8 pi/4 pi/2 pi 3*pi/2 7*pi/4 15*pi/8 2*pi ]; close for i = 1:9 x(i,1:end) = cos(w(i)*n); subplot(3,3,i); stem(n,x(i,:), 'ob' ); axis( [ -15 15 -1.5 1.5 ] ); title( ['x[n] = cos(' num2str(w(i)) 'n)'] ); if i==1 pause else pause(1) end end