Home > other >  LMS adaptive filter matlab code problem (code for LMS filter design)
LMS adaptive filter matlab code problem (code for LMS filter design)

Time:09-20

% input parameters:
% xn input signal sequence (column)
% dn the desired response sequence (column)
% M filter order number (a scalar)
% mu convergence factor (step) (scalar) require greater than zero, less than the maximum eigenvalue of correlation matrix of xn reciprocal
% output parameters:
% W filter weight matrix (matrix)
% size for M x itr,
% en (itr x 1) error sequence (column)
% yn the actual output sequence (column)
The function [yn, W, en]=LMSfilter (xn, dn, M, mu)
Itr=length (xn);
En=zeros (itr, 1); % error sequence, en (k) when the first k iteration error of the expected output and the actual input
W=zeros (M, itr); % each line represents a weighted parameters, each column represents - iteration, the initial 0
% iteration calculation
For k=M: itr % iteration is the first k
X=xn (k: 1: k - M + 1); % M a tap input filter, as a vector
Y=W (:, k - 1). '* x; The output of the % filter
En (k)=dn (k) - y; The first k % iteration error
% filter weight calculation of iterative
W (:, k)=W (:, k - 1) + 2 * mu * en * x (k);
End
When the optimal filter output sequence r % o if no yn return parameter can not below
Yn=inf * ones (size (xn)); Infinite % inf mean
For k=M: length (xn)
X=xn (k: 1: k - M + 1);
Yn (k)=W (:, end). '* x; % with finally get the best estimate of get output
End



This is a code, bosses, I mainly there are two problems not understand:

1. Yn=inf * ones (size (xn)); This line of code is for what purpose, I didn't see

2. It is time for the same signal this code, so you can use the last iteration as the optimal filter, but if is for time-varying signal, should change to yn (k)=W (:, k). '* x; Ah? But obviously didn't convergence completely the first part, the error is bigger, how top oh?
  • Related