forked from wangzichan/550400.github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroupworkrdocetcTIKZexample.tex
106 lines (90 loc) · 3.75 KB
/
groupworkrdocetcTIKZexample.tex
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
\tikzset{overlap/.style={fill=yellow!30},
block wave/.style={thick},
function f/.style={block wave, red!50},
function g/.style={block wave, green!50},
convolution/.style={block wave, blue!50},
function g position/.style={function g, dashed, semithick},
major tick/.style={semithick},
axis label/.style={anchor=west},
x tick label/.style={anchor=north, minimum width=7mm},
y tick label/.style={anchor=east},
}
\pgfkeys{/pgf/number format/.cd,fixed,precision=1}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand{\mainaxis}{
% Main axis
\draw (-2, 0) -- (2, 0) (0, 0) -- (0, 1.15);
% Small tickmarks on the x axis
\foreach \x in {-2,-1.9,...,2} {
\draw (\x, 0) -- (\x, -0.8pt);
}
% Labels on the $x$ axis; the llap makes the label center on the
% number without the minus.
\foreach \x/\label in {-2/\llap{$-$}2,-1/\llap{$-$}1,0/0,1/1,2/2} {
\node[x tick label] at (\x, 0) {$\label$};
\draw[major tick] (\x, 0) -- (\x, -1.25pt);
}
% Y tick mark.
\draw[major tick] (-1.25pt,.5) -- (0,.5);
% Y labels.
\node[y tick label] at (0,.5) {$\frac{1}{2}$};
\node[y tick label] at (0,1) {$1$};
}
\def\yshift{-2cm} % Shift of the lower axis
\newcommand{\drawaxes}{
\mainaxis
\node[axis label] at (2,0) {$\scriptstyle \tau$};
% Second axis, where the convultion will be drawn.
\begin{scope}[yshift=\yshift]
\foreach \y in {0.1,0.2,...,1.0}
\draw[black!20] (-2,\y) -- (2,\y);
\mainaxis
\node[axis label] at (2,0) {$\scriptstyle t$};
\end{scope}
\begin{pgfonlayer}{foreground}
\node at (0,1.25) {$f$};
\node[anchor=base] at (0,-.55)
{$f*g =\!\!\displaystyle\int\limits_{-\infty}^{\infty}
\!\!f(\tau)g(t-\tau)\,d\tau$};
\end{pgfonlayer}
\draw[major tick] (-1.25pt,.5) -- (0,.5) (-1.25pt,1) -- (0,1);
% f(\tau) is basically fixed.
\draw[function f] (-0.5, 0) -- +(0,1) -- +(1,1) -- +(1,0);
\clip (-2,-2) rectangle (2, 1.75);
}
\newcommand{\drawg}[1]{
\draw[function g] (#1,0) ++(-0.5, 0) -- +(0,1) -- +(1,1) -- +(1,0);
\draw[function g position] (#1,1.4) -- (#1,\yshift);
\node[fill=white] at (#1, 1.25) {$g$};
% We now slightly abuse \ifdim to determine whether
% there's an overlap.
\ifdim#1pt>-1pt\ifdim#1pt<1.01pt
% Draw legend.
\fill[overlap] (-2,1.51) rectangle +(0.15,0.15);
% The right side of f overlaps with the left side of g:
% 'entering'
\ifdim#1pt<0pt
\node[anchor=west] at (-1.85, 1.575)
{$f(\tau)g(\pgfmathprintnumber{#1} - \tau$)};
\begin{pgfonlayer}{background}
\fill[overlap] (-.5,0) rectangle (#1+.5,1);
\end{pgfonlayer}
\draw[convolution] (-1,\yshift) -- (#1, \yshift+1cm+#1 cm);
\else
% The left side of f overlaps with the right side of g:
% 'leaving'
\node[anchor=west] at (-1.85, 1.575)
{$f(\tau)g(\pgfmathprintnumber{#1} - \tau$)};
\begin{pgfonlayer}{background}
\fill[overlap] (#1-.5,0) rectangle (.5,1);
\end{pgfonlayer}
\draw[convolution] (-1,\yshift) -- +(1, 1) --
(#1,\yshift+1cm-#1 cm);
\fi
\else
% 'g' is completely past 'f', draw the result.
\draw[convolution] (-1,\yshift) -- +(1,1) -- +(2,0);
\fi\fi
}