Discussion:
[SciPy-User] Does/how does ifft expect frequencies (on x-axis)?
Matti Viljamaa
2016-08-29 13:57:14 UTC
Permalink
I was trying to ifft a filter magnitude response that’s simply drawn into an array of filter length, e.g. 64 samples.
So I have the array of 64 samples and this obviously means that the x-axis is in samples, not frequencies.

ifft:ing this array does give me something that looks like the impulse response, but I didn’t give ifft any frequency data, just samples 0-64 in the x-axis. What I think I could’ve done is rather specify the magnitude response in 2D array or something so that the frequency runs from [0.0, 1.0] (0.5 corresponding to the Nyquist frequency) and then specify the magnitudes in 64 samples evenly spread on [0.0, 1.0], which is what I _intend_ with my array.

So does ifft expect frequencies somehow or does it also work in the way that I used it, i.e. that the frequency response going into it is in samples rather than in frequencies?

The functions I’m interested are any ifft in SciPy.
Matti Viljamaa
2016-08-30 09:35:36 UTC
Permalink
What’s a simple way to get the frequency response of a filter that’s expressed as difference equation using SciPy?

Such as this lowpass filter:

https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/ <https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/>

y[i] = b * x[i] + (1-b) * y[i-1]
Neal Becker
2016-08-30 10:54:44 UTC
Permalink
What’s a simple way to get the frequency response of a filter that’s
expressed as difference equation using SciPy?
https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
<https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/>
y[i] = b * x[i] + (1-b) * y[i-1]
1st step is to get the z-transform
y = bx + (1-b) y z^{-1}

Solve for y/x.

Then your question is how to plot a frequency response from a z transform.
Plug in z=e^(j 2 pi f t)
Robert Kern
2016-08-30 11:55:30 UTC
Permalink
Post by Matti Viljamaa
What’s a simple way to get the frequency response of a filter that’s
expressed as difference equation using SciPy?
https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
Post by Matti Viljamaa
y[i] = b * x[i] + (1-b) * y[i-1]
This is a so-called Infinite Impulse Response (IIR) filter. In the terms
that scipy.signal works with, we need to convert it to a transfer function,
which is just a ratio of polynomials.


https://en.wikipedia.org/wiki/Infinite_impulse_response#Transfer_function_derivation

To avoid confusion, let me rename your variables (the transfer function
convention uses `b` to mean the array of coefficients of the numerator
polynomial).

y[i] = alpha * x[i] + (1-alpha) * y[i-1]

So we get:

b = [alpha]
a = [1.0, -(1-alpha)]

scipy.signal has a handy class for filters defined in terms of transfer
functions:

#
http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.TransferFunction.html#scipy.signal.TransferFunction
from scipy import signal
tf = signal.TransferFunction(b, a)

And it has a handy method for computing the frequency response (magnitude
and phase):


http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.dlti.freqresp.html#scipy.signal.dlti.freqresp

--
Robert Kern

Loading...