Example_2.m in nlms.rar


nlms algorithm and its examples to share with you, I hope everyone can help me m...Original Link
    Sponsored links

			
			clear;
alpha=0.5;  % Stepsize of NLMS
mu_lms=0.3; % Stepsize of LMS
M=5;
k=0:99;
x=cos(pi*k/100).*sin(pi*k/5);
b=[1,0,-1];
a=[1,1,0.9];
d=filter(b,a,x);
delta=0.05;
[e,w,mu_k]=nlms(alpha,M,x,d,delta);
[e_lms,w_lms]=lms(mu_lms,M,x,d);
[c,i]=max(mu_k);

%------------------------------------------------
subplot(3,1,1);
stem(k,x,'.');
hold on;
plot(k,cos(pi*k/100),'--','color','m');
title('Normalized LMS Method','fontsize',18)
ylabel('x(k)','fontsize',14);
grid on;
subplot(3,1,2);
stem(k,mu_k,'.');
text(i,c,'\leftarrow Peak Value');
ylabel('\mu(k)','fontsize',14);
grid on;
subplot(3,1,3);
stem(k,abs(e),'.');
ylabel('e(k)','fontsize',14);
xlabel('k','fontsize',14);
grid on;

%-------------------------------------------
mu_lms_vec=mu_lms*ones(1,100);
figure(2);
subplot(2,1,1);
stem(k,mu_k,'.');
ylim([0,10]);
title('Difference between NLMS and LMS','fontsize',18);
text(i,c,'\leftarrow Peak Value');
ylabel('\mu(k)','fontsize',14);
xlabel('NLMS','fontsize',14);
grid on;
subplot(2,1,2);
stem(k,mu_lms_vec,'.');
ylim([0,10]);
ylabel('\mu','fontsize',14);
xlabel('LMS','fontsize',14);
grid on;
%-------------------------------------------
y_nlms=filter(w,1,x);
y_lms=filter(w_lms,1,x);
% Compute the Frequency Response
D=fft(d);
Y_nlms=fft(y_nlms);
Y_lms=fft(y_lms);
f=0:0.01:0.99;

figure(3)
subplot(2,1,1);
plot(k,d,k,y_nlms,'r',k,y_lms,'g');
legend('The system H(z)','The Adaptive filter(NLMS)','The Adaptive filter(LMS)');
title('The waveform in time domain','fontsize',16);
ylabel('Amplitude','fontsize',14);
subplot(2,1,2);
plot(f,abs(D),f,abs(Y_nlms),'r',f,abs(Y_lms),'g');
legend('The system H(z)','The Adaptive filter(NLMS)','The Adaptive filter(LMS)');
title('Magnitude Response','fontsize',16);
xlabel('Normalized frequence','fontsize',12);
grid on;

figure(4)
subplot(2,1,1);
stem(k,abs(e),'.');
title('Error Comparison between NLMS and LMS','fontsize',18);
ylabel('e(k)','fontsize',14);
xlabel('NLMS','fontsize',14);
grid on;
subplot(2,1,2)
stem(k,abs(e_lms),'.')
ylabel('e(k)','fontsize',14);
xlabel('LMS','fontsize',14);
grid on;
			click here to download the whole source code package.

			
			


Project Files

    Sponsored links
NameSizeDate
 Example_2.m2.08 kB28-08-08 20:55
 nlms.m691.00 B28-08-08 20:54
 <nlms>0.00 B30-09-08 12:27
...

Related Items

    Sponsored links