# Possible to get transfer function coefficients from window?

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.

• Windows are usually not directly used as a filter, but they are used to design a filter by multiplying a window with coefficients of an ideal (infinitely long) filter. So I'm not sure if what you're trying to do is really what you want to do. Jul 23, 2020 at 5:31
• @MattL. This is definitely not my area of expertise, so any links or discussion of this or alternate answers I would appreciate. Usually I just convolve with a window to smooth signals. But the function filtfilt has so many nice features built in that I would like to use it (e.g., Gustaffson's method to deal with edges). I realize this is sort of weird, because it is more of a frequency domain method....my big concern is what am I doing wrong (i.e., will yield mistakes) or just weird? E.g., if I do what is in the accepted answer, will my smoothed signals be reasonable, or fubar?
– eric
Jul 23, 2020 at 14:27
• It's okay to use a window as a filter if you just want a simple smoothing, since it's just a weighted average of the last $N$ input samples. For more sophisticated filtering with more control over frequency domain parameters you'd need a better filter. But note that the implementation will be the same, you'd just have different filter coefficients. Jul 24, 2020 at 8:19

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)