- % RLS 算法
- <br>randn('seed', 0) ;
- <br>rand('seed', 0) ;
- <br>
- <br>NoOfData = 8000 ; % Set no of data points used for training
- <br>Order = 32 ; % Set the adaptive filter order
- <br>
- <br>Lambda = 0.98 ; % Set the forgetting factor
- <br>Delta = 0.001 ; % R initialized to Delta*I
- <br>
- <br>x = randn(NoOfData, 1) ;% Input assumed to be white
- <br>h = rand(Order, 1) ; % System picked randomly
- <br>d = filter(h, 1, x) ; % Generate output (desired signal)
- <br>
- <br>% Initialize RLS
- <br>
- <br>P = Delta * eye ( Order, Order ) ;
- <br>w = zeros ( Order, 1 ) ;
- <br>
- <br>% RLS Adaptation
- <br>
- <br>for n = Order : NoOfData ;
- <br>
- <br>u = x(n:-1:n-Order+1) ;
- <br>pi_ = u' * P ;
- <br>k = Lambda + pi_ * u ;
- <br>K = pi_'/k;
- <br>e(n) = d(n) - w' * u ;
- <br>w = w + K * e(n) ;
- <br>PPrime = K * pi_ ;
- <br>P = ( P - PPrime ) / Lambda ;
- <br>w_err(n) = norm(h - w) ;
- <br>
- <br>end ;
- <br>
- <br>% Plot results
- <br>
- <br>figure ;
- <br>plot(20*log10(abs(e))) ;
- <br>title('Learning Curve') ;
- <br>xlabel('Iteration Number') ;
- <br>ylabel('Output Estimation Error in dB') ;
- <br>
- <br>figure ;
- <br>semilogy(w_err) ;
- <br>title('Weight Estimation Error') ;
- <br>xlabel('Iteration Number') ;
- <br>ylabel('Weight Error in dB') ;
- <br>
复制代码
|