# LaTeX Trellis Diagrams for STBCs

I recently had to draw multiple trellises for space-time block codes (first introduced in this paper; the open-access version is here). I'd like to share the code with you here, so that the work doesn't have to be done twice.

As you see, I created a new command for plotting a trellis, where you can add the number of states, the PSK order, and the x- and y-distance between points as arguments:

\documentclass[a4paper]{article}

\usepackage{pst-plot,pst-sigsys}
\usepackage[nomessages]{fp}

\newcommand{\trellis}[4]{
\def \STATES {#1}
\def \PSK {#2}
\def \XDISTANCE {#3}
\def \YDISTANCE {#4}
\FPupn\NGROUPS{\STATES{} \PSK{} div 0 trunc}
\multido{\ryA=0+-\YDISTANCE,\nA=1+1}{\STATES}{%
\dotnode(0,\ryA){dotA\nA}
\dotnode(\XDISTANCE,\ryA){dotB\nA}
}
\multido{\nG=1+1,\nOffset=1+\PSK}{\NGROUPS}{%
\multido{\nStart=\nG+\NGROUPS}{\PSK}{%
\multido{\nArrows=\nOffset+1}{\PSK}{%
\ncline{dotA\nStart}{dotB\nArrows}
}
}
}
}

\begin{document}
\begin{pspicture}[showgrid=true](0,0)(12,-20)
\rput(0,0){\trellis{4}{4}{1.}{1}}
\rput(3,0){\trellis{16}{4}{1.5}{1}}
\rput(6,0){\trellis{8}{8}{2.25}{2.25}}
\end{pspicture}
\end{document}


• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. What exactly is your question? – Maarten Dhondt Jul 3 '15 at 7:32
• you should post this to the PSTricks mailing list. See pstricks.tug.org – user2478 Jul 3 '15 at 7:44
• @MaartenDhondt: Sorry, it is actually not a question, just some code I was looking for, couldn't find, and wanted to share now. – Bernhard Jul 3 '15 at 11:00
• @Herbert: Thanks for the tip, I will do that! – Bernhard Jul 3 '15 at 11:00

You have a lot of trailing spaces which move your image to the right. If you are not sure where to place a % at the line end then do it for every line:

\newcommand{\trellis}[4]{%
\def \STATES {#1}%
\def \PSK {#2}%
\def \XDISTANCE {#3}%
\def \YDISTANCE {#4}%
\FPupn\NGROUPS{\STATES{} \PSK{} div 0 trunc}%
\multido{\ryA=0+-\YDISTANCE,\nA=1+1}{\STATES}{%
\dotnode(0,\ryA){dotA\nA}
\dotnode(\XDISTANCE,\ryA){dotB\nA}
}%
\multido{\nG=1+1,\nOffset=1+\PSK}{\NGROUPS}{%
\multido{\nStart=\nG+\NGROUPS}{\PSK}{%
\multido{\nArrows=\nOffset+1}{\PSK}{%
\ncline{dotA\nStart}{dotB\nArrows}
}%
}%
}%
}


PSTricks macros itself kill all glue, so the last % three are not needed. But it doesn't hurt ...

and I suppose that you do not need the fppackage. Try \numexpr

\multido{\nG=1+1,\nOffset=1+\PSK}{\numexpr\STATES/\PSK}{%
\multido{\nStart=\nG+\numexpr\STATES/\PSK}{\PSK}{%

• That's embarassing...I always wondered why the pictures are shifted. Thanks a lot! – Bernhard Jul 3 '15 at 11:21