close all clear all clc load('homework2.mat') % defines t, x, T x = x - mean(x); x = [x, zeros(1,2*length(x))]; % trick to tighthen Fourier sampling N = length(x); t = (0:N-1)*T; X = fftshift(T*fft(x)); om = (-round((N-1)/2):round(N/2)-1) *2*pi/(N*T); Y = X.*(abs(om)>pi); % filter signal y = ifft(ifftshift(Y)/T); % filtered signal in time figure(1) subplot(2,2,1) plot(t,x) grid xlabel('t') ylabel('x(t)') title('time domain - distorted') axis([0 20 ylim]) subplot(2,2,2) plot(t,y) grid xlabel('t') ylabel('y(t)') title('time domain - filtered') axis([0 20 ylim]) subplot(2,2,3) semilogy(om,abs(X)) axis([xlim 5e-2 5e3]) grid xlabel('\omega') ylabel('X(\omega)') axis([0 20 1e1 1e4]) title('Fourier domain - distorted') subplot(2,2,4) semilogy(om,abs(Y)) grid xlabel('\omega') ylabel('Y(\omega)') axis([0 20 1e1 1e4]) title('Fourier domain - filtered') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 4.5]) print -dpng homework2.png -r100