I want to compare the performance of a Wiener Filter and the Kalman filer to estimate the value of a constant $d$ using mesurements corrupted by a white noise. That is, my measurements are of the form $$x(n) = d + v(n)$$ where $v(n)$ have a normal distribution with mean $0$ and known variance $\sigma^2$.

Using the Kalman filter, I could put it on State Space form $$d(n+1) = d(n)$$ $$x(n) = d(n) + v(n)$$ and solve the problem. But I am having difficults to set the problem so I can solve with the Wiener filter. My desided signal is the constant signal $x$. My filter input is the measurements $x$. But I have doubts if I am doing something wrong, because my estimated signal is not a really good estimative of the desired response. I used the following matlab code:

function test()
    n = 0:511;
    d = 10 * ones(1,512);
    v = 0.5*randn(1,512);
    x = d + v;
    w = WienerFIRFilter(x, d, 12);
    y = filter(w', 1, x);

    hold on
    plot(y, 'r')

The function WienerFIRFilter is defined as following

function w=WienerFIRFilter(u,d,M) 
    aux = xcorr(d,u,'biased'); 
    p = aux(1,(length(aux)+1)/2:((length(aux)+1)/2)+M-1); 
    [U, R] = corrmtx(u,M-1);

enter image description here

Am I doing something wrong?

  • 2
    $\begingroup$ tangent: Do not use inv! Use the blackslash operator (mldivide or mrdivide). $\endgroup$
    – Memming
    Oct 10, 2016 at 11:58

1 Answer 1


You can use this code

 function w=WienerFIRFilter(input,desired,M) 
     r=auto_corr(M+1:end); % positive lags only
     R=toeplitz(r); %correlation matrix
  • $\begingroup$ Thanks for your answer. But can you tell me what am I doing wrong? It is not correct, since I've made it by evaluating the mean, but I cant see what is wrong in my algorithm. $\endgroup$
    – Giiovanna
    Oct 10, 2016 at 19:52
  • $\begingroup$ Your'e welcome @Giiovanna. $\endgroup$
    – msm
    Oct 11, 2016 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.