LaTeX nerd LaTeX blog

Gibbs Phenomenon

I drew the Gibbs Phenomenon in CS 371. Check the notes here in page 60.

\begin{figure}[h!]
	\centering
\begin{tikzpicture}
\begin{axis}[
xmin = -4, xmax = 4,
ymin = -3, ymax = 3,
domain = -3 : 3,
xlabel = $x$,
ylabel = $y$,
axis x line = center,
axis y line = center,
every axis x label/.append style = {below},
every axis y label/.append style = {left},
samples = 100,
xtick = {-2, 0, 2},
xticklabels = {$-2$, $0$, $2$},
declare function = {
	s(\x) = ifthenelse(\x < 2,  ifthenelse(\x < -2, \x + 4, \x), \x -4);
	s0(\x) =  (4 / pi) * sin(deg(pi*\x)/2);
	s1(\x) = s0(\x) - (2 / pi) * sin(deg(pi*\x));
	s2(\x) = s1(\x) + (4 /(3* pi)) * sin(deg(pi*\x) * 3 / 2);
	s3(\x) = s2(\x) - (4 /(4* pi)) * sin(deg(pi*\x) * 4 / 2);
	s4(\x) = s3(\x) + (4 /(5* pi)) * sin(deg(pi*\x) * 5 / 2);
	s5(\x) = s4(\x) - (4 /(6* pi)) * sin(deg(pi*\x) * 6 / 2);
	s6(\x) = s5(\x) + (4 /(7* pi)) * sin(deg(pi*\x) * 7 / 2);
	s7(\x) = s6(\x) - (4 /(8* pi)) * sin(deg(pi*\x) * 8 / 2);
	s8(\x) = s7(\x) + (4 /(9* pi)) * sin(deg(pi*\x) * 9 / 2);
	s9(\x) = s8(\x) - (4 /(10* pi)) * sin(deg(pi*\x) * 10 / 2);
	s10(\x) = s9(\x) + (4 /(11* pi)) * sin(deg(pi*\x) * 11 / 2);
}, ]
\addplot[thick, black] {s(x)};
\addplot[thick, blue] {s0(x)};
%\addplot[thick, red] {s1(x)};
%\addplot[thick, orange] {s2(x)};
\addplot[thick, cyan] {s3(x)};
\addplot[thick, orange] {s10(x)};
%\legend{signal, $s_0$, $s_1$, $s_2$, $s_3$};    
% labels
\draw[gray, dashed] (0, 0.5) -- (2 * pi, 0.5);
\draw[gray, dashed] (2 * pi, 0) -- (2 * pi, 1);
\end{axis}

\end{tikzpicture}
\caption{Gibbs Phenomenon}
\end{figure}

Previously, I tried to do some animated stuff… but didn’t get that…