# Matlab freqz function in Python

## Matlab freqz function in Python

In version 1.2.0 of SciPy, the `fs` argument was added to `scipy.signal.freqz`. So you can write

``````f, h = freqz(range(1, 6), 1, fs=12.5)
``````

For example,

``````In : f, h = freqz(range(1, 6), 1, fs=12.5)

In : len(f)
Out: 512

In : f[:10]  # Matches the Matlab output shown in the question.
Out:
array([0.        , 0.01220703, 0.02441406, 0.03662109, 0.04882812,
0.06103516, 0.07324219, 0.08544922, 0.09765625, 0.10986328])
``````

In older versions of SciPy,
`signal.signal.freqz` doesnt have an option to return the frequencies in Hz, so youll have to scale the frequencies yourself afterwards.

The equivalent of Matlabs

``````[h, f] = freqz(b, a, n, fs)
``````

using `freqz` from `scipy.signal` is:

``````w, h = freqz(b, a, worN=n)
f = fs * w / (2*np.pi)
``````

For example,

``````In : import numpy as np

In : from scipy.signal import freqz

In : w, h = freqz(range(1,6), 1, worN=512)

In : h[:6]
Out:
array([ 15.00000000+0.j        ,  14.99755288-0.24541945j,
14.99021268-0.49073403j,  14.97798292-0.73583892j,
14.96086947-0.98062944j,  14.93888050-1.22500102j])

In : w[:6]
Out:
array([ 0.        ,  0.00613592,  0.01227185,  0.01840777,  0.02454369,
0.03067962])

In : f = 12.5*w/(2*np.pi)

In : f[:6]
Out:
array([ 0.        ,  0.01220703,  0.02441406,  0.03662109,  0.04882812,
0.06103516])
``````

In both languages `freqz` expects numerator coefficients `b` for the first argument, not `a` like you wrote. Should be

`freqz(b, a, ...)`

Looks like you are trying to find the response of an FIR filter, for which there are only numerator coefficients and `a` is always 1.