summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/dsptricks/dspblocks.sty
blob: b7aba995a9ee14a39a8c49dcbf989409917924fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%% This is the package dspblocks
%%
%% (c) Paolo Prandoni <paolo.prandoni _at_ epfl.ch>
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `dspblocks' is a companion package to dsptricks; it contains a
%%     set of macros to draw the types of block diagrams commonly
%%     used in DSP theory
%%
%% v1.0, July 2014
%%

% required packages:
\RequirePackage{calc}
\RequirePackage{fp}
\RequirePackage{pst-xkey}
\RequirePackage{fmtcount}
\RequirePackage{ifthen}
%
\ProvidesPackage{dspblocks}[2014/07/24 package for signal processing graphics]


% turn off FP messages
\FPmessagesfalse

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%% Set up BLOCK DIAGRAM plot
%
% \begin{psdrawBDmatrix}[OPTIONS]{X_SPACING}{Y_SPACING}
%
%   X_SPACING
%   Y_SPACING         vertical and horizontal spacing
%
% Once in Block diagram mode the following commands are available
%  (they all create nodes)
%
%  \BDadd                 adder
%  \BDmul                 multiplier
%  \BDdelay               z^{-1} delay block
%  \BDdelayN{N}           z^{-N} delay block
%  \BDfilter{text}        filter box
%  \BDfilterMulti{text}   multiline filter box
%  \BDsplit               splitting point (dot)
%  \BDupsmp{K}            upsampler by K
%  \BDdwsmp{K}            downsampler by K
%

\def\BDwidth{1.2pt}
\psset{xunit=1mm,yunit=1mm,linewidth=\BDwidth}
\def\BDadd{[mnode=circle] +}%
\def\BDsub{[mnode=circle] -}%
\def\BDmul{[mnode=circle] $\times$}%
\def\BDdelay{\psframebox[framesep=.3]{$z^{-1}$}}%
\def\BDdelayN#1{\psframebox[framesep=.3]{$z^{-#1}$}}%
\def\BDfilter#1{\psframebox[framesep=.3]{#1}}%
\def\BDfilterMulti#1{\psframebox%
  {\begin{tabular}{c} #1 \end{tabular}}}%
\def\BDsplit{[mnode=dot,linewidth=1.5pt]}%
\def\BDupsmp#1{[mnode=circle] $#1 \uparrow$}%
\def\BDdwsmp#1{[mnode=circle] $#1 \downarrow$}%
\def\BDsampler{\raisebox{-14.6pt}{
        \psset{xunit=1em,yunit=1em,linewidth=1.2pt}%
        \pspicture(-2.6,-1.8)(1,1.8)%
          \psline(-3,0)(-1.6,0)(0.7,1.2)
          \psline(0.8,0)(1,0)
          \psarc[linewidth=1pt]{<-}(-1.2,0){1.4em}{-10}{55}
        \endpspicture}}
\newcommand{\BDsamplerFramed}[1][1em]{
  \newskip\tmpLen \tmpLen=#1%
  \raisebox{-1.5\tmpLen}{%
    \psframebox[linewidth=1.2pt]{%
      \psset{unit=#1,linearc=0}%
      \pspicture(-3.1,-2)(3,2)%
      \psline(-2.8,-0.2)(-1.6,-0.2)(1.2,1.4)%
      \psline(1.1,-0.2)(1.8,-0.2)%
      \psarc[linewidth=1pt]{<-}(-1.6,0){2}{-10}{55}%
      \endpspicture}}}
\newcommand{\BDlowpass}[1][1em]{%
  \newskip\tmpLen \tmpLen=#1%
  \raisebox{-1.5\tmpLen}{%
    \psframebox[linewidth=1.2pt]{%
      \psset{unit=#1,linearc=0}%
      \pspicture(-3.1,-2)(3,2)%
      \psline{->}(-2.8,-1)(2.8,-1)%
      \psline{->}(0,-1.8)(0,2)%
      \psline[linewidth=1.5pt](-1,-1)(-1,0.8)(1,0.8)(1,-1)%
      \endpspicture}}}
\newcommand{\BDsinc}[1][1em]{%
  \newskip\tmpLen \tmpLen=#1%
  \raisebox{-1.5\tmpLen}{%
    \psframebox[linewidth=1.2pt]{%
      \psset{unit=#1,linearc=0}%
      \pspicture(-3.1,-2)(3,2)%
      \psline{->}(-2.8,-.5)(2.8,-.5)%
      \psline{->}(0,-1.8)(0,2)%
      \psplot[linewidth=1pt, plotpoints=500,linejoin=1]{-2.5}{2.5}{x \dspSinc{0}{0.5} 1.5 mul .5 sub}%
      \endpspicture}}}

\newenvironment{dspBlocks}[2]{%
  \begin{psmatrix}[colsep=#1,rowsep=#2,emnode=R] }{%
  \end{psmatrix}
}

\newcommand{\BDConnH}[5][]{\ncline[#1]{->}{#2,#3}{#2,#4}\taput{#5}}
\newcommand{\BDConnHNext}[2]{\FPupn\n{#2 1 add 0 trunc}\ncline{->}{#1,#2}{#1,\n}}
\newcommand{\BDConnV}[5][]{\ncline[#1]{->}{#2,#3}{#4,#3}\tlput{#5}}

\makeatother