This is the Python code to implement the filter.