LaTeX forum ⇒ Graphics, Figures & TablesAdding triangles to tikz-dsp

Information and discussion about graphics, figures & tables in LaTeX documents.
endolith
Posts: 1
Joined: Tue Apr 14, 2015 4:32 am

Adding triangles to tikz-dsp

Postby endolith » Tue Apr 14, 2015 4:46 am

Hello. I am completely new to TikZ. I was able to adapt the example from http://www.texample.net/tikz/examples/fir-filter/ and make a diagram:

  1. \documentclass{article}
  2.  
  3. \usepackage{tikz}
  4. \usetikzlibrary{dsp,chains}
  5.  
  6. \DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
  7. \newcommand{\z}{\mathpzc{z}}
  8.  
  9. \begin{document}
  10.  
  11. \centering
  12.  
  13. % IIR filter
  14. \begin{tikzpicture}
  15.  
  16. % Place nodes using a matrix
  17. \matrix[row sep=6mm, column sep=6mm]
  18. {
  19. %--------------------------------------------------------------------
  20. \node[dspnodeopen,dsp/label=above] (m00) {$x[n]$}; &
  21. \node[dspnodefull] (m01) {}; &
  22. \node[dspmixer, dsp/label=above] (m02) {$b_0$}; &
  23. \node[dspadder] (m03) {}; &
  24. \node[dspmixer, dsp/label=above] (m04) {$1/a_0$}; &
  25. \node[dspnodefull] (m05) {}; &
  26. \node[dspnodeopen,dsp/label=above] (m06) {$y[n]$}; & \\
  27. %--------------------------------------------------------------------
  28. \node[coordinate] (m10) {}; &
  29. \node[coordinate] (m11) {}; &
  30. \node[coordinate] (m12) {}; &
  31. \node[dspsquare] (m13) {$\z^{-1}$}; &
  32. \node[coordinate] (m14) {}; &
  33. \node[coordinate] (m15) {}; &
  34. \node[coordinate] (m16) {}; & \\
  35. %--------------------------------------------------------------------
  36. \node[coordinate] (m20) {}; &
  37. \node[dspnodefull] (m21) {}; &
  38. \node[dspmixer, dsp/label=above] (m22) {$b_1$}; &
  39. \node[dspadder] (m23) {}; &
  40. \node[dspmixer, dsp/label=above] (m24) {$-a_1$}; &
  41. \node[dspnodefull] (m25) {}; &
  42. \node[coordinate] (m26) {}; & \\
  43. %--------------------------------------------------------------------
  44. \node[coordinate] (m30) {}; &
  45. \node[coordinate] (m31) {}; &
  46. \node[coordinate] (m32) {}; &
  47. \node[dspsquare] (m33) {$\z^{-1}$}; &
  48. \node[coordinate] (m34) {}; &
  49. \node[coordinate] (m35) {}; &
  50. \node[coordinate] (m36) {}; & \\
  51. %--------------------------------------------------------------------
  52. \node[coordinate] (m40) {}; &
  53. \node[dspnodefull] (m41) {}; &
  54. \node[dspmixer, dsp/label=above] (m42) {$b_2$}; &
  55. \node[dspadder] (m43) {}; &
  56. \node[dspmixer, dsp/label=above] (m44) {$-a_2$}; &
  57. \node[dspnodefull] (m45) {}; &
  58. \node[coordinate] (m46) {}; & \\
  59. %--------------------------------------------------------------------
  60. \node[coordinate] (m50) {}; &
  61. \node (m51) {$\vdots$}; &
  62. \node[coordinate] (m52) {}; &
  63. \node (m53) {$\vdots$}; &
  64. \node[coordinate] (m54) {}; &
  65. \node (m55) {$\vdots$}; & \\
  66. %--------------------------------------------------------------------
  67. \node[coordinate] (m60) {}; &
  68. \node[dspnodefull] (m61) {}; &
  69. \node[dspmixer, dsp/label=above] (m62) {$b_{M-1}$}; &
  70. \node[dspadder] (m63) {}; &
  71. \node[dspmixer, dsp/label=above] (m64) {$-a_{N-1}$};&
  72. \node[dspnodefull] (m65) {}; &
  73. \node[coordinate] (m66) {}; & \\
  74. %--------------------------------------------------------------------
  75. \node[coordinate] (m70) {}; &
  76. \node[coordinate] (m71) {}; &
  77. \node[coordinate] (m72) {}; &
  78. \node[dspsquare] (m73) {$\z^{-1}$}; &
  79. \node[coordinate] (m74) {}; &
  80. \node[coordinate] (m75) {}; &
  81. \node[coordinate] (m76) {}; & \\
  82. %--------------------------------------------------------------------
  83. \node[coordinate] (m80) {}; &
  84. \node[coordinate] (m81) {}; &
  85. \node[dspmixer, dsp/label=above] (m82) {$b_M$}; &
  86. \node[dspadder] (m83) {}; &
  87. \node[dspmixer, dsp/label=above] (m84) {$-a_N$}; &
  88. \node[coordinate] (m85) {}; &
  89. \node[coordinate] (m86) {}; & \\
  90. %--------------------------------------------------------------------
  91. };
  92.  
  93. % Draw connections
  94.  
  95. \begin{scope}[start chain]
  96. \chainin (m00);
  97. \chainin (m01) [join=by dspflow];
  98. \chainin (m02) [join=by dspconn];
  99. \chainin (m03) [join=by dspconn];
  100. \chainin (m04) [join=by dspconn];
  101. \chainin (m05) [join=by dspflow];
  102. \chainin (m06) [join=by dspflow];
  103. \end{scope}
  104.  
  105. \begin{scope}[start chain]
  106. \chainin (m01);
  107. \chainin (m21) [join=by dspflow];
  108. \chainin (m22) [join=by dspconn];
  109. \chainin (m23) [join=by dspconn];
  110. \chainin (m13) [join=by dspconn];
  111. \chainin (m03) [join=by dspconn];
  112. \end{scope}
  113.  
  114. \begin{scope}[start chain]
  115. \chainin (m21);
  116. \chainin (m41) [join=by dspflow];
  117. \chainin (m42) [join=by dspconn];
  118. \chainin (m43) [join=by dspconn];
  119. \chainin (m33) [join=by dspconn];
  120. \chainin (m23) [join=by dspconn];
  121. \end{scope}
  122.  
  123. \begin{scope}[start chain]
  124. \chainin (m41);
  125. \chainin (m51) [join=by dspflow];
  126. \chainin (m61) [join=by dspflow];
  127. \chainin (m62) [join=by dspconn];
  128. \chainin (m63) [join=by dspconn];
  129. \chainin (m53) [join=by dspflow];
  130. \chainin (m43) [join=by dspconn];
  131. \end{scope}
  132.  
  133. \begin{scope}[start chain]
  134. \chainin (m61);
  135. \chainin (m81) [join=by dspline];
  136. \chainin (m82) [join=by dspconn];
  137. \chainin (m83) [join=by dspconn];
  138. \chainin (m73) [join=by dspconn];
  139. \chainin (m63) [join=by dspconn];
  140. \end{scope}
  141.  
  142.  
  143.  
  144. \begin{scope}[start chain]
  145. \chainin (m05);
  146. \chainin (m25) [join=by dspflow];
  147. \chainin (m24) [join=by dspconn];
  148. \chainin (m23) [join=by dspconn];
  149. \end{scope}
  150.  
  151. \begin{scope}[start chain]
  152. \chainin (m25);
  153. \chainin (m45) [join=by dspflow];
  154. \chainin (m44) [join=by dspconn];
  155. \chainin (m43) [join=by dspconn];
  156. \end{scope}
  157.  
  158. \begin{scope}[start chain]
  159. \chainin (m45);
  160. \chainin (m55) [join=by dspflow];
  161. \chainin (m65) [join=by dspflow];
  162. \chainin (m64) [join=by dspconn];
  163. \chainin (m63) [join=by dspconn];
  164. \end{scope}
  165.  
  166. \begin{scope}[start chain]
  167. \chainin (m65);
  168. \chainin (m85) [join=by dspline];
  169. \chainin (m84) [join=by dspconn];
  170. \chainin (m83) [join=by dspconn];
  171. \end{scope}
  172.  
  173. % \foreach \i [evaluate = \i as \j using int(\i+1),
  174. % evaluate = \i as \k using int(\i+2),] in {2,4,6}
  175. % {
  176. % \begin{scope}[start chain]
  177. % \chainin (m0\i);
  178. % \chainin (m0\j) [join=by dspconn];
  179. % \chainin (m0\k) [join=by dspline];
  180. % \chainin (m1\k) [join=by dspconn];
  181. % \chainin (m2\k) [join=by dspconn];
  182. % \end{scope}
  183. % \draw[dspconn] (m2\i) -- (m2\k);
  184. % }
  185.  
  186. % \draw[dspflow] (m28) -- (m2X);
  187.  
  188.  
  189. \end{tikzpicture}
  190.  
  191. \end{document}


my_iir_filter.png
my_iir_filter.png (28.17 KiB) Viewed 2134 times


I would like help with 2 things:

1. How can I replace the X-style multipliers with triangle-style multipliers? More like this:

Image

I was told people here would show how to customize the tikz-dsp library?

2. The state variable labels d_0[n], d_1[n], ... were added afterward in an image editing program. How could I make them in the document itself? Actually the lines are ugly, it would be best to fit the labels right next to the arrows they go with, like:

Image

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 9501
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Apr 14, 2015 11:17 am

Welcome to the forum!

endolith wrote:I was told people here would show how to customize the tikz-dsp library?


Yes, I said that. :-) Small modifications such as redefinitions or some new symbol should be manageable. Also those extra annotations.

Perhaps somebody comes up with a suggestion, anyway I will also take a look later.

Stefan
Site admin


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 19 guests