This file concludes some codes related to some topics of DIGITAL SIGNAL PROCESSING as Butterworth filter, Chebyshev filter and many others.............
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Â
DIGITAL SIGNAL PROCESSING BASED ON MATLAB
1. ROORKEE COLLEGE OF
ENGINEERING, ROORKEE
UNDER THE GUIDANCE OF:
īļ Miss. RUCHITA SINGH
(Asst. Professor, EEE Dept.)
ROORKEE COLLEGE OF
ENGINEERING, ROOORKEE
BY â PRASHANT SRIVASTAV
ROLL NO. - 661020108001
B.Tech.- EEE (Vth
sem.)
2. INDEX
SR.NO. NAME OF PROGRAM DATE TEACHERSâREMARK
1 WAVE FORM
GENERATION
2 LINEAR CONVOLUTION
3 DESIGN OF
BUTTERWORTH FILTER:
(I) ANALOG LOW PASS FILTER
(II) DIGITAL BANDPASS
FILTER
4 AUTOCORRELATION
5 DESIGN OF CHEBYSHEV
DIGITAL FILTER
(I) TYPE â I BANDPASS
(II) TYPE â II BANDPASS
(III) TYPE âII BANDSTOP
6 FFT & IFFT WITHOUT
USING FUNCTION
7 DESIGN OF FIR FILTER BY
USING HANNING
WINDOW
8 DESIGN OF FIR FILTER BY
USING CHEBYSHEV
WINDOW
3. 1.WAVE FORM GENERATION
COSINE WAVE
īˇ t=0:.01:pi;
īˇ y=cos(2*pi*t);
īˇ subplot(2,1,1);plot (t,y);ylabel('amplitude -->');
īˇ xlabel('(b) n -->');
GENERATION OF EXPONENTIAL SIGNAL
1. n=input('enter the length of the exponential sequence');
2. t=0:n;
3. a=input('enter the a value');
4. y2=exp(a*t);
5. subplot(2,2,4);
6. stem(t,y2);
7. ylabel('Amplitude -->');
8. xlabel('(d) n -->');
Enter the length of the exponential sequence'
Enter the a value'
4. GENERATION OF UNIT IMPULSE
1. t=-2:1:2;
2. y=[zeros(1,2),ones(1,1),zeros(1,2)];
3. subplot(2,2,1);
4. stem(t,y);
5. ylabel('amplitude_ _>');
6. xlabel('(a)n_ _>');
GENERATION OF UNIT STEP SEQUENCE
1. n=input('enter the N value');
2. t=0:1:n-1;
3. y1=ones(1,n);
4. subplot(2,2,2);
5. stem(t,y1);
6. ylabel('amplitude_ _>');
7. xlabel('(b)n_ _>');
enter the ânâ values.
5. GENERATION OF RAMP SEQUENCE
1. n=input('enter the length of the ramp sequence');
2. t=0:n;
3. subplot(2,2,3);
4. stem(t,t);
5. ylabel('amplitude -->');
6. xlabel('(c) n -->');
âEnter the length of the ramp sequence'
SINE WAVE
īˇ t=0:.01:pi;
īˇ y=sin(2*pi*t);figure(2);
īˇ subplot(2,1,1);plot (t,y);ylabel('amplitude -->');
īˇ xlabel('(a) n -->');
6. 2.LINEAR CONVOLUTION
īˇ clc;
īˇ clear all;
īˇ close all;
īˇ x=input('enter the 1st sequence');
īˇ h=input('enter the 2nd sequence');
īˇ y=conv(x,h);
īˇ figure;subplot(3,1,1);
īˇ stem(x);
īˇ ylabel('amplitude -->');
īˇ xlabel('(a) n -->');
īˇ subplot(3,1,2);
īˇ stem(h);ylabel('amplitude -->');
īˇ xlabel('(b) n -->');
īˇ subplot(3,1,3);
īˇ stem(y);ylabel('amplitude -->');
īˇ xlabel('(c) n -->');
īˇ disp('the resultant signal is ');y
example,
1st
sequence â [1, 2]
2nd
sequence â [1, 2, 4]
7. 3.DESIGN OF BUTTERWORTH FILTER
ANALOG LOW PASS FILTER
1. clc;
2. close all;
3. clear all;
4. format long
5. rp=input('enter the passband ripple');
6. rs=input('enter the stopband ripple');
7. wp=input('enter the passband freq');
8. ws=input('enter the stopband freq');
9. fs=input('enter the sampling freq');
10.w1=2*wp/fs;w2=2*ws/fs;
11.[n,wn]=buttord(w1,w2,rp,rs,'s');
12.[z,p,k]=butter(n,wn);
13.[b,a]=zp2tf(z,p,k);
14.[b,a]=butter(n,wn,'s');
15.w=0:.01:pi;
16.[h,om]=freqs(b,a,w);
17.m=20*log10(abs(h));
18.an=angle(h);
19.subplot(2,1,1);
20.plot(om/pi,m);
21.ylabel('Gain in dB --.');
22.xlabel('(a) Normalised frequency --.');
23.subplot(2,1,2);
24.plot(om/pi,an);
25.xlabel('(b) Normalised frequency --.');
26.ylabel('Phase in radians --.');
Example:
īˇ enter the passband ripple 0.15
īˇ enter the stopband ripple 60
īˇ enter the passband freq 1500
īˇ enter the stopband freq 3000
īˇ enter the stopband freq 7000
8. DIGITAL BANDPASS FILTER
īˇ clc;
īˇ clear all;
īˇ rp = input('Enter the passband ripple = ');
īˇ rs = input('Enter the stopband ripple = ');
īˇ wp = input('Enter the passband frequency = ');
īˇ ws = input('Enter the stopband frequency = ');
īˇ fs = input('Enter the sampling frequency = ');
īˇ w1 = 2*wp/fs;
īˇ w2 = 2*ws/fs;
īˇ [n] = buttord(w1,w2,rp,rs);
īˇ wn = [w1 w2];
īˇ [b,a] = butter(n,wn,'bandpass');
īˇ w = 0:0.01:pi;
īˇ [h,om] = freqz(b,a,w);
īˇ m = 20*log10(abs(h));
īˇ an = angle(h);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ title('Magnitude Response');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ subplot(2,1,2);
īˇ plot(om/pi,an);
īˇ title('Phase Response');
īˇ xlabel('Normalised Frequency ---->');
īˇ ylabel('Phase in radians ---->');
īˇ grid on;
īˇ Enter the passband ripple = 0.2
īˇ Enter the stopband ripple = 40
īˇ Enter the passband frequency = 1500
īˇ Enter the stopband frequency = 2000
īˇ Enter the sampling frequency = 9000
9. 4.AUTO-CORRELATION
Algorithm:
1. Get the signal x(n)of length N in matrix form
2. The correlated signal is denoted as y(n)
3. y(n)is given by the formula
y(n) 5 [ ( ) ( )] x k x k n k â =ââ â â where n52(N 2 1) to (N 2 1)
10. 5.DESIGN OF CHEBYSHEV
DIGITAL FILTER
TYPE-I BAND PASS FILTER
īˇ clc;
īˇ clear all;
īˇ rp = input('Enter the passband ripple = ');
īˇ rs = input('Enter the stopband ripple = ');
īˇ wp = input('Enter the passband frequency = ');
īˇ ws = input('Enter the stopband frequency = ');
īˇ fs = input('Enter the sampling frequency = ');
īˇ w1 = 2*wp/fs;
īˇ w2 = 2*ws/fs;
īˇ [n] = cheb1ord(w1,w2,rp,rs,'s');
īˇ wn = [w1 w2];
īˇ [b,a] = cheby1(n,rp,wn,'bandpass','s');
īˇ w = 0:0.01:pi;
īˇ [h,om] = freqs(b,a,w);
īˇ m = 20*log10(abs(h));
īˇ an = angle(h);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ title('Magnitude Response');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ subplot(2,1,2);
īˇ plot(om/pi,an);
īˇ title('Phase Response');
īˇ xlabel('Normalised Frequency ---->');
īˇ ylabel('Phase in radians ---->');
īˇ grid on;
īˇ Enter the passband ripple = 0.3
īˇ Enter the stopband ripple = 40
īˇ Enter the passband frequency = 1400
īˇ Enter the stopband frequency = 2000
īˇ Enter the sampling frequency = 5000
11. CHEBYSHEV TYPE-2 BANDSTOP FILTER
īˇ clc;
īˇ clear all;
īˇ rp = input('Enter the passband ripple = ');
īˇ rs = input('Enter the stopband ripple = ');
īˇ wp = input('Enter the passband frequency = ');
īˇ ws = input('Enter the stopband frequency = ');
īˇ fs = input('Enter the sampling frequency = ');
īˇ w1 = 2*wp/fs;
īˇ w2 = 2*ws/fs;
īˇ [n] = cheb2ord(w1,w2,rp,rs);
īˇ wn = [w1 w2];
īˇ [b,a] = cheby2(n,rs,wn,'stop');
īˇ w = 0:0.1/pi:pi;
īˇ [h,om] = freqz(b,a,w);
īˇ m = 20*log10(abs(h));
īˇ an = angle(h);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ title('Magnitude Response');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ subplot(2,1,2);
īˇ plot(om/pi,an);
īˇ title('Phase Response');
īˇ xlabel('Normalised Frequency ---->');
īˇ ylabel('Phase in radians ---->');
īˇ grid on;
īˇ Enter the passband ripple = 0.3
īˇ Enter the stopband ripple = 46
īˇ Enter the passband frequency = 1400
īˇ Enter the stopband frequency = 2000
īˇ Enter the sampling frequency = 8000
12. CHEBYSHEV TYPE-I BANDSTOP FILTER
īˇ clc;
īˇ clear all;
īˇ rp = input('Enter the passband ripple = ');
īˇ rs = input('Enter the stopband ripple = ');
īˇ wp = input('Enter the passband frequency = ');
īˇ ws = input('Enter the stopband frequency = ');
īˇ fs = input('Enter the sampling frequency = ');
īˇ w1 = 2*wp/fs;
īˇ w2 = 2*ws/fs;
īˇ [n] = cheb1ord(w1,w2,rp,rs);
īˇ wn = [w1 w2];
īˇ [b,a] = cheby1(n,rp,wn,'stop');
īˇ w = 0:0.1/pi:pi;
īˇ [h,om] = freqz(b,a,w);
īˇ m = 20*log10(abs(h));
īˇ an = angle(h);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ subplot(2,1,1);
īˇ plot(om/pi,m);
īˇ title('Magnitude Response');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ subplot(2,1,2);
īˇ plot(om/pi,an);
īˇ title('Phase Response');
īˇ xlabel('Normalised Frequency ---->');
īˇ ylabel('Phase in radians ---->');
īˇ grid on;
īˇ Enter the passband ripple = 0.25
īˇ Enter the stopband ripple = 40
īˇ Enter the passband frequency = 2500
īˇ Enter the stopband frequency = 2750
īˇ Enter the sampling frequency = 7000
>>
13. 6.FFT & IFFT WITHOUT USING
FUNCTION
īˇ clc;
īˇ clear all;
īˇ x = input('Enter the input sequence = ');
īˇ N = length(x);
īˇ for k = 1:N
īˇ y(k) = 0;
īˇ for n = 1:N
īˇ y(k) = y(k)+x(n)*exp(-1i*2*pi*(k-1)*(n-1)/N);
īˇ end
īˇ end
īˇ %code block to plot the input sequence
īˇ t = 0:N-1;
īˇ subplot(2,2,1);
īˇ stem(t,x);
īˇ ylabel('Amplitude ---->');
īˇ xlabel('n ---->');
īˇ title('Input Sequence');
īˇ grid on;
īˇ magnitude = abs(y); % Find the magnitudes of individual FFT points
īˇ disp('FFT Sequence = ');
īˇ disp(magnitude);
īˇ %code block to plot the FFT sequence
īˇ t = 0:N-1;
īˇ subplot(2,2,2);
īˇ stem(t,magnitude);
īˇ ylabel('Amplitude ---->');
īˇ xlabel('K ---->');
īˇ title('FFT Sequence');
īˇ grid on;
īˇ R = length(y);
īˇ for n = 1:R
īˇ x1(n) = 0;
īˇ for k = 1:R
īˇ x1(n) = x1(n)+(1/R)*y(k)*exp(1i*2*pi*(k-1)*(n-1)/R);
īˇ end
īˇ end
īˇ %code block to plot the IFFT sequence
15. 7.FIR USING HANNING WINDOW
īˇ clc;
īˇ clear all;
īˇ rp = input('Enter the passband ripple = ');
īˇ rs = input('Enter the stopband ripple = ');
īˇ fp = input('Enter the passband frequency = ');
īˇ fs = input('Enter the stopband frequency = ');
īˇ f = input('Enter the sampling frequency = ');
īˇ wp = 2*fp/f;
īˇ ws = 2*fs/f;
īˇ num = -20*log10(sqrt(rp*rs))-13;
īˇ dem = 14.6*(fs-fp)/f;
īˇ n = ceil(num/dem);
īˇ n1 = n+1;
īˇ if (rem(n,2)~=0)
īˇ n1 = n;
īˇ n = n-1;
īˇ end
īˇ y = hanning(n1);
īˇ % low-pass filter
īˇ b = fir1(n,wp,y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,1);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of LPF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ % high-pass filter
īˇ b = fir1(n,wp,'high',y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,2);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of HPF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ % band pass filter
īˇ wn = [wp ws];
16. īˇ b = fir1(n,wn,y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,3);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of BPF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ % band stop filter
īˇ b = fir1(n,wn,'stop',y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,4);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of BSF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ OUTPUT:
īˇ Enter the passband ripple = 0.03
īˇ Enter the stopband ripple = 0.01
īˇ Enter the passband frequency = 1400
īˇ Enter the stopband frequency = 2000
īˇ Enter the sampling frequency = 8000
17. 8. FIR FILTER USING
CHEBYSHEV WINDOW
īˇ clc;
īˇ clear all;
īˇ rp = input('Enter the passband ripple = ');
īˇ rs = input('Enter the stopband ripple = ');
īˇ fp = input('Enter the passband frequency = ');
īˇ fs = input('Enter the stopband frequency = ');
īˇ f = input('Enter the sampling frequency = ');
īˇ r = input('Enter the ripple value(in dBs) = ');
īˇ wp = 2*fp/f;
īˇ ws = 2*fs/f;
īˇ num = -20*log10(sqrt(rp*rs))-13;
īˇ dem = 14.6*(fs-fp)/f;
īˇ n = ceil(num/dem);
īˇ if(rem(n,2)==0)
īˇ n = n+1;
īˇ end
īˇ y = chebwin(n,r);
īˇ % low-pass filter
īˇ b = fir1(n-1,wp,y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,1);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of LPF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ % high-pass filter
īˇ b = fir1(n-1,wp,'high',y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,2);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of HPF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ % band pass filter
īˇ wn = [wp ws];
18. īˇ b = fir1(n-1,wn,y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,3);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of BPF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ % band stop filter
īˇ b = fir1(n-1,wn,'stop',y);
īˇ [h,o] = freqz(b,1,256);
īˇ m = 20*log10(abs(h));
īˇ subplot(2,2,4);
īˇ plot(o/pi,m);
īˇ title('Magnitude Response of BSF');
īˇ ylabel('Gain in dB ---->');
īˇ xlabel('Normalised Frequency ---->');
īˇ grid on;
īˇ OUTPUT:
īˇ Enter the passband ripple = 0.03
īˇ Enter the stopband ripple = 0.02
īˇ Enter the passband frequency = 1800
īˇ Enter the stopband frequency = 2400
īˇ Enter the sampling frequency = 10000
īˇ Enter the ripple value(in dBs) = 40