%
% $LastChangedRevision: 3344 $
% $LastChangedDate:: 2024-07-04 13:08:58 +0200#$
%
% This file is part of X2C. http://x2c.lcm.at/
%
% Copyright (c) 2013, Linz Center of Mechatronics GmbH (LCM) http://www.lcm.at/
% All rights reserved.
%
%
% This file is licensed according to the BSD 3-clause license as follows:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%     * Redistributions of source code must retain the above copyright
%       notice, this list of conditions and the following disclaimer.
%     * Redistributions in binary form must reproduce the above copyright
%       notice, this list of conditions and the following disclaimer in the
%       documentation and/or other materials provided with the distribution.
%     * Neither the name of the "Linz Center of Mechatronics GmbH" and "LCM" nor
%       the names of its contributors may be used to endorse or promote products
%       derived from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
% IN NO EVENT SHALL "Linz Center of Mechatronics GmbH" BE LIABLE FOR ANY
% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
Calculation:
\begin{equation*}%
    \mathrm{Out(k)} = \mathrm{In(k)} \cdot \mathrm{H(z)}%
\end{equation*}%

The transfer function H(z) of the filter is
\begin{equation*}%
	H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{1 + a_1 z^{-1} + a_2 z^{-2}}
\end{equation*}%

with coefficients derived from the transfer function
\begin{equation*}%
	H(s) = \frac{s^2 + \omega_0^2}{s^2 + \frac{\omega_0}{Q} + \omega_0^2}
\end{equation*}%

Two methods of discretizing a continuous transfer function are available: bilinear and matching.

%\begin{equation*}%
%	s = \frac{2}{T_s} \cdot \frac{z-1}{z+1}
%\end{equation*}%
%\begin{equation*}%
%	\omega_0^, = \frac{2}{T_s} \mathrm{tan}(\frac{\omega_0 \cdot T_s}{2})
%\end{equation*}%

Warning: In some cases, the function is very sensitive to the accuracy of the coefficients. Therefore, using a fixed-point implementation can sometimes give inaccurate results.

To illustrate this issue, see step responses in figures \ref{fig:NotchBiQ_step_tsfact1} and \ref{fig:NotchBiQ_step_tsfact10} below. Filter settings are $f_n = 50$\,Hz, $Q = 10$, $f_s = 10$\,kHz.

\begin{figure}[h!]
  \includegraphics[width=0.75\linewidth]{NotchBiQ_step_tsfact1.png}
  \caption{Step response for ts\_fact = 1.}
  \label{fig:NotchBiQ_step_tsfact1}
\end{figure}
\begin{figure}[h!]
	\includegraphics[width=0.75\linewidth]{NotchBiQ_step_tsfact10.png}
	\caption{Step response for t\_fact = 10.}
	\label{fig:NotchBiQ_step_tsfact10}
\end{figure}