3

I've been writing a paper on the FFT, and need to implement an image showing the basic premise of the 2-radix algorithm used. The image I want to create using Tikz is as follows. However, I've hardly any experience with Tikz (or Circuitikz if possible) as a package, and I'm at a loss when it comes to the syntax to implement something like this. Any help would be appreciated.

A 2-radix implementation of FFT

3
  • 1
    The only tricky bit is connection the leads to the box, for which one can use, for example ($(box 1.north west)!0.125!(box 1.south west)$) with tikzlibrary calc. Commented Apr 19, 2015 at 15:18
  • @JohnKormylo Thanks for that. I also was having issues with labelling the 1s and the w labels in the latter third of the image. Commented Apr 19, 2015 at 15:24
  • The [midway] and [neat start] locations can be useful, but for more control you would probably want to use calc again. Start by placing named coordinates or nodes at the end points. Commented Apr 19, 2015 at 15:34

2 Answers 2

5

You can do very easily to such things with the circuits libraries of TikZ.

A similar approach to add additional pseudo-anchors to a rectangular node can be found in Tikz surrounding box with automatically drawn border “ports”. A more proper way would be to define special anchors with an extra shape so that you would have anchors like .west 1, .west 2, etc.

The rest are some (possibly nested) loops and fine-tuned placement of current direction nodes.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[
  thick, node distance=.5cm, circuit ee IEC,
  box/.style={
    draw, align=center, shape=rectangle, minimum width=1.5cm, minimum height=4cm,
    append after command={% see also: https://tex.stackexchange.com/a/129668
      \foreach \side in {east,west} {
        \foreach \i in {1,...,#1} {
%          coordinate (\tikzlastnode-\i-\side)
%          at ($(\tikzlastnode.north \side)!{(\i-.5)/(#1)}!(\tikzlastnode.south \side)$)
           (\tikzlastnode.north \side) edge[draw=none, line to]
             coordinate[pos=(\i-.5)/(#1)] (\tikzlastnode-\i-\side) (\tikzlastnode.south \side)
        }}}}]
\node[box=4] (box-t) {$N/2$ \\\\ DFT};
\node[box=4, below=of box-t] (box-b) {$N/2$ \\\\ DFT};

\foreach \s[count=\i] in {0,2,6,8}
  \path (box-t-\i-west) edge node[at end, left]{$\chi[\s]$} ++(left:.5);
\foreach \s[count=\i] in {1,3,5,7}
  \path (box-b-\i-west) edge node[at end, left]{$\chi[\s]$} ++(left:.5);

\foreach \b/\s[count=\k] in {t/e, b/o}
  \foreach \i[evaluate={\j=int(\i-1)},
              evaluate={\J=int(ifthenelse(\k==2,\j+4,\j))}] in {1,...,4}
    \node [contact] (conn-\b-\i) at ([shift=(right:1.5)] box-\b-\i-east) {}
      edge node[above] {$X_{\s}[\j]$} (box-\b-\i-east)
     node [contact, label=right:{$X[\J]$}] (conn-\b-\i') at ([shift=(right:5)] box-\b-\i-east) {};

\begin{scope}[every info/.append style={font=\scriptsize, inner sep=+.5pt}]

\foreach \i[evaluate={\j=int(\i-1)},evaluate={\J=int(\i+3)}] in {1,...,4}
  \path (conn-t-\i) edge[current direction={pos=.27, info=$i$}] (conn-t-\i')
                    edge[current direction={pos=.1, info=$i$}] (conn-b-\i')
        (conn-b-\i) edge[current direction={pos=.87, info={$w_8^\J$}}] (conn-b-\i')
                    edge[current direction={pos=.9, info={$w_8^\j$}}] (conn-t-\i');
\end{scope}
\end{tikzpicture}
\end{document}

Output

enter image description here

4

Some foreach, two fit nodes and some labels. A nicer example in TeXample.net.

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}[c/.style={circle,fill, minimum size=4pt, 
                    inner sep=0pt, outer sep=0pt}]
\foreach \i [count=\xe from 0, count=\xo from 4, 
        evaluate={\ni=int(2*\i)}, evaluate={\nii=int(\ni+1)} ] in {0,1,2,3}{%
    \draw[-] (0,-\xe*0.75cm) coordinate (xe-\xe) -- 
              node [above]{$X_e[\xe]$} ++(0:2cm) coordinate[c] (xe-\xe-1);
    \draw[-] (xe-\xe-1)--++(0:2cm) coordinate[c, label=right:{$X[\xe]$},               
              label={[font=\scriptsize]below:{$w_8^\xe$}}] (xe-\xe-2);
    \draw[-] (-2cm,-\xe*0.75cm) coordinate (xe-\xe-0)--
              ++(0:-1cm)node[left]{$x[\ni]$}; 
    \begin{scope}[yshift=-4cm]
      \draw[-] (0,-\xe*0.75cm) coordinate (xo-\xe)--node [above]{$X_o[\xe]$} 
               ++(0:2cm) coordinate[c] (xo-\xe-1);
      \draw[-] (xo-\xe-1)--++(0:2cm) coordinate[c, label=right:{$X[\xo]$}, 
               label={[font=\scriptsize]below:{$w_8^\xo$}}] (xo-\xe-2);
      \draw[-] (-2cm,-\xe*0.75cm) coordinate (xo-\xe-0)--
               ++(0:-1cm)node[left]{$x[\nii]$}; 
    \end{scope}
}
\node[fit=(xe-0-0) (xe-3), draw, inner ysep=5mm, inner xsep=0pt, align=center]
          {N/2\\ DFT};
\node[fit=(xo-0-0) (xo-3), draw, inner ysep=5mm, inner xsep=0pt, align=center]
          {N/2\\ DFT};

\foreach \i in {0,1,2,3}{
    \draw (xe-\i -1) -- (xo-\i-2);
    \draw (xo-\i -1) -- (xe-\i-2);
}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .