Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% ELE 632 Lab 1 Report
- % *Author:* Scott Goddard 500723518
- %
- %% A.1)
- delta = @(n) 1.0.*(n==3);
- u = @(n) 1.0.*(n>=-1);
- x = @(n) cos((pi*n)/5.0).*u(n);
- x1 = @(n) x(n-3);
- x2 = @(n) x(-n);
- n = (-20:20)';
- figure(1);
- stem(n,delta(n)); grid on; title('I.'); xlabel('n');
- figure(2);
- stem(n,u(n)); grid on; title('II.'); xlabel('n');
- figure(3);
- stem(n,x(n)); grid on; title('III.'); xlabel('n');
- figure(4);
- stem(n,x1(n)); grid on; title('IV.'); xlabel('n');
- figure(5);
- stem(n,x2(n)); grid on; title('V.'); xlabel('n');
- % x1[n] is translating x[n] 3 units right.
- % x2[n] is horizontally mirroring x[n] across the y axis.
- %% A.2)
- n = [-10:70];
- u = @(n) 1.0.*(n>=0);
- y = @(n) 5.0.*exp(-1.0*n/8).*(u(n)-u(n-10));
- y1 = @(n) y(3.*n);
- y2 = @(n) y(n/3);
- figure(6);
- stem(n,y(n)); grid on; title('I.'); xlabel('n');
- axis([-10 70 0 6]);
- figure(7);
- stem(n,y1(n)); grid on; title('II.'); xlabel('n');
- axis([-10 70 0 6]);
- figure(8);
- stem(n,y2(n)); grid on; title('III.'); xlabel('n');
- axis([-10 70 0 6]);
- % y1[n] is horizontally compressing x[n] by 3.
- % y2[n] is horizontally stretch x[n] by 3.
- %% A.3)
- t = [-10:0.1:70];
- u = @(t) 1.0.*(t>=0);
- z = @(t) 5.0.*exp(-1.0*t/8).*(u(t)-u(t-10));
- y3 = @(t) z(t./3);
- n = [-10:70];
- figure(9);
- stem(n,y3(n)); grid on; title('I.'); axis([-10 70 0 6]);
- % II. y3[n] is not the same as y2[n] because it was sampled after the
- % signal was generated, so it has more values.
- %% B.2)
- n = 1:13;
- y = [2000,zeros(1,length(n)-1)];
- i = 1.02;
- for j = 1:13
- y(j+1) = i*y(j);
- end
- figure(10);
- stem(n,y(n)); grid on;
- xlabel('Month'); ylabel('Balance [$]'); title('B.2');
- axis([0 14 1000 12000]);
- %% B.3)
- n = 1:13;
- y = [2000,zeros(1,length(n)-1)];
- x = @(n) 100.*n;
- i = 1.02;
- for j = 1:13
- y(j+1) = i*y(j) + x(j);
- end
- figure(11);
- stem(n,y(n)); grid on;
- xlabel('Month'); ylabel('Balance [$]'); title('B.3');
- axis([0 14 1000 12000]);
- %% C.1)
- delta = @(n) 1.0.*(n==0);
- x = @(n) cos(pi*n./5)+delta(n-20)-delta(n-35);
- n = 0:44;
- figure(12);
- stem(n,x(n)); title('Input signal'); xlabel('n'); grid on;
- % Matlab function given below
- %
- % function [y] = maximum(x,N)
- % M = length(x);
- % y = [zeros(1,M)];
- % x2 = [zeros(1,(N-1)),x];
- % for i = 1:M
- % out = max(x2(i:(i+N-1)));
- % y4(i) = out;
- % end
- %% C.2)
- figure(13);
- y = maximum(x(n),4);
- stem(n,y); title('N = 4'); xlabel('n'); grid on;
- figure(14);
- y = maximum(x(n),8);
- stem(n,y); title('N = 8'); xlabel('n'); grid on;
- figure(15);
- y = maximum(x(n),12);
- stem(n,y); title('N = 12'); xlabel('n'); grid on;
- %% C.3)
- % For each value of N the signal is essentially taking the max value for
- % the last N points. That means a local maximum will persist for N values.
- % We lose a lot of information about the signal by increasing N.
- %% D.1)
- % Function given below:
- %
- % function [e,p] = enpow(x)
- % sq = abs(x).^2;
- % en = 0;
- % for i = 1:length(x)
- % en = en + sq(i);
- % end
- % e = en
- %
- % N0 = length(x)+1;
- % N = (length(x)-1)/2;
- % pow = 0;
- % for i = 1:N
- % pow = pow + sq(i);
- % end
- % p = N0^(-1)*pow
- % end
- %% D.2)
- u = @(n) 1.0.*(n>=0);
- x = @(n) 3.0.*n.*(u(n+3)-u(n-4));
- n = -3:3;
- figure(16);
- stem(n,x(n));title('x[n] original'); xlabel('n'); grid on;
- enpow(x(n));
- %%% HINT = USE MOD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement