Trying to write deconvolution function

187 Views Asked by At

I'm attempting to write my own deconvolution function in MATLAB, but am not sure my math is right. Can anyone assist?

Attempting to determine x(n) given $$ h(n) = (1/2)^n , 0<= n <=4$$ and 0, elsewhere. Output sequence y(n) is {1, 2, 2.5, 3, 3, 3, 2, 1, 0}

My attempt was to write the convolving vector as a 9x9 matrix and divide the output, y(n), by the inverse of h(n)... but I don't think I am getting the correct answer.

h_n=[1 1/2 1/4 1/8 1/16 0 0 0 0; 0 1 1/2 1/4 1/8 1/16 0 0 0; 0 0 1 ...

1/2 1/4 1/8 1/16 0 0; 0 0 0 1 1/2 1/4 1/8 1/16 0; 0 0 0 0 1 1/2 ...

1/4 1/8 1/16; 1/16 0 0 0 0 1 1/2 1/4 1/8; 1/8 1/16 0 0 0 0 1 1/2 ...

1/4; 1/4 1/8 1/16 0 0 0 0 1 1/2; 1/2 1/4 1/8 1/16 0 0 0 0 1];

y_n=[1 2 2.5 3 3 3 2 1 0];

x_n = y_n/h_n^(-1);

1

There are 1 best solutions below

0
On

Some pointers.

  1. If I understand it correctly, you want h_n to be a small convolution matrix. A hint would be to build it in a more systematic way than you do. It would reduce the risk for typos and also make it easier to change it without having to change it in many places in the code which further increases risk of error.
  2. There are many ways you can try and do a deconvolution. Usually explicitly calculating inverse ("^-1") and then afterwards doing something is not numerically a good idea. It is better to postpone with algebra into matrix-vector division or multiplication (if possible).
  3. Is x_n supposed to be the convolved signal or the deconvolved signal? A good idea is generally to have the true value to test against. So first decide a signal to convolve with, do a convolution so you have both input and output and then try and work your way backwards. This way you will have a method to check your solution.