1

I'm working on a FFT presentation and for that I need to replicate the following graph: Radix-2 Plot

I browsed through similar questions on this forum and came up with this:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,circuits.ee.IEC}
\usepackage{amssymb}
    \begin{tikzpicture}[
thick, node distance=.25cm, circuit ee IEC,
box/.style={
    draw, align=left, shape=rectangle, minimum width=1.5cm, minimum height=2cm,
    append after command={% see also: https://tex.stackexchange.com/a/129668
        \foreach \side in {east,west} {
            \foreach \i in {1,...,#1} {
                (\tikzlastnode.north \side) edge[draw=none, line to]
                coordinate[pos=(\i-.5)/(#1)] (\tikzlastnode-\i-\side) (\tikzlastnode.south \side)
}}}}]
\node[box=2] (box-tt) {$2$ \\\\ DFT};
\node[box=2, below=of box-tt] (box-t) {$2$ \\\\DFT};
\node[box=2, below=of box-t] (box-b) {$2$ \\\\DFT};
\node[box=2, below=of box-b] (box-bb) {$2$ \\\\ DFT};
%Conexiones a derecha
\foreach \s [count=\i] in {0,4}
    \path (box-tt-\i-east) edge node[at end, above,]{$\mathbb{X}[\s]$} ++(right:.5);
\foreach \s [count=\i] in {2,6}
    \path (box-t-\i-east) edge node[at end, above]{$\mathbb{X}[\s]$} ++(right:.5);
\foreach \s [count=\i] in {1,6}
    \path (box-b-\i-east) edge node[at end, above]{$\mathbb{X}[\s]$} ++(right:.5);
\foreach \s [count=\i] in {3,7}
    \path (box-bb-\i-east) edge node[at end, above]{$\mathbb{X}[\s]$} ++(right:.5);

\newcounter{k} \setcounter{k}{-1} \foreach \b/\s in {tt/g,t/i, b/j, bb/h} \foreach \i/\j in{1/0,2/1} \addtocounter{k}{1} \node [contact] (conn-\b-\i) at ([shift=(left:1)] box-\b-\i-west) {} node [contact] (conn2-\b-\i) at ([shift=(left:2.5)] box-\b-\i-west) {} node [contact] (connint2-\b-\i) at ([shift=(left:3)] box-\b-\i-west) {} node [contact] (conn3-\b-\i) at ([shift=(left:4.5)] box-\b-\i-west) {} node [contact] (connint3-\b-\i) at ([shift=(left:5)] box-\b-\i-west) {} node [contact] (conn4-\b-\i) at ([shift=(left:5.5)] box-\b-\i-west) {} edge node[at end,above left] {$\s[\j]$} (box-\b-\i-west) node [contact, label=left:{$x[\thek]$}] (conn5-\b-\i') at ([shift=(left:8)] box-\b-\i-west) {};

\begin{scope} \foreach \i in {1,...,2} \path (conn5-tt-\i') edge[current direction={pos=.25, info=$+$}] (conn4-tt-\i) %Primer nivel edge[current direction={pos=.99, info=$+$}] (conn4-b-\i) %Flechas abajp (conn5-t-\i') edge[current direction={pos=.25, info=$+$}] (conn4-t-\i) edge[current direction={pos=.99, info=$+$}] (conn4-bb-\i) (conn5-bb-\i') edge[current direction={pos=.25, info=$-$}] (conn4-bb-\i)%Flechas arriba edge[current direction={pos=.99, info=$+$}] (conn4-t-\i) (conn5-b-\i') edge[current direction={pos=.25, info=$-$}] (conn4-b-\i) edge[above right,current direction={pos=.99, info=$+$}] (conn4-tt-\i) %Segundo nivel (conn3-tt-\i) edge[current direction={pos=.25, info=$+$}] (connint2-tt-\i)%Flechas abajo edge[current direction={pos=.99, info=$+$}] (connint2-t-\i) (conn3-b-\i) edge[current direction={pos=.25, info=$+$}] (connint2-b-\i) edge[current direction={pos=.99, info=$+$}] (connint2-bb-\i) (conn3-bb-\i) edge[current direction={pos=.25, info=$-$}] (connint2-bb-\i)%Flechas arriba edge[current direction={pos=.99, info=$+$}] (connint2-b-\i) (conn3-t-\i) edge[current direction={pos=.25, info=$-$}] (connint2-t-\i) edge[current direction={pos=.99, info=$+$}] (connint2-tt-\i);%Tercer nivel \foreach \j in {tt,t,b,bb} \path (conn2-\j-1) edge[current direction={pos=.25, info=$+$}] (conn-\j-1) %Flechas abajo edge[current direction={pos=.99, info=$+$}] (conn-\j-2) (conn2-\j-2) edge[current direction={pos=.25, info=$-$}] (conn-\j-2) %Flechas arriba edge[current direction={pos=.99, info=$+$}] (conn-\j-1); \end{scope} \end{tikzpicture} \end{document}

The code above produces:

My radix-2 plot

Which is close to my desired result. However I'd to include the Weight factors, W, and to have more control over the position of the plus/minus signs. If you could help me with that I would be very grateful!

1 Answers1

2

Welcome to TeX.SE!!

This is a possibility, using two nested \foreachs to draw the lines, nodes and arrows in the y and x axes. I don't know exactly where you want to put the plus/minus signs, so perhaps this is wrong in my example (but it's easy to change).

My code:

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

\begin{document} \begin{tikzpicture}[y=-1cm] \foreach\y in {0,...,7} { \pgfmathtruncatemacro\yy{mod(abs(3.5-\y)+0.5,2)==0?\y:(\y<4?\y+3:\y-3)} % F value \draw[-latex] (-1,\y) node [left] {$f(\y)$} -- (-0.05,\y); \draw[-latex] (12,\y) -- (13,\y) node [right] {$F(\yy)$}; \foreach\x in {0,1,2} { \draw[-latex] (4\x,\y) --++ (2.95,0) ; \draw(4\x+3,\y) --++ (1,0); \foreach\z in {0,3} \node[circle,fill,inner sep=0.5mm] at (4\x+\z,\y) {}; \pgfmathtruncatemacro\i{pow(2,2-\x)} \pgfmathtruncatemacro\j{\i-2\imod(div(\y,\i),2)} % delta y for the arrows \node (A) at (4\x,\y) {}; \node (B) at (4\x+3,\y+\j) {}; \draw[-latex,thick,red] (A) -- (B); \ifnum\j < 0 \node[red] at (B) [shift={(225:0.2)}] {\tiny$+$}; \node[red] at (B) [shift={ (45:0.2)}] {\tiny$+$}; \else \pgfmathtruncatemacro\k{mod(\y,\i)(2-abs(\x-1))} % W exponent \node[red] at (B) [shift={(315:0.2)}] {\tiny$+$}; \node[red] at (B) [shift={(135:0.2)}] {\tiny$-$}; \node[red] at (B) [shift={(0.4,0.2)}] {$W^\k$}; \fi } } \end{tikzpicture} \end{document}

And the output: enter image description here

Juan Castaño
  • 28,426