I have created a block diagram with several nodes with text and I need to optimize the node creation and hopefully use the \foreach
construct to automate the creation of each node with its associated text. Moreover, is it a good idea to connect (ant)
and (ant2)
nodes with the (ch)
node as I suggested in the following code? I appreciate your ideas.
Here is my code:
\documentclass[10pt,a4paper]{standalone}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usetikzlibrary{arrows,positioning,shapes}
\begin{document}
\def\sp{4mm}
\begin{tikzpicture}
[line join=round, >=latex', blk/.style={draw,minimum height=1.4cm,align=center}, node distance=\sp, scale=0.8,line width=0.7pt]
\node [blk] (a) at (-8,5) {Binary \\sources};
\node [blk, right=of a](b) {Source \\coding};
\node [blk, right=of b](c) {Channel \\coding};
\node [blk, right=of c](d) {Pulse\\ modulation};
\node [blk, right=of d](e) {Bandpass\\ modulation};
\node [blk, right=of e](f) {Digital-\\to-analog\\ converting};
\node [blk, right=of f](g) {RF\\ front end};
\node [blk, below left= 10*\sp and 0.0*\sp of a] (a2){Binary \\sink};
\node [blk, right=of a2] (b2){Source \\decoding};
\node [blk, right=of b2] (c2){Channel \\decoding};
\node [blk, right=of c2] (d2){Detection};
\node [blk, right=of d2] (e2){Demod.\\and\\sampling};
\node [blk, right=of e2] (f2){Timing,\\synch, and\\equalization};
\node [blk, right=of f2] (g2){Analog-\\to-digital\\ converting};
\node [blk, right=of g2] (h2){RF\\ front end};
\foreach \x/\y in {a/b,b/c,c/d,d/e,e/f,f/g}
\draw [->](\x) -- (\y);
\foreach \x/\y in {a2/b2,b2/c2,c2/d2,d2/e2,e2/f2,f2/g2,g2/h2}
\draw [<-](\x) -- (\y);
% antennas, ant1:
\node [circle,minimum height=\sp,above right=of g](ant){};
\draw (ant.west)--(ant.east)-- (ant.south)--(ant.west)--cycle;
\draw (g) -| (ant.center);
% ant2:
\node [circle,minimum height=\sp,above right=of h2](ant2){};
\draw (ant2.west)--(ant2.east)--(ant2.south) -- (ant2.west)--cycle;
\draw (h2) -| (ant2.center);
%channel
\node [draw,minimum height=1cm,align=center,above=4*\sp of ant2](ch){Wireless\\channel};
%Transmissions, Upper:
\node [circle,minimum height=.7\sp](tr1)at($(ant)!.55!(ch.north)$){};
\draw [->](ant)--(tr1.south west)--(tr1.north east)--(ch.north);
%Lower:
\node [circle,minimum height=.7\sp](tr2)at($(ch.south)!.45!(ant2)$){};
\draw [->](ch.south)--(tr2.south west)--(tr2.north east)--(ant2);
\end{tikzpicture}
\end{document}
@LaRiFaRi-- I couldn't put long code in comments. You have provided a good code with nice looking radiation style. But technically (for this very system) the Wi-Fi decoration is not accepted and we should stick to the shape I suggested for wave propagation. So now, how could we possibly improve the following code? Also, any suggestions for the two dashed boxes with text? I appreciate your help.
My improved code:
\documentclass[10pt,tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}
\usetikzlibrary{arrows,positioning,calc,decorations.pathreplacing}
\begin{document}
\def\sp{4mm}
\tikzset{
blk/.style={draw,minimum height=1.4cm,align=center}
}
\tikzset{
sq/.style={shape=rectangle,sloped,minimum height=0.7\sp, minimum width=0.7\sp}
}
\tikzset{
dashedBox/.style={shape=rectangle,draw,dashed,minimum height=6*\sp,align=center}
}
\begin{tikzpicture}[line join=miter,line cap=round, >=latex', node distance=\sp, scale=0.8,line width=0.7pt]
\node [blk] (a) at (-8,5) {Binary\\sources};
\node [blk, right=of a](b) {Source\\coding};
\node [blk, right=of b](c) {Channel\\coding};
\node [blk, right=of c](d) {Pulse\\modulation};
\node [blk, right=of d](e) {Bandpass\\modulation};
\node [blk, right=of e](f) {Digital-\\to-analog\\ converting};
\node [blk, right=of f](g) {RF\\front end};
% Dashed Box
%\coordinate (L)at([yshift=3*\sp,xshift=-.5*\sp] d.north west);
%\coordinate (R)at([yshift=-.5*\sp,xshift=.5*\sp]e.south east);
%\draw [dashed](L) rectangle (R);
\node [dashedBox,yshift=\sp,minimum width=11.2*\sp](B1)at($(d.west)!0.5!(e.east)$){};
\node at(B1.north)[below,align=center]{Digital Modulation};
\node [blk, below= 9*\sp of a.west, anchor=west] (a2){Binary\\sink};
\node [blk, right=of a2] (b2){Source\\decoding};
\node [blk, right=of b2] (c2){Channel\\decoding};
\node [blk, right=of c2] (d2){Detection};
\node [blk, right=of d2] (e2){Demod.\\and\\sampling};
\node [blk, right=of e2] (f2){Timing,\\synch, and\\equalization};
\node [blk, right=of f2] (g2){Analog-\\to-digital\\converting};
\node [blk, right=of g2] (h2){RF\\front end};
% Dashed Box
\node [dashedBox,yshift=1*\sp,minimum width=10*\sp](B2)at($(d2.west)!0.5!(e2.east)$) {};
\node at(B2.north)[below,align=center]{Digital Demodulation};
\foreach \x/\y in {a/b,b/c,c/d,d/e,e/f,f/g}
\draw [->](\x) -- (\y);
\foreach \x/\y in {a2/b2,b2/c2,c2/d2,d2/e2,e2/f2,f2/g2,g2/h2}
\draw [<-](\x) -- (\y);
% antennas, ant1:
\node [circle,minimum height=\sp,above right=of g](ant){};
\draw (ant.west)--(ant.east)-- (ant.south)--(ant.west)--cycle;
\draw (g) -| (ant.center);
% ant2:
\node [circle,minimum height=\sp,above right=of h2](ant2){};
\draw (ant2.west)--(ant2.east)--(ant2.south) -- (ant2.west)--cycle;
\draw (h2) -| (ant2.center);
%channel
\path (ant)--node(ch)[draw,align=center]{Wireless\\channel}(ant2.south east);
%Transmission 1
\path(ant)--node(tr1)[sq]{}(ch);
\draw [->,shorten >=2pt](ant)--(tr1.south east)--(tr1.north west)--(ch);
%Transmission 2
\path(ch)--node(tr2)[sq]{}(ant2);
\draw [->,shorten >=2pt](ch)--(tr2.north east)--(tr2.south west)--(ant2.center);
\end{tikzpicture}
\end{document}
And here is the output:
\usepackage{times}
: it's an obsolete package. Either\usepackage{mathptmx}
or\usepackage{newtxtext,newtxmath}
, for getting Times font in your document.