\begin{tikzpicture}
\begin{axis}[xlabel=$t$,ylabel=$x(t)$,xmin=-5,xmax=5,ymin=-2,ymax=2,grid=major,grid style={solid}]
\addplot[bojagrafa,line width=1pt,smooth] expression{(sin(90*x))+0.5};
\addplot[domain=-5:5,blue,samples=125,line width=1pt] expression{sin(90*x)+0.4*rand};
\addplot[bojagrafa,line width=1pt, smooth]expression{(sin(90*x))-0.5};
\end{axis}
\end{tikzpicture}
这是图形函数:x(t) = sin(90t) + 0.4·rand
但是y(t) = sin(90t)±0.5
我无法像下图这样正确,有谁能帮帮我:(
答案1
编辑: 我将样本数量减少到 125。
请注意,所显示图像的精确副本与随机函数相反(函数的种子未定义,因此编译时可能不同)。因此,如果您确实想要精确副本,则需要扫描原始图像并将其作为图形文件包含在文档中,并在图像中添加有关图像来源的注释(这很诚实)。
\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-5, xmax=5, xlabel=$t$,
ymin=-2, ymax=2, ylabel=$x(t)$,
grid=major,
%
domain=-5:5,
samples=125,
every axis plot post/.append style={line width=1pt}
]
\addplot [red] expression{sin(90*x)+0.5};
\addplot [blue] expression{sin(90*x)+0.4*rand};
\addplot [red] expression{sin(90*x)-0.5};
\end{axis}
\end{tikzpicture}
\end{document}
附录: 我将以以下方式展示具有噪声限制的噪声正弦波的图示:
\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
trig format plots=rad,
grid,
minor y tick num=4,
minor x tick num=2,
xtick = {-1.5*pi,-pi,...,1.5*pi},
tick style = {font=\small},
xticklabels={$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,0,
$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$},
xmin=-1.5*pi, xmax=1.5*pi, xlabel=$t$,
ymin=-2, ymax=2, ylabel=$\sin(t)+ 0.4{\cdot}X(t)$,
%
domain=-1.5*pi:1.5*pi,
samples=301,
every axis plot post/.append style={thick, line join=round},
]
\addplot [red] expression{-sin(x)+0.4};
\addplot [blue] expression{-sin(x)+0.4*rand};
\addplot [red] expression{-sin(x)-0.4};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
你几天前问过这个问题,但在我发布答案之前你删除了你的问题。无论如何,这是我会怎么做的:
\documentclass[border=2cm,margin=4cm,varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds,snakes}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-2*pi:2*pi, ymax=2,
, samples=100, grid=major,
xlabel=$t$,
ylabel=$x(t)$,
xmin=-4,xmax=4,
ymin=-2,ymax=2,
xtick = {-4,...,4},
ytick = {-4,...,4}
]
\addplot[red](\x, {sin(\x r)-0.5});
\addplot[red](\x, {sin(\x r)+0.5});
%\addplot[only marks,blue,mark=*,mark size=1pt] (\x, {sin(\x r)+0.5*rand});
\addplot[blue] (\x, {sin(\x r)+0.49*rand});
\end{axis}
\end{tikzpicture}
\end{document}