close all
%h = [0.04 -0.05 0.07 -0.21 -0.5 0.72 0.36 0 0.21 0.03 0.07];
%h = [1 2 1];
%h = [1 2 3 2 1];
h = [-2 -4 6 3];
N = 32;
%N = 16;
r = xcorr(h, N);
r = r(N+1:end);
R = toeplitz(r);
p = zeros(N+1, 1);
k0 = round((N-length(h))/2);
p(k0:k0+length(h)-1) = fliplr(h);
w = R\p;
subplot(1,2,1)
stem(w)
subplot(1,2,2)
stem(conv(h, w))
pause
% generation of signal
NX = 4000;
x = randsrc(NX, 1, [-3 -1 1 3]);
y = conv(x, h);
s_lms = initlms(zeros(N+1,1), 1/5/sum(h.^2)/(N+1));
s_lms_se = initse(zeros(N+1,1), 1/50/sum(h.^2)/(N+1));
s_lms_sd = initsd(zeros(N+1,1), 1/5/sum(h.^2)/(N+1));
s_lms_ss = initss(zeros(N+1,1), 1/5/sum(h.^2)/(N+1));
s_rls = initrls(zeros(N+1,1), eye(N+1), 1);
s_kalman = initkalman(zeros(N+1,1), eye(N+1), 0.01, zeros(N+1));
y = y(bitshift(N,-1)+1:end);
[x, y] = eqtflength(x, y);
[x1_lms, e_lms, s_lms] = adaptlms(y(1:1000), x(1:1000), s_lms);
[x1_lms_se, e_lms_se, s_lms_se] = adaptse(y, x, s_lms_se);
[x1_lms_sd, e_lms_sd, s_lms_sd] = adaptsd(y, x, s_lms_sd);
[x1_lms_ss, e_lms_ss, s_lms_ss] = adaptss(y, x, s_lms_ss);
[x1_rls, e_rls, s_rls] = adaptrls(y(1:1000), x(1:1000), s_rls);
[x1_kalman, e_kalman, s_kalman] = adaptkalman(y(1:1000), x(1:1000), s_kalman);
figure
subplot(2,1,1)
plot(e_lms)
title('LMS')
subplot(2,1,2)
plot(x1_lms,'.')
figure
subplot(2,1,1)
plot(e_lms_se)
title('LMS --- sign error')
subplot(2,1,2)
plot(x1_lms_se,'.')
figure
subplot(2,1,1)
plot(e_lms_sd)
title('LMS --- sign data')
subplot(2,1,2)
plot(x1_lms_sd,'.')
figure
subplot(2,1,1)
plot(e_lms_ss)
title('LMS --- sign sign')
subplot(2,1,2)
plot(x1_lms_ss,'.')
figure
subplot(2,1,1)
plot(e_rls)
title('RLS')
subplot(2,1,2)
plot(x1_rls,'.')
