0% found this document useful (0 votes)
97 views

Code RLS, Lms

This document discusses using an adaptive filter to estimate an unknown system based on an input signal and desired output signal. It generates random input data, applies it to an unknown FIR system with added noise to create the desired output. It then uses an LMS adaptive filter to estimate the unknown system based on minimizing the error between the filter output and desired output over time. Plots show the desired output, estimated output, and error converging as the adaptive filter learns the unknown system.

Uploaded by

Bui Nhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Code RLS, Lms

This document discusses using an adaptive filter to estimate an unknown system based on an input signal and desired output signal. It generates random input data, applies it to an unknown FIR system with added noise to create the desired output. It then uses an LMS adaptive filter to estimate the unknown system based on minimizing the error between the filter output and desired output over time. Plots show the desired output, estimated output, and error converging as the adaptive filter learns the unknown system.

Uploaded by

Bui Nhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

h a n g e Pro h a n g e Pro

XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
X n hi u ch nghi Ch ng II
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr e tr re
ar
.

.
ac ac
k e r- s o ft w k e r- s o ft w a

K t n i h th ng ch a bi t v i b l c thch nghi nh hnh v .


Cho x tc ng ln c 2 h th ng
So snh u ra c a 2 h th ng, nh n c l i e_lms
e_lms c c ti u => h th ng ch a bi t c th m t b ng b l c FIR
ng v i tr ng thi cu i cng c a l c thch nghi.
:
>> x = randn(1,500); % u vo b l c
>> b = fir1(31,0.5); % H th ng c n nh n d ng c c u trc FIR
>> n = 0.1*randn(1,500); % Nhi u
>> d = filter(b,1,x)+n; % Tn hi u tham chi u (Desired signal)
>> mu = 0.008; %B c thch nghi LMS.
>> ha = adaptfilt.lms(32,mu);% L y ra it ng LMS
>> [y,e] = filter(ha,x,d); % L c thch nghi b ng thu t ton LMS
>> subplot(2,1,1); plot(1:500,[d;y;e]); % V th
>> title('Cac tin hieu');
>> legend('Desired','Output','Error');
>> xlabel('Thoi gian'); ylabel('Tin hieu');
>> subplot(2,1,2); stem([b.',ha.coefficients.']);
>> legend('Dung','Uoc luong');

66
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
X n hi u ch nghi Ch ng II
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr e tr re
ar
.

.
ac ac
k e r- s o ft w k e r- s o ft w a

>> xlabel('Cac mau cua dap ung xung'); ylabel('Do lon'); grid on;

Cac tin hieu


4
Desired
2 Output
Tin hieu

Error
0

-2

-4
0 50 100 150 200 250 300 350 400 450 500
Thoi gian

0.6
Dung
0.4 Uoc luong
Do lon

0.2

-0.2
0 5 10 15 20 25 30 35
Cac mau cua dap ung xung

i t p 2.6. M ng kh nhi u thch nghi trong Matlab s ng thu t n


RLS.

N p 1 o n m thanh:
>> load mtlb;
L p l i 10 l n:

67
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
X n hi u ch nghi Ch ng II
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr e tr re
ar
.

.
ac ac
k e r- s o ft w k e r- s o ft w a

>> s=repmat(mtlb,10,1);
V th :
>> subplot(3,1,1)
>> plot(s(1:length(mtlb)));title('Tin hieu goc');
Nghe n m thanh:
>> soundsc(s,Fs)
T o t p tr ng phn b chu n:
>> noise=randn(length(s),1);
T o nhi u 1:
>> noise1=filter([1 1],1,noise);
T o nhi u 2:
>> noise2=filter([1 -1],1,noise);
T o tn hi u c ng nhi u:
>> sn=s+noise1;
V th :
>> subplot(3,1,2);
>> plot(sn(1:length(mtlb)));title('Tin hieu+ nhieu');
Nghe n hi u l n nhi u:
>> soundsc(sn,Fs)
L y ra it ng l c thch nghi rls:
>> ha1=adaptfilt.rls(16)
ha1 =
Algorithm: 'Direct-Form FIR RLS Adaptive Filter'
FilterLength: 16
ForgettingFactor: 1
KalmanGain: [] ;
PersistentMemory: false
Ch n l c tn hi u nhi u v i thu t ton rls:
>> [y,e]=filter(ha1,noise2,sn);

68
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
X n hi u ch nghi Ch ng II
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr e tr re
ar
.

.
ac ac
k e r- s o ft w k e r- s o ft w a

V c :
>> subplot(3,1,3);
>> plot(e(1:length(mtlb)));title('Loi = Tin hieu sau loc');
Nghe m thanh sau c:
>> soundsc(e,Fs)
c tnh xung ng v i tr ng thi sau cng c a b l c:
>> b=impz(ha1)
b= 0.8832 1.7683 1.6532 1.5340 1.4144 1.2986 1.1840 1.0682
0.9512 0.8344 0.7177 0.5988 0.4803 0.3628 0.2430 0.1211

Tin hieu goc


5

-5
0 500 1000 1500 2000 2500 3000 3500 4000 4500
Tin hieu+ nhieu
10

-10
0 500 1000 1500 2000 2500 3000 3500 4000 4500
Loi = Tin hieu sau loc
5

-5
0 500 1000 1500 2000 2500 3000 3500 4000 4500

i t p 2.7. Hi u ch nh tn hi u b bi n d ng b i knh truy n:


>> h=[ -2 -4 6 3];% p ng xung a knh
>> NX=4000; % S m u n hi u
>> levels=[ -3 -1 1 3]; % c m c n hi u
>> x= randsrc(NX,1,levels); % o n hi u ng u nhin

69
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
X n hi u ch nghi Ch ng II
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr e tr re
ar
.

.
ac ac
k e r- s o ft w k e r- s o ft w a

>> y=conv(x,h); % n hi u u ra knh truy n


>> N=32; % i a c ch nghi
>> mu=1/var(levels,1)/sum(h.^2)/N;%B c ch nghi
>> ha_lms=adaptfilt.lms(N,mu); % it ng LMS
>> y=y(round(N/2)+1:end); % i n hi u ra
>> [x,y]=eqtflength(x,y); % Cho i a y b ng ax
>> [x1_lms,e_lms]=filter(ha_lms,y(1:1000),x(1:1000)); % c ch nghi
>> subplot(2,1,1);
>> plot(e_lms); title(Loi loc);
>> subplot(2,1,1);
>> plot(x1_lms); title(Tin hieu ra);
L i c n hi u ra c cho nh d i. th nh n th y l i c m
d n t i 0 theo ti n nh ch nghi.
Loi loc
4

-2

-4
0 100 200 300 400 500 600 700 800 900 1000

Tin hieu ra
4

-2

-4
0 100 200 300 400 500 600 700 800 900 1000

70

You might also like