[Tex/LaTex] Block diagram with dsp/TikZ for adaptive feedback cancellation

tikz-pgf

Hello graphic tex lovers 🙂
I'm trying to draw a diagram in TikZ as close as possible to this one:
enter image description here

I'm using the dsp TikZ library and I think my attempt is going in the right direction; however there are a few things I didn't manage to set up properly, as you can see from the MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{dsp,chains}
\begin{document}

\begin{tikzpicture}

% Blocks and nodes
\node[dspnodeopen,dsp/label=below] (ns) {$v(t)$}; 
\node[dspmultiplier,left=of ns,fill=gray] (mic) {};
\node[dspadder,left=of mic,left=1.5cm] (add) {};
\node[coordinate,left=of add,left=2.35cm]                  (fp1) {};
\node[dspfilter,above=of fp1,above=1.5cm]                     (gain) {$G$};
\node[coordinate,above=of gain,above=1.5cm]                  (fp2) {};
\node[dspnodefull,right=of fp2,right=2.55cm]                  (adnode) {$u(t)$};
\node[dspfilter,right=of gain,right=1.15cm]                     (adfilt) {$\hat{F}$};
\node[dspsquare,right=of fp2,right=4cm]                  (ls) {};
\node[dspfilter,right=of gain,right=4cm]                  (feedback) {F};
\node[dspnodefull,left=of add]                  (afupd1) {};
\node[coordinate,above=of afupd1,above=1cm]                  (afupd2) {};
\node[coordinate,right=of adfilt,above=3.5cm,right=0.5cm]                  (afupd3) {};
% Connections
\draw[dspconn] (ns) -- (mic);
\draw[dspline] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- (afupd3);
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspline] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) -- (feedback);
\draw[dspconn] (feedback) -- (mic);

 \end{tikzpicture}

 \end{document}

This is what my MWE looks like:

enter image description here

Namely, the things I couldn't properly recreate are:

  1. the microphone and loudspeaker symbols (those gray blocks)
  2. the vertical alignment of the filter blocks
  3. the right positioning of the dashed olique line (it should cut the block with \hat{F} right in the middle)
  4. curved lines to and from the filter block with F
  5. plus and minus signs in the adder.

Is anybody willing to help this poor TikZ user?

Thanks 😉

Best Answer

One possibility:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{dsp,chains,calc,shapes.geometric}

\begin{document}

\begin{tikzpicture}

% Blocks and nodes
\node[dspnodeopen,dsp/label=below] 
  (ns) {$v(t)$}; 
\node[left=of ns,fill=gray,circle,draw] 
  (mic) {};
\draw ([yshift=8pt]mic.east) -- ([yshift=-8pt]mic.east);
\node[dspadder,left=of mic,left=1.5cm,label={above right:$-$},label={below right:$+$}] 
  (add) {};
\node[coordinate,left=of add,left=2.35cm]
  (fp1) {};
\node[dspfilter,minimum height=2cm,above=of fp1,above=1.5cm]
  (gain) {$G$};
\node[coordinate,above=of gain,above=1.5cm]
  (fp2) {};
\node[dspnodefull,right=of fp2,right=2.55cm]
  (adnode) {$u(t)$};
\node[dspfilter,minimum height=2cm,right=of gain,right=1.15cm] 
  (adfilt) {$\hat{F}$};
\node[draw,right= 4cm of fp2,fill=gray,trapezium,shape border rotate=90,shape border uses incircle]
  (ls) {};
\draw ([yshift=-10pt]ls.west) -- ([yshift=10pt]ls.west);
\node[dspfilter,minimum height=2cm,right=of gain,right=4cm]
  (feedback) {F};
\node[dspnodefull,left=of add]
  (afupd1) {};
\node[coordinate,above=of afupd1,above=1cm]
  (afupd2) {};
\coordinate (aux) at ([yshift=-4pt]adfilt.center);
% Connections

\draw[dspconn] (ns) -- (mic);
\draw[dspconn] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- ( $ (afupd2)!2.7cm!(aux) $ );
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspconn] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) to[out=0,in=90] (feedback);
\draw[dspconn] (feedback) to[out=-90,in=30] ([yshift=3pt]mic.east);

 \end{tikzpicture}

 \end{document}

enter image description here

The answers to specific questions:

  1. Use standard TikZ shapes. The speaker, for example, is simply a rotated trapezium from the shapes.geometric library.

  2. No need for additional tweaks. You can use the standard minimum height key for the dspfilter nodes.

  3. I placed an auxiliary coordinate at adfilt.center (slightly shifted downwards to preven the line from overlapping the "F") and then used the ( $ (<name1>)!<length>!(<name2>) $ ) from the calc library.

  4. You can use to[out=<angle1>,in=<angle2>].

  5. I placed the desired labels to the add node.

In a comment, some problem with cut labels was mentioned when including the figure from an external file. In this case, I'd suggest you to use the standalone class to produce your image as a separate pdf file that then can be easily included in your document using the standard \includegraphics mechanism from graphicx; you can use the border option for standalone to control the padding around your figure, in case it is required:

For example, save the following as, say, MyImage.tex:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{dsp,chains,calc,shapes.geometric}

\begin{document}

\begin{tikzpicture}

% Blocks and nodes
\node[dspnodeopen,dsp/label=below] 
  (ns) {$v(t)$}; 
\node[left=of ns,fill=gray,circle,draw] 
  (mic) {};
\draw ([yshift=8pt]mic.east) -- ([yshift=-8pt]mic.east);
\node[dspadder,left=of mic,left=1.5cm,label={above right:$-$},label={below right:$+$}] 
  (add) {};
\node[coordinate,left=of add,left=2.35cm]
  (fp1) {};
\node[dspfilter,minimum height=2cm,above=of fp1,above=1.5cm]
  (gain) {$G$};
\node[coordinate,above=of gain,above=1.5cm]
  (fp2) {};
\node[dspnodefull,right=of fp2,right=2.55cm]
  (adnode) {$u(t)$};
\node[dspfilter,minimum height=2cm,right=of gain,right=1.15cm] 
  (adfilt) {$\hat{F}$};
\node[draw,right= 4cm of fp2,fill=gray,trapezium,shape border rotate=90,shape border uses incircle]
  (ls) {};
\draw ([yshift=-10pt]ls.west) -- ([yshift=10pt]ls.west);
\node[dspfilter,minimum height=2cm,right=of gain,right=4cm]
  (feedback) {F};
\node[dspnodefull,left=of add]
  (afupd1) {};
\node[coordinate,above=of afupd1,above=1cm]
  (afupd2) {};
\coordinate (aux) at ([yshift=-4pt]adfilt.center);
% Connections

\draw[dspconn] (ns) -- (mic);
\draw[dspconn] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- ( $ (afupd2)!2.7cm!(aux) $ );
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspconn] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) to[out=0,in=90] (feedback);
\draw[dspconn] (feedback) to[out=-90,in=30] ([yshift=3pt]mic.east);

 \end{tikzpicture}

 \end{document}

After processing it through pdflatex you'll get a MyImage.pdf file looking like (gray area around the figure is not part of the resulting pdf):

enter image description here

Then you can use

\usepackage{graphicx}% in preamble
\includegraphics{MyImage}% in document body

in your .tex file to include the image. You can control individual margins with the boder key (refer to the standalone documentation).

Related Question