Вопрос

I am implementing a bandpass filter in Python using scipy.signal (using the firwin function). My original signal consists of two frequencies (w_1=600Hz, w_2=800Hz). There might be a lot more frequencies that's why I need a bandpass filter.

In this case I want to filter the frequency band around 600 Hz, so I took 600 +/- 20Hz as cutoff frequencies. When I implemented the filter and reproduced the signal in the time domain using lfilter the frequency is fine.

The amplitude is reproduced in the right magnitude as well. But the problem is the signal is shifted in the y-direction. For example: s(t)=s_1(t)+s_2(t) with s_1(t)=sin(w_1 t)+3 and s_2(t)=sin(w_2 t) returns a filtered signal which varies around 0 but not [2,4]`.

Это было полезно?

Решение 2

So finally I adapted one filter to get the zerofrequency and another bandpassfilter to get the 600 Hz frequency. Passzero has to be true just for the zerofrequency then it works. I'm not yet happy with the phase delay but I'm working on it.

1)bandpass 600 Hz:

taps_bp = bandpass_fir(ntaps, lowcut, highcut, fs)

Function for the bandpassfilter

def bp_fir(ntaps, lowcut, highcut, fs, window = 'hamming') taps = scipy.signal.firwin(ntaps,[lowcut, highcut],nyq, pass_zero=False) return taps

2)zerofrequency filter

taps_zerofrequency = zero_fir(ntaps, zerofreq=1, fs)

Function for the zerofrequency filter

def zero_fir(ntaps, zerofreq, fs, window = 'hamming') taps = scipy.signal.firwin(ntaps,[zerofreq],nyq, pass_zero=True) return taps

Другие советы

You may want to look at the documentation: http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.firwin.html

Check the argument pass_zero.

To be speciffic, that missing 3.0 is the 0 frequency, non-periodic, or "DC" offset. You should not be getting this 3.0 from the output signal. If you are resolute, however, try:

scipy.signal.firwin(numtaps, [1,600-20,600+20,800-20,800+20,nyquist], pass_zero=True)

Not sure if that will work though.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top