Advanced Digital Signal Processing Lab
Advanced Digital Signal Processing Lab
ADSP Lab
1
INDEX
To write MATLAB code for random number generation and plot it.
2 7
2
To write MATLAB code to downsample an input sequence by a factor
11 M=3 with a frequency of 0.042 Hz. 30
ADDITIONAL TASKS/PROGRAMS
14 34
3
EXPERIMENT-1
Exercises:
>> a=[1 2 3 4 5 6]
a=
1 2 3 4 5 6
>> b=a+2
b=
3 4 5 6 7 8
>> plot(b)
7.5
6.5
5.5
4.5
3.5
3
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
4
>> bar(b)
0
1 2 3 4 5 6
5
pounds
0
1 2 3 4 5 6
s a m p le #
5
>> plot(b,'*')
7.5
6.5
5.5
4.5
3.5
3
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
10
0
0 1 2 3 4 5 6 7 8 9 10
6
EXPERIMENT-2
AIM: To write MATLAB code for random number generation and plot it.
Code:
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
1 2 3 4 5 6 7 8 9 10
7
EXPERIMENT-3
AIM: To write MATLAB code for waveform addition and plot it.
Code:
>> fs=100;
>> t=[1:100]/fs;
>> a1=input('enter value of amplitude a1:=');
enter value of amplitude a1:=5
>> a2=input('enter value of amplitude a2:=');
enter value of amplitude a2:=10
>> a3=input('enter value of amplitude a3:=');
enter value of amplitude a3:=15
>> s1=a1*sin(2*pi*t*5);
>> s2=a1*sin(2*pi*t*15);
>> s3=a1*sin(2*pi*t*30);
>> subplot(2,2,1);
>> plot(s1);
>> xlabel('sine waveform with frequency=5 hz');
>> ylabel('amplitude');
>> subplot(2,2,2);
>> plot(s2);
>> xlabel('sine waveform with frequency=15 hz');
>> ylabel('amplitude');
>> subplot(2,2,3);
>> plot(s3);
>> xlabel('sine waveform with frequency=30 hz');
>> ylabel('amplitude');
>> subplot(2,2,4);
>> s4=s1+s2+s3;
>> plot(s4);
>> xlabel('addition of three sine waves');
>> ylabel('amplitude');
8
5 5
amplitude
amplitude
0 0
-5 -5
0 50 100 0 50 100
sine waveform with frequency=5 hz sine waveform with frequency=15 hz
5 20
10
amplitude
amplitude
0 0
-10
-5 -20
0 50 100 0 50 100
sine waveform with frequency=30 hz addition of three sine waves
9
EXPERIMENT-4
AIM: To write MATLAB code for folding a sequence and plot it.
Code:
>> n=[-5:5];
>> x=[10:-1:0];
>> subplot(2,1,1);
>> stem(n,x);
>> title('the original sequence');
>> xlabel('samples n');
>> ylabel('x(n)');
>> y=fliplr(x);
>> subplot(2,1,2);
>> stem(n,y);
>> title('the folded sequence x(n)');
>> xlabel('samples n');
>> ylabel('x(-n)');
6
x(n)
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
sam ples n
the folded sequence x(n)
10
5
x(-n)
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
sam ples n
10
EXPERIMENT-5
Code:
>> ns=input('enter the ending point of the sequence if it is not from n=0:=');
enter the ending point of the sequence if it is not from n=0:=10
>> n=[ns:ne];
>> u=[(n-ns)>=0];
>> subplot(2,2,1);
>> stem(n,u);
>> title('sample n');
>> ylabel('u(n)');
>> e=a*exp(n);
>> subplot(2,2,2);
>> stem(n,e);
>> title('exponential signal e=(a^n)');
>> xlabel('sample n');
>> ylabel('e=(a^n)');
>> m=u.*e;
>> subplot(2,1,2);
>> stem(n,m);
>> title('multiplied signal m=u*e');
>> xlabel('samples n');
>> ylabel('m=a*exp(n).*u');
11
n
sample n x 10exponential signal e=(a )
8
1 6
e=(an)
u(n) 0.5
2
0 0
10 15 20 10 15 20
sample n
x 10
8 multiplied signal m=u*e
5
4
m=a*exp(n).*u
0
10 11 12 13 14 15 16 17 18 19 20
samples n
12
EXPERIMENT-6
Code:
>> ns=input('enter the ending point of the sequence if it is not from n=0:=');
enter the ending point of the sequence if it is not from n=0:=5
>> ne=input('enter the ending point of the sequence:=');
enter the ending point of the sequence:=12
>> n=[ns:ne];
>> u=[(n-ns)>=0];
>> stem(n,u);
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
5 6 7 8 9 10 11 12
13
EXPERIMENT-7
Code:
>> x=exp(complex(sigma,w).*n)
x=
-1.6733e+004 +1.4324e+004i
n=
2 4
1 3
>> x=exp(complex(sigma,w).*n)
x=
1.0e+003 *
14
>> plot(x,n)
Warning: Imaginary parts of complex X and/or Y arguments ignored
3.5
2.5
1.5
1
-500 0 500 1000 1500 2000 2500 3000
15
EXPERIMENT-8
Code:
a.Design of a low pass filter with cutoff frequency 0.6*pi radians per samples
(with filter order specified)
>> fc=0.6;
>> N=20;
>> Hf=fdesign.lowpass('N,fc',N,fc);
>> hd(1)=design(Hf,'window','window',@hamming);
>> hd(2)=design(Hf,'window','window',{@chebwin,50});
>> hfvt=fvtool(hd);
>> legend(hfvt,'hamming window design','dolph chebyshev window design');
-20
-30
Magnitude (dB)
-40
-50
-60
-70
16
b.(Without specifying filter order)
>> fp=0.6;
>> fst=0.7725;
>> fc=(fp+fst)/2;
>> Ap=0.01;
>> Ast=90;
>> setspecs(Hf,'fp,fst,Ap,Ast',fp,fst,Ap,Ast);
>> Hd(4)=design(Hf,'Kaiserwin');
>> hfvt=fvtool(Hd(4));
-20
-40
Magnitude (dB)
-60
-80
-100
17
c.Optimal Filter Design
>> Hd(5)=design(Hf,'equiripple');
>> hfvt=fvtool(Hd(4:5));
>> legend(hfvt,'Kaiser Window Design,Filter order 68','Equiripple Design,Filter Order 53')
Magnitude Response (dB)
-40
Magnitude (dB)
-60
-80
-100
>> N=20;
>> setspecs(Hf,'N,fc,Ap,Ast',N,fc,Ap,Ast);
>> Hd(6)=design(Hf,'equiripple');
>> hfvt=fvtool(Hd(5:6));
>> legend(hfvt,'Equiripple design,53 coefficients','Equiripple design,20 coefficients')
18
Magnitude Response (dB)
-10
-20
Equiripple design,53 coefficients
Equiripple design,20 coefficients
-30
-40
Magnitude (dB)
-50
-60
-70
-80
-90
-100
>> setspecs(Hf,'N,fp,fst',N,fp,fst);
>> Hd(7)=design(Hf,'Equiripple');
>> measure(Hd(7))
ans =
>> hfvt=fvtool(Hd(5),Hd(7));
>> legend(hfvt,'Equiripple design,53 coefficients','Equiripple design,20 coefficients')
19
Magnitude Response (dB)
-10
-20
Equiripple design,53 coefficients
Equiripple design,20 coefficients
-30
-40
Magnitude (dB)
-50
-60
-70
-80
-90
-100
>> Hd(8)=design(Hf,'Equiripple','Wstop',5);
>> measure(Hd(8))
ans =
>> hfvt=fvtool(Hd(7:8));
20
>> legend(hfvt,'passband weight=1,Stopband weight=1','Passband weight=1,Stopband
weight=5')
-15
-20
Magnitude (dB)
-25
-30
-35
-40
-45
-50
>> setspecs(Hf,'N,fp,fst,Ast',N,fp,fst,Ast);
>> Hd(9)=design(Hf,'Equiripple');
>> hfvt=fvtool(Hd(8:9));
>> legend(hfvt,'Equiripple design using weights','Equripple design constraining the stopband')
21
Magnitude Response (dB)
-10
-20
Equiripple design using w eights
Equripple design constraining the stopband
-30
-40
Magnitude (dB)
-50
-60
-70
-80
-90
-100
22
EXPERIMENT-9
Code:
>> N=8;
>> f3db=0.4;
>> d=fdesign.lowpass('N,f3db',N,f3db);
>> Hbutter=design(d,'butter');
>> hfvt=fvtool([Hbutter]);
Magnitude Response (dB)
-20
-40
-60
-80
Magnitude (dB)
-100
-120
-140
-160
-180
-200
b.Chebyshev type 1
>> Ap=0.5;
>> setspecs(d,'N,f3db,Ap',N,f3db,Ap);
>> Hcheby1=design(d,'cheby1');
>> hfvt=fvtool([Hbutter,Hcheby1],'color','white');
>> legend(hfvt,'Butterworth','Chebyshev Type 1');
23
Magnitude Response (dB)
-50
-100
Magnitude (dB)
-150
Butterworth
Chebyshev Type 1
-200
c.Chebyshev type II
>> Ast=80;
>> setspecs(d,'N,f3db,Ast',N,f3db,Ast);
>> Hcheby2=design(d,'Cheby2');
>> set(hfvt,'filters',[Hbutter;Hcheby2]);
>> legend(hfvt,'Butterworth','Chebyshev Type II');
24
Magnitude Response (dB)
-20
-40
-60
Butterworth
Chebyshev Type II
-80
Magnitude (dB)
-100
-120
-140
-160
-180
-200
d.Elliptic Filter
>> setspecs(d,'N,f3db,Ap,Ast',N,f3db,Ap,Ast);
>> Hellip=design(d,'Ellip');
>> set(hfvt,'Filters',[Hbutter,Hcheby1,Hcheby2,Hellip]);
>> axis([0 1 -90 2])
>> legend(hfvt,'Butterworth','Chebyshev Type I','Chebyshev Type II','Elliptic');
>>
25
Magnitude Response (dB)
-10
-40
Magnitude (dB)
-50
-60
-70
-80
-90
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency (×π rad/sample)
After Zoom
-0.5
-1
Butterw orth
Chebyshev Type I
-1.5
Chebyshev Type II
Elliptic
-2
Magnitude (dB)
-2.5
-3
-3.5
-4
-4.5
-5
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4
Normalized Frequency (×π rad/sample)
26
e.Group delay analysis
>> set(hfvt,'Analysis','grpdelay');
Group Delay
45
40
35
30
Group delay (in samples)
Butterw orth
25
Chebyshev Type I
Chebyshev Type II
20 Elliptic
15
10
>> fp=0.1;fst=0.3;Ap=1;Ast=60;
>> setspecs(d,'fp,fst,Ap,Ast',fp,fst,Ap,Ast);
>> Hd=design(d,'alliir');
>> set(hfvt,'Filters',Hd,'Analysis','magnitude','Designmask','On');
>> axis([0 1 -70 2])
>> legend(hfvt,'Butterworth','Chebyshev Type I','Chebyshev Type II','Elliptic');
27
Magnitude Response (dB)
-10
-20
-30 Butterworth
Magnitude (dB)
Chebyshev Type I
Chebyshev Type II
Elliptic
-40
-50
-60
-70
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency (×π rad/sample)
>> order(Hd)
ans =
7 5 5 4
28
EXPERIMENT-10
Code:
0.8
0.6
0.4
0.2
0
1 1.5 2 2.5 3 3.5 4 4.5 5
0.8
0.6
0.4
0.2
0
0 5 10 15
29
EXPERIMENT-11
Code:
0.5
-0.5
-1
0 2 4 6 8 10 12 14 16 18 20
0.5
-0.5
-1
1 2 3 4 5 6 7
30
EXPERIMENT-12
Code:
1.Butterworth Filter
>> N=8;
>> f3db=0.4;
>> d=fdesign.lowpass('N,f3db',N,f3db);
>> Hbutter=design(d,'butter');
>> hfvt=fvtool([Hbutter]);
>> cost(Hbutter)
ans =
Number of Multipliers : 17
Number of Adders : 16
Number of States :8
MultPerInputSample : 17
AddPerInputSample : 16
2.Chebyshev-1
>> Ap=0.5;
>> setspecs(d,'N,f3db,Ap',N,f3db,Ap);
>> Hcheby1=design(d,'cheby1');
>> hfvt=fvtool([Hbutter,Hcheby1],'color','white');
>> cost(Hcheby1)
ans =
Number of Multipliers : 17
Number of Adders : 16
Number of States :8
MultPerInputSample : 17
AddPerInputSample : 16
31
EXPERIMENT-13
Code:
>> n=(1:1000)';
>> s=sin(0.075*pi*n);
>> v=0.8*randn(1000,1);
>> ar=[1,0.5];
>> v1=filter(1,ar,v);
>> x=s+v1;
>> ma=[1,-0.8,0.4,-0.2];
>> v2=filter(ma,1,v);
>> L=7;
>> hlms=adaptfilt.lms(7);
>> hnlms=adaptfilt.nlms(7);
>> [mumaxlms,mumaxmselms]=maxstep(hlms,x);
Warning: Step size is not in the range 0 < mu < mumaxmse/2:
Erratic behavior might result.
> In adaptfilt.lms.maxstep at 32
>> [mumaxlms,mumaxmsenlms]=maxstep(hnlms);
>> [ylms,elms]=filter(hlms,v2,x);
>> [ynlms,enlms]=filter(hnlms,v2,x);
>> bw=firwiener(L-1,v2,x);
>> yw=filter(bw,1,v2);
>> ew=x-yw;
>> plot(n(900:end),[ew(900:end),elms(900:end),enlms(900:end)]);
>> legend('wiener filter denoised sinusoid','NLMS denoised sinusoid','LMS
denoised sinusoid');
>> xlabel('time index (n)');
>> ylabel('amplitude');
>> [bw.' hlms.coefficients.' hnlms.coefficients.']
ans =
32
4
wiener filter denoised sinusoid
NLMS denoised sinusoid
LMS denoised sinusoid
3
1
amplitude
-1
-2
-3
-4
900 910 920 930 940 950 960 970 980 990 1000
time index (n)
33
ADD ON PROGRAMS
Matlab Basics
>>t=linspace(1,10,10)
t=
1 2 3 4 5 6 7 8 9 10
>> sin(t)
ans =
Columns 1 through 9
Column 10
-0.5440
>> x=t.*sin(t)
x=
Columns 1 through 9
Column 10
-5.4402
>> t.^2
ans =
1 4 9 16 25 36 49 64 81 100
34
>> z=sin(t.^2)
z=
Columns 1 through 9
Column 10
-0.5064
>> a=[1,2;3,4]
a=
1 2
3 4
>> nthroot(a,3)
ans =
1.0000 1.2599
1.4422 1.5874
35
Program to plot sine wave
x=linspace(0,2*pi,100);
>> y=sin(x);
>> plot(x,y)
>> title('plot created by gaurav')
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
36
Generation of delayed sine wave
>> t=0:pi/100:2*pi;
>> a=1;
>> y=a*sin(t);
>> y1=a*sin(t-0.25);
>> y1=a*sin(t-0.5);
>> y1=a*sin(t-0.25);
>> y2=a*sin(t-0.5);
>> y3=a*sin(t+0.25);
>> y4=a*sin(t+0.5);
>> plot(t,y,t,y1,t,y2,t,y3,t,y4);
>> grid on;
>> xlabel('time');
>> ylabel('amplitude');
0.8
0.6
0.4
0.2
amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
time
37
FIR Filter
a. Design of a low pass filter with cutoff frequency 0.4*pi radians per samples
(with filter order specified)
>> fc=0.4;
>> N=25;
>> Hf=fdesign.lowpass('N,fc',N,fc);
>> hd(1)=design(Hf,'window','window',@hamming);
>> hd(2)=design(Hf,'window','window',{@chebwin,50});
>> hfvt=fvtool(hd);
>> legend(hfvt,'hamming window design','dolph chebyshev window design');
-10
hamming w indow design
dolph chebyshev w indow design
-20
-30
Magnitude (dB)
-40
-50
-60
-70
38
b.Without specifying filter order
>> fp=0.3;
>> fst=0.3725;
>> fc=(fp+fst)/2;
>> Ap=0.05;
>> Ast=100;
>> setspecs(Hf,'fp,fst,Ap,Ast',fp,fst,Ap,Ast);
>> Hd(4)=design(Hf,'Kaiserwin');
>> hfvt=fvtool(Hd(4));
-20
-40
-60
Magnitude (dB)
-80
-100
-120
-140
-160
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
39
c.Optimal Filter Design
>> Hd(5)=design(Hf,'equiripple');
>> hfvt=fvtool(Hd(4:5));
>> legend(hfvt,'Kaiser Window Design,Filter order 68','Equiripple Design,Filter
Order 53')
-20
Kaiser Window Design,Filter order 68
Equiripple Design,Filter Order 53
-40
-60
Magnitude (dB)
-80
-100
-120
-140
-160
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
40
d.Controlling filter parameters
>> N=10;
>> setspecs(Hf,'N,fc,Ap,Ast',N,fc,Ap,Ast);
>> Hd(6)=design(Hf,'equiripple');
>> hfvt=fvtool(Hd(5:6));
>> legend(hfvt,'Equiripple design,53 coefficients','Equiripple design,20
coefficients')
-20
-40
Magnitude (dB)
-60
-80
-100
41
e.Transition Width Control
>> setspecs(Hf,'N,fp,fst',N,fp,fst);
>> Hd(7)=design(Hf,'Equiripple');
>> measure(Hd(7))
ans =
>> hfvt=fvtool(Hd(5),Hd(7));
>> legend(hfvt,'Equiripple design,53 coefficients','Equiripple design,20
coefficients')
-20
-40
Magnitude (dB)
-60
-80
-100
42
f.Stop Band Attenuation Control
>> Hd(8)=design(Hf,'Equiripple','Wstop',50);
>> measure(Hd(8))
ans =
>> hfvt=fvtool(Hd(7:8));
>> legend(hfvt,'passband weight=1,Stopband weight=1','Passband
weight=1,Stopband weight=50')
0
passband w eight=1,Stopband w eight=1
Passband w eight=1,Stopband w eight=50
-10
Magnitude (dB)
-20
-30
-40
-50
43
g.No control over passband ripples
>> setspecs(Hf,'N,fp,fst,Ast',N,fp,fst,Ast);
>> Hd(9)=design(Hf,'Equiripple');
>> hfvt=fvtool(Hd(8:9));
>> legend(hfvt,'Equiripple design using weights','Equripple design constraining the
stopband')
-40
Magnitude (dB)
-60
-80
-100
44
IIR Filters
>> N=80;
>> f3db=0.8;
>> d=fdesign.lowpass('N,f3db',N,f3db);
>> Hbutter=design(d,'butter');
>>hfvt=fvtool([Hbutter]);
-100
-200
-300
Magnitude (dB)
-400
-500
-600
-700
-800
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
45
b.Chebyshev type 1
>> Ap=50;
>> setspecs(d,'N,f3db,Ap',N,f3db,Ap);
>> Hcheby1=design(d,'cheby1');
hfvt=fvtool([Hbutter,Hcheby1],'color','white');
legend(hfvt,'Butterworth','Chebyshev Type 1');
-200
Butterw orth
-400
Chebyshev Type 1
Magnitude (dB)
-600
-800
-1000
-1200
46
c.Chebyshev type II
>> Ast=80;
>> setspecs(d,'N,f3db,Ast',N,f3db,Ast);
>> Hcheby2=design(d,'Cheby2');
>> set(hfvt,'filters',[Hbutter;Hcheby2]);
>> legend(hfvt,'Butterworth','Chebyshev Type II');
-100
-200
Butterw orth
Chebyshev Type II
-300
Magnitude (dB)
-400
-500
-600
-700
-800
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
47
d.Elliptic Filter
>> setspecs(d,'N,f3db,Ap,Ast',N,f3db,Ap,Ast);
>> Hellip=design(d,'Ellip');
??? Error using ==> feval
Error using ==> fdesign.abstracttype.ellip at 19
The filter must be stable.
>> Ast=800;
>> setspecs(d,'N,f3db,Ast',N,f3db,Ast);
>> Hcheby2=design(d,'Cheby2');
set(hfvt,'filters',[Hbutter;Hcheby2]);
legend(hfvt,'Butterworth','Chebyshev Type II');
-100
-200
Butterw orth
Chebyshev Type II
-300
Magnitude (dB)
-400
-500
-600
-700
-800
>> setspecs(d,'N,f3db,Ap,Ast',N,f3db,Ap,Ast);
>> Hellip=design(d,'Ellip');
??? Error using ==> feval
Error using ==> fdesign.abstracttype.ellip at 19
Frequency value from the prototype filter must be between 0 and 1.
48
MATLAB code to design an adaptive filter to extract a desired signal from
noise corrupted signal by cancelling the noise.
1. With ar=[1,0.8];
>> n=(1:1000)';
>> s=sin(0.075*pi*n);
>> v=0.8*randn(1000,1);
>> ar=[1,0.8];
>> v1=filter(1,ar,v);
>> x=s+v1;
>> ma=[1,-0.8,0.4,-0.2];
>> v2=filter(ma,1,v);
>> L=7;
>> hlms=adaptfilt.lms(7);
>> hnlms=adaptfilt.nlms(7);
>> [mumaxlms,mumaxmselms]=maxstep(hlms,x);
>> [mumaxlms,mumaxmsenlms]=maxstep(hnlms);
>> [ylms,elms]=filter(hlms,v2,x);
>> [ynlms,enlms]=filter(hnlms,v2,x);
>> bw=firwiener(L-1,v2,x);
>> yw=filter(bw,1,v2);
>> ew=x-yw;
>> plot(n(900:end),[ew(900:end),elms(900:end),enlms(900:end)]);
>> legend('wiener filter denoised sinusoid','NLMS denoised sinusoid','LMS
denoised sinusoid');
>> xlabel('time index (n)');
>> ylabel('amplitude');
>> [bw.' hlms.coefficients.' hnlms.coefficients.']
ans =
49
3
wiener filter denoised sinusoid
NLMS denoised sinusoid
LMS denoised sinusoid
0
amplitude
-1
-2
-3
-4
900 910 920 930 940 950 960 970 980 990 1000
time index (n)
2. With ar=[1,0.2];
>> n=(1:1000)';
>> s=sin(0.075*pi*n);
>> v=0.8*randn(1000,1);
>> ar=[1,0.2];
>> v1=filter(1,ar,v);
>> x=s+v1;
>> ma=[1,-0.8,0.4,-0.2];
>> v2=filter(ma,1,v);
>> L=7;
>> hlms=adaptfilt.lms(7);
>> hnlms=adaptfilt.nlms(7);
>> [mumaxlms,mumaxmselms]=maxstep(hlms,x);
Warning: Step size is not in the range 0 < mu < mumaxmse/2:
Erratic behavior might result.
> In adaptfilt.lms.maxstep at 32
>> [mumaxlms,mumaxmsenlms]=maxstep(hnlms);
>> [ylms,elms]=filter(hlms,v2,x);
>> [ynlms,enlms]=filter(hnlms,v2,x);
>> bw=firwiener(L-1,v2,x);
50
>> yw=filter(bw,1,v2);
>> ew=x-yw;
>> plot(n(900:end),[ew(900:end),elms(900:end),enlms(900:end)]);
>> legend('wiener filter denoised sinusoid','LMS denoised sinusoid','NLMS
denoised sinusoid');
>> xlabel('time index (n)');
>> ylabel('amplitude');
>> [bw.' hlms.coefficients.' hnlms.coefficients.']
ans =
50
wiener filter denoised sinusoid
LMS denoised sinusoid
NLMS denoised sinusoid
40
30
amplitude
20
10
-10
900 910 920 930 940 950 960 970 980 990 1000
time index (n)
51
3. With ar=[1,0.5];
>> n=(1:1000)';
>> s=sin(0.075*pi*n);
>> v=0.8*randn(1000,1);
>> ar=[1,0.5];
>> v1=filter(1,ar,v);
>> x=s+v1;
>> ma=[1,-0.8,0.4,-0.2];
>> v2=filter(ma,1,v);
>> L=7;
>> hlms=adaptfilt.lms(7);
>> hnlms=adaptfilt.nlms(7);
>> [mumaxlms,mumaxmselms]=maxstep(hlms,x);
Warning: Step size is not in the range 0 < mu < mumaxmse/2:
Erratic behavior might result.
> In adaptfilt.lms.maxstep at 32
>> [mumaxlms,mumaxmsenlms]=maxstep(hnlms);
>> [ylms,elms]=filter(hlms,v2,x);
>> [ynlms,enlms]=filter(hnlms,v2,x);
>> bw=firwiener(L-1,v2,x);
>> yw=filter(bw,1,v2);
>> ew=x-yw;
>> plot(n(900:end),[ew(900:end),elms(900:end),enlms(900:end)]);
>> legend('wiener filter denoised sinusoid','LMS denoised sinusoid','NLMS
denoised sinusoid');
>> xlabel('time index (n)');
>> ylabel('amplitude');
>> [bw.' hlms.coefficients.' hnlms.coefficients.']
ans =
52
20
wiener filter denoised sinusoid
LMS denoised sinusoid
NLMS denoised sinusoid
10
0
amplitude
-10
-20
-30
-40
900 910 920 930 940 950 960 970 980 990 1000
time index (n)
53