你不能只使用伪逆吗?这将意味着而不是:
h^=(XTX)−1XTy
你用
h^pseudo=(XTX)†XTy
或者
h^pseudo2=X†y
下图显示了当我在 python 中做一个简短的例子时会发生什么(下面的代码)。这x在这种情况下只是一个正弦曲线。虽然长度可能太短,但它仍然给出了一个不错的答案,而inv
(通常的逆)由于奇异性而有问题XTX.
下面的代码
from numpy import random, zeros, arange, cos
from scipy import pi
from scipy.linalg import toeplitz, inv, pinv
from pylab import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show, subplot
N = 5
h = [0.2,1,-1,0.6,1]
# x = random.normal(0, 0.01, N)
x = cos(2*pi*0.01234*arange(N) + 2*pi*random.uniform(-1,1))
X = toeplitz(x, zeros(N)) # Need to in fill with zeros.
H = toeplitz(h, zeros(N)) # Need to in fill with zeros.
y = H @ x
y2 = X @ h
h_hat = pinv(X.transpose() @ X) @ X.transpose() @ y
h_hat2 = pinv(X.transpose() @ X) @ X.transpose() @ y2
h_hat3 = pinv(X) @ y
figure(1, figsize=(20, 6))
subplot(1, 3, 1)
plot(h)
title("True FIR filter")
subplot(1, 3, 2)
plot(y)
plot(y2,'r.')
title("$\mathbf{Xh}$ (red) and $\mathbf{Hx}$ (blue) of filter")
subplot(1, 3, 3)
plot(h)
plot(h_hat,'ro')
plot(h_hat2,'g.')
plot(h_hat3,'k+',markersize=10)
title("True (blue) and estimated (red) filter just pseudo +")