matlab experiments eg
TRANSCRIPT
-
8/6/2019 Matlab experiments eg
1/26
butterworth digital low-pass
lc;
lear all;
p= input ('Enter the passband ripple : ');
s= input ('Enter the stopband ripple : ');
p= input ('Enter the passband frequency : ');
s= input ('Enter the stopband frequency : ');
s= input ('Enter the sampling frequency : ');
Converting frequency into radians
1 = 2*wp/fs;
2 = 2*ws/fs;
Cutoff frequency and order of the filter
n,wn]= buttord (w1,w2,rp,rs);
system function of the filter
b,a]=butter(n,wn);
= 0:0.01:pi;
h,om]= freqz(b,a,w);%
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('Phase in radians'),title('PHASE PLOT');
ample output
nter the passband ripple : .15
nter the stopband ripple : 60nter the passband frequency : 1500
nter the stopband frequency : 3000nter the sampling frequency : 7000
-
8/6/2019 Matlab experiments eg
2/26
-
8/6/2019 Matlab experiments eg
3/26
BUTTERWORTH DIGITAL HIGH-PASS
lc;
lear all;
p= input ('Enter the passband ripple : ');
s= input ('Enter the stopband ripple : ');
p= input ('Enter the passband frequency : ');
s= input ('Enter the stopband frequency : ');s= input ('Enter the sampling frequency : ');
Converting frequency into radians
1 = 2*wp/fs;
2 = 2*ws/fs;
Cutoff frequency and order of the filter
n,wn]= buttord (w1,w2,rp,rs);
system function of the filter
b,a]=butter(n,wn,'high');
= 0:0.01:pi;
h,om]= freqz(b,a,w,'whole');=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
ample output
nter the passband ripple : .15
nter the stopband ripple : 60
nter the passband frequency : 1500nter the stopband frequency : 3000
nter the sampling frequency : 7000
-
8/6/2019 Matlab experiments eg
4/26
-
8/6/2019 Matlab experiments eg
5/26
BUTTERWORTH bandPASS
lc;
lear all;
lose all;
p= input ('Enter the passband ripple : ');
s= input ('Enter the stopband ripple : ');
p= input ('Enter the passband frequency : ');
s= input ('Enter the stopband frequency : ');
s= input ('Enter the sampling frequency : ');
Converting frequency into radians
1 = 2*wp/fs;2 = 2*ws/fs;
Cutoff frequency and order of the filter
n]= buttord (w1,w2,rp,rs);
n=[w1 w2];
system function of the filter
b,a]=butter(n,wn,'bandpass');
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
nter the passband ripple : .3
nter the stopband ripple : 40
nter the passband frequency : 1500
nter the stopband frequency : 2000
nter the sampling frequency : 9000
-
8/6/2019 Matlab experiments eg
6/26
-
8/6/2019 Matlab experiments eg
7/26
BUTTERWORTH bandstop
lc;
lear all;
lose all;
p= input ('Enter the passband ripple : ');
s= input ('Enter the stopband ripple : ');
p= input ('Enter the passband frequency : ');
s= input ('Enter the stopband frequency : ');
s= input ('Enter the sampling frequency : ');
Converting frequency into radians
1 = 2*wp/fs;2 = 2*ws/fs;
Cutoff frequency and order of the filter
n]= buttord (w1,w2,rp,rs);
n=[w1 w2];
system function of the filter
b,a]=butter(n,wn,'stop');
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
nter the passband ripple : .4
nter the stopband ripple : 46
nter the passband frequency : 1100
nter the stopband frequency : 2200
nter the sampling frequency : 6000
-
8/6/2019 Matlab experiments eg
8/26
-
8/6/2019 Matlab experiments eg
9/26
CHEBYSHEV LOWPASS FILTER
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filtern,wn]= cheb1ord (w1,w2,rp,rs);
system function of the filter
b,a]= cheby1(n,rp,wn);
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('Phase in radians'),title('PHASE PLOT');
ample output
nter the passband ripple :.2
nter the stopband ripple :45nter the passband frequency:1300
nter the stopband frequency:1500
nter the sampling frequency:10000
-
8/6/2019 Matlab experiments eg
10/26
-
8/6/2019 Matlab experiments eg
11/26
CHEBYSHEV HIGHPASS FILTER
lc;
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filter
n,wn]= cheb1ord (w1,w2,rp,rs);
system function of the filter
b,a]= cheby1(n,rp,wn,'high');
= 0:0.01/pi:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
ample output
nter the passband ripple :.3
nter the stopband ripple :60
nter the passband frequency:1500nter the stopband frequency:2000
nter the sampling frequency:9000
-
8/6/2019 Matlab experiments eg
12/26
-
8/6/2019 Matlab experiments eg
13/26
CHEBYSHEV BANDPASS FILTER
lc;
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filter
n]= cheb1ord (w1,w2,rp,rs);
n=[w1 w2];
system function of the filter
b,a]= cheby1(n,rp,wn,'bandpass');
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
nter the passband ripple :.4
nter the stopband ripple :35
nter the passband frequency:2000nter the stopband frequency:2500
nter the sampling frequency:10000
-
8/6/2019 Matlab experiments eg
14/26
-
8/6/2019 Matlab experiments eg
15/26
CHEBYSHEV BANDstop FILTER
lc;
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filter
n]= cheb1ord (w1,w2,rp,rs);
n=[w1 w2];
system function of the filter
b,a]= cheby1(n,rp,wn,'stop');
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
nter the passband ripple :.25
nter the stopband ripple :40
nter the passband frequency:2500
nter the stopband frequency:2750
nter the sampling frequency:7000
-
8/6/2019 Matlab experiments eg
16/26
-
8/6/2019 Matlab experiments eg
17/26
CHEBYSHEV type2 LOWPASS FILTER
lc;
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filter
n,wn]= cheb2ord (w1,w2,rp,rs);
system function of the filter
b,a]= cheby2(n,rs,wn);
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
ample output
nter the passband ripple :.15nter the stopband ripple :35
nter the passband frequency:1500
nter the stopband frequency:2000
nter the sampling frequency:8000
-
8/6/2019 Matlab experiments eg
18/26
-
8/6/2019 Matlab experiments eg
19/26
CHEBYSHEV type2 highpass FILTER
lc;
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filter
n,wn]= cheb2ord (w1,w2,rp,rs);
system function of the filter
b,a]= cheby2(n,rs,wn,'high');
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);
label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
nter the passband ripple :.25
nter the stopband ripple :40
nter the passband frequency:1400nter the stopband frequency:1800
nter the sampling frequency:7000
-
8/6/2019 Matlab experiments eg
20/26
-
8/6/2019 Matlab experiments eg
21/26
-
8/6/2019 Matlab experiments eg
22/26
-
8/6/2019 Matlab experiments eg
23/26
CHEBYSHEV type2 bandstop FILTER
lc;
lear all;
p= input ('Enter the passband ripple :');
s= input ('Enter the stopband ripple :');
p= input ('Enter the passband frequency:');
s= input ('Enter the stopband frequency:');
s= input ('Enter the sampling frequency:');
frequency in radians
1 = 2*wp/fs;
2 = 2*ws/fs;
order and cutoff frequency of the filter
n]= cheb2ord (w1,w2,rp,rs);
n=[w1 w2];
system function of the filter
b,a]= cheby2(n,rs,wn,'stop');
= 0:0.01:pi;
h,om]= freqz(b,a,w);
=20*log10(abs(h));
n=angle(h);
ubplot(2,1,1);
lot(om/pi,m);label('Gain in dB'),xlabel('Normalised frequency'),title('MAGNITUDE PLOT');
ubplot(2,1,2);
lot(om/pi,an);
label('Normalised frequency'),ylabel('phase in radians'),title('PHASE PLOT');
nter the passband ripple :.3
nter the stopband ripple :46
nter the passband frequency:1400nter the stopband frequency:2000
nter the sampling frequency:8000
-
8/6/2019 Matlab experiments eg
24/26
IR FILTER 1
To design a 25-tap lowpass filter with cutoff frequency
.5pi using hanning and hamming window
lear all;
c=.5*pi;
=25;
lpha=(N-1)/2;
ps=.001;
=0:1:N-1;
d=(sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));r=hann(N); %hanning window sequence
n=hd'.*wr; % filter coefficients
=0:0.01:pi;
=freqz(hn,1,w);
lot(w/pi,abs(h),'red');
old on
b=hamming(N); %hamming window sequence
n=hd'.*wb; % filter coefficients
=0:0.01:pi;
=freqz(hn,1,w);
lot(w/pi,abs(h));
label('Magnitude');
label('Normalised frequency');old off
-
8/6/2019 Matlab experiments eg
25/26
IR FILTER 2
To design FIR LPF using rectangular & blackmann window
lc;
lear all;
c=.5*pi; %cutoff frequency
=25;
=fir1(N,wc/pi,rectwin(N+1));
=0:0.01:pi;
=freqz(b,1,w);
lot(w/pi,abs(h),'red');
old on
=fir1(N,wc/pi,blackman(N+1));
=0:0.01:pi;
=freqz(b,1,w);
lot(w/pi,abs(h));
label('Magnitude');
label('Normalised frequency');
old off
-
8/6/2019 Matlab experiments eg
26/26
requency Response of the first order system
lc;
lear all;
=1;
=[1 0.36]
= 0:0.1:pi;
h w]=freqs(b,a,w);
ubplot(2,1,1);
lot(w/pi,abs(h));
label('w');label('|H(w)|');
itle('Frequency Response-Magnitude Function');
ubplot(2,1,2);
lot(w/pi,angle(h));
label('w');
label('angle|H(w)|');
itle('Frequency Response-Phase Function');