Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
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)));
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
%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
%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;
%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
% 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
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
Swanirbhar SMD
SEARCH OUR S
You are here: Blog > College > Lab > DSP Lab programs
Here are the lab programs for DSP Lab(V sem Electronics and communication) Subject Code : 06ECL57 Awesome Resources: DSPGuide and DSPRelated
%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.
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.
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.
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.
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.
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.
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.
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.
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);
11.
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.
%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.
Share this:
Login
Comments (7)
Sort by: Date Rating Last Activity
0
MyMusic