Skip to content

Instantly share code, notes, and snippets.

@fhchl
Created September 24, 2020 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhchl/075353235a0166c20b06c8e9057a6dda to your computer and use it in GitHub Desktop.
Save fhchl/075353235a0166c20b06c8e9057a6dda to your computer and use it in GitHub Desktop.
inverse_filtering.py
# To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'
# %%
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal
h = np.zeros(128)
h[8] = 1
h[9] = 1
plt.plot(h)
x = np.array([1, 2, 1, 0, 4])
y = np.convolve(h, x)
# %%
H = np.fft.rfft(h)
plt.plot(np.abs(H))
# %%
plt.plot(x)
plt.plot(y)
# %%
d = np.zeros(len(h))
d[64] = 1
D = np.fft.rfft(d)
plt.plot(d)
# %%
# wiener filter
C = D * H.conj() / (np.abs(H)**2 + 0.05)
c = np.fft.irfft(C)
plt.plot(c)
# %%
plt.plot(np.abs(C))
# %%
C
# %%
plt.plot(np.abs(C*H))
# %%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment