Akhil Pratap Singh
Akhil Pratap Singh

Reputation: 171

How to apply filter in time-domain signal in Python

I have a signal in frequency domain which I Fourier transformed into time domain. Now, there is one main peak and few sidebands. I want to filter out particular peak from time domain response. How can I do it?

Upvotes: 4

Views: 4437

Answers (1)

martianwars
martianwars

Reputation: 6500

You need to multiply your signal with a rectangular window (time limited window in general). scipy has a signal processing module, scipy.signal which can help you achieve many such operations.

In this case, you can create a rectangular window using scipy.signal.boxcar. Alternatively, you can try out different windows from scipy.signal.get_window. After this you could multiply your signal with this window to get the final result.

Here is a sample code,

import numpy as np
import scipy.signal
# signal
input = np.random.rand(100)
window = scipy.signal.boxcar(10)
# Pad the window to make its size equal to signal size
# I'm assuming your peak is between sample 45 and 55
window = np.lib.pad(window, (45, 45), 'constant')
output = input*window

In the case you wish to do this in the frequency domain, you need to pass your signal through an appropriate low pass filter. (assuming your peaks are in the frequency domain). Here is a well detailed answer to help you achieve this with Butterworth filters - Creating lowpass filter in SciPy - understanding methods and units.

Upvotes: 4

Related Questions