tikz 中的四种不同的增加噪声曲线

tikz 中的四种不同的增加噪声曲线

我需要在 tikz 中绘制四条不同的噪声曲线。这四条线必须不同(它们必须具有不同的振幅和噪声。)

他们需要从自己的基线开始,并再次以该基线结束。

在此处输入图片描述

我的代码如下

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}
\newcommand\XA{1}
\newcommand\YA{10}
\newcommand\LengthProbe{5}
\newcommand\widthProbe{0.5}
\newcommand\contactPoint{0.10}
\newcommand\neuronX{3}
\newcommand\neuronY{8.5}

\path[use as bounding box,draw,black] (0,0) rectangle (12,12);

\node [circle,draw] at (\neuronX,\neuronY) (N1) {}; 
\node [circle,draw,below right = 0.2cm and 0.2cm of N1] () {};
\node [circle,draw,below right = 0.15cm and -0.2cm of N1] () {};
\node [circle,draw,below left = 0.6cm and -0.2cm of N1] () {};
\node [circle,draw,above right = 0.05cm and 0.2cm of N1] () {};
\node [circle,draw,below right = 0.8cm and 0.3cm of N1] () {};
\node [circle,draw,below left = 0.6cm and -0.2cm of N1] (N3) {};
\node [circle,draw,below right = 1.2cm and 0.2cm of N1] (N4) {};
\node [circle,draw,below left = 1.4cm and 0.0cm of N1] (N4) {};

\node[yshift = 10.5cm,xshift = 3.5cm] () {Before Optimization};

\coordinate (A1) at (2.5,10);
\coordinate (B1) at (2,5);
\draw (A1) to [bend left=10] (B1);

\coordinate (A2) at (4 , 10);
\coordinate (B2) at (4.5 , 5);
\draw (A2) to [bend right=10] (B2);

\draw (\XA,\YA) -- (\XA,\YA-\LengthProbe) -- (\XA+\widthProbe,\YA-\LengthProbe -\widthProbe) --(\XA+\widthProbe,\YA) -- (\XA,\YA); %linear probes

\foreach \ix in {0.2,0.8,...,4.6}
\draw (\XA+0.1,\YA-\ix) rectangle (\XA+\contactPoint+0.1,\YA-\ix-\contactPoint);

\foreach \ix in {0.3,0.9,...,5.0}
\draw (\XA+0.3,\YA-\ix-0.2) rectangle (\XA+\contactPoint+0.3,\YA-\ix-\contactPoint-0.2);

\end{tikzpicture}

\end{figure}

 \end{document}

答案1

另一种选择是元帖子,包裹在luamplib,因此用 来编译它lualatex

在此处输入图片描述

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}

vardef exp(expr x) = mexp(256x) enddef; % wrap MP's version of exp

vardef normal_pdf(expr x) = 
    exp(-1/2x*x)/2.50662827463  % \sqrt(2\pi) \simeq 2.50663 
enddef;

vardef noisy_normal_pdf(expr w, h, noisiness, frequency) = 
    ( (-4, normal_pdf(-4) + (noisiness/128) * normaldeviate) 
    for x=frequency-4 step frequency until 4:
       -- (x, normal_pdf(x) + (noisiness/128) * normaldeviate) 
   endfor ) xscaled 0.125 w yscaled 2.50663 h
enddef;  % scaled so that the curve has width w and height h

beginfig(1);
    for r = 0 upto 4:
        draw noisy_normal_pdf(5cm, 1cm, 2r, 1/32) shifted (0,r * cm);
    endfor
endfig;
\end{mplibcode}
\end{document}

答案2

这是我第一次尝试创建您要求的内容。目前我无法控制频率,但您应该能够实现您想要的效果。

在此处输入图片描述

一些代码取自这个问题:Tikz/pgf 装饰仅向 y 坐标添加噪声

\documentclass[a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}

\pgfdeclaredecoration{jiggly}{step}
{
  \state{step}[width=+\pgfdecorationsegmentlength]
  { \pgfmathsetmacro{\delta}{rand*\pgfdecorationsegmentamplitude}
    \pgfmathsetmacro{\deltax}{\delta*cos(90+\pgfdecoratedangle}
    \pgfmathsetmacro{\deltay}{\delta*sin(90+\pgfdecoratedangle}
    \pgfpathlineto{\pgfpoint{\pgfdecorationsegmentlength-\deltax}{\deltay}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{tikzpicture}[decoration={jiggly, amplitude=0.1cm}]


\draw[decoration={jiggly, amplitude=0.2cm},smooth] [decorate] 
(0,0) --++(2,1)--++(2,0)-- ++(2,-1);

\draw[decoration={jiggly, amplitude=0.3cm},smooth] [decorate] 
(0,2) --++(2,1)--++(2,0)-- ++(2,-1);

\draw[decoration={jiggly, amplitude=0.5cm},smooth] [decorate] 
(0,4) --++(2,1)--++(2,0)-- ++(2,-1);

\draw[decoration={jiggly, amplitude=0.7cm},smooth] [decorate]
(0,6) --++(2,1)--++(2,0)-- ++(2,-1);

\end{tikzpicture}

\end{document}

相关内容