Program 5 .Using the DFT and IDFT, compute the following for any two given sequences a)Circular convolution b) Linear convolution % 1.Get the input sequence1 and Plot input the sequence1 x=input ('Enter the sequence x(n) = ') a=0: length(x)-1; Subplot (2, 2, 1); Stem ( a,x ); xlabel ('n'); ylabel ('x(n)'); title('SEQUENCE x(n)'); Grid on; %2.Get the input sequence2 and Plot input the sequence2 h=input ('Enter the sequence h(n) = ') b=0: length (h)-1; subplot (2,2,2); stem ( b,h ); xlabel ('n'); ylabel ('h(n)'); title('SEQUENCE h(n)'); grid on ;
contd %3.Find the Linear Convolution of the two given sequence using DFT & IDFT and Plot the output sequence L=length(x)+length(h)-1; XK= fft ( x,L ); HK= fft ( h,L ); YK=XK.*HK; disp (‘Linear Convolution of the two given sequence using DFT & IDFT’); y=real( ifft (YK)) c=0:length(y)-1; subplot(2,2,3); stem( c,y ); xlabel ('n'); ylabel ('y(n)'); title(' Linear Convolution of the two given sequence using DFT & IDFT '); grid on ;
Enter the sequence x(n) = [1 2 3 4] x = 1 2 3 4 Enter the sequence h(n) = [2] h = 2 Linear Convolution of the two given sequence using DFT & IDFT y = 2 4 6 8
Circular Convolution b) Computation of circular convolution of two given sequences using DFT and IDFT %1.Get the input sequence1 and Plot input the sequence1 x=input('Enter the sequence x(n) = ') a=0:length(x)-1; subplot(2,2,1); stem( a,x ); xlabel ('n'); ylabel ('x(n)'); title('SEQUENCE x(n)'); grid on; %2.Get the input sequence2 and Plot input the sequence2 h=input('Enter the sequence h(n) = ') b=0:length(h)-1; subplot(2,2,2); stem( b,h ); xlabel ('n'); ylabel ('h(n)'); title('SEQUENCE h(n)'); grid on;
5.Circular Convolution Find the Circular Convolution of the two given sequence using DFT & IDFT Plot the output sequence L=max(length(x),length(h)); XK= fft ( x,L ); HK= fft ( h,L ); YK=XK.*HK; disp (‘Circular Convolution of the two given sequence using DFT & IDFT’); y=real( ifft (YK)) c=0:length(y)-1; subplot(2,2,3); stem( c,y ); xlabel ('n'); ylabel ('y(n)'); title(' Circular Convolution of the two given sequence using DFT & IDFT '); grid on;
Convolution Circular Convolution using DFT & IDFT Enter the sequence x(n) = [1 0 1 0] x = 1 0 1 0 Enter the sequence h(n) = [1 1 1 1] h = 1 1 1 1 Circular Convolution of the two given sequence using DFT & IDFT y = 2 2 2 2
Program 6.Verification of DFT properties. disp ('Verification of DFT Linearity Property: ax1(n)+bx2(n)=aX1(k)+bX2(k)'); a=input('Enter value of a='); b=input('Enter value of b='); x1=input('Enter x1(n)='); x2=input('Enter x2(n)='); LHS= fft (a*x1+b*x2) RHS=a* fft (x1)+b* fft (x2) disp ('LHS=RHS, DFT Linearity Property proved.');
Contd % DFT Circular Time Shift Property disp ('Verification of DFT Circular Time Shift Property: DFT{x((n- m))N}=WN^( mk )*X(k)'); m=input('Enter value of m='); N=length(x1); k=0:1:N-1; LHS= fft ( circshift (x1,[1,m])) % Twiddle factor WN^( mk ) WN=exp(-j*2*pi/N); mk =m'*k; WNmk =WN.^( mk ); RHS= fft (x1).* WNmk disp ('LHS=RHS, DFT Circular Time Shift Property proved.'); disp (RHS) % DFT Circular Frequency Shift Property disp ('Verification of DFT Circular Frequency Shift Property: DFT{WN^(- mk )*x(n)}=X((k-m))N'); WNmk =WN.^(- mk ); LHS= fft (WNmk.*x1) RHS= circshift ( fft (x1),[1,m]) disp ('DFT Circular Frequency Shift Property proved.');
Contd DFT{WN^(- mk )*x(n)}=X((k-m))N'); WNmk =WN.^(- mk ); LHS= fft (WNmk.*x1) RHS= circshift ( fft (x1),[1,m]) disp ('DFT Circular Frequency Shift Property proved.'); Output: Verification of DFT Linearity Property: ax1(n)+bx2(n)=aX1(k)+bX2(k) Enter value of a=2 Enter value of b=6 Enter x1(n)=[2 3 1 4] Enter x2(n)=[1 2 2 1] LHS = 56.0000 -4.0000 - 4.0000i -8.0000 -4.0000 + 4.0000i RHS = 56.0000 -4.0000 - 4.0000i -8.0000 -4.0000 + 4.0000i LHS=RHS, DFT Linearity Property proved. Verification of DFT Circular Time Shift Property: DFT{x((n-m))N}=WN^( mk )*X(k) Enter value of m=2 LHS = 10.0000 -1.0000 - 1.0000i -4.0000 -1.0000 + 1.0000i RHS = 10.0000 -1.0000 - 1.0000i -4.0000 - 0.0000i -1.0000 + 1.0000i LHS=RHS, DFT Circular Time Shift Property proved. Verification of DFT Circular Frequency Shift Property: DFT{WN^(- mk )*x(n)}=X((k-m))N LHS = -4.0000 + 0.0000i 1.0000 - 1.0000i 10.0000 - 0.0000i 1.0000 + 1.0000i RHS = -4.0000 1.0000 - 1.0000i 10.0000 1.0000 + 1.0000i DFT Circular Frequency Shift Property proved.
Expt 8:DESIGN AND IMPLEMENTATION OF DIGITAL HIGH PASS FIR FILTER USING A WINDOW TO MEET THE GIVEN SPECIFICATIONS
Result Enter the Value of Sampling frequency ( fs ) in Hz=8000 Enter the Value of Cutoff frequency ( fc )in Hz=2000 Enter the Order (ODD Order) =30
Output
8b Result 10b: Enter the Value of Sampling frequency ( fs ) inHz =2000 Enter the Value of Cutoff frequency ( fc )in Hz=500 Enter the Order (ODD Order)20
output
Expt 9.DESIGN AND IMPLEMENTATION OF DIGITAL IIR BUTTERWORTH LOW PASS FILTER TO MEET THE GIVEN SPECIFICATIONS clc ; clear all fs =input('Enter the Value of Sampling frequency ( fs ) in Hz='); kp =input('Enter the Value of Pass band Attenuation in dB='); ks =input('Enter the Value of Stop band Attenuation in dB='); fp =input('Enter the Value of Pass band Frequency in Hz='); fstop =input('Enter the Value of Stop band Frequency in Hz='); wp = fp /( fs /2); wstop = fstop /( fs /2); [N, wc ]= buttord ( wp,wstop,kp,ks ) [b, a]=butter( N,wc,'low ') freqz (b,a,1000,fs)
Result 9a: Enter the Value of Sampling frequency ( fs ) in Hz=1000 Enter the Value of Pass band Attenuation in dB=3 Enter the Value of Stop band Attenuation in dB=60 Enter the Value of Pass band Frequency in Hz=40 Enter the Value of Stop band Frequency in Hz=150 N =5 wc =0.0810 b = 1.0e-03 *0.0227 0.1136 0.2272 0.2272 0.1136 0.0227 a =1.0000 -4.1768 7.0358 -5.9686 2.5478 -0.4375
output
Result 9 b: Enter the Value of Sampling frequency ( fs ) in Hz=5000 Enter the Value of Pass band Attenuation in dB=7 Enter the Value of Stop band Attenuation in dB=70 Enter the Value of Pass band Frequency in Hz=50 Enter the Value of Stop band Frequency in Hz=500 N = 4 wc = 0.0276 b =1.0e-04 *0.0315 0.1259 0.1888 0.1259 0.0315 a =1.0000 -3.7737 5.3464 -3.3701 0.7974
output
10.DESIGN AND IMPLEMENTATION OF DIGITAL IIR BUTTERWORTH HIGH PASS FILTER TO MEET THE GIVEN SPECIFICATIONS clc ; clear all fs =input('Enter the Value of Sampling frequency ( fs ) in Hz='); kp =input('Enter the Value of Pass band Attenuation in dB='); ks =input('Enter the Value of Stop band Attenuation in dB='); fp =input('Enter the Value of Pass band Frequency in Hz='); fstop =input('Enter the Value of Stop band Frequency in Hz='); wp = fp /( fs /2); wstop = fstop /( fs /2); [N, wc ]= buttord ( wp,wstop,kp,ks ) [b, a]=butter( N,wc,'high ') freqz (b,a,1000,fs)
Result 10a: Enter the Value of Sampling frequency ( fs ) in Hz=1000 Enter the Value of Pass band Attenuation in dB=3 Enter the Value of Stop band Attenuation in dB=60 Enter the Value of Pass band Frequency in Hz=40 Enter the Value of Stop band Frequency in Hz=150 N = 5 wc =0.0810 b =0.6615 -3.3073 6.6145 -6.6145 3.3073 -0.6615 a =1.0000 -4.1768 7.0358 -5.9686 2.5478 -0.4375
output
Result 10b: Result 12a: Enter the Value of Sampling frequency ( fs ) in Hz=5000 Enter the Value of Pass band Attenuation in dB=7 Enter the Value of Stop band Attenuation in dB=70 Enter the Value of Pass band Frequency in Hz=50 Enter the Value of Stop band Frequency in Hz=500 N = 4 wc =0.0276 b = 0.8930 -3.5719 5.3579 -3.5719 0.8930 a = 1.0000 -3.7737 5.3464 -3.3701 0.7974