Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- delta = @(n) (mod(n,1) == 0).*1.0.*(n == 0);
- n = (-10:10);
- figure;
- stem(n,delta(n-3));
- title('Figure A.1 I. delta[n-3]');xlabel('n');ylabel('delta[n-3]');
- % II. u[n+1]
- u = @(n) (mod(n,1) == 0).*1.0.*(n>=0);
- n = (-10:10);
- figure;
- stem(n,u(n+1));
- title('Figure A.1 II. u[n+1]');xlabel('n');ylabel('u[n+1]');
- % III.
- x = @(n) cos(n*pi/5).*u(n);
- figure;
- stem(n,x(n));
- title('Figure A.1 III. cos(n*pi/5).*u(n)');xlabel('n');ylabel('cos(n*pi/5).*u(n)');
- % IV.
- figure;
- stem(n,x(n-3));
- title('Figure A.1 IV. x1(n)');xlabel('n');ylabel('x(n-3)');
- % V.
- figure;
- stem(n,x(-1.0.*n));
- title('Figure A.1 V. x2(n)');xlabel('n');ylabel('x(-n)');
- % In x1(n), a shift to the right by 3 is performed and in x2(n), a
- % reflection in the y-axis is performed.
- % I.
- u = @(n) (mod(n,1) == 0).*1.0.*(n>=0);
- y = @(n) 5.*exp(-1.0.*n/8).*(u(n)-u(n-10));
- n = (-10:70);
- figure;
- stem(n,y(n));
- title('Figure A.2 I. y(n)');xlabel('n');ylabel('y(n)');
- % II.
- figure;
- stem(n,y(3.0.*n));
- title('Figure A.2 II. y1(n)');xlabel('n');ylabel('y(3n)');
- % III.
- figure;
- stem(n,y((1/3).*n));
- title('Figure A.2 III. y1(n)');xlabel('n');ylabel('y((1/3)n)');
- % In y1[n], y[n] is scaled down and compressed by a factor of 3. This is an
- % example of downsampling because sample points are lost. In y2[n], y[n] is
- % time scaled and stretched by a factor of 3, no sample points are lost.
- % I.
- t = (-10:0.1:70);
- uc = @(t) 1.0.*(t>=0);
- z = @(t) 5.*exp(-1.0.*t/8).*(uc(t)-uc(t-10));
- figure;
- plot(t,z(t));
- title('Figure A.3 Ia. z(t)');xlabel('t');ylabel('z(t)');
- y3 = @(t) z(t/3);
- figure;
- plot(t,y3(t));
- title('Figure A.3 Ib. y3(t)');xlabel('t');ylabel('y3(t)');
- figure;
- stem(n,y3(n));
- title('Figure A.3 Ic. y3(n)');xlabel('n');ylabel('y3(n)');
- % II.
- % Y2[n] obtained in part 2 III is not the same as as Y3[n] obtained here
- % because in part 2 III, the scaling is performed on a discrete function
- % and so sample points are lost due to down sampling. Y3[n] is a discrete
- % graph of a Y3(t), where the transformation is performed on the continuous
- % function. Here, no sample points are lost to down sampling.
- n = (0:13);
- y = [2000; zeros(length(n)-1,1)];
- for s = 2: length(n)-1,1;
- y(s) = 1.02.*y(s-1);
- end
- figure
- stem(n,y);
- title('Figure B.1 y(n)');xlabel('n');ylabel('y(n)');
- n = (0:13);
- y = [2000; zeros(length(n)-1,1)];
- for s = 2: length(n)-1,1;
- y(s) = 1.02.*y(s-1) + 100.*s;
- end
- figure
- stem(n,y);
- title('Figure B.3 y(n)');xlabel('n');ylabel('y(n)');
- delta=@(n)1.0*(n==0);
- x = @(n)cos((pi/5).*n) + delta(n-20) - delta(n-35);
- n =[0:1:44];
- figure
- stem (n, x(n));
- xlabel('n'); ylabel('x[n]'); title('Figure C.2 x[n]');
- snapnow;
- figure
- stem (n, filt(x(n),4));
- xlabel('n'); ylabel('x[n] Max Filtered at N =4'); title('Figure C.2 x[n] Max Filtered at N=4');
- figure
- stem (n, filt(x(n),8));
- xlabel('n'); ylabel('x[n] Max Filtered at N =8'); title('Figure C.2 x[n] Max Filtered at N=8');
- figure
- stem (n, filt(x(n),12));
- xlabel('n'); ylabel('x[n] Max Filtered at N =12'); title('Figure C.2 x[n] Max Filtered at N=12');
- x = [-9 -6 -3 0 3 6 9];
- result = calc(x);
- energy = result(1)
- power = result(2)
- function [y] = filt(x,N)
- M = length(x);
- x = x(:);
- x = [zeros(N-1,1);x];
- y = zeros(M,1);
- delta = @(n) (mod(n,1) == 0).*1.0.*(n == 0);
- n = (-10:10);
- figure;
- stem(n,delta(n-3));
- title('Figure A.1 I. delta[n-3]');xlabel('n');ylabel('delta[n-3]');
- % II. u[n+1]
- u = @(n) (mod(n,1) == 0).*1.0.*(n>=0);
- n = (-10:10);
- figure;
- stem(n,u(n+1));
- title('Figure A.1 II. u[n+1]');xlabel('n');ylabel('u[n+1]');
- % III.
- x = @(n) cos(n*pi/5).*u(n);
- figure;
- stem(n,x(n));
- title('Figure A.1 III. cos(n*pi/5).*u(n)');xlabel('n');ylabel('cos(n*pi/5).*u(n)');
- % IV.
- figure;
- stem(n,x(n-3));
- title('Figure A.1 IV. x1(n)');xlabel('n');ylabel('x(n-3)');
- % V.
- figure;
- stem(n,x(-1.0.*n));
- title('Figure A.1 V. x2(n)');xlabel('n');ylabel('x(-n)');
- % In x1(n), a shift to the right by 3 is performed and in x2(n), a
- % reflection in the y-axis is performed.
- % I.
- u = @(n) (mod(n,1) == 0).*1.0.*(n>=0);
- y = @(n) 5.*exp(-1.0.*n/8).*(u(n)-u(n-10));
- n = (-10:70);
- figure;
- stem(n,y(n));
- title('Figure A.2 I. y(n)');xlabel('n');ylabel('y(n)');
- % II.
- figure;
- stem(n,y(3.0.*n));
- title('Figure A.2 II. y1(n)');xlabel('n');ylabel('y(3n)');
- % III.
- figure;
- stem(n,y((1/3).*n));
- title('Figure A.2 III. y1(n)');xlabel('n');ylabel('y((1/3)n)');
- % In y1[n], y[n] is scaled down and compressed by a factor of 3. This is an
- % example of downsampling because sample points are lost. In y2[n], y[n] is
- % time scaled and stretched by a factor of 3, no sample points are lost.
- % I.
- t = (-10:0.1:70);
- uc = @(t) 1.0.*(t>=0);
- z = @(t) 5.*exp(-1.0.*t/8).*(uc(t)-uc(t-10));
- figure;
- plot(t,z(t));
- title('Figure A.3 Ia. z(t)');xlabel('t');ylabel('z(t)');
- y3 = @(t) z(t/3);
- figure;
- plot(t,y3(t));
- title('Figure A.3 Ib. y3(t)');xlabel('t');ylabel('y3(t)');
- figure;
- stem(n,y3(n));
- title('Figure A.3 Ic. y3(n)');xlabel('n');ylabel('y3(n)');
- % II.
- % Y2[n] obtained in part 2 III is not the same as as Y3[n] obtained here
- % because in part 2 III, the scaling is performed on a discrete function
- % and so sample points are lost due to down sampling. Y3[n] is a discrete
- % graph of a Y3(t), where the transformation is performed on the continuous
- % function. Here, no sample points are lost to down sampling.
- n = (0:13);
- y = [2000; zeros(length(n)-1,1)];
- for s = 2: length(n)-1,1;
- y(s) = 1.02.*y(s-1);
- end
- figure
- stem(n,y);
- title('Figure B.1 y(n)');xlabel('n');ylabel('y(n)');
- n = (0:13);
- y = [2000; zeros(length(n)-1,1)];
- for s = 2: length(n)-1,1;
- y(s) = 1.02.*y(s-1) + 100.*s;
- end
- figure
- stem(n,y);
- title('Figure B.3 y(n)');xlabel('n');ylabel('y(n)');
- delta=@(n)1.0*(n==0);
- x = @(n)cos((pi/5).*n) + delta(n-20) - delta(n-35);
- n =[0:1:44];
- figure
- stem (n, x(n));
- xlabel('n'); ylabel('x[n]'); title('Figure C.2 x[n]');
- snapnow;
- figure
- stem (n, filt(x(n),4));
- xlabel('n'); ylabel('x[n] Max Filtered at N =4'); title('Figure C.2 x[n] Max Filtered at N=4');
- figure
- stem (n, filt(x(n),8));
- xlabel('n'); ylabel('x[n] Max Filtered at N =8'); title('Figure C.2 x[n] Max Filtered at N=8');
- figure
- stem (n, filt(x(n),12));
- xlabel('n'); ylabel('x[n] Max Filtered at N =12'); title('Figure C.2 x[n] Max Filtered at N=12');
- x = [-9 -6 -3 0 3 6 9];
- result = calc(x);
- energy = result(1)
- power = result(2)
- function [y] = filt(x,N)
- M = length(x);
- x = x(:);
- x = [zeros(N-1,1);x];
- y = zeros(M,1);
- for m = 1:M
- y(m) = max(x([m:m+(N-1)]));
- end
- end
- function o = calc(x)
- e = 0;
- for i = 1:length(x)
- e = e + abs(x(i))^2;
- end
- p = e/length(x);
- o = [e,p];
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement