How to properly deconvolve a signal covoled with the 'same' mode (in python)?

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]

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

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)