Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(modification of HW3 5 & 6) The Fourier series approximation for a rectified sin

ID: 3528826 • Letter: #

Question

(modification of HW3 5 & 6) The Fourier series approximation for a rectified sine wave is given by F(t) = 2/pi + 4/pi 1 / 1 - 4k2 cos (2kpit) Write a function M-file that will compute F(t) for any input t. Approximate F(t) to 3 sig figs. Name this file FourierRectSin.m . Then, just like in HW3_6, write a script M-file to plot both the rectified sine wave f(t) = |sin (pit)| and F(t) (FourierRectSin) on the same figure, for -1 t 1. Use fplot. You'll have to create an anonymous function for f(t). This time, you will find that the Fourier series approximation is pretty close to the rectified sine wave. Make each line a different color, and include a legend. Upload function M-file, script M-file and the jpg.

Explanation / Answer

%FOURIER_SERIES_01_MAT

%

fig_size = [232 84 774 624];

x = [0.1 0.9 0.1];% 1 period of x(t)

x = [x x x x];% 4 periods of x(t)

tx = [-2 -1 0 0 1 2 2 3 4 4 5 6];% time points for x(t)

figure(1),plot(tx,x),grid,xlabel('Time (s)'),ylabel('Amplitude'),...

title('Periodic Signal x(t)'),axis([-2 6 0 1]),...

set(gcf,'Position',fig_size)

%

a0 = 0.5;% DC component of Fourier Series

ph0 = 0;

n = [1 3 5 7 9];% Values of n to be evaluated

an = -3.2 ./ (pi * n).^2;% Fourier Series coefficients

mag_an = abs(an);

ph_an = -180 * ones(1,length(n));

%

n = [0 n];

mag_an = [a0 mag_an];% Including a0 with a_n

ph_an = [ph0 ph_an];

%

figure(2),clf,subplot(211),plot(n,mag_an,'o'),grid,xlabel('Harmonic Number'),...

ylabel('Magnitude'),title('Fourier Series Magnitude'),axis([0 10 0 0.6]),...

set(gcf,'Position',fig_size)

%

subplot(212),plot(n,ph_an,'o'),grid,xlabel('Harmonic Number'),...

ylabel('Phase (deg)'),title('Fourier Series Phase'),axis([0 10 -200 0]),...

set(gcf,'Position',fig_size)

%

w0 = pi;% Fundamental Frequency

t = [-2:0.002:6];% time vector for approximations

%

x1 = 0;% approximation with DC + 1 term

fori = 1:2

x1 = x1 + mag_an(i)*cos(n(i)*w0*t + ph_an(i)*pi/180);

end

%

x2 = x1;% approximation with DC + 2 terms

i = 3;

x2 = x2 + mag_an(i)*cos(n(i)*w0*t + ph_an(i)*pi/180);

%

x3 = x2;% approximation with DC + 3 terms

i = 4;

x3 = x3 + mag_an(i)*cos(n(i)*w0*t + ph_an(i)*pi/180);

%

x4 = x3;% approximation with DC + 5 terms

fori = 5:6

x4 = x4 + mag_an(i)*cos(n(i)*w0*t + ph_an(i)*pi/180);

end

%

figure(3),subplot(221),plot(t,x1),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('DC + 1 Term'),axis([-2 6 0 1]),...

subplot(222),plot(t,x2),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('DC + 2 Terms'),axis([-2 6 0 1]),...

subplot(223),plot(t,x3),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('DC + 3 Terms'),axis([-2 6 0 1]),...

subplot(224),plot(t,x4),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('DC + 5 Terms'),axis([-2 6 0 1]),...

set(gcf,'Position',fig_size)

%