1

I'm very comfortable writing LaTeX, and moderately comfortable with tikz. Is there a standard way to draw diagrams as they appear in signals and systems classes? I'm a TA for one now, and the other instructors use Microsoft PowerPoint to draw figures, but I'm really bad at cutting and pasting objects and placing them at precise spots.

Thank you.

EDIT - I am just a TikZ beginner.

3

1 Answer 1

4

I'd like to argue that it is much more fun to just draw these with elementary TikZ commands. My previous answers were unnecessarily complicated.

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\tikzset{declare function={unitstep(\x)=notless(\x,0);}}
\tikzset{declare function={delta(\x)=equal(\x,0);}}
\begin{document}
\[ u[n]=\begin{cases} 1 & n\ge0 \\
0 & n<0 \end{cases}\]
\begin{tikzpicture}[thick,scale=0.5]
\draw[-] (-10,0) -- (10,0) node [below] {$n$};
\node[below](0,0){0};
\foreach \x in {-9,...,9}
 {\draw[fill=black] (\x,0) -- (\x,{unitstep(\x)})  circle (0.2cm);
 }
\end{tikzpicture}
\[ \delta[n]=\begin{cases} 1 & n=0 \\
0 & n\ne0 \end{cases}\]
\begin{tikzpicture}[thick,scale=0.5]
\draw[-] (-10,0) -- (10,0) node [below] {$n$};
\node[below](0,0){0};
\foreach \x in {-9,...,9}
 {\draw[fill=black] (\x,0) -- (\x,{delta(\x)})  circle (0.2cm);
 }
\end{tikzpicture}

Let's now plot $u[x]+u[x-2]$.\\
\begin{tikzpicture}[thick,scale=0.5]
\draw[-] (-10,0) -- (10,0) node [below] {$n$};
\node[below](0,0){0};
\foreach \x in {-9,...,9}
 {\draw[fill=black] (\x,0) -- (\x,{unitstep(\x)+unitstep(\x-2)})  circle (0.2cm);
 }
\end{tikzpicture}
\end{document}

enter image description here

2
  • This is amazing. I should probably go back and modify my post, to say I'm a TikZ beginner. I've drawn circuits with it before, but never these diagrams. The problem is, I can understand TikZ code, but don't have enough of a TikZ vocabulary to write stuff on my own. For instance, you've given me the template to draw discrete-time signals. But I would still not be able to draw, say, the signal $u(t) + 2u(t - 1)$. And how does one even search for something lke that? Thanks so much for your response!
    – lazulikid
    Commented Jan 13, 2018 at 18:45
  • @convexityftw I added some more explanations (and apologize for the edit in between, I misplaced a /2).
    – user121799
    Commented Jan 13, 2018 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .