I am trying to plot the curve and the shaded area shown in the screenshot below. I do not have the expression for the curve, but I was thinking about maybe using some kind of interpolating curve to get the right shape. However, I am quite new to the TikZ-package and I am not sure how I would start in order to achieve this. Also, how can the shaded area be drawn?
With approximation of your function by controls
macro:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots} % had to be instead tikz
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows.meta,
patterns,
pgfplots.fillbetween} % <---
\begin{document}
\begin{tikzpicture}[>=Straight Barb,
every pin edge/.append style={Circle-, color=black, semithick}
]
% function
\path[name path=A] (-3,0) -- (3,0);
\draw[thick,
name path=B] (-3,0.1) .. controls +(1.0,0) and +(-0.3,0) .. (-1,1.5)
.. controls +(0.3,0) and +(-0.3,0) .. ( 0,1.0)
.. controls +(0.3,0) and +(-0.3,0) .. ( 1,1.5)
.. controls +(0.3,0) and +(-1.0,0) .. ( 3,0.1);
\tikzfillbetween[of=A and B] {fill=cyan!30};
\coordinate[pin=75:{Area $E[x^2]$}] (aux) at (1.5,0.5);
% axis
\draw[->] (-3.5,0) -- (3.5,0) node[below left] {$\omega$};
\draw[->] (0,-0.1) node[below] {0} -- (0,3) node[below right] {$S_{xx}(\omega)$};
\end{tikzpicture}
\begin{tikzpicture}[>=Straight Barb,
every pin edge/.append style={Circle-, color=black, semithick}
]
% function
\path[name path=A] (-3,0) -- (3,0);
\draw[thick,
name path=B] (-3,0.1) .. controls +(1.0,0) and +(-0.3,0) .. (-1,1.5)
.. controls +(0.3,0) and +(-0.3,0) .. ( 0,1.0)
.. controls +(0.3,0) and +(-0.3,0) .. ( 1,1.5)
.. controls +(0.3,0) and +(-1.0,0) .. ( 3,0.1);
\tikzfillbetween[of=A and B] {pattern color=gray,
pattern=north east lines};
\coordinate[pin=75:{Area $E[x^2]$}] (aux) at (1.5,0.5);
% axis
\draw[->] (-3.5,0) -- (3.5,0) node[below left] {$\omega$};
\draw[->] (0,-0.1) node[below] {0} -- (0,3) node[below right] {$S_{xx}(\omega)$};
\end{tikzpicture}
\end{document}
I came with this, with a similar approach but without any fancy package.
\documentclass[tikz,border=3.14159mm]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[line width=.75pt]
\def\xa{5.5} \def\ya{.2}
\def\xb{1.8} \def\yb{2}
\def\xc{0} \def\yc{1.3}
\def\tang{.7}
\def\curve{
(-\xa,\ya) .. controls ++ (1.5,0) and ++ (-1.5*\tang,0) ..
(-\xb,\yb) .. controls ++ (\tang,0) and ++ (-\tang,0) ..
(-\xc,\yc) .. controls ++ (\tang,0) and ++ (-\tang,0) ..
(\xb,\yb) .. controls ++ (1.5*\tang,0) and ++ (-1.5,0) ..
(\xa,\ya)
}
\draw [-stealth] (-\xa-1,0) -- (\xa+1,0) node[below left] {$\omega$};
\draw [-stealth] (0,0) node[below] {$0$} -- (0,3) node[below right] {$S_x(\omega)$};
\path[pattern=north west lines, pattern color=orange] (-\xa,0) -- \curve -- (\xa,0) -- cycle;
\draw \curve;
\draw (\xb+.5,\yc) --++ (1,1) node [inner sep=1pt,right] {Area $E[x^2]$};
\end{tikzpicture}
\end{document}
\draw plot[smooth] coordinates {<coordinate1> <coordinate2> <coordinate3> ...}
to draw the curve (also see: tex.stackexchange.com/q/33607/47927). – Jasper Habicht Feb 23 at 12:12