5

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. enter image description here 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}

enter image description here

2
  • 3
    It would be a one liner if you escape to python or lua though
    – percusse
    Commented Sep 8, 2016 at 17:20
  • 1
    @percusse, could you show us how you would do that using lua? Commented Dec 11, 2016 at 12:42

0

You must log in to answer this question.

Browse other questions tagged .