I want to draw a simple graphical example of a convolution of two discrete sequences in TikZ. I used the code from this link to get my result, which is already what I want but, so far, the values of the different signals at the different time instants are just numbers computed somewhere else.
I'm curious to know if there is an easy way to define two variables for the two sequences and compute the convolution signal, i.e. directly in TikZ.
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}
\begin{tikzpicture}
%/*
\pgfplotsset{
standard/.style={%Axis format configuration
width=5cm,
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis plot post/.style={mark options={fill=white}},
xticklabel style={align=center},
xmin=-0.5, xmax=6,
ymin=0, ymax=2,
xlabel={$n$},
}
}
%
\begin{groupplot}[
group style={
group size=3 by 1,
vertical sep=25pt,
horizontal sep=35pt
},
]
% Plot [1, 1]
\nextgroupplot[
standard,
title={$a[n]$},
]
\addplot+[ycomb,black,thick] plot coordinates {(0,1) (1,0.5) (2,1) (3,1)};
% Plot [1, 2]
\nextgroupplot[
standard,
title={$b[n]$},
]
\addplot+[ycomb,black,thick] plot coordinates {(0,1) (1,0.5) (2,0.25)};
% Plot [1, 3]
\nextgroupplot[
standard,
title={$c[n] = a[n]\ast b[n]$},
]
\addplot+[ycomb,black,thick] plot coordinates {(0,1) (1,1) (2,1.5) (3,1.625) (4,0.75) (5,0.25)};
\end{groupplot}
%*/
\end{tikzpicture}%
\end{document}