Signal Processing Asked on November 30, 2021
I am hoping to use scipy.signals.filtfilt()
to smooth some signals in Python, and wanted to build the filter based on a window like a hanning window or whatever. E.g.:
import scipy.signal.windows as windows
window = windows.hann(filter_width)
But standard filters don’t just take in windows, they take in numerator and denominator transfer function coefficient arrays a
and b
:
data_smoothed = scipy.signal.filtfilt(b, a, data_noisy)
Is there a way to calculate the transfer function coefficients a
and b
from a window? I like filtfilt()
more than straight-up convolution with the window because it has a lot of useful features baked in.
What you are describing is an FIR filter, such that all the denominator coefficients are zero, save the basis, a[0]=1
. So you could do something like:
data_smoothed = scipy.signal.filtfilt(window, 1, data_noisy)
There is a notable point. The DC gain of the filter is equal to the sum of the coefficients for FIR filters. Your window is likely normalized to 1, so the sum is probably higher than 1, which means your filter will have gain at low frequencies. You would want to divide all the coefficients by the sum of the window to keep the gain to unity.
Answered by Dan Szabo on November 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP