EXERCISE #1: FOURIER SERIES - I
The Fourier series for a square wave $f(x) = \begin{cases} 1 & 0 \le x < \pi \\ 0 & \pi \le x < 2\pi \\ f(x + 2\pi) & \text{elsewhere} \end{cases}$ is given by
$f(x) = \frac{1}{2} + \frac{2}{\pi} \sum_{n=1, n \text{ odd}}^{\infty} \frac{\sin nx}{n}$
First, write a user-defined function in MATLAB to accept the number of harmonics, $n$, as
input and produce the Fourier series waveform up to and including the $n$ harmonics using the
following code segment.
function [x,f] = FS_sq(N)
x = linspace(0,10);
f = 0.5;
for i = 1:2:N
b = 2/(pi*i);
f = f + b*sin(i*x);
end
Next, write a script in MATLAB to test this function by generating and plotting
(on the same figure using subplot commands) the following cases:
(1) N = 5 (2) N = 10 (3) N = 20 (4) N = 50
Label all the axes and assign a title to each subplot.