Ex1_12 - for k = 1:nterm cwt = cos(k*omega*tcycle(i)); swt =

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
tau = 2; npts = 1000; ncycle = 5; nterm = 50; Y = 0.1; omega = 2*pi/tau; dt = tau/npts; d aa = 0; a = zeros(nterm,1); b = zeros(nterm,1); t = [0:dt:tau]; for i = 1:npts+1 f(i) = Y*t(i)/tau; aa = aa + 2/tau*f(i)*dt; for k = 1:nterm cwt = cos(k*omega*t(i)); swt = sin(k*omega*t(i)); a(k) = a(k) + 2/tau*f(i)*cwt*dt; b(k) = b(k) + 2/tau*f(i)*swt*dt; end end aa a b pause; p ef = zeros(ncycle*npts+1,1); ef = ef + aa/2*ones(ncycle*npts+1,1); tcycle = [0:dt:ncycle*tau]; for i = 1:ncycle*npts+1
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for k = 1:nterm cwt = cos(k*omega*tcycle(i)); swt = sin(k*omega*tcycle(i)); af(i) = Y*mod(tcycle(i),tau)/tau; ef(i) = ef(i) + a(k)*cwt + b(k)*swt; end end e subplot(2,1,1) plot(tcycle,af,'--') axis([0 5*tau -0.02 0.12]) xlabel('t') ylabel('periodic function') subplot(2,1,2) plot(tcycle,ef) axis([0 5*tau -0.02 0.12]) xlabel('t') ylabel('Fourior series approximation') title('Comparison between af and ef')...
View Full Document

Ask a homework question - tutors are online