I have encountered problem with pseudo-real data deconvolution. What I want to do is to create some pulse profile, convolve with gaussian, add some little noise and deconvolve. However this adding of slight discrepancy (having finite number of measurements) will destroy deconvolution result.
As you can see in this figure the profiles for both convolved profiles are 'almost' identical. However...
You can see I got two completely different results :/ Any ideas how to handle this problem?
The code which I used is here:
import random
import numpy
import matplotlib.pyplot as plt
import scipy.signal
def create_pulse(lenght, peak):
#creates pulse shape
pulse_zeros = numpy.zeros(lenght)
for i in range(len(pulse_zeros)):
if i <= peak:
pulse_zeros[i] = float(i)/float(peak)
if i > peak:
pulse_zeros[i] = float((len(pulse_zeros)-i)*peak)/(float(i)*(len(pulse_zeros)-peak))
return pulse_zeros
plt.plot(create_pulse(200,10))
plt.show()
def normalize(data):
data = data/max(data)
return data
def mesh_up(pulse, region_l, sigma, repetitons):
#convolves mutliple pulses via addition at random points with sigma distribution around region_l/2
pulse_len = len(pulse)
region = numpy.zeros(region_l)
starts = numpy.random.normal(loc= region_l/2, scale= sigma, size = repetitons).round().astype(numpy.int)
for pos in starts:
#print(pos)
region[pos: pos + pulse_len] += pulse
return region
def one_up(pulse, region_l, sigma, repetitons):
#create pulse for scipy convolve
pulse_len = len(pulse)
region = numpy.zeros(region_l)
starts = [int(region_l/2)]
for pos in starts:
#print(pos)
region[pos: pos + pulse_len] += pulse
return region
result_a = mesh_up(create_pulse(200,10), 1000, 25/1.42, 10000)
signal = one_up(create_pulse(200,10), 1000, 25, 1)
result_b = scipy.signal.convolve(signal, gauss, mode='same')
plt.plot(signal, label = 'original')
plt.plot(normalize(result_a), label = 'rand_generated')
plt.plot(normalize(result_b), label = 'convolve')
plt.legend()
plt.show()
gauss = numpy.exp(-((numpy.linspace(0,100,101)-50.)/float(25.))**2 )
plt.plot(gauss)
plt.show()
deconv_a, _ = scipy.signal.deconvolve(normalize(result_a), gauss)
deconv_b, _ = scipy.signal.deconvolve(normalize(result_b), gauss)
plt.plot(normalize(deconv_a), label = 'rand_generated')
plt.plot(normalize(deconv_b), label = 'convolve')
plt.legend()
plt.show()