Search code examples
pythonfilterscipysignalssignal-processing

Why when using scipy's freqz on a firwin filter we get a limited frequency resolution?


I have recently been working with data sampled at high sampling rates (1M and higher)

I am trying to write an efficient polyphase filter, (based on the code seen here)

My decimation rates are close to 10000, and so the Nyquist frequency to filter around is ~100Hz

After some debugging, I realized that when representing my filter taps using scipy.signal.freqz the resolution is limited at approx 1000 Hz, this does not change when increasing the fir filter order.

I couldn't find any documentation on the issue, how could I observe my filter with higher resolution?


Solution

  • The resolution of scipy.signal.freqz is limited by the number of frequency points worN through the formula fs/2/worN for half-spectrum (or fs/worN for full-spectrum). Since worN is by default 512, with your signal sampled at 1MHz you'd get a resolution of approximately 1000000Hz/2/512 ~ 1000.

    To increase the resolution of freqz on your filterCoefficients (in your case obtained by firwin), simply increase worN. For example with something like:

    w,h = freqz(filterCoefficients, worN=2048, fs=fs)