Why would you force the filter to be symmetric and expect it to work?
Dirk
Reply by ldkha1979●July 28, 20052005-07-28
hi all,
i have to design an adaptive filter using Matlab. What i need is to
find a symmetric FIR filter from 2 signals, desired and input. I don't
know why my results cannot be converged. I'm using NLMS algorithm. Here
are my code. Can anyone help me to find my wrong part, or can give me a
suitable one? Thks so much
function h = adp_filter(d,x,f0)
% h = adp_filter(d,x,f0)
% Inputs:
% - d: desired signal
% - x: input
% - f0: initial values
% Outputs:
% - h: output coefficients
% This function is written for finding a FIR and symmetric filter
% Date: 27/7/2005
L = length(d);
l = length(f0);
l1 = (l + 1) / 2;
y = zeros(1,L); %output
e = zeros(1,L); %error
pa = zeros(1,L); %variance power
w = fliplr(f0(1:l1));%symmetric
alpha = 1/32;
for i = l1:(L - l1 + 1)
%calculate y(n)
y(i) = w(1) * x(i);
for j = 2:l1
y(i) = y(i) + w(j) * (x(i - j + 1) + x(i + j - 1));
end
%error
e(i) = d(i) - y(i);
%calculate variance power
if i == 1
pa(i) = max(1/i,1/16) * x(i) * x(i);
else
pa(i) = (1 - max(1/i,1/16)) * pa(i - 1) + max(1/i,1/16) * x(i)
* x(i);
end
%update coefficients
w(1) = w(1) + alpha * e(i) * x(i) / (pa(i) + 0.00001);
for j = 2:l1
w(j) = w(j) + alpha * e(i) * (x(i - j + 1) + x(i + j - 1)) /
(pa(i) + 0.00001);
end
end
h = [fliplr(w) w(2:l1)]; % symmetric
return