Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%Problem A.1
- u=@(t) 1.0*(t>=0);
- x=@(t) u(t)-u(t-10);
- h=@(t) u(t)-u(t-10);
- dtau = 0.005; tau = 0:dtau:20;
- ti = 0; tvec = 0:0.01:20;
- z = NaN*zeros(1,length(tvec)); % Pre-allocate memory
- for t = tvec
- ti = ti+1; % Time index
- xh = x(t-tau).*h(tau); lxh = length(xh);
- z(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
- end
- plot(tvec, z)
- title('z(t)=x(t)*x(t)');
- xlabel('t');
- ylabel('z(t)');
- figure;
- %%Problem A.2
- N = 100; PulseWidth = 10;
- t = [0:1:(N-1)];
- X = [ones(1,PulseWidth), zeros(1,N-PulseWidth)];
- stairs(t,X); grid on; axis([-10,110,-0.1,1.1])
- title('x(t)=pulse with width of 10');
- xlabel('t');
- ylabel('x(t)');
- Xf=fft(X);
- Zf=Xf.*Xf;
- %%Problem A.3
- figure;
- f=[-(N/2):1:(N/2)-1]*(1/N);
- w=2*pi*f;
- subplot(211); plot(f,fftshift( abs(Zf))); grid on;
- title('|Z(f)|');
- xlabel('f');
- ylabel('|Z(f)|');
- subplot(212); plot(f,fftshift(angle(Zf))); grid on;
- title('phase of Z(f)');
- xlabel('f');
- ylabel('phase of Z(f)');
- %%problem A.4
- figure;
- N = 100; PulseWidth = 10;
- t = [0:1:(N-1)];
- x = [ones(1,PulseWidth), zeros(1,N-PulseWidth)];
- f = [-(N/2):1:(N/2)-1]*(1/N);
- z=conv(x,x);
- T=[0:1:(2*N)-2];
- plot(T,z)
- axis([0 N -2 10])
- title('time domain operation');
- xlabel('f');
- ylabel('z(t)');
- figure;
- xF=fft(x);
- zF=xF.*xF;
- Z=ifft(zF);
- plot(t,Z)
- title('frequency domain operation');
- xlabel('f');
- ylabel('z(t)');
- %the Plots shown using the time-domain and frequency are the
- %exact same, as was predicted by the property of the fourier transform
- %which states the multiplication in the frequency domain is the same as
- %convolution in the time domain
- %% problem A.5
- N = 100; PulseWidth = 5;
- t = [0:1:(N-1)];
- X = [ones(1,PulseWidth), zeros(1,N-PulseWidth)];
- Zf=fft(X);
- f=[-(N/2):1:(N/2)-1]*(1/N);
- w=2*pi*f;
- figure;
- subplot(211); plot(f,fftshift( abs(Zf))); grid on;
- title('magnitude of frequencies of x(t) with a width of 5');
- xlabel('f');
- ylabel('x(f)');
- subplot(212); plot(f,fftshift(angle(Zf))); grid on;
- title('phase plot of x(t) with a width of 5');
- xlabel('f');
- ylabel('x(f)');
- figure;
- N = 100; PulseWidth = 25;
- t = [0:1:(N-1)];
- X = [ones(1,PulseWidth), zeros(1,N-PulseWidth)];
- Zf=fft(X);
- f=[-(N/2):1:(N/2)-1]*(1/N);
- w=2*pi*f;
- subplot(211); plot(f,fftshift( abs(Zf))); grid on;
- title('magnitude of frequencies of x(t) with a width of 25');
- xlabel('f');
- ylabel('x(f)');
- subplot(212); plot(f,fftshift(angle(Zf))); grid on;
- title('phase plot of x(t) with a width of 25');
- xlabel('f');
- ylabel('x(f)');
- figure;
- %the magnitude of frequency plot it scaled according to the
- %time scale. in addition, the frequency plot of phase is also
- %scaled proportional to the time scale.
- %this is the same as the property which states: a time scale of a
- %will be :(1/|a|)X(w/a)
- %%problem A.6
- N = 100; PulseWidth = 5;
- t = [0:1:(N-1)];
- X = [ones(1,PulseWidth), zeros(1,N-PulseWidth)];
- f = [-(N/2):1:(N/2)-1]*(1/N);
- ex1=exp(i*(pi/3).*t);
- wplus=fft(ex1.*X);
- subplot(211); plot(f,fftshift( abs(wplus))); grid on;
- title('magnitude plot of x(t)*e^{j*(pi/3)*t}');
- xlabel('f');
- ylabel('|z(f)| with shift');
- subplot(212); plot(f,fftshift(angle(wplus))); grid on;
- title('phase plot of x(t)*e^{j*(pi/3)*t}');
- xlabel('f');
- ylabel('angle of z(f) with shift');
- figure;
- ex2=exp(-i*(pi/3).*t);
- wminus=fft(ex2.*X);
- subplot(211); plot(f,fftshift( abs(wminus))); grid on;
- title('magnitude plot of x(t)*e^{-j*(pi/3)*t}');
- xlabel('f');
- ylabel('|z(f)| with shift');
- subplot(212); plot(f,fftshift(angle(wminus))); grid on;
- title('phase plot of x(t)*e^{-j*(pi/3)*t}');
- xlabel('f');
- ylabel('angle of z(f) with shift');
- figure;
- thing=cos(t*pi/3);
- wc=fft(thing.*X);
- subplot(211); plot(f,fftshift( abs(wc))); grid on;
- title('magnitude plot of x(t)*cos((pi/3)*t)');
- xlabel('f');
- ylabel('');
- subplot(212); plot(f,fftshift(angle(wc))); grid on;
- title('phase plot of x(t)*cos((pi/3)*t)');
- xlabel('f');
- ylabel('');
- %this final property is an example of a shift in the frequency domain
- %if you multiply a function with a complex exponential, that corresponds to
- %a horizontal shift in the frequency domain. this is clearly seen in the
- %first 2 graphs for A.6. the last graph is just the real component of a
- %complex exponential, which is why it is not a perfect shift.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement