I would like to draw discrete signals, as shown in the illustration below, but not by way of drawings of individual lines.gnuplot
could be used for this work? It would be nice to be able to choose the sampling period, or something similar.
-
–1: Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.– TobiNov 25, 2013 at 10:29
4 Answers
Using TikZ and pgfplots the best option is adding ycomb
to your plot, as follows:
\documentclass{article}
\usepackage{tikz,pgfplots}%http://www.ctan.org/pkg/pgf http://www.ctan.org/pkg/pgfplots
\begin{document}
\pgfplotsset{
standard/.style={%Axis format configuration
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis y label/.style={at={(current axis.above origin)},anchor=north east},
every axis plot post/.style={mark options={fill=white}}
}
}
\begin{figure}%Unit step squence
\begin{tikzpicture}
\begin{axis}[%
standard,
domain = 0:15,
samples = 16,
xlabel={$n$},
ylabel={$\mu[n]$},
ymin=0,
ymax=1.5]
\addplot+[ycomb,black,thick] {1};
\end{axis}
\end{tikzpicture}
\end{figure}
\begin{figure}%Sampled sine squence
\begin{tikzpicture}
\begin{axis}[%
standard,
domain = 0:15,
samples = 16,
xlabel={$n$},
ylabel={$x[n]$}]
\addplot+[ycomb,black,thick] {sin(2*180*x/13)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
The result:
Possibly you can improve the look, might be tedious but add a sequence always easy.
The first function
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot,pst-node}
\begin{document}
\psset{xunit=.5}
\begin{pspicture}(-1,-.5)(16.5,2)
\psaxes[Dy=.5]{->}(0,0)(-.9,0)(16,1.5)[$n$,0][$l[n]$,90]
\curvepnodes[plotpoints=16]{0}{15}{t 1}{A}
\psset{linecolor=red}
\multido{\i=0+1}{\numexpr\Anodecount+1}{\psline{-o}(!\i\space dt mul 0)(A\i)}
\end{pspicture}
\end{document}
The second function
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot,pst-node}
\begin{document}
\psset{xunit=.5}
\makeatletter
\begin{pspicture}(-1,-1.)(16.5,2)
\psaxes[Dy=.5,labels=y,ticks=y]{->}(0,0)(-.9,0)(16,1.5)[$n$,0][$x[n]$,90]
\degrees[13]
\curvepnodes[plotpoints=16]{0}{15}{t t \pst@angleunit sin}{A}
\psset{linecolor=red}
\multido{\i=0+1}{\numexpr\Anodecount+1}
{
\psline{-o}(!\i\space dt mul 0)(A\i)
\psxTick[xlabelsep=\ifnum \ifnum\i<13 \i \else 0 \fi > 7 -17 \else 5\fi pt](\i){$\i$}
}
\end{pspicture}
\makeatother
\end{document}
-
It seems to be very difficult for me, but thank you from a very very nice answer. Nov 15, 2013 at 19:46
-
5
-
5@azetina: At the time I wrote the code I heavily concentrated on the conditional part to separate the x-label in the interval from 8 to 12 from other intervals. As a result, I forgot to think of the animation. I apologize for this inconvenience. :-) Nov 15, 2013 at 20:40
Although not exact solution, but using gnuplottex as mentioned in your Q. In anycase, pgfplots
would always be best for this task.
% Need "-shell-escape" enabled and gnuplot 4.4
\documentclass[preview=true,12pt,border=5pt]{standalone}
\usepackage{gnuplottex}
\begin{document}
\begin{gnuplot}[terminal=epslatex,terminaloptions=color]
unset border
set samples 16 # no of sampling points
set xtics 1 nomirror # custom tick marks and labels
set ytics 0.5 nomirror
set xlabel '$n$'
set ylabel '$\mu[n]$'
xmin=0;xmax=15;ymin=0;ymax=1; # co-ordinates of xaxis and yaxis
set arrow from xmin-0.05,ymin to xmax+0.9,ymin lt -1 lw 4 # x-axis
set arrow from xmin,ymax to xmin,ymax+0.15 lt -1 lw 4 # y-axis
set arrow from 8,ymin-0.14 to 10,ymin-0.14 #x-axis label arrow
set arrow from xmin-2.2,0.65 to xmin-2.2 ,0.8 #y-axis label arrow
plot [0:15] [0:1.1 ] 1 with impulses lt -1 lw 4 notitle ,1.02 with points ps 3 pt 6 lt 3 lw 4 lc rgb 'black' notitle
# plot discrete signal first "with impulses " and then circular markers at discrete locations
# "with linespoints "
\end{gnuplot}
\end{document}
% Need "-shell-escape" enabled and gnuplot 4.4
\documentclass[preview=true,12pt,border=5pt]{standalone}
\usepackage{gnuplottex}
\begin{document}
\begin{gnuplot}[terminal=epslatex,terminaloptions=color]
unset border
set xzeroaxis # set zero xaxis
set xtics axis # move the xaxis tick lables to center
set xtics 2 offset 0.55,1.75 nomirror # custom tick marks and labels
unset ytics
set ytics ("0.5" 0.5, "1" 1) nomirror
set samples 16 # no of sampling points
set xlabel '$n$' offset 18, 9.5
set ylabel '$x[n]$'
xmin=0;xmax=15;ymin=-1;ymax=1; # co-ordinates of xaxis and yaxis
set arrow from xmin-0.05,0 to xmax+0.9,0 lt -1 lw 4 # x-axis
set arrow from xmin,0 to xmin,ymax+0.15 lt -1 lw 4 # y-axis
set arrow from 14,-0.15 to 16,-0.15 #x-axis label arrow
set arrow from xmin-2,0.2 to xmin-2 ,0.5 #y-axis label arrow
plot [0:15] [-1.1:1.1] sin(2*pi*x/13) with impulses lt -1 lw 4 notitle, sin(2*pi*x/13)+.00 with points ps 3 pt 6 lt -1 lw 4 lc rgb 'black' notitle
\end{gnuplot}
\end{document}
and another PSTricks solution:
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-1,-1.)(8.5,2)
\psaxes[Dy=.5,labels=y,ticks=y]{->}(0,0)(-.9,0)(7.5,1.5)[$n$,0][$x[n]$,90]
\psplot[plotpoints=16,plotstyle=LineToXAxis,linecolor=red,
showpoints,dotstyle=o,dotscale=2,algebraic]{0}{7}{0.9}
\end{pspicture}
\begin{pspicture}(-1,-1.)(8.5,2)
\psaxes[Dy=.5,labels=y,ticks=y]{->}(0,0)(-.9,0)(7.5,1.5)[$n$,0][$x[n]$,90]
\psplot[plotpoints=16,plotstyle=LineToXAxis,
showpoints,dotstyle=o,dotscale=2,algebraic]{0}{7}{0.9*sin(x)}
\end{pspicture}
\end{document}