You are on page 1of 11

FILTRE FIR SI IIR

For the NLMS algorithm and FIR filter we used the the filter`s order of 3 and the step 0.2 , while for IIR
filter we used the order 10 and the step 0.001.

In the case of the RLS algorithm , for the FIR type of the filter we used the order 3 and for IIR we used
the order 15.

Codul Matlab :
%%
clear all
close all
clc

N=10000;

miu1 = 0.2;
miu2 = 0.001;
ord1=3;
ord2=10;

x1= randn(N,1);
x2= filter(1,[1,-1.2,0.8],randn(N,1));

d1= filter([1,-1.2,0.8],1,x1);
d2= filter([1,-1.2,0.8],1,x2);
d3= filter(1,[1,-0.8],x1);
d4= filter(1,[1,-0.8],x2);

[W1,E1] = nlms0(x1,d1,miu1,ord1);
[W2,E2] = nlms0(x1,d3,miu2,ord2);
[W3,E3] = nlms0(x2,d2,miu1,ord1);
[W4,E4] = nlms0(x2,d4,miu2,ord2);

figure(1), plot(W1),title('Semnal Gaussian ,FIR,NLMS'), ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(2),plot(E1),title('Semnal Gaussian ,FIR,NLMS'),xlabel('Numarul de
esantioane'),ylabel('Eroarea')

figure(3), plot(W2),title('Semnal Gaussian ,IIR,NLMS'),ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(4),plot(10*log10(E2.^2)),title('Semnal Gaussian
,IIR,NLMS'),xlabel('Numarul de esantioane'),ylabel('Eroarea [db]')

figure(5), plot(W3),title('Semnal AR ,FIR,NLMS'),ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(6),plot(E3),title('Semnal AR ,FIR,NLMS'),xlabel('Numarul de
esantioane'),ylabel('Eroarea')
figure(7), plot(W4),title('Semnal AR ,IIR,NLMS'),ylabel('Valoarea
coeficientilor'),xlabel('Numarul de esantioane')
figure(8),plot(10*log10(E4.^2)),title('Semnal AR ,IIR,NLMS'),xlabel('Numarul
de esantioane'),ylabel('Eroarea [db]')

%%
clear all
close all
clc

N=10000;

miu = 0.2;
%ord=3;
ord=15;
lam=0.9999;
delta = 0.001;

x1= randn(N,1);
x2= filter(1,[1,-1.2,0.8],randn(N,1));

d1= filter([1,-1.2,0.8],1,x1);
d2= filter([1,-1.2,0.8],1,x2);
d3= filter(1,[1,-0.8],x1);
d4= filter(1,[1,-0.8],x2);

[W5,E5] = rls0(x1,d1,delta,lam,ord);
[W6,E6] = rls0(x1,d3,delta,lam,ord);
[W7,E7] = rls0(x2,d2,delta,lam,ord);
[W8,E8] = rls0(x2,d4,delta,lam,ord);

figure(9),plot(W5),title('Semnal Gaussian ,FIR,RLS'), ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(10),plot(E5),title('Semnal Gaussian ,FIR,RLS'),xlabel('Numarul de
esantioane'),ylabel('Eroarea')

figure(11),plot(W6),title('Semnal Gaussian ,IIR,RLS'), ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(12),plot(10*log10(E6.^2)),title('Semnal Gaussian
,IIR,RLS'),xlabel('Numarul de esantioane'),ylabel('Eroarea [db]')

figure(13),plot(W7),title('Semnal AR ,FIR,RLS'), ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(14),plot(E7),title('Semnal AR ,FIR,RLS'),xlabel('Numarul de
esantioane'),ylabel('Eroarea')

figure(15),plot(W8),title('Semnal AR ,IIR,RLS'), ylabel('Valoarea


coeficientilor'),xlabel('Numarul de esantioane')
figure(16),plot(10*log10(E8.^2)),title('Semnal AR ,IIR,RLS'),xlabel('Numarul
de esantioane'),ylabel('Eroarea [db]')
%%
Functia nlms0 :

function [W,E]=nlms0(x,d,miu,ord)
N=length(x);
w=zeros(ord,1);
x1=zeros(ord,1);
E=zeros(N,1);
W=zeros(N,ord);
h = waitbar(0,'Please wait NLMS');
for n=1:N
x1=[x(n);x1(1:ord-1)];
mu=miu/(0.001+norm(x1)^2);
y=w'*x1;
E(n)=d(n)-y;
w=w+mu*x1*E(n)';
W(n,:)=w.';
waitbar(n/N,h)
end
close(h)

Functia rls0 :

function [W,E]=rls0(x,d,delta,lam,ord)

x=x(:);
d=d(:);
P=delta^(-1)*eye(ord);
w=zeros(ord,1);
x1=zeros(ord,1);
N=length(x);
W=zeros(N,ord);
E=zeros(N,1);

h = waitbar(0,'Please wait RLS');


for n=1:N
x1=[x(n);x1(1:ord-1)];
z=x1'*P;
k=(P*x1)/(lam+z*x1);
E(n)=d(n)-w'*x1;
w=w+k*E(n)';
P=1/lam*(P-k*z);
W(n,:)=w.';
waitbar(n/N,h)
end
close(h)

You might also like