Use Notch Filter
Introduction.
The notch filter allow to remove a band of frequencies from an input signal.
Parameters.
Here, the transfer function representation of the notch filter:
\[H(s) = \dfrac{s^2 + (2 \pi f_0)^2}{s^2 + 2 \pi \Delta f .s + (2 \pi f_0)^2}\]
Where:
-
\(f_0\) is the notch frequency,
-
\(\Delta f\) is the bandwidth of the filter.
Discretization.
Using the \(z\)-transform we get the following form:
\[
\begin{align}
H(z^{-1}) = \dfrac{b_0 + b_1.z^{-1} + b_2.z^{-2}}{ a_0 + a_1.z^{-1}+ a_2.z^{-2}} \\ \\
H(z) = \dfrac{b_0.z^2 + b_1.z^{1} + b_2}{ a_0.z^2 + a_1.z^{1}+ a_2} \\ \\
\end{align}
\]
As there's a direct relation between \(z^{-1}\) and \(q^{-1}\) the delay operator, we can write the reccuring equations we will use in the code.
\[
out_k = b_0 . in_k + b_1 . in_{k-1} + b_2 . in_{k-2} - a_1 . out_{k-1} - a_2 . out_{k-2}.
\]
Where:
\[
\begin{align}
b_0 &= \dfrac{1}{1+ \pi . \Delta f . T_s} \\ \\
b_1 &= -2 . b_0 .\cos(2\pi.f_0.T_s) \\ \\
b_2 &= b_0 \\ \\
a_1 &= b_1 \\ \\
a_2 &= 2 b_0 - 1
\end{align}
\]
Use of the NotchFilter
object.
3 steps to use the notchfilter.
Before to run, we advise to reset
the filter, in the setup_routine()
of the
OwnTech Power API.