SLIDE 13 h = stem(1:max(N),MSE,’k’); set(h(1),’Marker’,’.’); set(h(1),’MarkerSize’,11); set(h(2),’LineWidth’,1.4); xlabel(’Harmonics (k)’); ylabel(’MSE’); box off; AxisSet(8); print -depsc PulseMSE;
Portland State University ECE 223 CT Fourier Series
51
Example 5: MATLAB Code
function [] = Pulse(); close all; T = 2; w0 = 2*pi/T; Ts = 0.005; t = (-2.5:Ts:2.5)’; tm = mod(t,T); x = 1.*(tm<0.25) + 1.*(tm>=1.75); figure(1); FigureSet(1,’LTX’); N = 25; k = [-N:-1 1:N]; a = j*2*pi*k; Bk = (1./(k*pi)).*sin(k*pi/4); k = [k(1:N) k(N+1:2*N) ]; Bk = [Bk(1:N) 0.25 Bk(N+1:2*N)]; h = goodstem(k,Bk); set(h,’Color’,[0 0.6 0]); set(h,’MarkerSize’,8); xlabel(’kth (harmonic)’); ylabel(’B_k’); title(’Fourier Series Coefficients Amplitude B_k’); box off; AxisSet(8); print -depsc PulseSpectrum; %N = [1,2,5,10,50,100]; N = [1 5 10 25 50 100]; MSE = zeros(max(N),1);
Portland State University ECE 223 CT Fourier Series
49
Sinc Functions sinc(t) sin(πt) πt ∞
−∞
sinc(t) dt = 1
- The sinc function arises frequently in Fourier analysis
- sinc(0) = 1
- sinc(k) = 0 for all integers k
- The main lobe spans t = −1 to t = 1
- The other ripples are called side lobes
- J. McNames
Portland State University ECE 223 CT Fourier Series
52
for cnt = 1:length(N), xh = 1/4; % DC Offset a_0 figure; FigureSet(1,’LTX’); t2 = [-2.5 2.5]; h = plot(t2,xh*[1 1],’g’); set(h,’Color’,[0.0 0.6 0.0]); hold on; for cnt2 = 1:N(cnt), k = cnt2; ak = (2/(k*pi))*sin(k*pi/4); bk = 0; xk = ak*cos(k*w0*t) + bk*sin(k*w0*t); xh = xh + xk; t2 = (-2.5:0.02:2.5); xk = ak*cos(k*w0*t2) + bk*sin(k*w0*t2); h = plot(t2,xk,’g’); set(h,’Color’,[0.0 0.6 0.0]); MSE(cnt2) = sum((x-xh).^2)*Ts/T; end; h = plot(t,x,’r’,t,xh,’b’,[-2 2],[0 0],’k:’,[0 0],[-2 2],’k:’); hold off; set(h(1),’LineWidth’,1.2); set(h(2),’LineWidth’,1.7); xlabel(’Time (sec)’); st = sprintf(’Fourier Series Approximation (N=%d)’,N(cnt)); title(st); axis([-2.5 2.5 -0.6 1.2]); box off; AxisSet(8); st = sprintf(’print -depsc Pulse%d’,N(cnt)); eval(st); end; figure; FigureSet(1,’LTX’);
Portland State University ECE 223 CT Fourier Series
50