Killertechno
Posts: 177
Joined: Wed Jan 02, 2013 8:28 am

Get filter kernel from output signal?

Wed Apr 24, 2019 1:29 pm

Hi to all, I was taking a look to this convolution example:

Code: Select all

import numpy as np
import scipy.signal
import matplotlib
import matplotlib.pyplot as plt
import sys 
matplotlib.use('TkAgg')


# test convolve

kernel = [0.5, 0.45, 0.05,  0]
input_signal = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]
filtered_signal = np.convolve(kernel , input_signal)

plt.title("kernel")
plt.plot(kernel)
plt.show()



plt.subplot(211)
plt.title("input signal")
plt.plot(input_signal)
plt.subplot(212)
plt.title("output signal")
plt.plot(filtered_signal)
plt.show()

Now.... is there a way I can get kernel from input_signal and filtered_signal?
Thanks.

User avatar
paddyg
Posts: 2359
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Get filter kernel from output signal?

Fri Apr 26, 2019 11:41 am

I think that it's possible because it acts linearly so 'just' a matter of solving simultaneous equations. Things that would make it difficult would be a) knowing the size of the kernel b) edge behavior, which is related to a. as the default edge behavior would tell you the size of the kernel. c) lack of info such as input and output being all zero.

You could re-arrange your signal, kernel and output as a system of equations and use https://docs.scipy.org/doc/numpy/refere ... solve.html Possibly working your way along the array until to got to a soluble section.

i.e. for you it might be something like

Code: Select all

k0*i8 + k1*i7 + k2*i6 + k3*i5 = o8
k0*i9 + k1*i8 + k2*i7 + k3*i6 = o9
k0*i10 + k1*i9 + k2*i8 + k3*i7 = o10
k0*i11 + k1*i10 + k2*i9 + k3*i8 = o11
where k0,k1 etc are the unknowns x in the example
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”