Você está na página 1de 30

DSP MATLAB programs

MATLAB Programs as per Exercises

Saturday, October 22, 2011


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 : FS1=2KHz; FS2=5KHz; FS3=10KHz; 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 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 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 connection. 7. WAP to check whether a given system H1(z) is LTI. 8. WAP to check whether a given system H1(z) is stable and time invariant . 9. WAP to check whether a given system H1(z) is stable and follows the superposition theorem. 10. WAP to calculate the correlation of two time domain signals without using any of the MATLAB inbuilt convolution, correlation and filter commands. 11. 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. 12. 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. 13. WAP for generating a MATALB function for DFT without using the fft command and check the result 14. WAP for generating a MATALB function for Inverse DFT without using the ifft command and chek the result. 15. 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. 16. 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. 17. 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. 18. WAP to design a BPF of same specifications being IIRB 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. 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. 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 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. 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 FIRW 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 FIRW 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 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.

Posted by Swanirbhar at 9:15 PM 0 comments Links to this post

Sunday, October 16, 2011


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; 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)));

%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); 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)));

%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); [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)));

%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,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; 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);

[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))) Posted by Swanirbhar at 6:55 AM 0 comments Links to this post

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))) 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); figure subplot 211, plot(n,abs(fft(x))) y=filter(b,a,x); subplot 212, plot(n,abs(fft(y))) Posted by Swanirbhar at 6:51 AM 0 comments Links to this post

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)))

%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))) Posted by Swanirbhar at 6:45 AM 0 comments Links to this post Older Posts Home Subscribe to: Posts (Atom)

My Links

My Profile Departmental Profile ACADEMIC SECTION Blog Journal Crap Programs

Blog Archive Contributors


Swanirbhar SMD

SEARCH OUR S

College How-tos My Projects Reviews Uncategorized Downloads Random >>

You are here: Blog > College > Lab > DSP Lab programs

DSP Lab programs


November 29th, 2010College, featured, LabManish 7 Comments

Here are the lab programs for DSP Lab(V sem Electronics and communication) Subject Code : 06ECL57 Awesome Resources: DSPGuide and DSPRelated

EXPERIMENTS USING MATLAB


1. Verification of Sampling theorem.
clc;clear all;close all; %Program to verify the sampling theorem %Generate 15Hz sinusoidal signal of 0.1s duration sampled at 1000Hz t=0:0.001:0.1; fm=15; x=sin(2*pi*fm*t); figure(1) plot(t,x),xlabel('Time'),ylabel('Amplitude'); title('Original Analog signal');

%Analog signal sampled at fs<<2fm fs=10; n=0:1/fs:0.1; xn=sin(2*pi*fm*n); figure(2) subplot(2,1,1);stem(n,xn); xlabel('Time'),ylabel('Amplitude'); title('Undersampled fs<<2fm signal'); subplot(2,1,2);plot(n,xn); xlabel('Time'),ylabel('Amplitude'); title('Reconstructed undersampled fs<<2fm signal'); %Analog signal sampled at Nyquist rate fs=2fm fs=30; n=0:1/fs:0.1; xn=sin(2*pi*fm*n); figure(3) subplot(2,1,1);stem(n,xn); xlabel('Time'),ylabel('Amplitude'); title('Sampled at Nyquist rate fs=2fm signal''); subplot(2,1,2);plot(n,xn); xlabel('Time'),ylabel('Amplitude'); title('Reconstructed Nyquist rate fs=2fm signal'); %Analog signal sampled at oversampling fs>>2fm fs=500; n=0:1/fs:0.1; xn=sin(2*pi*fm*n); figure(4) subplot(2,1,1);stem(n,xn); xlabel('Time'),ylabel('Amplitude'); title('Oversampled fs>>2fm signal'); subplot(2,1,2);plot(n,xn); xlabel('Time'),ylabel('Amplitude'); title('Reconstructed oversampled fs>>2fm signal');

2.

Impulse response of a given system

clc;clear all;close all; a=input('Enter the feedback coefficients:'); b=input('Enter the feedforward coefficients:'); h=impz(b,a); n=0:length(h)-1; stem(n,h);grid on xlabel('Time');ylabel('Amplitude'); title('Impulse Response h[n]');

3.

Linear convolution of two given sequences.

clc;clear all;close all; x=input('Enter x[n]:'); nx=0:length(x)-1; h=input('Enter h[n]:'); nh=0:length(h)-1; z=conv(x,h); nz=0:length(z)-1; subplot(3,1,1); stem(nx,x);

xlabel('Time');ylabel('Amplitude'); title('Input sequence x[n]'); subplot(3,1,2); stem(nh,h); xlabel('Time');ylabel('Amplitude'); title('Impulse response of the system h[n]'); subplot(3,1,3); stem(nz,z); xlabel('Time');ylabel('Amplitude'); title('Linear Convolution');

4.

Circular convolution of two given sequences

clc;clear all;close all; x=input('Enter x[n]:'); h=input('Enter h[n]:'); xl=length(x); hl=length(h); m=max(xl,hl); z=ifft(fft(x,m).*fft(h,m)); zl=length(z); %Plots nx=0:xl-1; nh=0:hl-1; nz=0:zl-1; subplot(3,1,1); stem(nx,x); xlabel('Time');ylabel('Amplitude'); title('Input sequence x[n]'); subplot(3,1,2); stem(nh,h); xlabel('Time');ylabel('Amplitude'); title('Impulse response of the system h[n]'); subplot(3,1,3); stem(nz,z); xlabel('Time');ylabel('Amplitude'); title('Circular Convolution');

5.

Autocorrelation of a given sequence and verification of its properties.

clc;clear all;close all; x=input('Enter x[n]:'); n=0:1:length(x)-1; subplot(2,1,1); stem(n,x); xlabel('Time');ylabel('Amplitude'); title('Input sequence x[n] '); Rxx=xcorr(x); nRxx=-length(x)+1:length(x)-1; subplot(2,1,2); stem(nRxx,Rxx); xlabel('Time');ylabel('Amplitude'); title('Autocorrelation of x[n]'); %Verification of properties center_index=ceil(length(Rxx)/2); Rxx_0=Rxx(center_index); E=sum(x.^2);

if Rxx_0==E disp('Energy (Mean square value) property is verified.'); else disp('Energy property is not verified.'); end Rxx_right=Rxx(center_index:length(Rxx)); Rxx_left=Rxx(center_index:-1:1); if Rxx_right==Rxx_left disp('Autocorrelation is an even function. Hence symmetry property is verified.'); else disp('Autocorrelation is not even.'); end m=max(Rxx); if m==Rxx_0 disp('Maximum value of autocorrelation function is at zero.'); else disp('Maximum value is not at zero.'); end z=x.*2; Rzz=xcorr(z)/2; Rmn=Rxx+Rxx; if Rzz==Rmn disp('Linearity property is verified'); else disp('Linearity property is not verified'); end

6.

Cross correlation of given sequences and verification of its properties.

clc;clear all;close all; x=input('Enter the first sequence x[n]:'); y=input('Enter the second sequence y[n]:'); nx=length(x); ny=length(y); n=max(nx,ny); Rxy=xcorr(x,y); subplot(3,1,1); nxl=0:1:nx-1; stem(nxl,x); xlabel('Time');ylabel('Amplitude'); title('Input sequence x[n]'); subplot(3,1,2); nyl=0:1:ny-1; stem(nyl,y); xlabel('Time');ylabel('Amplitude'); title('Input sequence y[n]'); subplot(3,1,3); l=-n+1:n-1; stem(l,Rxy); xlabel('Time');ylabel('Amplitude'); title('Cross correlation of x[n] and y[n]'); %Verification of properties z=fliplr(Rxy); Ryx=xcorr(y,x); if z==Ryx disp('Rxy(-k)=Ryx(k) - Verified.'); end

a=Rxy.*Rxy; Rxx=xcorr(x); Ryy=xcorr(y); c1=ceil(length(Rxx)/2); c2=ceil(length(Ryy)/2); Rxx_0=Rxx(c1); Ryy_0=Ryy(c2); if a<=Rxx_0.*Ryy_0 disp('Rxy(k)^2<=Rxx(0).Ryy(0) - Verified.'); end

7.

Solving a given difference equation.

clc;clear all;close all; a=input('Enter the coefficients of y[n]:'); b=input('Enter the coefficients of x[n]:'); x=input('Enter the input values:'); ic=input('Enter the initial conditions:'); zi=filtic(b,a,ic); y=filter(b,a,x,zi); n=0:length(y)-1; stem(n,y); xlabel('Time');ylabel('Amplitude'); title('Solution of difference equation: ');

8. Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum.
clc;clear all;close all; x=input('Enter x[n]:'); nx=0:length(x)-1; N=32; %Compute DFT n=0:length(x)-1; for k=0:N-1 w=exp(-j*2*pi*k*n/N); dot_prod=x.*w; X(k+1)=sum(dot_prod); end %Plot the input subplot(3,1,1); stem(nx,x); xlabel('Time');ylabel('Input x[n]'); title('Input sequence x[n] '); title('Computation of DFT '); %Plot the magnitude spectrum subplot(3,1,2); stem(abs(X)); xlabel('Time');ylabel('Amplitude'); title('Magnitude Spectrum'); %Plot the phase spectrum subplot(3,1,3); stem(angle(X)); xlabel('Time');ylabel('Angle in radian'); title('Phase Spectrum');

9.

Linear convolution of two sequences using DFT and IDFT.

clc;clear all;close all; x=input('Enter x[n]:'); h=input('Enter h[n]:'); nx=length(x); nh=length(h); n=nx+nh-1; xnew=[x zeros(1,n-nx)]; hnew=[h zeros(1,n-nh)]; xf=fft(xnew); hf=fft(hnew); zf=xf.*hf; z=ifft(zf); lx=0:1:nx-1; lh=0:1:nh-1; nz=0:1:length(z)-1; subplot(3,1,1); stem(lx,x); xlabel('Time');ylabel('Amplitude'); title('Input sequence x[n]'); subplot(3,1,2); stem(lh,h); xlabel('Time');ylabel('Amplitude'); title('Impulse Response h[n]'); subplot(3,1,3); stem(nz,z); xlabel('Time');ylabel('Amplitude'); title('Linear Convolution '); %Verification z1=conv(xnew,hnew)

10.

Circular convolution of two given sequences using DFT and IDFT

clc;clear all;close all; x=input('Enter x[n]:'); h=input('Enter h[n]:'); nx=length(x); nh=length(h); n=max(nx,nh); xnew=[x zeros(1,n-nx)]; hnew=[h zeros(1,n-nh)]; xf=fft(xnew); hf=fft(hnew); zf=xf.*hf; z=ifft(zf); lx=0:1:nx-1; lh=0:1:nh-1; nz=0:1:length(z)-1; subplot(3,1,1); stem(lx,x); xlabel('Time');ylabel('Amplitude'); title('Input sequence x[n] '); subplot(3,1,2); stem(lh,h); xlabel('Time');ylabel('Amplitude'); title('Impulse Response h[n]'); subplot(3,1,3);

stem(nz,z); xlabel('Time');ylabel('Amplitude'); title('Circular Convolution');

11.

Design and implementation of FIR filter to meet given specifications.

clc;close all;clear all; rp=input('Enter the passband ripple:'); rs=input('Enter the stoopband ripple:'); fp=input('Enter the passband frequency:'); fs=input('Enter the stoopband frequency:'); f=input('Enter the sampling frequency:'); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1; end y=boxcar(n1); %-----> (1) b=fir1(n,wp,'low',y); %-----> (2) [h,o]=freqz(b,1,256); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(o/pi,m); title('Magnitude response'); xlabel('Normalised frequency'); ylabel('Gain in dB'); subplot(2,1,2);plot(o/pi,an); title('Phase response'); xlabel('Normalised frequency'); ylabel('Gain in rad'); %make relevent changes in (1) for diff. window % % % % % % boxcar------->rectangular window bartlett----->bartlett window blackman----->blackman window chebwin------>chebyshev window hamming------>hamming window hanning------>hanning window

%make relevent changes in (2) for diff. types %low pass-------->(n,wp,'low',y); %high pass------->(n,wp,'high',y); %band pass------->(n,[wp ws],'bandpass',y); %band stop------->(n,[wp ws],'stop',y); % for kaisar window make these changes % beta=input('Enter the value of beta----->after line 6 %y=kaiser(n1,beta)------>in line 17 % Eg: (Values work for all types of FIR filters) % rp=0.02 rs=0.01 fp=1000 fs=1500 f=10000 beta=5.8

12.

Design and implementation of IIR filter to meet given specifications.

%butterworth filter clc;close all;clear all; format long; rp=input('Enter the passband ripple:'); rs=input('Enter the stoopband ripple:'); fp=input('Enter the passband frequency:'); fs=input('Enter the stoopband frequency:'); f=input('Enter the sampling frequency:'); wp=2*fp/f; ws=2*fs/f; [n,wn]=buttord(wp,ws,rp,rs); %--------->(1) [b,a]=butter(n,wn,'low'); %--------->(2) w=0:0.01:pi; [h,o]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(o/pi,m); title('Magnitude response'); xlabel('Normalised frequency'); ylabel('Gain in dB'); subplot(2,1,2);plot(o/pi,an); title('Phase response'); xlabel('Normalised frequency'); ylabel('Gain in rad'); %chebyshev type I filter %(1)------>[n,wn]=cheb1ord(wp,ws,rp,rs); %(2)------>[b,a]=cheby1(n,rp,wn,'low'); %chebyshev type II filter %(1)------>[n,wn]=cheb2ord(wp,ws,rp,rs); %(2)------>[b,a]=cheby2(n,rs,wn,'low'); % rp=.035 rs=35 fp=1500 fs=2000 f=8000

B. LIST OF EXPERIMENTS USING DSP PROCESSOR 1. 2. 3. Linear convolution of two given sequences. Circular convolution of two given sequences. Computation of N- Point DFT of a given sequence

4. Realization of an FIR filter (any type) to meet given specifications .The input can be a signal from function generator / speech signal. 5. Audio applications such as to plot time and frequency (Spectrum) display of Microphone output plus a cosine using DSP. Read a wav file and match with their respective spectrograms 6. Noise: Add noise above 3kHz and then remove; Interference suppression using 400 Hz tone.

7.

Impulse response of first order and second order system

You may also like -

HDL Lab Programs

eBook for web design competition

Nokia E63 (s60 v3) free apps

[Review] ASUS 1015 PEM netbook

Share this:

Login

Follow the discussion

Comments (7)
Sort by: Date Rating Last Activity
0

Hariraj 13 weeks ago


Sir, If you could can you please show manual calculations : ) ty Reply 4 replies active 11 weeks ago +1

manishchiniwalar 18p 13 weeks ago


calculations of? Reply 0

Hariraj 13 weeks ago


Sir, for example when we go for labs, our lab in charge gives us a sum which we solve it and then we try to prove it via the programs that the calculations so obtained are true. Reply +2

manishchiniwalar 18p 13 weeks ago


Ok. I'll try and do that when i get some free time. I too need some revision :P Which college, by the way? Reply 0

Hariraj 11 weeks ago


i am from Dayanand Sagar :P bangalore Reply 0

adi 11 weeks ago


sir, if you have analog communication lab manual,pleace provide me.. Reply 1 reply active 11 weeks ago +4

manishchiniwalar 18p 11 weeks ago


Sorry buddy, i dont have it. i'll mail it to you when i get it :) And dont call me sir, i'm still 21 :P Reply

Post a new comment


Enter text right here!

Comment as a Guest, or login:


Login to IntenseDebate Login to WordPress.com facebook Login to OpenID

Name Email Website (optional)

Submit Comment Subscribe to Copyright 2010 Powered by: Manish R Chiniwalar

MyMusic

Você também pode gostar