You are on page 1of 18

DSP MATLAB programs

http://nerist98.blogspot.in/

Share

Report Abuse

Next Blog

Create Blog

DSP MATLAB programs

MATLAB Programs as per Exercises

SATURDAY, OCTOBER 22, 2011

My Links My Profile Departmental Profile ACADEMIC SECTION Blog Journal Crap Programs Blog Archive

EC 6120 and EC 5102 Program Sheet

Students are advised to submit the soft copy+printed and bound hard copy to the co-ordinator on 8th November 2011 the Program Sheet <- Click 2 get the soft copy of the program List The lists are as under: In case any data is missing you are free to take a valid assumption as long as you specify your assumption Sampling frequencies : FS =2KHz; FS =5KHz; FS =10KHz;
1 2 3

Attenuation in dB: Passband= Ap and Stopband=Ap Abbreviations: WAP=Write a Program LPF= Low Pass Filter HPF= High Pass Filter BPF=Band Pass Filter BSF= Band Stop Filter IIR-B=Butterworth IIR filter IIRC-I=Chebyshev Type I IIR filter IIRC-II=Chebyshev Type II IIR filter IIRE=Elliptic IIR filter FIRPM= Park Mc Lellens FIR Equiripple filter FIRW= Window based FIR filter DFT= Discrete Fourier Transform EC 6120 (Introduction to Digital Signal Processing) for Final year Electrical Engg Students Contributors SMD Swanirbhar

Take Transfer functions:

H(z)={num=[2.24, 2.49, 2.24]; den=[1, -0.4, 0.75]} H1(z)={num=[1, 2, 0.24]; den=[1, -0.9, 1]} H2(z)={num=[1, 3, 2]; den=[1, -0.1, 0.5]} Programs: 1. WAP a MATLAB function to plot a square wave of desired time delay /frequency and amplitude. 2. WAP a MATLAB function to plot a triangular wave of desired time delay /frequency and amplitude. 3. WAP a MATLAB function to plot a sawtooth wave of desired time delay /frequency and amplitude. 4. WAP to generate random noise of amplitude 0.2Vpp, add it to a generated low frequency signal of 100Hz and pass it through an LPF of 300Hz and FS1 and compare the filtered output with the

1 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

original signal to see if the noise is reduced. 5. WAP to generate a sinusoidal signal consisting of frequencies 200Hz, 300Hz and 600Hz with FS2 and pass it through any LTI system and compare the time and frequency domain input and output. 6. WAP to generate a sinusoidal signal consisting of frequencies 200Hz, 300Hz and 600Hz with FS1 and pass it through a system H(z) which is cascade combination of two LTI systems H1(z) and H2(z) with zero initial condition and prove the output is same even if u change the order of H1(z) and H2(z) in the cascade 7. 8. 9. 10. connection. WAP to check whether a given system H1(z) is LTI. WAP to check whether a given system H1(z) is stable and time invariant . WAP to check whether a given system H1(z) is stable and follows the superposition theorem. WAP to calculate the correlation of two time domain signals without using any of the MATLAB inbuilt convolution, correlation and filter commands. WAPs to generate two (2) MATLAB functions for circular convolution for desired number of points and sine wave generation of a desired sampling rate and desired amplitude and single tone frequency. WAP to find the 10 point DFT of x(n)=[ 5 -1 4 -2 3 -3 2 -4 1 -5] using 5 point DFT and check the result. WAP for generating a MATALB function for DFT without using the fft command and check the result WAP for generating a MATALB function for Inverse DFT without using the ifft command and chek the result. WAP to design a LPF of same specifications being IIRC-I and IIRC-II type and compare their outputs in time domain when a signal lying in transition band is passed through them. WAP to design a BSF of same specifications being IIRC-I and IIRC-II type and compare their outputs in time domain when a signal lying in transition band is passed through them. WAP to design a HPF of same specifications being IIRE and IIRC-II type and compare their outputs in time domain when a signal lying in transition band is passed through them. WAP to design a BPF of same specifications being IIRB and IIRE

11.

12. 13. 14. 15.

16.

17.

18.

type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap and As. 19. WAP to design a BPF of same specifications being FIRPM and IIRE type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap and As. 20. WAP to design a BSF of same specifications being FIRPM and IIRC-I type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap and As.. 21. WAP to design a LPF of same specifications being FIRPM and IIRC-II type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap and As. 22. WAP to design a HPF of same specifications being FIRPM and IIRB type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap and As. 23. WAP to design an IIRB BPF with an IIRB LPF and a HPF and compare the result with a direct IIRB BPF.

2 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

24. WAP to design an FIR BPF with passbands 300 to 400Hz and 600 to 800Hz with FS1. 25. WAP to design an FIR BSF with stopbands 300 to 400Hz, 600 to 800Hz and 1200 to 1400 with FS2. 26. WAP to compare the variation of output for a signal in transition band of an IIR-B as its order is increased by 3 when its input signal is lying in the transition band. 27. WAP to compare the variation of output for a signal in pass band of an IIR-B as its order is increased by 3 when its input signal is lying in the transition band. 28. WAP to compare the variation of output for a signal in stop band of an IIR-B as its order is increased by 3 when its input signal is lying in the transition band. 29. WAP to compare the variation of output for a signal in transition band of an IIR-CI as its order is increased by 3 when its input signal is lying in the transition band. 30. WAP to compare the variation of output for a signal in pass band of an IIR-CI as its order is increased by 3 when its input signal is lying in the transition band. 31. WAP to compare the variation of output for a signal in stop band of an IIR-CII as its order is increased by 3 when its input signal is lying in the transition band. 32. WAP to compare the variation of output for a signal in transition band of an IIR-CII as its order is increased by 3 when its input signal is lying in the transition band. 33. WAP to design a BPF of IIR-B and IIR-E of same specifications and keep their order same (i.e take order N= max[NIIR-B, NIIR-E])and compare their outputs in the pass band with FS2. 34. WAP to design an LPF of IIR-CI and IIR-CII of same specifications and keep their order same (i.e take order N= max[NIIR-CI NIIR-CII)and compare their outputs in the passband edge, cutoff and stopband edge with FS3. 35. WAP to design an LPF of IIR-E and IIR-CII of same specifications and keep their order same (i.e take order N= max[NIIR-CII, NIIR-E])and compare their outputs in the passband edge, cutoff and stopband edge with FS3.

EC 5102 (Digital Signal Processing) for Pre-Final year Electronics and Comm Engg Students

Take Transfer functions:

H(z)={num=[1, 3, 2]; den=[1, -0.1, 0.5]} H1(z)={num=[2.24, 2.49, 2.24]; den=[1, -0.4, 0.75 ]} H2(z)={num=[1, 2, 0.24]; den=[1, -0.9, 1]} Programs: 1. WAP to generate random noise of amplitude 0.5Vpp, add it to a generated low frequency signal of 200Hz and pass it through an LPF of 300Hz and FS1 and compare the filtered output with the original signal to see if the noise is reduced. 2. WAP to generate a sinusoidal signal consisting of frequencies 300Hz, 600Hz and 1200Hz with FS2 and pass it through any LTI system H(z) and compare the time and frequency domain input and output. 3. WAP to generate a sinusoidal signal consisting of frequencies 100Hz, 200Hz and 1000Hz with FS1 and pass it through a system

3 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

H(z) which is cascade combination of two LTI systems H1(z) and H2(z) with zero initial condition and prove the output is same even if u change the order of H1(z) and H2(z) in the cascade connection. 4. WAP to check whether a given system H1(z) and H2(z) in cascade is LTI. 5. WAP to check whether a given system H1(z) and H(z) in cascade is stable and time invariant . 6. WAP to check whether a given system H1(z) and H2(z) in cascade is stable and follows the superposition theorem. 7. WAP to calculate the convolution output of x(n)=[1 2 3 4 -1 -2 -3 0 1 2 0 -1 0 4 3] using overlap-add method with h(n)=[ 1 0 -1] without using the inbuilt commands and compare the result with the output of the conv command. 8. WAP to calculate the convolution output of x(n)=[1 2 3 4 -1 -2 -3 0 1 2 0 -1 0 4 3] using overlap-save method with h(n)=[ 1 0 -1] without using the inbuilt commands and compare the result with the output of the conv command. 9. WAP to calculate the convolution output of x(n)=[1 2 3 4 -1 -2 -3 0 1 2 0 -1 0 4 3] using overlap-save method with h(n)=[ 1 -1] without using the inbuilt commands and compare the result with the output of the overlap-add output of the same. 10. WAP to find the 7 point DFT of x1(n) = [-2 3 -3 2 -4 1 -5] and x2(n) = [2 -3 0 -2 4 0 -1] using a single 7 point DFT and check the result when fft command is applied to them separately. 11. WAP to design a LPF of same specifications being IIRB and IIRC-II type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.5dB and As=50dB. 12. WAP to design a BSF of same specifications being IIRC-I and IIRE type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.5dB and As=60dB. 13. WAP to design a HPF of same specifications being IIR-CI and IIRC-II type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.7dB and As=50dB. 14. WAP to design a BPF of same specifications being IIRB and IIR-CII type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.5dB and As=80dB. 15. WAP to design a BPF of same specifications being hamming FIR-W and IIRE type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.7dB and As=50dB. 16. WAP to design a BSF of same specifications being FIRPM and Kaiser FIR-W type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.6dB and As=40dB. 17. WAP to design a LPF of same specifications being FIRPM and hanning FIR-W type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.8dB and As=80dB. 18. WAP to design a HPF of same specifications being FIRPM and Gaussian FIRW type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.5dB and As=50dB.

4 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

19. WAP to design an IIRE BPF with an IIRE LPF and a HPF and compare the result with a direct IIRE BPF with Ap=0.5dB and As=50dB. 20. WAP to design an FIR BPF with passbands 300 to 700Hz and 900 to 1400Hz with FS1 with Ap=0.5dB and As=80dB. 21. WAP to design an FIR BSF with stopbands 100 to 400Hz, 800 to 1000Hz and 1200 to 1400 with FS2 , Ap=0.5dB and As=50dB. 22. WAP to compare the variation of output for a signal in transition band of an Kaiser FIR-W as its order is increased by 10 when its input signal is lying in the transition band. 23. WAP to compare the variation of output for a signal in pass band of an IIR-CII as its order is increased by 3 when its input signal is lying in the transition band. 24. WAP to compare the variation of output for a signal in stop band of an IIR-CI as its order is increased by 3 when its input signal is lying in the transition band. 25. WAP to compare the variation of output for a signal in transition band of a Kaiser FIR-W as its order is increased by 10 when its input signal is lying in the transition band. 26. WAP to compare the variation of output for a signal in pass band of a Gaussian FIR-W as its order is increased by 10 when its input signal is lying in the transition band. 27. WAP to compare the variation of output for a signal in stop band of a Hamming FIR-W as its order is increased by 10 when its input signal is lying in the transition band. 28. WAP to compare the variation of output for a signal in transition band of an IIR-E as its order is increased by 3 when its input signal is lying in the transition band. 29. WAP to design a BPF of IIR-CI and IIR-CII of same specifications and keep their order same (i.e take order N= max[NIIR-CI, NIIR-CII])and compare their outputs in the pass band with FS1. 30. WAP to design a LPF of IIR-B and IIR-E of same specifications and keep their order same (i.e take order N= max[NIIR-B NIIR-E)and compare their outputs in the passband edge, cutoff and stopband edge with FS1. 31. WAP to design a LPF of IIR-B and IIR-CII of same specifications and keep their order same (i.e take order N= max[NIIR-CII, NIIR-B])and compare their outputs in the passband edge, cutoff and stopband edge with FS1. 32. WAP to design a BSF of IIR-E and IIR-CI of same specifications and keep their order same (i.e take order N= max[NIIR-E, NIIR-CI])and compare their outputs in the passband edge, cutoff and stopband edge with FS3. 33. WAP to design a BSF of FIR-PM and Kaiser FIR-W of same specifications and keep their order same (i.e take order N= max[NFIR-W, NFIR-PM])and compare their outputs in the passband edge, cutoff and stopband edge with FS2. 34. WAP to design a HPF of FIR-PM and Kaiser FIR-W of same specifications and keep their order same (i.e take order N= max[NFIR-W, NFIR-PM])and compare their outputs in the passband edge, cutoff and stopband edge with FS2. 35. WAP to design a HPF of Hamming FIR-W and Kaiser FIR-W of same specifications and keep their order same and compare their outputs in the passband edge, cutoff and stopband edge with FS3. 36. WAP to design a LPF of Gaussian FIR-W and Kaiser FIR-W of same specifications and keep their order same and compare their

5 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

outputs in the passband edge, cutoff and stopband edge with FS3. 37. WAP to design a BPF of Blackman Harries FIR-W and Kaiser FIR-W of same specifications and keep their order same and compare their outputs in the passband edge, cutoff and stopband edge with FS2. 38. WAP to design a BPF of same specifications being Cebyshev FIR-W and IIR-CII type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.5dB and As=80dB with FS2. 39. WAP to design a HPF of same specifications being Cebyshev FIR-W and IIR-CI type and compare their outputs in time domain when a signal lying in transition band is passed through them with Ap=0.5dB and As=80dB with FS2. 40. WAP to design a IIR-B LPF reduce the minimum order by 2 and check its linearity property. 41. WAP to design a IIR-CI LPF reduce the minimum order by 2 and check its stability property. 42. WAP to design a IIR-E LPF reduce the minimum order by 2 and check its time invariance property. 43. WAP to design a FIR-PM LPF reduce the minimum order by 5 and check its linearity property. 44. WAP to design a Kaiser FIR-W LPF reduce the minimum order by 5 and check its linearity property. 45. WAP to design a Hamming FIR-W and an IIR-B LPF reduce the minimum order by 3 for each and check their superposition property.

FIR WINDOW based (different windows)

%LPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); N=66; W=.4;

6 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

w=window(@blackmanharris,N+1);%blackman harris window figure subplot 121, plot(1:N+1,w); b = fir1(N, W, 'low',w); [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

%HPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); N=66; W=.4; w=window(@hanning,N+1);%Hanning window figure subplot 121, plot(1:N+1,w); b = fir1(N, W, 'high',w); [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

%BPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); N=66; W=[.4 .6]; w=window(@gausswin,N+1);%Gaussian window figure subplot 121, plot(1:N+1,w); b = fir1(N, W, 'bandpass',w); [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

7 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

%BSF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); N=66; W=[.4 .6]; w=window(@Hamming,N+1);%Hamming window figure subplot 121, plot(1:N+1,w); b = fir1(N, W, 'stop');%if nothing is given, the DEFAULT WINDOW=Hamming [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y))); Posted by Swanirbhar at 7:35 AM 0 comments Links to this post

FIR KAISER WINDOW

%LPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [N,W,bta,filtype] = kaiserord( [300 400], [1 0], [dp ds], samp ); w = window(@kaiser,N+1,bta); figure subplot 121, plot(1:N+1,w); b = fir1(N, W, filtype, kaiser(N+1,bta), 'noscale'); [h,o]=freqz(b,1,256);

8 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

%HPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [N,W,bta,filtype] = kaiserord( [300 400], [0 1], [ds dp], samp ); w = window(@kaiser,N+1,bta); figure subplot 121, plot(1:N+1,w); b = fir1(N, W, filtype, kaiser(N+1,bta), 'noscale'); [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

%BPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [N,W,bta,filtype] = kaiserord( [300 450 550 650 ], [0 1 0], [ds dp ds], samp ); w = window(@kaiser,N+1,bta); figure subplot 121, plot(1:N+1,w); b = fir1(N, W, filtype, kaiser(N+1,bta), 'noscale'); [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

9 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

%BSF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [N,W,bta,filtype] = kaiserord( [300 450 550 650 ], [1 0 1], [dp ds dp], samp ); w = window(@kaiser,N+1,bta); figure subplot 121, plot(1:N+1,w); b = fir1(N, W, filtype, kaiser(N+1,bta), 'noscale'); [h,o]=freqz(b,1,256); subplot 122, plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y))); Posted by Swanirbhar at 7:17 AM 0 comments Links to this post

FIR EQIRIPPLE (OPTIMAL METHOD)

%LPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [n,fo,mo,w] = firpmord( [300 400], [1 0], [dp ds], samp ); b = firpm(n,fo,mo,w);

10 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

[h,o]=freqz(b,1,256); figure plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

%HPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [n,fo,mo,w] = firpmord( [300 400], [0 1], [ds dp], samp ); b = firpm(n,fo,mo,w); [h,o]=freqz(b,1,256); figure plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

%BPF clc clear close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [n,fo,mo,w] = firpmord( [300 400 550 650], [0 1 0], [ds dp ds], samp ); b = firpm(n,fo,mo,w); [h,o]=freqz(b,1,256); figure plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y)));

11 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

close all samp=2000; n=0:1/samp:1; x=cos(2*pi*100*n)+cos(2*pi*500*n)+cos(2*pi*700*n); ap=0.5;%ap=-20*log10(1-dp) as=80;%as=-20*log10(ds) dp=1-10^(-ap/20); ds=10^(-as/20); [n,fo,mo,w] = firpmord( [300 400 550 650], [1 0 1], [dp ds dp], samp ); b = firpm(n,fo,mo,w); [h,o]=freqz(b,1,256); figure plot(o/pi, 20*log10(abs(h))); y=filter(b,1,x); figure subplot 211, plot(abs(fft(x))); subplot 212, plot(abs(fft(y))); Posted by Swanirbhar at 7:00 AM 0 comments Links to this post

IIR ELLIPTIC
% LPF clc; clear; close all; %LPF of cut off 500Hz fp=500; fs=600; samp=2000; ap=.5; as=40; wp=fp/(samp/2); ws=fs/(samp/2); [N,wn]=ellipord(wp,ws,ap,as); [b,a]=ellip(N,ap, as,wn); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*700*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

% HPF clc; clear; close all; %HPF of cut off 500Hz fs=500; fp=600; samp=2000; ap=.5; as=40;

12 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

wp=fp/(samp/2); ws=fs/(samp/2); [N,wn]=ellipord(wp,ws,ap,as); [b,a]=ellip(N,ap, as,wn,'high'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*700*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

%BPF clc; clear; close all; %BPF of pass 400-600Hz fs1=300; fp1=400; fp2=600; fs2=700; samp=2000; ap=.5; as=40; wp=[fp1 fp2]/(samp/2); ws=[fs1 fs2]/(samp/2); [N,wn]=ellipord(wp,ws,ap,as); [b,a]=ellip(N,ap, as,wn,'bandpass'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

%BSF clc; clear; close all; %BSF of stop 400-600Hz fp1=300; fs1=400; fs2=600; fp2=700; samp=2000; ap=.5; as=40; wp=[fp1 fp2]/(samp/2); ws=[fs1 fs2]/(samp/2);

13 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

[N,wn]=ellipord(wp,ws,ap,as); [b,a]=ellip(N,ap, as,wn,'stop'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

IIR CHEBYSHEV TYPE II

% LPF clc; clear; close all; %LPF of cut off 500Hz fp=500; fs=600; samp=2000; ap=.5; as=40; wp=fp/(samp/2); ws=fs/(samp/2); [N,wn]=cheb2ord(wp,ws,ap,as); [b,a]=cheby2(N,as,wn); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*700*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

% HPF clc; clear; close all; %HPF of cut off 500Hz fs=500; fp=600; samp=2000; ap=.5; as=40; wp=fp/(samp/2); ws=fs/(samp/2); [N,wn]=cheb2ord(wp,ws,ap,as); [b,a]=cheby2(N,as,wn,'high'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H)))

14 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*700*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

%BPF clc; clear; close all; %BPF of pass 400-600Hz fs1=300; fp1=400; fp2=600; fs2=700; samp=2000; ap=.5; as=40; wp=[fp1 fp2]/(samp/2); ws=[fs1 fs2]/(samp/2); [N,wn]=cheb2ord(wp,ws,ap,as); [b,a]=cheby2(N,as,wn,'bandpass'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

%BSF clc; clear; close all; %BSF of stop 400-600Hz fp1=300; fs1=400; fs2=600; fp2=700; samp=2000; ap=.5; as=40; wp=[fp1 fp2]/(samp/2); ws=[fs1 fs2]/(samp/2); [N,wn]=cheb2ord(wp,ws,ap,as); [b,a]=cheby2(N,as,wn,'stop'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n);

15 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

IIR CHEBYSHEV TYPE I

% LPF clc; clear; close all; %LPF of cut off 500Hz fp=500; fs=600; samp=2000; ap=.5; as=40; wp=fp/(samp/2); ws=fs/(samp/2); [N,wn]=cheb1ord(wp,ws,ap,as); [b,a]=cheby1(N,ap,wn); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*700*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

% HPF clc; clear; close all; %HPF of cut off 500Hz fs=500; fp=600; samp=2000; ap=.5; as=40; wp=fp/(samp/2); ws=fs/(samp/2); [N,wn]=cheb1ord(wp,ws,ap,as); [b,a]=cheby1(N,ap,wn,'high'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*700*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

16 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

%BPF clc; clear; close all; %BPF of pass 400-600Hz fs1=300; fp1=400; fp2=600; fs2=700; samp=2000; ap=.5; as=40; wp=[fp1 fp2]/(samp/2); ws=[fs1 fs2]/(samp/2); [N,wn]=cheb1ord(wp,ws,ap,as); [b,a]=cheby1(N,ap,wn,'bandpass'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

%BSF clc; clear; close all; %BSF of stop 400-600Hz fp1=300; fs1=400; fs2=600; fp2=700; samp=2000; ap=.5; as=40; wp=[fp1 fp2]/(samp/2); ws=[fs1 fs2]/(samp/2); [N,wn]=cheb1ord(wp,ws,ap,as); [b,a]=cheby1(N,ap,wn,'stop'); [H,W]=freqz(b,a,256); plot(W/(2*pi),20*log10(abs(H))) n=0:1/samp:1; x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y)))

17 of 18

03-05-2012 11:00

DSP MATLAB programs

http://nerist98.blogspot.in/

Older Posts

18 of 18

03-05-2012 11:00