[SciPy-User] Does/how does ifft expect frequencies (on x-axis)?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[SciPy-User] Does/how does ifft expect frequencies (on x-axis)?

Matti Viljamaa
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.
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[SciPy-User] Difference equation to frequency response?

Matti Viljamaa
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:


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

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Difference equation to frequency response?

Neal Becker
Matti Viljamaa wrote:

> 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]

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)

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Difference equation to frequency response?

Robert Kern-2
In reply to this post by Matti Viljamaa
On Tue, Aug 30, 2016 at 10:35 AM, Matti Viljamaa <[hidden email]> wrote:
>
> 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/
>
> 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

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Loading...