close all clear all clc load('homework1.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); % find max: range [4,8] set by looking at the plot [maxval,pos] = max(abs(X).*(om>4).*(om<8)); om0 = om(pos); % estimated omega0 disp(['estimated Tp = 2 pi/omega0 = ' num2str(2*pi/om0)]) figure(1) subplot(2,1,1) plot(t,x) grid xlabel('t') ylabel('x(t)') title('ECG signal in time') axis([0 20 ylim]) subplot(2,2,3) semilogy(om,abs(X)) axis([xlim 5e-2 5e3]) grid xlabel('\omega') ylabel('X(\omega)') title('Fourier domain') subplot(2,2,4) semilogy(om,abs(X)) hold on semilogy(om0,maxval,'ro') grid xlabel('\omega') ylabel('X(\omega)') axis([0 20 1e1 3e3]) title('zoom') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 4.5]) print -dpng homework1.png -r100