Converting from samplerate/cutoff frequency to pi-radians/sample in a discrete time sampled IIR filter system

StackOverflow https://stackoverflow.com/questions/4697235

Question

I am working on doing some digital filter work using Python and Numpy/Scipy.

I'm using scipy.signal.iirdesign to generate my filter coefficents, but it requires the filter passband coefficents in a format I am not familiar with

wp, ws : float

  Passband and stopband edge frequencies, normalized from 0 to 1 (1 corresponds 
      to pi radians / sample). 
  For example:
  Lowpass: wp = 0.2, ws = 0.3
  Highpass: wp = 0.3, ws = 0.2

(from here)

I'm not familiar with digital filters (I'm coming from a hardware design background). In an analog context, I would determine the desired slope and the 3db down point, and calculate component values from that.

In this context, how do I take a known sample rate, a desired corner frequency, and a desired rolloff, and calculate the wp, ws values from that?

(This might be more appropriate for math.stackexchange. I'm not sure)

Was it helpful?

Solution

If your sampling rate is fs, the Nyquist rate is fs/2. This represents the highest representable frequency you can have without aliasing. It is also equivalent to the normalized value of 1 referred to by the documentation. Therefore, if you are designing a low pass filter with a corner frequency of fc, you'd enter it as fc / (fs/2).

For example, you have fs=8000 so fs/2=4000. You want a low pass filter with a corner frequency of 3100 and a stop band frequency of 3300. The resulting values would be wp=fc/(fs/2)=3100/4000. The stopband frequency would be 3300/4000.

Make sense?

OTHER TIPS

Take the function x(t) = cos(2*pi*fa*t). If we're sampling at frequency fs, the sampled function is x(n*ts) = x(n/fs) = cos(2*pi*n*fa/fs). The maximum frequency before aliasing (folding) is the Nyquist frequency fa = fs/2, which normalizes to (fs/2)/fs = 1/2. The normalized angular frequency is 2*pi*1/2 rad/sample = pi rad/sample. Thus the signal x[n] = cos[pi*n] = [1,-1,1,-1,...].

The sampled version of a given frequency such as a corner frequency 2*pi*fc rad/s would be 2*pi*fc/fs rad/sample. As a fraction of the Nyquist frequency pi, that's 2*fc/fs = fc/(fs/2).

A few formulas to live by:

exp[j*w*n] = cos[w*n] + j*sin[w*n]
x_even[n] = 0.5*x[n] + 0.5*x[-n]
cos[w*n] = 0.5*exp[j*w*n] + 0.5*exp[-j*w*n]    # cos is even
x_odd[n] = 0.5*x[n] - 0.5*x[-n]
j*sin[w*n] = 0.5*exp[j*w*n] - 0.5*exp[-j*w*n]  # sin is odd

The DFT of the even component (a sum of cosines) of a real-valued signal will be real and symmetric while the DFT of the odd component (a sum of sines) will be imaginary and anti-symmetric. Thus for real-valued signals such as the impulse response of a typical filter, the magnitude spectrum is symmetric while the phase spectrum is antisymmetric. Thus you only have to specify a filter for the range 0 to pi, which is normalized to [0,1].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top