close all clear all clc load('homework2.mat') % defines t, x, g, T N = length(x); X = fftshift(T*fft(x)); G = fftshift(T*fft(g)); om = (-round((N-1)/2):round(N/2)-1) *2*pi/(N*T); Y = X.*G; y = ifft(ifftshift(Y)/T); y2 = T*conv(x,g); y2 = y2(1:length(x)); figure(1) subplot(2,2,1) plot(t,x) grid xlabel('t') ylabel('x(t)') title('pancreatic secretion') subplot(2,2,2) plot(t,g) grid xlabel('t') ylabel('g(t)') title('impulse response') subplot(2,1,2) plot(t,y,t,y2) grid xlabel('t') ylabel('y(t)') legend('via fft','via conv') title('plasma concentration') sgtitle('time domain') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 4.5]) print -dpng homework2a.png -r100 figure(2) subplot(2,2,1) semilogy(om,abs(X)) grid xlabel('\omega') ylabel('X(\omega)') title('pancreatic secretion') subplot(2,2,2) semilogy(om,abs(G)) grid xlabel('\omega') ylabel('G(\omega)') title('transfer function') subplot(2,1,2) semilogy(om,abs(Y)) grid xlabel('\omega') ylabel('Y(\omega)') title('plasma concentration') sgtitle('Fourier domain') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 4.5]) print -dpng homework2b.png -r100