Created
June 7, 2021 10:31
-
-
Save Theaninova/5b4ffeabeb08627425e731125031fc34 to your computer and use it in GitHub Desktop.
Signal Diagram LaTeX Macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{tikzpicture} | |
\newcounter{xi} | |
\addtocounter{xi}{1}; | |
\foreach \x in {10,20,...,200}{ | |
\ifodd\value{xi} | |
{}\else{\node[anchor=north,x=1cm/1.5] at (\value{xi},0pt) {$\x$};}\fi | |
\addtocounter{xi}{1}; | |
} | |
\draw (0,0) -- (0,12); | |
\newcounter{yi} | |
% Edit the Y Lables here | |
\foreach \y in {$y_3$, $y_2$, $y_1$, $t_5$, $t_4$, $t_3$, $t_2$, $t_1$, $x_1$, $x_2$, $x_3$, $x_4$}{ | |
\draw[->, x=1cm/1.5] (0,\value{yi}) -- (21, \value{yi}); | |
\setcounter{xi}{0} | |
\addtocounter{xi}{1}; | |
% Edit the X Lables here | |
\foreach \x in {10,20,...,200}{ | |
\draw[x=1cm/1.5] (\value{xi},\value{yi}+0.05) -- (\value{xi}, \value{yi}-0.05); | |
\addtocounter{xi}{1}; | |
} | |
\node[anchor=east] at (0,\value{yi}+0.5) {\y}; | |
\addtocounter{yi}{1}; | |
} | |
\node[anchor=north west,x=1cm/1.5] at (21,0) {$t/ns$}; | |
\node[anchor=north,x=1cm/1.5] at (0,0) {$0$}; | |
\newcounter{xVal} | |
\newcounter{yVal} | |
\newcounter{prevY} | |
\newcounter{prevX} | |
\def\kline#1#2#3{ | |
\setcounter{xVal}{0} | |
\setcounter{yVal}{#2} | |
\setcounter{prevY}{#2} | |
\setcounter{prevX}{0} | |
\foreach \x in #3{ | |
\addtocounter{xVal}{\x} | |
\draw[thick, x=1cm/1.5] | |
(\value{prevX},{#1+(Mod(\value{prevY},2)/2)}) | |
-- (\value{prevX},{#1+(Mod(\value{yVal},2)/2)}) | |
-- (\value{xVal},{#1+(Mod(\value{yVal},2)/2)}); | |
\setcounter{prevY}{\value{yVal}} | |
\addtocounter{yVal}{1} | |
\setcounter{prevX}{\value{xVal}} | |
} | |
} | |
\kline{11}{0}{{4,2,2,1,1,4,2,1,2,1}} | |
\kline{10}{0}{{3,4,3,5,3,2}} | |
\kline{9}{0}{{2,7,4,7}} | |
\end{tikzpicture} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment