[Tex/LaTex] How to properly draw block diagrams with multiple inputs in TiKz

drawtikz-pgftikz-styles

I would like to recreate the following block diagram. But is still unsuccessful on how to correctly position the blocks and arrows. I've tried several things, and this is what I have so far. Any help is much appreciated.

f and g block diagram

\documentclass{beamer}
\usetheme{Boadilla}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc}

\begin{document}

\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]

\begin{frame}{}

\begin{center}
\begin{tikzpicture}
    \node (input) at (0,0) {$\mathbf{x}$};
    \node [draw, fill=blue!20, rectangle, 
    minimum height=3.0em, minimum width=4.5em, right = 1cm of input, name=f]{$\mathbf{f}$};
    \node [draw, fill=blue!20, rectangle, 
    minimum height=3.0em, minimum width=4.5em, above right = -5mm and 4.5cm of input, name=g]{$\mathbf{g}$};
    \node [output, right = 1cm of g, name=z]{};
    \node [right = 0.1cm of z]{$\mathbf{z}$};
    \node (input) [above left = 0.3cm and 0.6cm of g, name=w]{$\mathbf{w}$};

    % Draw the connecting arrows and labels
    \draw [->, very thick] (input) -- (f);
    \draw [->, very thick] (f) -- (g) node [midway, above] {$\mathbf{y}$};
    \draw [->, very thick] (g) -- (z);
    \draw [->, very thick] (w) -- (g);
\end{tikzpicture}
\end{center}

\end{frame}

\end{document}

enter image description here

Best Answer

See, if the following solution is acceptable to you:

\documentclass[border=3mm,tikz]{standalone}
\usepackage{bm}
\usetikzlibrary{shapes, arrows, positioning, calc}
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{document}
\begin{tikzpicture}
    \node (input) at (0,0) {$\mathbf{x}$};
    \node [draw, fill=blue!20, rectangle, 
    minimum height=3.0em, minimum width=4.5em, right = 1cm of input, name=f]{$\mathbf{f}$};
    \node [draw, fill=blue!20, rectangle, 
    minimum height=3.0em, minimum width=4.5em, right = 4.5cm of input, name=g]{$\mathbf{g}$};
    \node [output, right = 1cm of g, name=z]{};
    \node [right = 0.1cm of z]{$\mathbf{z}$};

    % Draw the connecting arrows and labels
    \draw [->, very thick] (input) -- (f);
    \draw [->, very thick] (f) -- (g) node [midway, below] {$\mathbf{y}$};
    \draw [->, very thick] (g) -- (z);
    \begin{scope}[transform canvas={yshift=+3mm}]
        \draw [->, very thick] ($(f)!0.4!(g)$) -- (g) node [midway, above] {$\mathbf{w}$};
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here