3

Any idea how to do this, please?

enter image description here

CarLaTeX
  • 62,716
Cris
  • 41
  • Welcome to TeX.SE. circuitikz.sty may helps you, also refer https://tex.stackexchange.com/questions/39016/label-name-in-circuitikz – MadyYuvi Apr 15 '23 at 05:49
  • Is the curve below the derivative of the curve above? – vi pa Apr 15 '23 at 07:22
  • 2
    @MadyYuvi no, there is no provision for function plotting in circuitikz. Maybe you meant pgfplots? – Rmano Apr 15 '23 at 09:05
  • You can draw the main functions with pgfplots and add noise using rand, as in https://tex.stackexchange.com/a/144275/38080 --- what have you tried? – Rmano Apr 15 '23 at 09:21
  • @vipa probably, given that they are named θ and θ'. Although noise should be more pronounced in the lower one if that's the case... – Rmano Apr 15 '23 at 09:23

2 Answers2

8

I will give you an idea with pgfplots and the declare function facility of TikZ.

I define a function (using a piecewise approach with the ternary function test ? true value : false value) and its more-or-less derivative, and then a "fake" noise function; fake in the sense that it's just a sinusoidal with a bit of randomness added to it, to simulate noise visually.

I also use styles to minimize repetitions and to concentrate common definitions in one site.

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=newest}% change to the current release
\begin{document}
\pgfplotsset{
    base plot/.style={% common style for the plots
        width=10cm, height=5cm,
        xmin=0, xmax=10,
        domain=0:10,
        samples=100,
        axis x line = center,
        axis y line = center,
        enlarge x limits,
        enlarge y limits,
        xlabel = {$x$},
        % not used, but...
        legend style = {nodes={right, font=\scriptsize}, at={(0.05,0.6)}, anchor=west},
        clip mode = individual,
}}

\begin{tikzpicture}[declare function={ % constant-ramp-constant function xrampz(\x)=\x<2 ? 0 : (\x<6 ? \x-2 : 4); % generic derivate of the above Dxrampz(\x)=\x<2 ? 0 : (\x<6 ? 1 : 0); % pseudo-noise function, created "by feel" fakenoisesin(\A,\f,\x)=\A(0.6rand+sin(\f*\x)); }] \begin{axis}[ base plot, ymin=-1, ymax=5, ylabel = {$y$}, ] \addplot[thick] {xrampz(x)+fakenoisesin(.1,400,x)}; \addplot[red, thin] {xrampz(x)}; \end{axis} \begin{axis}[ base plot, yshift=-4cm,% move it down ymin=-1, ymax=2, ylabel = {$y'$}, ] \addplot[thick] {Dxrampz(x)+fakenoisesin(.2,400,x)}; \addplot[red, thin] {Dxrampz(x)}; \end{axis} \end{tikzpicture} \end{document}

example of noisy functions

Rmano
  • 40,848
  • 3
  • 64
  • 125
2

Just for fun: The blue line is random white noise, and the red line has been processed by a 5 point weighted moving average filter.

One should really do this using C++ or matlab for both speed and accuracy.

demo

\documentclass[border=10pt]{standalone}
%\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=newest}% change to the current release
\usepackage{pgfplotstable}
\begin{document}

\pgfmathsetmacro{\noise}{rand} \foreach \x in {1,...,50} {\pgfmathsetmacro{\y}{1.0*rand}% \xdef\noise{\noise,\y}}% \edef\noise{{\noise}}% pgfmath array

\pgfmathsetmacro{\ma}{0.375\noise[0]+0.25\noise[1]+0.0625\noise[2]}% \pgfmathsetmacro{\y}{0.25\noise[0]+0.375\noise[1]+0.25\noise[2]+0.0625\noise[3]}% \xdef\ma{\ma,\y}% \foreach \x in {2,...,48} {\pgfmathsetmacro{\y}{0.0625\noise[\x-2]+0.25\noise[\x-1]+0.375\noise[\x]+0.25\noise[\x+1]+0.0625\noise[\x+2]}% \xdef\ma{\ma,\y}}% \pgfmathsetmacro{\y}{0.0625\noise[47]+0.25\noise[48]+0.375\noise[49]+0.25\noise[50]}% \edef\ma{\ma,\y} \pgfmathsetmacro{\y}{0.0625\noise[48]+0.25\noise[49]+0.375*\noise[50]}% \edef\ma{{\ma,\y}}

\pgfplotstablenew[columns={x,random,banded}, create on use/x/.style={create col/set list={0,1,...,50}}, create on use/random/.style={create col/set list/.expand once=\noise}, create on use/banded/.style={create col/set list/.expand once=\ma}] {51}\mytable

%\pgfplotstabletypeset{\mytable}

\begin{tikzpicture} \begin{axis} \addplot[blue] table[y=random] \mytable; \addplot[red] table[y=banded] \mytable; \end{axis} \end{tikzpicture} \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120