Home » Source Code » » Example_2.m - nlms algorithm and its examples to share
Click here to see more ▼
Click here to hide ▲

Example_2.m - nlms algorithm and its examples to share


			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;
			
Expand> <Close
    Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
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
...
    Sponsored links

Related source codes

    Sponsored links
×

Login CodeForge

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com
×

Sorry, you don't have enough CF coins! ^_^|||

Fast channel (Get CF coins immediately):

10 CF coins (points) for $10.00 USD
22 CF coins (points) for20.00USD
55 CF coins (points) for50.00USD
120 CF coins (points) for100.00USD
Free channel :

Submit your source codes
You could get 1-10 CF coins
More……
×

切换到中文版?

×

Where are you going?

×

Tips

This user hasn't enable blog!