0
$\begingroup$

Python deconvolution works fine when I convolve 2 signals in the full mode :

w = [1,2,3]

r = [4,5,6,7,8,9,10]

s = np.convolve(w, r,mode='full')
N= len(s)


from scipy.signal import deconvolve
recovered, _ = deconvolve(signal=s, divisor=w)

print('Convolved signal: ', r)
print('Recoverd signal: ',recovered)

Output :

Convolved signal:  [4, 5, 6, 7, 8, 9, 10]
Recoverd signal:  [ 4.  5.  6.  7.  8.  9. 10.]

But when I convolve signals in the same mode :

w = [1,2,3]

r = [4,5,6,7,8,9,10]

s = np.convolve(w, r,mode='same')
N= len(s)


from scipy.signal import deconvolve
recovered, _ = deconvolve(signal=s, divisor=w)

print('Convolved signal: ', r)
print('Recoverd signal: ',recovered)

Output :

Convolved signal:  [4, 5, 6, 7, 8, 9, 10]
Recoverd signal:  [ 13. 2.  -9.  52. -31.]

My question is: is there a deconvolution method for signals convolved in the 'same' mode ?
Without applying changes on the given array : r = [4,5,6,7,8,9,10]

$\endgroup$
1
  • 1
    $\begingroup$ I doubt it "Full mode" truncates up to half of the output signal. Once the information is gone, it's gone. $\endgroup$
    – Hilmar
    Aug 29, 2022 at 11:45

1 Answer 1

1
$\begingroup$

You can use scipy.linalg.convolution_matrix to get the matrix equivalent transformation equivalent to the convolution with the kernel w, and scipy.linalg.lstsq to compute a least squares solution (in the real world you will have noise).

import numpy as np
import scipy.linalg
w = [1,2,3]

r = [3,4,5,6,7,8,9,10]

s_full = np.convolve(w, r,mode='full')
s = np.convolve(w, r, mode='same')
N= len(s)

# here the deconvolution doe
A = scipy.linalg.convolution_matrix(w, len(r), 'same')
recovered, _, _, _ = scipy.linalg.lstsq(A, s)

# your print 
print('Convolved signal: ', r)
print('Recoverd signal: ',recovered)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.