I'm trying to draw a block schematic for a LMS filter using TikZ. I'd like to use two layers, such that I can draw an arrow "beneath" one of the blocks for the adaptive part (on the background layer). However, I get an error saying
Code: Select all
! Missing number, treated as zero.
<to be read again>
\pgf@layerbox@foreground layer
l.35 \begin{pgfonlayer}{foreground layer}
?
If I compile the exact same code without the layers, everything works fine (although the figure is not how I want it to be). I've made plenty of figures like this before, the only difference now is that I use the matrix library to place the different blocks in the schematic, so there's obviously something with this that causes the error, but I can't figure out what, so hopefully someone can help me out.

The following code is what I try to compile (with error)
Code: Select all
\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{float}
\usepackage[obeyall]{siunitx}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usetikzlibrary{shapes}
\usetikzlibrary{matrix}
\begin{document}
\thispagestyle{empty}
\tikzstyle{block} = [draw, minimum width = 3em, minimum height = 2em, semithick, rectangle, fill = white]
\tikzstyle{sum} = [draw, circle, inner sep = 0mm, minimum size = 1mm, semithick]
\tikzstyle{branch} = [circle, inner sep = 0pt, minimum size = 1mm, fill = black, draw = black]
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background, main, foreground}
\begin{figure}
\centering
\begin{tikzpicture}[semithick,>=latex']
\begin{pgfonlayer}{foreground layer}
\matrix[ampersand replacement = \&, row sep = 0.4cm, column sep = 1.0cm]{
\node[] (i0) {}; \& \\
\& \& \node[block] (f0) {$\hat{\mathbf{h}}[n]$}; \& \& \node[block] (f1) {$\mathbf{h}[n]$}; \\
\& \\
\node[] (i1) {}; \& \node[branch] (b0) {}; \& \node[sum] (s0) {$+$}; \& \& \node[sum] (s1) {$+$}; \& \node[] (i2) {}; \\
};
\node at ($(i0.west)+(-0.5,0)$) (input) {$x[n]$};
\node at ($(i1.west)+(-0.5,0)$) (error) {$e[n]$};
\node at ($(i2.east)+(0.5,0)$) (noise) {$\eta[n]$};
\draw[semithick,->] (input) -| (f0.north);
\draw[semithick,->] (input) -| (f1.north);
\draw[semithick,->] (noise) -- (s1.east);
\draw[semithick,->] (s1.west) -- node[above] () {$\tilde{y}[n]$} (s0.east);
\draw[semithick] (s0.west) -- (b0.east);
\draw[semithick,->] (b0.west) -- (error);
\draw[semithick,->] (f1.south) -- node[right] () {$y[n]$} (s1.north);
\draw[semithick,->] (f0.south) -- node[right] () {$\hat{y}[n]$} (s0.north);
\end{pgfonlayer}
\begin{pgfonlayer}{background layer}
\draw[semithick,->] (b0) -- ($(b0.north)+(0.8,0)$) -- ($(f0.north east)+(0.5,0)$);
\end{pgfonlayer}
\end{tikzpicture}
\end{figure}
\end{document}