1

我在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 的镜像。这肯定是不对的。

提前致谢。

4

1 回答 1

0

没问题。

我完全知道您要做什么。但是,如果你想要做的是获得一些信噪比,并试图通过一些线性一阶系统来模拟这些效果,你应该纠正你的PG多项式,如果是这样的话,这是完全错误的。键入help filter并查看AB定义。

这是正确的代码:

k = 1:100;
sigma = 0.1;
s1 = randn(1,100);
n1 = randn(1,100) * sigma;
Pnum = [0 0.1];
Pdenum = [1 -0.9];
Gnum = [0 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) * 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');

toeplitz 仍然存在病态。我就这样吧,因为你仍然可以玩得开心。这也很容易解决。

伙计们是真的。StackOverflow 不是为了解决你的作业,而是为了帮助你找到光明。

于 2014-09-13T21:18:30.697 回答