MATLAB freqz2 equivalent in Python

Question:

I’m trying to find a Python library that works equivalently to MATLAB’s freqz2 for image processing, since scipy.signal.freqz only seems to work for 1-D arrays.

Asked By: Facundo Farall

||

Answers:

Found an amazing library for plotting the 3D surface of the 2-D FFT called plotly. I leave here the lines of code I used to emulate the same behaviour of freqz2 in Python:

import scipy.fft as fft
import plotly.graph_objects as go

N = 128
h = fspecial('unsharp', alpha=0.2)
H = fft.fftshift(fft.fft2(h, [N, N]))
f = fft.fftshift(fft.fftfreq(N))
fig = go.Figure(data=[go.Surface(x=f, y=f, z=np.abs(H))])
fig.show()

The 3D graphs is interactive, and the fspecial function in python I implemented it myself copying what MATLAB does (I can also post it if asked).
enter image description here

Which is the equivalent to MATLAB’s:

h = fspecial('unsharp');
freqz2(h);

enter image description here

Answered By: Facundo Farall

Thanks for your answer.

You have called fspecial(), while it isn’t a python function and is defined in MATLAB.
Can you explain how you used it in python without error?

Answered By: T_N