Professional Documents
Culture Documents
% declare time values % summation limit (use N odd) % fundamental frequency (rad/s) % dc bias
% Compute yce, the Fourier Series in complex exponential form yce = c0*ones(size(t)); % initialize yce to c0 for n = -N:2:N, % loop over series index n % cn = 2/(j*n*wo); % Fourier Series Coefficient cn = (A/T0) * sin(pi * (1/T0) * (T0 / K) * n) / (pi * (1/T0) * n); yce = yce + cn*exp(1i*n*wo*t); end % Fourier Series computation
subplot(1,1,1) % plot([-3 -2 -2 -1 -1 0 0 1 1 2 2 3],... % plot original y(t) % [-1 -1 1 1 -1 -1 1 1 -1 -1 1 1], ':'); hold; plot(t,yce - 0.5); set(gca,'XTick',-m*pi:pi/2:pi*m); %set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'}); grid; xlabel('t (seconds)') ylabel('y(t)'); ttle = ['ECE 120: Truncated Exponential Fourier Series with N = ',... num2str(N)]; title(ttle); hold % Draw the amplitude spectrum from exponential Fourier Series figure(2) % put next plots on figure 2 subplot(2,1,1) tau = T0 / K; asd = stem(0,A * tau / T0); set(get(asd,'BaseLine'),'LineStyle',':') set(asd,'MarkerFaceColor','green')
% plot c0 at nwo = 0
hold for n = -N:step:N, % loop over series index n cn = (A/T0) * sin(pi * (1/T0) * (T0 / K) * n) / (pi * (1/T0) * n); %cn = 2/(j*n*wo); % Fourier Series Coefficient r = stem(n*wo,abs(cn)); % plot |cn| vs nwo set(get(r,'BaseLine'),'LineStyle',':') set(r,'MarkerFaceColor','green') end set(gca,'XTick',-N:1:N); xlabel('w (rad/s)'); ylabel('|cn|'); ttle = ['ECE 120: Amplitude Spectrum']; title(ttle); hold; % Draw the phase spectrum from exponential Fourier Series subplot(2,1,2) h = stem(0,angle(c0)*180/pi); % plot angle of c0 at nwo = 0 set(h,'MarkerFaceColor','green'); hold for n = -N:step:N, % loop over odd series index n cn = (A/T0) * sin(pi * (1/T0) * (T0 / K) * n) / (pi * (1/T0) * n); yaxis = angle(cn)*180/pi; if n > 0, yaxis = -yaxis; end; %cn = 2/(j*n*wo); % Fourier Series Coefficient h = stem(n*wo,yaxis); % plot |cn| vs nwo set(get(h,'BaseLine'),'LineStyle',':'); set(h,'MarkerFaceColor','green'); end set(gca,'XTick',-N:1:N); xlabel('w (rad/s)') ylabel('angle(cn) (degrees)') ttle = ['ECE 120: Phase Spectrum with N = ',num2str(N)]; title(ttle); hold
Output Figure 1
Figure 2
Output N N N N N N N =-3: cn =0.00031837 =-2: cn =0.00037729 =-1: cn =0.50007 =0: cn =0 =1: cn =0.50007 =2: cn =0.00037729 =3: cn =0.00031837