Skip to content

Use Notch Filter

Introduction.

The notch filter allow to remove a band of frequencies from an input signal.

notch filter bode plot notch filter bode plot

Parameters.

Here, the transfer function representation of the notch filter:

H(s)=s2+(2πf0)2s2+2πΔf.s+(2πf0)2

Where:

  • f0 is the notch frequency,

  • Δf is the bandwidth of the filter.

Discretization.

Using the z-transform we get the following form:

H(z1)=b0+b1.z1+b2.z2a0+a1.z1+a2.z2H(z)=b0.z2+b1.z1+b2a0.z2+a1.z1+a2

As there's a direct relation between z1 and q1 the delay operator, we can write the reccuring equations we will use in the code.

outk=b0.ink+b1.ink1+b2.ink2a1.outk1a2.outk2.

Where:

b0=11+π.Δf.Tsb1=2.b0.cos(2π.f0.Ts)b2=b0a1=b1a2=2b01

Use of the NotchFilter object.

3 steps to use the notchfilter.

    #include "filters.h"

    const float32_t f0 = 50.0;               // notch frequency [Hz]
    const float32_t bandwidth = 5.0;         // notch bandwidth [Hz]
    const float32_t Ts = 100e-6;              // sampling time [s]
    myfilter = NotchFilter(Ts, f0, bandwidth);

Before to run, we advise to reset the filter, in the setup_routine() of the OwnTech Power API.

myfilter.reset();

In the loop_critical_task() you can call the method calculateWithReturn().

signal_filtered = myfilter.calculateWithReturn(signal_to_filter);

It returns the data filtered.

Note

Remind that the loop_critical_task() is called at the sampling time you define and must be equal to Ts.