% \N and \Ns must be defined before calling this picture.
\def\N{5}
\def\Ns{10}
\begin{tikzpicture}
\begin{axis}[
	name=plot1,
	axis y line=middle, axis x line=bottom,
	enlargelimits = upper, clip=true,
	scale only axis,
	width=\textwidth,
	height=0.2\textwidth,
	ymin=0,	ymax=1.1,
	xmin={0}, xmax={44},
	axis line style={->,>=stealth},
	%y axis line style={draw=none},
	x axis line style={shorten >= -0.25cm}, 
	xlabel={\large $n$},
	ylabel={\large $h[n]$},
	every axis x label/.style={
		at={(ticklabel* cs:1)},
		xshift=0.25cm,
		anchor=north,
	},
	every axis y label/.style={
		at={(ticklabel* cs:0.95)},
		anchor=south,
		xshift=0.6cm,
	},
	xtick={0, 9},
	xticklabels={0, $M$},
	%xticklabel style={xshift=-0.15cm, yshift=-0.1cm},
	ytick={1},
	every outer y axis line/.append style={white!15!black},
	every y tick label/.append style={font=\color{white!15!black}},
	legend style={draw=white!15!black,fill=white,legend cell align=left}]
	%\addplot[ycomb, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt, domain=-\Ns-\N:\Ns+\N, samples=2*(\Ns+\N)+1] {triang(x+2*\Ns-\N, \N) + triang(x-\N, \N) + triang(x-\N-\Ns, \N) + triang(x-\N+\Ns, \N)};
	\addplot[ycomb, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt, domain=0:\Ns-1, samples=\Ns] {triang(x-\N, \N)};
	\node[fill=black!20, text width=3cm, align=center, inner sep=2mm, anchor=south west] at (axis cs: 10, 0.5) {Filter coefficients \\ Length $M+1$};
\end{axis}

\begin{axis}[
	name=plot2,
	at=(plot1.below south east), anchor=above north east,
	axis y line=middle, axis x line=middle,
	enlargelimits = false, clip=true,
	scale only axis,
	width=\textwidth,
	height=0.2\textwidth,
	ymin=-2,	ymax=2,
	%y axis line style={draw=none},
	xmin={0}, xmax={44},
	axis line style={->,>=stealth},
	x axis line style={shorten >= -0.25cm}, 
	xlabel={\large $n$},
	ylabel={\large $x[n]$},
	every axis x label/.style={
		at={(ticklabel* cs:1)},
		xshift=0.25cm,
		anchor=north,
	},
	every axis y label/.style={
		at={(ticklabel* cs:1)},
		anchor=south,
		xshift=0.6cm,
	},
	xtick={0},
	ytick=\empty,
	every outer y axis line/.append style={white!15!black},
	every y tick label/.append style={font=\color{white!15!black}},
	legend style={draw=white!15!black,fill=white,legend cell align=left}]
	
	\only<1|handout:1>{	
	\addplot[ycomb, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt]
	table[row sep=crcr]{
		0 0.10491 \\
		1 0.54919 \\
		2 0.70362 \\
		3 1.0626 \\
		4 1.2488 \\
		5 1.1636 \\
		6 1.0408 \\
		7 0.9144 \\
		8 0.84567 \\
		9 0.72187 \\
		10 0.19381 \\
		11 -0.093603 \\
		12 -0.095644 \\
		13 -0.45954 \\
		14 -0.54561 \\
		15 -0.57977 \\
		16 -0.48307 \\
		17 -0.21808 \\
		18 -0.051949 \\
		19 0.22502 \\
		20 0.70008 \\
		21 0.69747 \\
		22 0.94023 \\
		23 1.311 \\
		24 1.4125 \\
		25 1.6667 \\
		26 1.7249 \\
		27 1.4084 \\
		28 1.1416 \\
		29 0.60004 \\
		30 0.30779 \\
		31 -0.0025167 \\
		32 -0.47202 \\
		33 -0.98919 \\
		34 -1.3251 \\
		35 -1.3521 \\
		36 -1.3193 \\
		37 -1.2023 \\
		38 -0.88282 \\
		39 -0.64963 \\
		40 -0.42971 \\
		41 -0.004122 \\
		42 0.43751 \\
		43 0.90842 \\
		44 1.0804 \\
	};
	}

	\only<2-4|handout:2-4>{	
	\addplot[ycomb, blue2, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt]
	table[row sep=crcr]{
		0 0.10491 \\
		1 0.54919 \\
		2 0.70362 \\
		3 1.0626 \\
		4 1.2488 \\
		5 1.1636 \\
		6 1.0408 \\
		7 0.9144 \\
		8 0.84567 \\
		9 0.72187 \\
		10 0.19381 \\
		11 -0.093603 \\
		12 -0.095644 \\
		13 -0.45954 \\
		14 -0.54561 \\
	};
	\node[anchor=south west, blue2] at (axis cs: 8, 0.8) {\Large $x_0[n]$};
	\node[below, blue2] at (axis cs: 7, 0.1) {$L$ samples};
	}

	\only<3-4|handout:3-4>{	
	\addplot[ycomb, red2, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt]
	table[row sep=crcr]{
		15 -0.57977 \\
		16 -0.48307 \\
		17 -0.21808 \\
		18 -0.051949 \\
		19 0.22502 \\
		20 0.70008 \\
		21 0.69747 \\
		22 0.94023 \\
		23 1.311 \\
		24 1.4125 \\
		25 1.6667 \\
		26 1.7249 \\
		27 1.4084 \\
		28 1.1416 \\
		29 0.60004 \\
	};
	\node[anchor=south west, red2] at (axis cs: 16, 0.8) {\Large $x_1[n]$};
	\node[below, red2] at (axis cs: 23, 0.1) {$L$ samples};
	}

	\only<4|handout:4>{	
	\addplot[ycomb, green2, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt]
	table[row sep=crcr]{
		30 0.30779 \\
		31 -0.0025167 \\
		32 -0.47202 \\
		33 -0.98919 \\
		34 -1.3251 \\
		35 -1.3521 \\
		36 -1.3193 \\
		37 -1.2023 \\
		38 -0.88282 \\
		39 -0.64963 \\
		40 -0.42971 \\
		41 -0.004122 \\
		42 0.43751 \\
		43 0.90842 \\
		44 1.0804 \\
	};
	\node[anchor=south west, green2] at (axis cs: 39, -2) {\Large $x_2[n]$};
	\node[above, green2] at (axis cs: 35, 0) {$L$ samples};
	}
\end{axis}

\begin{axis}[
name=plot3,
at=(plot2.below south east), anchor=above north east,
axis y line=middle, axis x line=center,
enlargelimits = false, clip=true,
scale only axis,
width=\textwidth,
height=0.2\textwidth,
ymin=-11,	ymax=11,
%y axis line style={draw=none},
xmin={0}, xmax={44},
axis line style={->,>=stealth},
x axis line style={shorten >= -0.25cm}, 
xlabel={\large $n$},
ylabel={},
every axis x label/.style={
	at={(ticklabel* cs:1)},
	xshift=0.25cm,
	anchor=north,
},
every axis y label/.style={
	at={(ticklabel* cs:1)},
	anchor=south,
	xshift=0.6cm,
},
xtick=\empty,
ytick=\empty,
every outer y axis line/.append style={white!15!black},
every y tick label/.append style={font=\color{white!15!black}},
legend style={draw=white!15!black,fill=white,legend cell align=left}]

\only<2-4|handout:2-4>{
\addplot[ycomb, blue2, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt] 
table[row sep=crcr]{
	0 0 \\
	1 0.020982 \\
	2 0.1518 \\
	3 0.42334 \\
	4 0.90742 \\
	5 1.6412 \\
	6 2.5658 \\
	7 3.4789 \\
	8 4.2934 \\
	9 4.852 \\
	10 5.0554 \\
	11 4.8532 \\
	12 4.3257 \\
	13 3.5541 \\
	14 2.5648 \\
	15 1.4274 \\
	16 0.44524 \\
	17 -0.29135 \\
	18 -0.80681 \\
	19 -0.96931 \\
	20 -0.76919 \\
	21 -0.53031 \\
	22 -0.31015 \\
	23 -0.10912 \\
}; % y1
\node[anchor=south west, blue2] at (axis cs: 1, -8) {\large $y_0 = h[n]~\encircle{N}~x_0[n]$};
}

\only<3-4|handout:3-4>{
\addplot[ycomb, red2, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt] 
table[row sep=crcr]{
	15 0 \\
	16 -0.11595 \\
	17 -0.32852 \\
	18 -0.58471 \\
	19 -0.85128 \\
	20 -1.0729 \\
	21 -0.9225 \\
	22 -0.43942 \\
	23 0.31893 \\
	24 1.3603 \\
	25 2.5941 \\
	26 3.7653 \\
	27 4.9059 \\
	28 5.9084 \\
	29 6.6045 \\
	30 6.9006 \\
	31 6.67 \\
	32 5.8889 \\
	33 4.7325 \\
	34 3.3817 \\
	35 2.0733 \\
	36 1.0983 \\
	37 0.46833 \\
	38 0.12001 \\
}; %y2
\node[anchor=south west, red2] at (axis cs: 18, -8) {\large $y_1 = h[n]~\encircle{N}~x_1[n]$};
}

\only<4-|handout:4->{
\addplot[ycomb, green2, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt] 
table[row sep=crcr]{
	30 0 \\
	31 0.061559 \\
	32 0.12261 \\
	33 0.089265 \\
	34 -0.14192 \\
	35 -0.63813 \\
	36 -1.5279 \\
	37 -2.6805 \\
	38 -3.8847 \\
	39 -4.8699 \\
	40 -5.4549 \\
	41 -5.5235 \\
	42 -5.0656 \\
	43 -4.1338 \\
	44 -2.865 \\
	45 -1.3852 \\
	46 -0.0040502 \\
	47 1.1149 \\
	48 1.8184 \\
	49 1.982 \\
	50 1.5835 \\
}; %y3
\node[anchor=south west, green2] at (axis cs: 30, -12) {\large $y_2 = h[n]~\encircle{N}~x_2[n]$};
}
\end{axis}

\begin{axis}[
	name=plot4,
	at=(plot3.below south east), anchor=above north east,
	axis y line=middle, axis x line=center,
	enlargelimits = false, clip=true,
	scale only axis,
	width=\textwidth,
	height=0.2\textwidth,
	ymin=-10,	ymax=10,
	%y axis line style={draw=none},
	xmin={0}, xmax={44},
	axis line style={->,>=stealth},
	x axis line style={shorten >= -0.25cm}, 
	xlabel={\large $n$},
	ylabel={\large $y[n]$},
	every axis x label/.style={
		at={(ticklabel* cs:1)},
		xshift=0.25cm,
		anchor=north,
	},
	every axis y label/.style={
		at={(ticklabel* cs:1)},
		anchor=south,
		xshift=0.6cm,
	},
	xtick=\empty,
	%xticklabel style={xshift=-0.15cm, yshift=-0.1cm},
	ytick=\empty,
	every outer y axis line/.append style={white!15!black},
	every y tick label/.append style={font=\color{white!15!black}},
	legend style={draw=white!15!black,fill=white,legend cell align=left}]
	
	\only<2|handout:2>{
		\addplot[ycomb, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt] 
		table[row sep=crcr]{
			0 0 \\
			1 0.020982 \\
			2 0.1518 \\
			3 0.42334 \\
			4 0.90742 \\
			5 1.6412 \\
			6 2.5658 \\
			7 3.4789 \\
			8 4.2934 \\
			9 4.852 \\
			10 5.0554 \\
			11 4.8532 \\
			12 4.3257 \\
			13 3.5541 \\
			14 2.5648 \\
			15 1.4274 \\
			16 0.44524 \\
			17 -0.29135 \\
			18 -0.80681 \\
			19 -0.96931 \\
			20 -0.76919 \\
			21 -0.53031 \\
			22 -0.31015 \\
			23 -0.10912 \\
		}; % y1
	}	

	\only<3|handout:3>{
		\addplot[ycomb, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt] 
		table[row sep=crcr]{
			0 0 \\
			1 0.020982 \\
			2 0.1518 \\
			3 0.42334 \\
			4 0.90742 \\
			5 1.6412 \\
			6 2.5658 \\
			7 3.4789 \\
			8 4.2934 \\
			9 4.852 \\
			10 5.0554 \\
			11 4.8532 \\
			12 4.3257 \\
			13 3.5541 \\
			14 2.5648 \\
			15 1.4274 \\
			16 0.32928 \\
			17 -0.61988 \\
			18 -1.3915 \\
			19 -1.8206 \\
			20 -1.842 \\
			21 -1.4528 \\
			22 -0.74957 \\
			23 0.20981 \\
			24 1.3603 \\
			25 2.5941 \\
			26 3.7653 \\
			27 4.9059 \\
			28 5.9084 \\
			29 6.6045 \\
			30 6.9006 \\
			31 6.67 \\
			32 5.8889 \\
			33 4.7325 \\
			34 3.3817 \\
			35 2.0733 \\
			36 1.0983 \\
			37 0.46833 \\
			38 0.12001 \\
			39 0 \\
		};
	}

	\only<4|handout:4>{
	\addplot[ycomb, mark=*, fill=white, mark options={scale=1.5, fill=white}, line width=1.5pt] 
	table[row sep=crcr]{
		0 0 \\
		1 0.020982 \\
		2 0.1518 \\
		3 0.42334 \\
		4 0.90742 \\
		5 1.6412 \\
		6 2.5658 \\
		7 3.4789 \\
		8 4.2934 \\
		9 4.852 \\
		10 5.0554 \\
		11 4.8532 \\
		12 4.3257 \\
		13 3.5541 \\
		14 2.5648 \\
		15 1.4274 \\
		16 0.32928 \\
		17 -0.61988 \\
		18 -1.3915 \\
		19 -1.8206 \\
		20 -1.842 \\
		21 -1.4528 \\
		22 -0.74957 \\
		23 0.20981 \\
		24 1.3603 \\
		25 2.5941 \\
		26 3.7653 \\
		27 4.9059 \\
		28 5.9084 \\
		29 6.6045 \\
		30 6.9006 \\
		31 6.7315 \\
		32 6.0115 \\
		33 4.8217 \\
		34 3.2397 \\
		35 1.4352 \\
		36 -0.42955 \\
		37 -2.2122 \\
		38 -3.7647 \\
		39 -4.8699 \\
		40 -5.4549 \\
		41 -5.5235 \\
		42 -5.0656 \\
		43 -4.1338 \\
		44 -2.865 \\
		45 -1.3852 \\
		46 0.19957 \\
		47 1.6994 \\
		48 2.9545 \\
		49 3.7801 \\
		50 4.1463 \\
		51 4.0495 \\
		52 3.5973 \\
		53 2.8912 \\
		54 2.1459 \\
		55 1.4112 \\
		56 0.82002 \\
		57 0.40605 \\
		58 0.16283 \\
		59 0.030059 \\
		60 0 \\
	};	
}
\end{axis}
\end{tikzpicture}	
