# deconv

## 语法

``[x,r] = deconv(y,h)``
``[x,r] = deconv(y,h,shape)``
``[x,r] = deconv(___,Name=Value)``

## 说明

### 多项式长除法

``[x,r] = deconv(y,h)` 使用多项式长除法对向量 `y` 进行反卷积以消除 `h`，并返回商 `x` 和余数 `r`，以使 `y = conv(x,h) + r`。如果 `y` 和 `h` 是由多项式系数组成的向量，则对它们进行反卷积相当于将 `y` 表示的多项式除以 `h` 表示的多项式。`

### 最小二乘反卷积

``[x,r] = deconv(y,h,shape)` 指定卷积信号 `y` 的分段，其中 `y = conv(x,h,shape) + r`。如果使用最小二乘反卷积方法 (`Method="least-squares"`)，则您可以将 `shape` 指定为 `"full"`、`"same"` 或 `"valid"`。否则，如果使用默认长除法反卷积方法 (`Method="long-division"`)，则 `shape` 必须为 `"full"`。`
````[x,r] = deconv(___,Name=Value)` 支持上述语法中的任何输入参量组合，且可使用一个或多个名称-值参量指定选项。 您可以使用 `deconv(__,Method=algorithm)` 指定反卷积方法，其中 `algorithm` 可以是 `"long-division"` 或 `"least-squares"`。您还可以使用 `deconv(__,RegularizationFactor=alpha)` 将吉洪诺夫正则化因子指定为反卷积方法的最小二乘解。 ```

## 示例

```y = [2 7 4 9]; h = [1 0 1]; [x,r] = deconv(y,h)```
```x = 1×2 2 7 ```
```r = 1×4 0 0 2 2 ```

```N = 200; n = 0.1*(1:N); rng("default") x = 2*exp(-0.5*((n-10)).^2); h = 0.1*randn(1,length(x)); y = conv(x,h);```

```figure tiledlayout(3,1) nexttile plot(n,x) title("Original Signal") nexttile plot(n,h) title("Impulse Response") nexttile plot(0.1*(1:length(y)),y) title("Convolved Signal")```

```[x1,r1] = deconv(y,h); x1(end)```
```ans = 7.5992e+90 ```

`[x2,r2] = deconv(y,h,Method="least-squares");`

```figure tiledlayout(2,1) nexttile plot(n,x1) title("Deconvolved Signal Using ""long-division"" Method") nexttile plot(n,x2) title("Deconvolved Signal Using ""least-squares"" Method")```

```xin = [-1 2 3 -2 0 1 2]; h = [2 4 -1 1]; y = conv(xin,h,"same")```
```y = 1×7 15 5 -9 7 6 7 -1 ```

`[x,r] = deconv(y,h,"same",Method="least-squares")`
```x = 1×7 -1.0000 2.0000 3.0000 -2.0000 0.0000 1.0000 2.0000 ```
```r = 1×7 10-14 × 0 0.0888 0.1776 0 0 0 0 ```

```xin = [-1 2]; h = [2 5]; y = conv(xin,h,"valid")```
```y = -1 ```

`[x,r] = deconv(y,h,"valid",Method="least-squares")`
```x = 1×2 -0.1724 -0.0690 ```
```r = -3.3307e-16 ```

`yfull = conv(x,h,"full")`
```yfull = 1×3 -0.3448 -1.0000 -0.3448 ```

```N = 200; n = 0.1*(1:N); rng("default") x = 2*exp(-0.8*(n - 8).^2) - 4*exp(-2*(n - 10).^2); h = 2.*exp(-1*(n - 5).^2).*cos(4*n); y = conv(x,h); y = y + max(y)*0.05*randn(1,length(y));```

```figure tiledlayout(3,1) nexttile plot(n,x) title("Original Signal") nexttile plot(n,h) title("Impulse Response") nexttile plot(0.1*(1:length(y)),y) title("Convolved Signal with Added Noise")```

`[x1,r1] = deconv(y,h,Method="least-squares");`

```figure; tiledlayout(3,1); nexttile plot(n,x) title("Original Signal") nexttile plot(n,x1) title("Deconvolved Signal Without Regularization");```

`[x2,r2] = deconv(y,h,Method="least-squares",RegularizationFactor=1);`

```nexttile plot(n,x2) title("Deconvolved Signal Using Regularization")```

## 输入参数

• 如果 `y``h` 中有一个或两个都是 `single` 类型，则输出的类型也是 `single`。否则，输出的类型为 `double`

• 输入的长度应满足 `length(h) <= length(y)`。但是，如果 `length(h) > length(y)`，则 `deconv` 返回的输出为 `x = 0``r = y`

• `"full"`（默认值）- `y` 包含 `x``h` 的全卷积。

• `"same"` - `y` 包含与 `x` 大小相同的卷积的中心部分。

• `"valid"` - `y` 仅包含计算的没有补零边缘的卷积部分。使用此选项时，`length(y)``max(length(x)-length(h)+1,0)`，但 `length(h)` 为零时除外。如果 `length(h) = 0`，则 `length(y) = length(x)`

### 名称-值参数

• `"long-division"` - 通过多项式长除法（默认值）进行反卷积。

• `"least-squares"` - 通过最小二乘法进行反卷积，其中计算反卷积信号 `x` 以最小化残差信号的范数（或余数）`r`。也就是说，`x` 是最小化 `norm(y - conv(x,h))` 的解。

## 参考

[1] Nagy, James G. “Fast Inverse QR Factorization for Toeplitz Matrices.” SIAM Journal on Scientific Computing 14, no. 5 (September 1993): 1174–93. https://doi.org/10.1137/0914070.