Wednesday, October 14, 2015

Nummer Drei

%Part 1
T=.05;
t=-4:T:4;
tl=-8:T:8;
x= -((t+.25).*(US(t+2)-US(t-1)));
y= 2*exp(-0.4*(t+.5)).*cos(.5*pi*t-(pi/4)).*(US(t+.5)-US(t-2.5));
z= T*conv(x,y);
plot(t,x)
hold on
plot(t,y,'-r')
plot(tl,z,'-g')
title('Part 1 convolution')
hold off
%questions
%-8 to 8
%x from -2.05 to 1.1,y from -.55 to 2.5
%z from -2.55 to 3.45
%You don't really notice T smaller
%but it becomes blocky with larger Ts.

%Part 2
clear all
T=.01;
t=-8:T:8;
tl=-16:T:16;
x=exp(-.5*t).*US(t);
y=2*exp(.75*t).*US(-t);
z= T*conv(x,y);
figure
plot(t,x)
hold on
plot(t,y,'-r')
title('Part 2 x and y')
hold off
figure
zintegral=1.6.*exp(.75*tl).*(tl<0)+1.6.*exp(-.5*tl).*(tl>=0);
plot(tl,z)
hold on
plot(tl,zintegral,'-r')
title('Part 2 z and zintegral')
hold off

%repeat for different segments

clear all
T=.01;
t=-6:T:6;
tl=-12:T:12;
x=exp(-.5*t).*US(t);
y=2*exp(.75*t).*US(-t);
z= T*conv(x,y);
figure
plot(t,x)
hold on
plot(t,y,'-r')
title('Part 2 x and y smaller segment')
hold off
figure
zintegral=1.6.*exp(.75*tl).*(tl<0)+1.6.*exp(-.5*tl).*(tl>=0);
plot(tl,z)
hold on
plot(tl,zintegral,'-r')
title('Part 2 z and zintegral smaller segment')
hold off
%interval -4 to 4
clear all
T=.01;
t=-4:T:4;
tl=-8:T:8;
x=exp(-.5*t).*US(t);
y=2*exp(.75*t).*US(-t);
z= T*conv(x,y);
figure
plot(t,x)
hold on
plot(t,y,'-r')
title('Part 2 x and y smaller segment')
hold off
figure
zintegral=1.6.*exp(.75*tl).*(tl<0)+1.6.*exp(-.5*tl).*(tl>=0);
plot(tl,z)
hold on
plot(tl,zintegral,'-r')
title('Part 2 z and zintegral smaller segment')
hold off
%interval -2 to 2
clear all
T=.01;
t=-2:T:2;
tl=-4:T:4;
x=exp(-.5*t).*US(t);
y=2*exp(.75*t).*US(-t);
z= T*conv(x,y);
figure
plot(t,x)
hold on
plot(t,y,'-r')
title('Part 2 x and y smallest segment')
hold off
figure
zintegral=1.6.*exp(.75*tl).*(tl<0)+1.6.*exp(-.5*tl).*(tl>=0);
plot(tl,z)
hold on
plot(tl,zintegral,'-r')
title('Part 2 z and zintegral smallest segment')
hold off
%As you decrease the interval the approximated z
%gets farther off from the actual z from the integral.

%Part 3
clear all
T=.005;
t=-2:T:3;
tl=-4:T:6;
x= 3*US(((t-.0875)/1.75)+(1/2))-3*US(((t-.0875)/1.75)-(1/2));
y= 1.5*sin(4*pi*t);
z=T*conv(x,y);
ztrue=(-2.25/pi)*cos(4*pi*tl);
figure
plot(tl,z)
hold on
plot(tl,ztrue,'-r')
title('Part 3 z and ztrue')
hold off
figure
plot(t,x)
hold on
plot(t,y,'-r')
title('Part 3 x and y')
hold off
%In Part 3 aside from being shifted somewhat
%the true z seems to continue beyond the range
%of our approximation which is nonzero from about -3 to 4

%Part 4
clear all
figure
T=0.01;
t=-1:T:12;
x_imp = zeros(size(t));
x_imp(t==0) = 1/T;
H=zeros(size(t));
H(1)=0;
H(2)=0;
for i=3:1:length(t)
    H(i)=(x_imp(i)*(.9*T^2+.2*T)-.2*T*x_imp(i-1)-.3*H(i-2)+H(i-1)*(.6+.4*T))/(.3+.4*T+.8*T^2);
end
plot(t,H);
title('Part 4 Impulse response');
xlim([-2 12])
figure
tl=-2:T:24;
x=2-cos(.2*pi*t)+.25*cos(2*pi*t);
plot(t,x);
hold on
z=T*conv(x,H);
plot(tl,z,'-r');
xlabel('t');
xlim([-2 12])
ylabel('magnitude');
title('Part 4 Input and Output');
hold off

No comments:

Post a Comment