我在matlab中做了一个维纳滤波器模拟,但似乎我在代码中犯了一个错误,因为结果不正确。如果有人查看代码并指出错误,我将不胜感激。
这是代码:
k = 1:100;
sigma = 0.1;
s1 = randn(1,100);
n1 = randn(1,100) * sigma;
Pnum = [1 0.1];
Pdenum = [1 0.9];
Gnum = [1 0.9];
Gdenum = [1 0.1];
n = filter(Pnum, Pdenum, n1);
s = filter(Gnum, Gdenum, s1);
x = n + s;
rxx = xcorr(x);
rxs = xcorr(x,s);
toeplitz_rxx = toeplitz(rxx);
wopt = inv(toeplitz_rxx) * rxs;
wopt = inv(toeplitz_rxx) * transpose(rxs);
s_hat = filter(wopt,1,x);
error = x - s_hat; %this is where the wrong result is being calculated
plot(k,error, 'r',k,s_hat, 'b', k, x, 'g');
问题是计算出的误差正好是 s_hat 的镜像。这肯定是不对的。
提前致谢。