0
$\begingroup$

I have a time series of measurements which I want to high pass with Butterworth filter.

Python scipy package has a built in function for Butterworth filter (signal.butter) and I know how to apply it to the data in the time domain.

Let's say that x is my data with sampling frequency fs and a vector of time stamps t. I computed the power spectrum in the following way:

import scipy
import numpy as np
    
n = len(t)
xhat = scipy.fft.fft(x,n)
PSD = xhat * np.conj(xhat)/n

My question is if I transform my time series to the frequency domain, how do I apply the Butterworth filter in the frequency domain at cutoff frequency fC?

I am looking for an answer preferably in Python but I am also just generally interested in an answer such as formulas or steps explained in words.

$\endgroup$

1 Answer 1

2
$\begingroup$

Butterworth filter is an IIR filter whose impulse response has an infinite length and is aperiodic, meaning that the DFT (FFT) of its impulse response doesn't exist. Thus, you cannot apply a Butterworth filter in the frequency domain by FFT.

You should filter your time series in the time domain, then transform it into frequency domain and calculate the PSD of the filtered series.

If you want to do filtering in the frequency domain anyway, approximation (error) must be introduced. But I doubt that there is no merit in that way. In terms of computational complexity, memory consumption, latency, and accuracy, you should go with a direct time-domain IIR filter.

$\endgroup$
2
  • $\begingroup$ I am confused because I got a task to apply it in the frequency domain so I am wondering why they would tell me so if it is not possible/desirable/brings errors. Also I found a youtube video applying it in the frequency domain (youtube.com/watch?v=HZDsS3aXLI4) but I don't fully understand it. It is applying it to image processing whereas I have a time series, but I assume the spatial and temporal procedures are equivalent. $\endgroup$
    – Judita
    Feb 4, 2022 at 10:42
  • $\begingroup$ @Judita the video you mentioned is an approximation. She uses the frequency response of a Butterworth filter and then apply multiplication in the frequency domain, which is not a proper way for time sequence. Maybe this should help: dsp.stackexchange.com/questions/6220/… $\endgroup$
    – ZR Han
    Feb 4, 2022 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.