DSP
A53 B

Description

The code is a LaTeX document that creates a simple graph of a discrete-time signal using the TikZ and pgfplots packages. The signal is defined by a data file called "data.dat" that contains two columns of data representing the discrete-time index and the signal value, respectively.

The graph is created using the "axis" environment provided by pgfplots. The x-axis and y-axis are labeled using the "xlabel" and "ylabel" commands, and the tick marks on the x-axis are set using the "xtick" command. The "ymin" and "ymax" commands set the minimum and maximum values of the y-axis.

Finally, the signal is plotted using the "ycomb" command to create a stem plot, with the data read in from the "data.dat" file. The resulting graph shows the discrete-time signal as a sequence of discrete values at integer time indices.

Keywords

tikzpicture, axis, xlabel, ylabel, xtick, ymin, ymax, addplot, ycomb, black, thick, table.

Source Code

DSP

\documentclass[border={10pt}]{standalone}
\usepackage{tikz,pgfplots,filecontents,amsmath}
\pgfplotsset{compat=1.5}
 
\begin{filecontents}{data.dat}
 n   yn 
-2   0.0
-1   0.0
 0   1.0
 1   2.0
 2   3.0
 3   4.0
 4   4.0
 5   4.0
 6   4.0 
 7   4.0 
 8   4.0
% 3   0.0 
 %4   0.0 
% 5   0.0
\end{filecontents}
 
 
\begin{document}
 
\begin{tikzpicture}
\begin{axis}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    axis x line=middle,
    axis y line=middle,
    every axis x label={at={(current axis.right of origin)},anchor=north west},
    every axis y label={at={(current axis.above origin)},anchor= north west},
    every axis plot post/.style={mark options={fill=black}},
    xlabel={$n$},
    ylabel={$\boldsymbol{y[n]}$},
    xtick={-2,0, ..., 8},
    ymin=0,
    ymax=4,
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addplot+[ycomb,black,thick] table [x={n}, y={yn}] {data.dat};
\end{axis}
\end{tikzpicture}
 
\end{document}
 
Deploy to Overleaf