在 Tikz 中绘制组合 LFSR

在 Tikz 中绘制组合 LFSR

有人能指导我画出下面的图表吗?开始会很有帮助...我会继续画剩下的部分。

组合 LFSR

答案1

带有 tikzmatrix库。

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning,calc,fit}

\tikzset{circ/.style={draw,circle,node distance=2mm,inner sep=0.1pt},topath/.style={to path={|-(\tikztotarget)}}}
\begin{document}


\begin{tikzpicture}
\matrix (M) [matrix of math nodes,nodes={draw,minimum width=7mm},column sep=-\pgflinewidth,row sep=1cm]
{
a_{10} & a_9 & a_8 & a_7 & a_6 & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\
a_{10} & a_9 & a_8 & a_7 & a_6 & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\
a_{10} & a_9 & a_8 & a_7 & a_6 & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\
a_{10} & a_9 & a_8 & a_7 & a_6 & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\
       &     &     &     &     & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\
       &     &     &     &     & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\
       &     &     &     &     & a_5 & a_4 & a_3 & a_2 & a_1 & a_0 \\              
};

\foreach \i/\j in {1/9,2/3,2/4,2/9,3/2,3/4,3/5,3/6,3/7,
3/8,3/9,4/2,4/5,4/10,5/8,5/9,5/10,6/7,6/9,6/10,7/7,7/9,7/10}
{\node (c-\i-\j) [circ,above=of M-\i-\j]{$+$};
\draw[->] (M-\i-\j)--(c-\i-\j);}

% arrows ----  

\draw[->] (M-1-11)edge [topath](c-1-9)  (c-1-9)-| ($(M-1-1.west)+ (-3mm,0)$)--(M-1-1);

\draw[->] (M-2-11)edge [topath](c-2-9)  (c-2-9)  edge (c-2-4) (c-2-4) edge (c-2-3) (c-2-3)-| ($(M-2-1.west)+ (-3mm,0)$)--(M-2-1);

\draw[->] (M-3-11)edge [topath](c-3-9)  (c-3-9)  edge (c-3-8) (c-3-8) edge (c-3-7) (c-3-7) edge (c-3-6) (c-3-6) edge (c-3-5) (c-3-5) edge (c-3-4) (c-3-4) edge (c-3-2) (c-3-2)-| ($(M-3-1.west)+ (-3mm,0)$)--(M-3-1);

\draw[->] (M-4-11)edge [topath](c-4-10) (c-4-10) edge (c-4-5) (c-4-5) edge (c-4-2) (c-4-2)-| ($(M-4-1.west)+ (-3mm,0)$)--(M-4-1);

\draw[->] (M-5-11)edge [topath](c-5-10) (c-5-10) edge (c-5-9) (c-5-9) edge (c-5-8) (c-5-8)-| ($(M-5-6.west)+ (-3mm,0)$)--(M-5-6);

\draw[->] (M-6-11)edge [topath](c-6-10) (c-6-10) edge (c-6-9) (c-6-9) edge (c-6-7) (c-6-7)-| ($(M-6-6.west)+ (-3mm,0)$)--(M-6-6);

\draw[->] (M-7-11)edge [topath](c-7-10) (c-7-10) edge (c-7-9) (c-7-9) edge (c-7-7) (c-7-7)-| ($(M-7-6.west)+ (-3mm,0)$)--(M-7-6);

% -----------

\coordinate (flc) at ($(M.south east)+(1.5,0)$);
\coordinate (frc) at ($(M.north east)+(3,0)$);
\node(s)[draw, fit=(flc) (frc),inner sep=0pt] {$f$};
\foreach \j in {1,2,...,7}  
{\draw (M-\j-11)--(M-\j-11 -| flc);}

\end{tikzpicture}

\end{document}

输出

在此处输入图片描述

答案2

这是我使用链条的看法,正如评论中所建议的那样。(更新:添加了一些缺失的边缘。)

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains, positioning, shapes, arrows}

\begin{document}
\begin{tikzpicture}[start chain=1 going left,
    start chain=2 going left,
    start chain=3 going left,
    start chain=4 going left,
    start chain=5 going left,
    start chain=6 going left,
    start chain=7 going left,]
  \tikzstyle{abox}=[draw,minimum width=2.5em,minimum height=2.5em]
  \tikzstyle{acircle}=[draw,circle,minimum size=1em,inner sep=0pt]
  \tikzstyle{boxchain}=[node distance=0pt]
  \tikzstyle{arrowline}=[draw, -latex']
  \def\chainshift{7em}
  \def\connectionsep{1.5em}

  \begin{scope}[boxchain]
    \foreach \i in {0,...,10}{
      \node [on chain=1, abox] (ch1a\i) {$a_{\i}$};
    }
  \end{scope}

  \begin{scope}[boxchain]
    \node [on chain=2,abox,yshift=-\chainshift] (ch2a0) {$a_0$};
    \foreach \i in {1,...,10}{
      \node [on chain=2, abox] (ch2a\i) {$a_{\i}$};
    }
  \end{scope}

  \begin{scope}[boxchain]
    \node [on chain=3,abox,yshift=-2*\chainshift] (ch3a0) {$a_0$};
    \foreach \i in {1,...,10}{
      \node [on chain=3, abox] (ch3a\i) {$a_{\i}$};
    }
  \end{scope}

  \begin{scope}[boxchain]
    \node [on chain=4,abox,yshift=-3*\chainshift] (ch4a0) {$a_0$};
    \foreach \i in {1,...,10}{
      \node [on chain=4, abox] (ch4a\i) {$a_{\i}$};
    }
  \end{scope}

  \begin{scope}[boxchain]
    \node [on chain=5,abox,yshift=-4*\chainshift] (ch5a0) {$a_0$};
    \foreach \i in {1,...,5}{
      \node [on chain=5, abox] (ch5a\i) {$a_{\i}$};
    }
  \end{scope}

  \begin{scope}[boxchain]
    \node [on chain=6,abox,yshift=-5*\chainshift] (ch6a0) {$a_0$};
    \foreach \i in {1,...,5}{
      \node [on chain=6, abox] (ch6a\i) {$a_{\i}$};
    }
  \end{scope}

  \begin{scope}[boxchain]
    \node [on chain=7,abox,yshift=-6*\chainshift] (ch7a0) {$a_0$};
    \foreach \i in {1,...,5}{
      \node [on chain=7, abox] (ch7a\i) {$a_{\i}$};
    }
  \end{scope}

  \node [abox, minimum height={6*\chainshift+2em}, right=4em of ch4a0] (f) {$\mathit{f}$};
  \path [draw] (f.east) -- ([xshift=3em]f.east);

  % Connections from chains towards f.
  \foreach \i in {1,...,7}{
    \path [draw] (ch\i a0) -- (ch\i a0-|f.west);
  }

  % Chain 1 connections

  \node [acircle,above=\connectionsep of ch1a2] (p-ch1a2) {$+$};
  \path [arrowline] (ch1a0) --(p-ch1a2-|ch1a0) |- (p-ch1a2);
  \path [arrowline] (ch1a2) -- (p-ch1a2);
  \path [arrowline] (p-ch1a2) -- ([xshift=-1.5em]p-ch1a2-|ch1a10.west) |- (ch1a10.west);

  % Chain 2 connections

  \foreach \i in {2,7,8}{
    \node [acircle,above=\connectionsep of ch2a\i] (p-ch2a\i) {$+$};
    \path [arrowline] (ch2a\i) -- (p-ch2a\i);
  }
  \path [arrowline] (ch2a0) --(p-ch2a2-|ch2a0) |- (p-ch2a2);
  \path [arrowline] (p-ch2a2) -- (p-ch2a7);
  \path [arrowline] (p-ch2a7) -- (p-ch2a8);
  \path [arrowline] (p-ch2a8) -- ([xshift=-1.5em]p-ch2a8-|ch2a10.west) |- (ch2a10.west);

  % Chain 3 connections

  \foreach \i in {2,...,7,9}{
    \node [acircle,above=\connectionsep of ch3a\i] (p-ch3a\i) {$+$};
    \path [arrowline] (ch3a\i) -- (p-ch3a\i);
  }
  \foreach \i in {3,...,7}{
    % Edges between individual pluses.
    \pgfmathsetmacro{\j}{int(\i-1)}
    \path [arrowline] (p-ch3a\j) -- (p-ch3a\i);
  }
  \path [arrowline] (ch3a0) --(p-ch3a2-|ch3a0) |- (p-ch3a2);
  \path [arrowline] (p-ch3a7) -- (p-ch3a9);
  \path [arrowline] (p-ch3a9) -- ([xshift=-1.5em]p-ch3a9-|ch3a10.west) |- (ch3a10.west);

  % Chain 4 connections

  \foreach \i in {1,6,9}{
    \node [acircle,above=\connectionsep of ch4a\i] (p-ch4a\i) {$+$};
    \path [arrowline] (ch4a\i) -- (p-ch4a\i);
  }
  \path [arrowline] (ch4a0) --(p-ch4a1-|ch4a0) |- (p-ch4a1);
  \path [arrowline] (p-ch4a1) -- (p-ch4a6);
  \path [arrowline] (p-ch4a6) -- (p-ch4a9);
  \path [arrowline] (p-ch4a9) -- ([xshift=-1.5em]p-ch4a9-|ch4a10.west) |- (ch4a10.west);

  % Chain 5 connections

  \foreach \i in {1,...,3}{
    \node [acircle,above=\connectionsep of ch5a\i] (p-ch5a\i) {$+$};
    \path [arrowline] (ch5a\i) -- (p-ch5a\i);
  }
  \foreach \i in {2,3}{
    % Edges between individual pluses.
    \pgfmathsetmacro{\j}{int(\i-1)}
    \path [arrowline] (p-ch5a\j) -- (p-ch5a\i);
  }
  \path [arrowline] (ch5a0) --(p-ch5a1-|ch5a0) |- (p-ch5a1);
  \path [arrowline] (p-ch5a3) -- ([xshift=-1.5em]p-ch5a3-|ch5a5.west) |- (ch5a5.west);

  % Chain 6 connections

  \foreach \i in {1,3,4}{
    \node [acircle,above=\connectionsep of ch6a\i] (p-ch6a\i) {$+$};
    \path [arrowline] (ch6a\i) -- (p-ch6a\i);
  }
  \path [arrowline] (ch6a0) --(p-ch6a1-|ch6a0) |- (p-ch6a1);
  \path [arrowline] (p-ch6a1) -- (p-ch6a3);
  \path [arrowline] (p-ch6a3) -- (p-ch6a4);
  \path [arrowline] (p-ch6a4) -- ([xshift=-1.5em]p-ch6a4-|ch6a5.west) |- (ch6a5.west);

  % Chain 7 connections

  \foreach \i in {1,2,4}{
    \node [acircle,above=\connectionsep of ch7a\i] (p-ch7a\i) {$+$};
    \path [arrowline] (ch7a\i) -- (p-ch7a\i);
  }
  \path [arrowline] (ch7a0) --(p-ch7a1-|ch7a0) |- (p-ch7a1);
  \path [arrowline] (p-ch7a1) -- (p-ch7a2);
  \path [arrowline] (p-ch7a2) -- (p-ch7a4);
  \path [arrowline] (p-ch7a4) -- ([xshift=-1.5em]p-ch7a4-|ch7a5.west) |- (ch7a5.west);


\end{tikzpicture}
\end{document}

结果

答案3

作为对 @wilx 的补充/评论,很好的答案。经过一番努力,代码更简洁,并按照所呈现的移位寄存器进行组织。为了确定函数的框,f使用了 TikZ 库calc。还省略了定义节点样式的过时语法:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows, calc, chains, positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 0mm,
   box/.style = {shape=rectangle, draw, minimum size=2em, outer sep=0pt, on chain=#1},
   sum/.style = {shape=circle, draw, inner sep=0pt, node contents={$+$}},
every path/.append style = {-latex'}
                        ]
\def\scopeyshift{19mm}
% first
    \begin{scope}[start chain=ch1 going left]
\foreach \i in {0,...,10}{\node [box=ch1] (ch1-\i) {$a_{\i}$};}
\node (c2) [sum,above=of ch1-2];
\draw (ch1-0) |- (c2);
\draw (c2) -| ([xshift=-5mm] ch1-10.west) -- (ch1-10);
\draw (ch1-2) -- (c2); 
    \end{scope}
% second   
    \begin{scope}[start chain=ch2 going left,yshift=-\scopeyshift]
\foreach \i in {0,...,10}{\node [box=ch2] (ch2-\i) {$a_{\i}$};}
\foreach \j in {2,7,8}
{
\node   (c\j) [sum,above=of ch2-\j];
\draw   (ch2-\j) -- (c\j);
}
\draw   (ch2-0) |- (c2)
        (c2) edge (c7)    (c7) edge (c8)
        (c8) -| ([xshift=-5mm] ch2-10.west) -- (ch2-10);
    \end{scope}
% third
    \begin{scope}[start chain=ch3 going left,yshift=-2*\scopeyshift]
\foreach \i in {0,...,10}{\node [box=ch3] (ch3-\i) {$a_{\i}$};}
\foreach \j in {2,...,7,9}
{
\node   (c\j) [sum,above=of ch3-\j];
\draw   (ch3-\j) -- (c\j);
}
\draw   (ch3-0) |- (c2)
        (c2) edge (c3)  (c3) edge (c4)  (c4) edge (c5)  
        (c5) edge (c6)  (c6) edge (c7)  (c7) edge (c9)
        (c9) -| ([xshift=-5mm] ch3-10.west) -- (ch3-10);
    \end{scope}
% forth
    \begin{scope}[start chain=ch4 going left,yshift=-3*\scopeyshift]
\foreach \i in {0,...,10}{\node [box=ch4] (ch4-\i) {$a_{\i}$};}
\foreach \j in {1,6,9}
{
\node   (c\j) [sum,above=of ch4-\j];
\draw   (ch4-\j) -- (c\j);
}
\draw   (ch4-0) |- (c1)
        (c1) edge (c6)  (c6) edge (c9)
        (c9) -| ([xshift=-5mm] ch4-10.west) -- (ch4-10);
    \end{scope}
% five
    \begin{scope}[start chain=ch5 going left,yshift=-4*\scopeyshift]
\foreach \i in {0,...,5}{\node [box=ch5] (ch5-\i) {$a_{\i}$};}
\foreach \j in {1,2,3}
{
\node   (c\j) [sum,above=of ch5-\j];
\draw   (ch5-\j) -- (c\j);
}
\draw   (ch5-0) |- (c1)
        (c1) edge (c2)  (c2) edge (c3)
        (c3) -| ([xshift=-5mm] ch5-5.west) -- (ch5-5);
    \end{scope}
% sixt
    \begin{scope}[start chain=ch6 going left,yshift=-5*\scopeyshift]
\foreach \i in {0,...,5}{\node [box=ch6] (ch6-\i) {$a_{\i}$};}
\foreach \j in {1,3,4}
{
\node   (c\j) [sum,above=of ch6-\j];
\draw   (ch6-\j) -- (c\j);
}
\draw   (ch6-0) |- (c1)
        (c1) edge (c3)  (c3) edge (c4)
        (c4) -| ([xshift=-5mm] ch6-5.west) -- (ch6-5);
    \end{scope}
% seven
    \begin{scope}[start chain=ch7 going left,yshift=-6*\scopeyshift]
\foreach \i in {0,...,5}{\node [box=ch7] (ch7-\i) {$a_{\i}$};}
\foreach \j in {1,2,4}
{
\node   (c\j) [sum,above=of ch7-\j];
\draw   (ch7-\j) -- (c\j);
}
\draw   (ch7-0) |- (c1)
        (c1) edge (c2)  (c2) edge (c4)
        (c4) -| ([xshift=-5mm] ch7-5.west) -- (ch7-5);
    \end{scope}
% function (interleave?)
\path   let \p1 = ($(ch1-0.north)-(ch7-0.south)$),
            \n1 = {veclen(\y1,\x1)} in 
        node[draw,minimum height=\n1, inner sep=3mm,
             below right=0mm and 11mm of ch1-0.north east] (f) {$f$};
\foreach \i in {1,...,7}{\draw (ch\i-0) -- (ch\i-0 -| f.west);}
\draw   (f) -- ([xshift=11mm] f.east);
    \end{tikzpicture}
\end{document}

MWE 给出:

在此处输入图片描述

相关内容