# 12/1/2011

2011

Digital Signal Processing Lab

Faiz Karobari
S.L.N. Engineering College, Raichur.
2011-12

H.K.E. SOCIETY’S

SAROJINI LEELADHARAN NAIR COLLEGE OF ENGINEERING
Yermaras Camp, RAICHUR – 584 101

LABORATORY CERTIFICATE
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING

This is to Certify that Mr./Mrs./Miss ___________________
__________________________
of
B.E.,
Vth
semester
having
USN______________ has satisfactorily conducted course of experiments in
DSP LAB practical prescribed by Visvesvaraya Technical University during the
year 2011-12.
Staff incharge

Date : __________
Roll No. :________
USN:___________
Examiners: 1._____________

2._________________

INDEX
A. LIST OF EXPERIMENT USING MATLAB

Page No.

1. Linear Convolotion of Two Sequences.

5

2. Impulse Response (Deconvolution) of two given Sequences.

9

3. Impulse Response of a given Sequences.

11

4. Difference Equation.

15

5. Autocorrelation of a given sequence.

18

6. Cross Correlation of a given sequence.

22

7. Circular Convolution of Two given Sequences.

25

8. N pt. DFT of a Given Sequence.

29

9. N pt. IDFT of a Given Sequence.

33

10. Circular Convolution using DFT and IDFT.

37

11. Linear Convolution using DFT and IDFT.

42

12. Linear Convolution using Circular Convolution.

45

13. Sampling Theorem using Spline Function.

47

14. Sampling Theorem without using Spline Function

51

15. FIR Filter Design using MATLAB

53

16. Digital Filter Design using MATLAB

56

Page | 3
DSP LAB – 2011/12

LIST OF EXPERIMENT USING MATLAB PROCESSOR Page No.B. Impluse Response Using DSP Processor 62 Page | 4 DSP LAB – 2011/12 . DFT Using DSP Processor 61 4. N Pt. Circular Convolution Using DSP Processor 60 3. Linear Convolution Using DSP Processor 59 2. 1.

2.3.3.4} & h(n)={4.3. Soln: x(n)={1.4 0.1}.5 0 0. output and unit sample response of the system.2. LINEAR CONVOLUTION OF TWO SEQUENCES Linear Convolution relates the input.1} input x(n) output h(n) 4 amplitude of h(n) amplitude of x(n) 4 3 2 1 0 0 1 2 samples of x(n) input x1(n) 1 0 1 2 samples of h(n) input y1(n) 3 0 1 2 samples of y1(n) 3 4 amplitude of y1(n) amplitude of x1(n) 2 0 3 1 0.1.2 0 -1 3 -0.3.2.5 samples of x1(n) 1 3 2 1 0 Page | 5 DSP LAB – 2011/12 .8 0.6 0.4} h(n)={4. Find the Linear Convolution between x(n) & h(n). It is defined as_ y(n) = x(n) * h(n) ∞ = 𝑥 𝑘 ℎ 𝑛−𝑘 𝑘=−∞ Ex: For x(n)={1.2.

11.20.4} input y(n) 30 amplitude of y(n) 25 20 15 10 5 0 0 1 2 3 samples of y(n) 4 5 6 Page | 6 DSP LAB – 2011/12 .5 1 1.5 1 0.5 0 0 0.5 samples of x(2) input x(3) 2 0 0 1 2 3 samples of y2(n) output y3(n) 4 0 2 4 samples of y3(n) 6 15 amplitude of y3(n) amplitude of x(3) 4 2 3 2 1 0 6 0 1 2 samples of x(3) 10 3 5 0 y(n) = y1(n)+y2(n)+y3(n)+y4(n) = {4.20.11.30.input x(2) output y2(n) 8 amplitude of y2(n) amplitude of x(2) 2 1.

hn). subplot(3. stem(n2.1] yn 4 11 20 30 20 11 4 Page | 7 DSP LAB – 2011/12 . disp(yn).2. n=0:1:(length(xn)-1). stem(n.1. title('input x(n)').hn). ylabel('amplitude of y(n)').3. ylabel('amplitude of h(n)'). ylabel('amplitude of x(n)'). title('output y(n)'). xn =input('Enter the sequence x(n)'). n2=0:1:(length(yn)-1). xlabel('samples of x(n)'). xlabel('samples of y(n)'). xlabel('samples of h(n)'). disp('yn'). stem(n1. yn =conv(xn.3. subplot(3.yn). n1=0:1:(length(hn)-1).MATLAB CODE: clc.2.1. hn =input('Enter the sequence h(n)').4] Enter the sequence h(n)[4. subplot(3.1.2). title('input h(n)').xn). Output : Enter the sequence x(n)[1.1).3).

5 samples of h(n) output y(n) 2 2.5 1 1.5 3 0 0.5 3 0 1 2 3 samples of y(n) 4 5 6 4 2 0 40 20 0 Page | 8 DSP LAB – 2011/12 .amplitude of y(n) amplitude of h(n) amplitude of x(n) Plot : input x(n) 4 2 0 0 0.5 samples of x(n) input h(n) 2 2.5 1 1.

2. yn =input('Enter the sequence y(n)'). disp('hn'). title('output impulse response h(n)'). n=0:1:(length(xn)-1). stem(n2. xlabel('samples of h(n)').1. title('input x(n)'). xlabel('samples of y(n)'). n2=0:1:(length(hn)-1).30.3. xn =input('Enter the sequence x(n)'). ylabel('amplitude of h(n)').xn). subplot(3.1.20.xn).2). title('input y(n)').11. stem(n1.1).4] Enter the sequence y(n)[4. subplot(3.2. stem(n.4] hn 4 3 2 1 Page | 9 DSP LAB – 2011/12 . MATLAB CODE FOR DECONVOLUTION (IMPULSE RESPONSE) OF TWO GIVEN SEQUENCE clc.yn). subplot(3. ylabel('amplitude of y(n)').1. n1=0:1:(length(yn)-1).20.11.3).hn). disp(hn). xlabel('samples of x(n)'). hn =deconv(yn. Output : Enter the sequence x(n)[1. ylabel('amplitude of x(n)').

5 3 5 6 2.5 1 0 1 2 0 0.amplitude of h(n) amplitude of y(n) amplitude of x(n) Plot : input x(n) 4 2 0 0 0.5 samples of h(n) 2 Page | 10 DSP LAB – 2011/12 .5 samples of x(n) input y(n) 2 2.5 3 40 20 0 3 4 samples of y(n) output impulse response h(n) 4 2 0 1 1.5 1.

3.2.4}. Y Z Z HZ =X = 4+11𝑍 −1 +20𝑍 −2 +30𝑍 −3 +20𝑍 −4 +11𝑍 −5 +4𝑍 −6 1+2𝑍 −1 +3𝑍 −2 +4𝑍 −3 4 + 3𝑍 −1 + 2𝑍 −2 + 𝑍 −3 1 + 2𝑍 −1 + 3𝑍 −2 + 4𝑍 −3 4 + 11𝑍 −1 + 20𝑍 −2 + 30𝑍 −3 + 20𝑍 −4 + 11𝑍 −5 + 4𝑍 −6 4 + 08𝑍 −1 + 12𝑍 −2 + 16𝑍 −3 3𝑍 −1 + 8𝑍 −2 + 14𝑍 −3 + 20𝑍 −4 + 11𝑍 −5 + 4𝑍 −6 3𝑍 −1 + 6𝑍 −2 + 9𝑍 −3 + 12𝑍 −4 2𝑍 −2 + 5𝑍 −3 + 8𝑍 −4 + 11𝑍 −5 + 4𝑍 −6 2𝑍 −2 + 4𝑍 −3 + 6𝑍 −4 + 8𝑍 −5 𝑍 −3 + 2𝑍 −4 + 3𝑍 −5 + 4𝑍 −6 𝑍 −3 + 2𝑍 −4 + 3𝑍 −5 + 4𝑍 −6 𝐻 𝑍 = 4 + 3𝑍 −1 + 2𝑍 −2 + 𝑍 −3 On applying inverse Z T ℎ 𝑛 = {4. Soln: x(n)= applying ZT on both sides.11.t.4} and y(n)={4. Ex1: Find the impulse response for a given sequence x(n)={1.11.1}. 𝑌 𝑍 = 4 + 11𝑍 −1 + 20𝑍 −2 + 30𝑍 −3 + 20𝑍 −4 + 11𝑍 −5 + 4𝑍 −6 w.. Page | 11 DSP LAB – 2011/12 .3.30. which is known as impulse response of the system.20.2. IMPULSE RESPONSE OF A GIVEN SEQUENCE A complete characterization of an LTI system can be represented interms of its response to an unit impulse.3. 𝑋 𝑍 = 1 + 2𝑍 −1 + 3𝑍 −2 + 4𝑍 −3 y(n)= applying ZT on both sides.k.20. OR The impulse response is the output of a LTI system due to an impulse input applied at t=0 or n=0.

5 By Power Series Method 1+ 0.25 0.25 𝑍 0.0.5 0. 1 if 𝐻 𝑍 = 1−0.25 𝑍2 Z-0.25 𝑍 0.1.125 𝑍2 Therefore h(n)=.5𝑍 −1 𝑍 = 𝑍−0.5.………….0.125. Calculate h(n).5𝑍 −1 .5 0.5- 0.- Page | 12 DSP LAB – 2011/12 .5 Z Z-0.125 − 𝑍2 𝑍 0. Soln: 1 Given 𝐻 𝑍 = 1−0.Ex2: Determine the impulse response when H[Z] is given.5 𝑍 + 0.

stem(n1.hn).5] Enter the length of the sequence7 hn= 1.n). a=input('Enter the coefficients of numerator').0625 0.5000 0. xlabel('samples of h(n)'). n=input('Enter the length of the sequence').-0.0000 0. Output : Enter the coefficients of numerator[1] Enter the coefficients of denominator[1.b. n1=0:1:n-1. b=input('Enter the coefficients of denominator').0313 0. disp('hn='). hn=impz(a. ylabel('amplitude of h(n)'). disp(hn).MATLAB CODE: clc. title('output impulse response h(n)').2500 0.1250 0.0156 Page | 13 DSP LAB – 2011/12 .

8 amplitude of h(n) 0.6 0.1 0 0 1 2 3 samples of h(n) 4 5 6 Page | 14 DSP LAB – 2011/12 .3 0.7 0.Plot : output impulse response h(n) 1 0.5 0.4 0.2 0.9 0.

8 y(3) + x(5) . 3 y(3) = 4 y(2) .4 y(n-1) + 8 y(n-2) = x(n) . x(-1)=0. 3 y(5) = 4 y(4) .4.8 y(-1) + x(1) .1.8 y(2) + x(4) . Soln: 3 1 1 y(n) .6042 at n=3.8 y(1) + x(3) .7568 at n=6.4 y(n-1) + 8 y(n-2) = x(n) .1.3 x(3) y(4) = 1.1.1.3 x(2) y(3) = 1. IMPLEMENTATION OF DIFFERENCE EQUATION Solve the difference equation 3 1 1 y(n) .3 x(n-1) at n=0.3 x(4) y(5) = 1. 3 y(4) = 4 y(3) .1.1.8 y(-2) + x(0) .7357 at n=5. 3 y(2) = 4 y(1) = 8 y(0) + x(2) .1.3 x(-1) y(0)=1 at n=1.1} and N=10 at initial conditions y(-1)=0.4166 at n=2.3 x(1) y(2) = 1.3 x(n-1) where x(n)={1.3 x(0) y(1) = 1. 3 1 1 y(0) = 4 y(-1) .6927 at n=4.1.7673 Page | 15 DSP LAB – 2011/12 . 3 y(6) = 4 y(5) .3 x(5) y(6) = 1. y(-2)=0. 3 1 1 1 1 1 1 1 1 1 1 1 1 y(1) = 4 y(0) .8 y(4) + x(6) .

3 x(8) y(9) = 1.8 y(7) + x(9) .at n=7.3 x(6) y(7) = 1.3 x(7) y(8) = 1.7752 at n=9. 3 y(9) = 4 y(8) .8 y(6) + x(8) .7726 at n=8. 3 1 1 1 1 1 1 y(7) = 4 y(6) .7765 Page | 16 DSP LAB – 2011/12 .8 y(5) + x(7) . 3 y(8) = 4 y(7) .

0000 1.-1/3] Enter the coefficients of y[1.1.yn).1. Output : Enter the coefficients of x[1. title('output y(n)').7726 1.-3/4.7765 Plot : output y(n) amplitude of y(n) 2 1. b=input('Enter the coefficients of y').xn).7752 1. xlabel('samples of y(n)'). disp(yn).7673 1.MATLAB CODE: clc. ylabel('amplitude of y(n)'). n=0:1:(length(yn)-1).b. yn=filter(a.7568 1. a=input('Enter the coefficients of x').1. disp('yn=').6927 1.1/8] Enter the sequence of x(n)[1.5 1 0.4167 1. stem(n1.1] yn= 1. xn=input('Enter the sequence of x(n)').1.1.1.7357 1.6042 1.5 0 0 1 2 3 4 5 samples of y(n) 6 7 8 9 Page | 17 DSP LAB – 2011/12 .1.1.

𝟏} Page | 18 DSP LAB – 2011/12 .𝟑.2.𝟓.𝟕.1} 1 11 1 2 1 2 1 1 21 2 4 2 11 1 2 1 11 1 2 1 𝒓𝒙𝒙={𝟏.𝟑. ±2. it is called autocorrelation.1} x(-n)={1. It is given by ∞ 𝑟𝑥𝑥 𝑙 = x l x(n − l) 𝑛=−∞ For n=0.1} Sol: x(n)={1. AUTO CORRELATION OF A GIVEN SEQUENCE AND VERIFCATION OF ITS PROPERTIES When the signal is correlated with itself. ±1.𝟓.2.1.2.1. … … Ex: Evaluate auto correlation of the sequence x(n)={1.5.1.

𝟏𝟏. Page | 19 DSP LAB – 2011/12 . 𝟐𝟎 𝐫𝐱𝐱−right = 𝟐𝟎.2.𝟐𝟎. The centre index is 4. x(n)={1.𝟒 Energy of x(n) is 3 𝐸= x 2 𝑛=0 2 =1 + 22 + 32 + 42 E =30 Hence the energy E is equal to rxx (0) hence it is an energy signal 𝐫𝐱𝐱−left = 𝟒.3.𝟐𝟎.2.3.VERFICATION: Ex: Find the auto correlation of x(n)={1.2.1} 1 4 4 3 3 2 2 1 1 2 8 6 4 2 3 12 9 6 3 4 16 12 8 4 𝐫𝐱𝐱= 𝟒. 𝟏𝟏.4} x(-n)={4.3.𝟑𝟎. 𝟒 Hence rxx is symmetric about the origin (30) hence it is an even signal.4} and verify its properties Soln: Given.𝟏𝟏. 𝟏𝟏.

ylabel('amplitude of z(n)').xn). n2=-(length(zn)-1)/2:1:(length(zn)-1)/2. stem(n1. ylabel('amplitude of x(n)'). xlabel('samples of x(n)'). disp(zn). subplot(3. xlabel('samples of y(n)').MATLAB CODE: clc. Output : Enter the input signal x(n)=[1. subplot(3. title('input y(n)'). yn =fliplr(xn). xlabel('samples of z(n)'). stem(n2. xn =input('Enter the input signal x(n)='). disp('zn').1] zn 1 3 5 7 5 3 1 Page | 20 DSP LAB – 2011/12 .2.zn).yn).1.1). title('input x(n)'). n=0:1:(length(xn)-1).1.yn).3).1.1. zn =conv(xn. subplot(3. stem(n. n1=-(length(yn)-1):1:0. title('output z(n)').2). ylabel('amplitude of y(n)').

5 0 -2 -1 0 samples of z(n) 1 2 3 2 1 10 5 0 -3 Page | 21 DSP LAB – 2011/12 .5 samples of x(n) input y(n) 2 2.amplitude of z(n) amplitude of y(n) amplitude of x(n) Plot : input x(n) 2 1 0 0 0.5 3 0 -3 -2.5 samples of y(n) output z(n) -1 -0.5 1 1.5 -2 -1.

𝟒.6.1}.𝟏} Page | 22 DSP LAB – 2011/12 .1.1} y(n)={1.1.2.𝟓.1.1} 1 11 2 1 1 2 1 1 22 4 2 2 11 2 1 1 11 2 1 1 𝒓𝒙𝒚={𝟏.2.2. … … Ex: Evaluate cross correlation of the fallowing sequence x(n)={1.𝟔.𝟐. ±1.1. CROSS CORRELATION OF A GIVEN SEQUENCE When the correlation of two different signals is performed it called cross correlation. Sol: x(n)={1. ±2. It is given by ∞ 𝑟𝑥𝑦 𝑙 = x l y(n − l) 𝑛=−∞ for n=0.2.1} y(-n)={1.𝟔.

yn1). xlabel('samples n'). xlabel('samples n'). subplot(4.yn1). zlen2=-(length(zn)-1)/2. stem(n3. title('input yn'). ylabel('amplitude yn').1.1] zn= 1 4 6 6 5 2 1 Plot : Page | 23 DSP LAB – 2011/12 . zlen1=(length(zn)-1)/2.1. xn=input('Enter the first sequence x(n)='). yn1=fliplr(yn). ylabel('amplitude xn'). ylen=length(yn)-1. ylabel('amplitude zn'). stem(n1. yn1len=-(length(yn1)-1). yn=input('Enter the second sequence y(n)=').3). zn=conv(xn. title('input yn'). n4=zlen2:1:zlen1.1] Enter the second sequence y(n)=[1. disp(zn).1. xlen=length(xn)-1.xn). ylabel('amplitude yn'). Output : Enter the first sequence x(n)=[1.4). subplot(4.MATLAB CODE clc. disp('zn=').zn). title('input xn').1. subplot(4.1. stem(n4. n2=0:1:ylen. n3=yn1len:1:0.1. xlabel('samples n').2.2). subplot(4.yn). stem(n2.2. xlabel('samples n'). n1=0:1:xlen.1). title('output zn').

5 3 0 0.amplitude xn amplitude yn 2 amplitude zn 2 amplitude yn input xn 2 1 0 0 0.5 0 -2 -1 0 samples n 1 2 3 1 0 1 10 5 0 -3 Page | 24 DSP LAB – 2011/12 .5 samples n input yn 2 2.5 samples n input yn 2 2.5 3 0 -3 -2.5 1 1.5 -2 -1.5 1 1.5 samples n output zn -1 -0.

3.6.(N-1) Ex: ind the circular convolution for x(n)={1.7.2.1. CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCE The circular convolution of the two sequence 𝑥1 (n) and 𝑥2 (n) is denoted by y(m)= x1 n N x2 n ∞ 𝑦𝑚 𝑚 = x1 l x2 ((m − n))N 𝑛 =−∞ for m=0.7. 3 y 0 = x n h((−n))4 𝑛=0 y(0)=x(0)h(0)+x(1)h(3)+X(2)h(2)+x(3)h(3) =1*5+2*8+3*7+4*6 =66 For m=1.8} Soln: y(m) = x(n) N h(n) ∞ y m = x n y((m − n))4 𝑛=−∞ For m=0.2. … ….4} and h(n)={5. 3 y 1 = x n h((1 − n))4 𝑛=0 y(1)=x(0)h(1)+x(1)h(0)+x(2)h(3)+x(3)h(2) =1*6+2*5+3*8+4*7 =68 Page | 25 DSP LAB – 2011/12 .

For m=2. 3 y 2 = x n h((2 − n))4 𝑛=0 y(2)=x(0)h(2)+x(1)h(1)+x(2)h(0)+x(3)h(3) =1*7+2*6+3*5+4*8 =66 For m=3 3 y 3 = x n h((3 − n))4 𝑛=0 =x(0)h(3)+x(1)h(2)+x(2)h(1)+x(3)h(0) =1*8+2*7+3*6+4*5 =60 Page | 26 DSP LAB – 2011/12 .

3.2. if(j<=0) j=N+j.MATLAB CODE: x=input('Enter the sequence of x(n)'). subplot(2.2).N3)].1] circular convolution output is y= 24 22 24 30 Page | 27 DSP LAB – 2011/12 .1.-N3)].2. h=[h.y). Output : Enter the sequence of x(n)[1. N=max(N1.zeros(1. xlabel('samples of y'). y N4=0:1:N-1. N2=length(h). end end disp('circular convolution output is'). title('output y'). end y(n)=y(n)+x(i)*h(j). if(N3>0). for i=1:N j=n-i+1.N2). h=input('Enter the sequence of h(n)'). stem(N4. N1=length(x). ylabel('amplitude of y').3.zeros(1. end for n=1:N y(n)=0. N3=N1-N2. end if(N3<0) x=[x.4] Enter the sequence of h(n)[4.

Plot : output y 30 amplitude of y 25 20 15 10 5 amplitude zn amplitude yn 0 0 1 2 samples of y 3 input yn 2 1 0 -3 -2.5 samples n output zn -1 -0.5 -2 -1.5 0 -2 -1 0 samples n 1 2 3 10 5 0 -3 Page | 28 DSP LAB – 2011/12 .

3 x n e−j 𝑋 1 = 2π 1∗n 4 𝑛=0 =x(0) + x(1) e−j π 2 + x(2) e−j π + x(3) e−j 3π 2 =(-j)+(-2)+3j X(1) = -2+2j Page | 29 DSP LAB – 2011/12 .8.1. N-POINT DFT OF A GIVEN SEQUENCE The n point DFT of a sequence x(n) is given by x(n) X(k) N DFT N−1 x n e−j 𝑋 𝑘 = 2π kn N 𝑛=0 Ex: Find the DFT of the sequence x(n)={0.3} Soln: x(n)={0.2.3} N−1 x n e−j 𝑋 𝑘 = 2π kn N 𝑛=0 For k=0.1.2. 3 𝑋 0 = x n ∗1 𝑛=0 = 0+1+2+3= 6 X(0) = 6 For k=1.

-2+2j.-2. X(k)={6. 3 π x n e−j(2 )3n 𝑋 3 = 𝑛=0 =x(0) + x(1) e −j 3π 2 + x(2) e−j 3π + x(3) e −j 9π 2 =0+j-2-3j X(3) = -2-2j Therefore.For k=2. 3 x n e−jπn 𝑋 2 = 𝑛=0 X(2) = 0-1+2-3 X(2) = -2 For k=3.-2-2j} Page | 30 DSP LAB – 2011/12 .

0000i -2.1). subplot(2.. stem(k.0000i Page | 31 DSP LAB – 2011/12 . xlabel('k.0000 -2.').0000 ..').. ylabel('magnitude of X(k)').1.2.1. [N. if M~=1.'). subplot(2.0000 .. x=input('Enter the DFT of x(n)=.[0.. n=0:N-1.3] 6..... for k=0:N-1 X(k+1)=exp(-j*2*pi*k*n/N)*x.0000 + 2.. title('phase of X(k)')..2.M]=size(x).0000i -2.1. xlabel('k=. k=0:N-1. title('magnitude of X(k)'). ylabel('phaseof X(k)'). stem(k. end disp(X).0.angle(X)').abs(X)).. end X=zeros(N.MATLAB CODE: clc. k=0:N-1.2). x=x'.. Output : Enter the DFT of x(n)=.. N=M.1).

Page | 32 DSP LAB – 2011/12 ...Plot : magnitude of X(k) 6 magnitude of X(k) 5 4 3 2 1 0 0 0. 2 2..5 3 phase of X(k) 4 phaseof X(k) 2 0 -2 -4 0 0....5 3 2 2.5 1 1..5 1 1..5 k=.5 k.

2. x(1)= = x(1)=- 1 4 1 4 𝟏 𝟐 [ X(0) + X(1) ej π 2 + x(2) ejπ + X(3) ej 3π 2 ] [1+2j-3+4(-1)] - 𝟏 𝟐 𝒋 Page | 33 DSP LAB – 2011/12 .4} Soln: X(k)={1.2. x(0)= = x(0)= 1 4 1 4 [X(0)+X(1)+x(2)+X(3)] [1+2+3+4] 𝟓 𝟐 For n=1.9. N-POINT IDFT OF A GIVEN SEQUENCE The N-point IDFT of a sequence X(k) is given by x(n) X(k) N IDFT 1 𝑥 𝑛 = 𝑁 N−1 X k ej 2π kn N 𝑛=0 Ex: find the IDFT of the sequence x(n)={1.3.4} x(n) X(k) N IDFT 1 𝑥 𝑛 = 4 3 X k e j 2π kn 4 𝑛=0 For n=0.3.

x(n)= { 𝟓 𝟐 .for n=2. x(2)= = 1 [ X(0) + X(1) ejπ + x(2) ej2π + X(3) ejπ ] 4 1 [1 + 2 −1 + 3 + 4(−10)] 4 x(2)=− 𝟏 𝟐 for n=3. x(3)= = 1 [ X(0) + X(1) ej 4 1 + x(2) ej3π + X(3) ej 9π 2 ] [1 +2(-j) + 3 + 4(-1) ] 4 x(3) =- 3π 2 𝟏 𝟐 + 𝟏 𝟐 𝒋 Therefore.− 𝟏 𝟐 − 𝟏 𝟐 𝒋 .− 𝟏 𝟐 .− 𝟏 𝟐 + 𝟏 𝟐 𝒋 } Page | 34 DSP LAB – 2011/12 .

0000i 3.M]=size(Xk).')..2)... Xk=input('Enter the DFT of X(k)=.-2.0000 + 0...0000i Page | 35 DSP LAB – 2011/12 .MATLAB CODE: clc.0000i 2. subplot(2. for n=0:N-1 Xn(n+1)=exp(j*2*pi*k*n/N)*Xk. stem(n.'..[6. disp(Xn). [N. Output : Enter the DFT of X(k)=. end Xn=zeros(N. N=M..1). n=0:N-1.0000 .1.0000 . n=0:N-1.').1).1.0. stem(n. Xk=Xk.')... xlabel('n. disp('X(n)=. end Xn=Xn/N. if M~=1.. ylabel('magnitude of Xn'). k=0:N-1...-2-2j] X(n)=.. title('magnitude of Xn').0.. 0 1..-2+2j.').angle(Xk)').. xlabel('n=.. subplot(2.abs(Xk)). ylabel('phaseof Xk').... title('phase of Xk').

..5 1 1.5 n... Page | 36 DSP LAB – 2011/12 .... 2 2.5 1 1.5 n=.5 3 2 2.5 3 phase of Xk 4 phaseof Xk 2 0 -2 -4 0 0..Plot : magnitude of Xn 6 magnitude of Xn 5 4 3 2 1 0 0 0.

3. -2-2j } Page | 37 DSP LAB – 2011/12 . Ex: Find the circular convolution of x(n)={1.2} finding X(k) using DIT FFT algorithm 𝐹1 (0) = 4 x(0)=1 x(2)=3 -1 𝐹1 (1) = −2 -1 𝐹2 (0) = 6 x(1)=2 x(3)=4 X(0)=10 -1 𝐹2 (1) = −2 X(1)=-2-2j X(2)=-2 -1 x(3)=-2-2j X(k) = {10 . CIRCULAR CONVOLUTION USING DFT & IDFT It states that.4} h(n)={4.2.2. -2 .2} using DFT and IDFT method. If 𝑥1 𝑛 𝑋1 (𝑘) N DFT and 𝑥2 𝑛 𝑋2 (𝑘) N DFT Then 𝑥1 𝑛 N 𝑥2 𝑛 N DFT 𝑋1 (𝑘) 𝑋2 (𝑘) It is stated that multiplication of two DFT’S is equivalent to circular convolution of their sequences in time domain. Soln: Given.3.3.3. -2-2j .4} and h(n)={4. x(n)={1.10.

20. 10. 2+3j } Y(k)=X(k)H(k) 10 −2 + 2𝑗 𝑌 𝑘 = −2 −2 − 2𝑗 9 90 2 − 3𝑗 2 + 10𝑗 = 3 −6 2 + 3𝑗 2 − 10𝑗 Y(k)={ 90 . -6 .Finding H(k) using DIT FFT algorithm 𝐹1 (0) = 6 h(0) h(2) 𝐹1 (1) = 2 -1 - 𝐹2 (0) = 3 h(1) h(3) H(0)=9 𝐹2 (1) = 3 -1 H(1)=2-3j -1 H(2)=3 -1 H(3)=2+3j H(k)={ 9 . 2-3j . 2-10j } Finding y(n) using DIT FFT algorithm Y(0)=90 Y(2)=-6 -1 88 𝑃1 (1) = 96 76 𝑃2 (0) = 4 Y(1)=2+10j Y(3)=2-10j 𝑃1 (0) = 84 -1 𝑃2 (1) = 20𝑗 -1 -1 80 116 1 y(0)=22 4 1 y(1)=10 4 1 4 1 4 y(2)=20 y(3)=29 y(n)={ 22. 29 } Page | 38 DSP LAB – 2011/12 . 2+10j . 3 .

MATLAB CODE :
clc;
x=input('Enter the sequence x(n)=....');
h=input('Enter the sequence h(n)=....');
N1=length(x);
N2=length(h);
N3=max(N1,N2);
N=N1-N2;
X=fft(x,N3);
disp('dft of x(n) is');
X
H=fft(h,N3);
disp('dft of h(n) is');
H
z=X.*H;
disp('dft of x & h is');
z
subplot(2,1,1);
n=0:N3-1;
stem(n,abs(z));
xlabel('n.....');
ylabel('magnitude of z');
z=ifft(z,N3);
disp('IDFT of z is.....');
z
subplot(2,1,2);
n1=0:N3-1;
stem(n1,abs(z));
xlabel('n.....');
ylabel('magnitude of z');
title('IDFT of z');

Page | 39
DSP LAB – 2011/12

Output :
Enter the sequence x(n)=....[1,2,3,4]
Enter the sequence h(n)=....[2,3,4,0]

dft of x(n) is
X=
10.0000

-2.0000 + 2.0000i -2.0000

-2.0000 - 2.0000i

dft of h(n) is
H=
9.0000

-2.0000 - 3.0000i 3.0000

-2.0000 + 3.0000i

dft of x & h is
z=
90.0000

10.0000 + 2.0000i -6.0000

10.0000 - 2.0000i

IDFT of z is.....
z=
26 23 16 25

Page | 40
DSP LAB – 2011/12

Plot :

100

magnitude of z

80
60
40
20
0

0

0.5

1

1.5
n.....

2

2.5

3

2

2.5

3

IDFT of z
30

magnitude of z

25
20
15
10
5
0

0

0.5

1

1.5
n.....

Page | 41
DSP LAB – 2011/12

M=3 N=L+M-1 Therefore. Ex: Find the linear convolution of x(n)={1. -1 .0} and h(n)={1. Y(k)=x(k)h(k) Therefore the linear convolution of two sequence is the N point IDFT of Y(k).3.3} here L=2.0. N=4 x(n)={1.2.2.2} h(n)={1. x(n)={1. then X(k) and H(k) their DFT’s of length N=L+M-1. 1-2j . Soln: Given.3} using DFT and IDFT method. LINEAR CONVOLUTION USING DFT & IDFT If x(n) and h(n) are the two sequences of length ‘l’ and ‘m’ respectively. 1+2j } Page | 42 DSP LAB – 2011/12 .2} and h(n)={1.11.0} X(k) using DIT FFT algorithm x(0)=1 x(2)=0 𝐹1 (0)=1 -1 𝐹1 (1)=1 x(1)=2 x(3)=0 X(0)=3 𝐹2 (0)=2 -1 𝐹2 (1)=2 X(1)=1-2j -1 -1 X(2)=-1 X(3)=1+2j X(K)={3 .2.2.

20 . 2+10j .H(k) using DIT FFT algorithm h(0)=1 h(2)=3 𝐹1 (0)=4 -1 𝐹1 (1)=--2 h(1)=2 h(3)=0 H(0)=6 H(1)=-2-2j 𝐹2 (0)=2 -1 -1 𝐹2 (1)=2 H(2)=2 -1 H(3)=-2+2j H(k)={9 . 3 . -6 . 19 . 2-3j . 29 } Page | 43 DSP LAB – 2011/12 . 2-10j } Y(n) using DIT FFT algorithm Y0)=18 Y(2)=-2 -1 Y(1)=2 Y(3)=-6-6j H(0)=6 20 H(1)=-2-2j 1/4 y(1)=4 H(2)=2 1/4 y(2)=7 -12 -1 y(0)=1 16 4j -1 -1 H(3)=-2+2j 1/4 1/4 y(3)=6 y(n)={ 22 . 2+3j } Y(k)=x(k)h(k) 10 −2 + 2𝑗 Y(k)= −2 −2 − 2𝑗 9 90 2 − 3𝑗 2 + 10𝑗 = 3 −6 2 + 3𝑗 2 − 10𝑗 Y(k)={ 90 .

N1=length(x). N=N1+N2-1.. Y=X..2. h=input('Enter the sequence h(n)=.. yn=ifft(Y.. disp('yn=.N). H=fft(h..5 3 Page | 44 DSP LAB – 2011/12 .3] yn=..5 samples of yn 2 2.[2.yn). 2 7 12 9 Plot : Output yn 12 amplitude of yn 10 8 6 4 2 0 0 0.N). X=fft(x.*H.. title('Output yn')... N2=length(h). Output : Enter the sequence x(n)=. disp(yn).3] Enter the sequence h(n)=.5 1 1... x=input('Enter the sequence x(n)=.N). xlabel('samples of yn')..'). stem(n.')...MATLAB CODE: clc.').[1.. n=0:N-1. ylabel('amplitude of yn')..

zeros(1. subplot(2. xlabel('samples of y'). for n=1:N y(n)=0.2. end y(n)=y(n)+x(i)*h(j). N1=length(x). N2=length(h). title('output y').12.7.2. h=input('Enter the sequence of h(n)'). end end disp('Linear convolution output is').6. ylabel('amplitude of y').zeros(1. clc. for i=1:N j=n-i+1.y). x=[x.8] Linear convolution output is y= 5 16 34 60 61 52 32 Page | 45 DSP LAB – 2011/12 . Output : Enter the sequence of x(n)[1.3. stem(N3.N1-1)].4] Enter the sequence of h(n)[5.N2-1)]. x=input('Enter the sequence of x(n)').2). MATLAB CODE FOR LINEAR CONVOLUTION USING CIRCULAR CONVOLUTION. if(j<=0) j=N+j. y N3=0:1:length(y)-1. h=[h. N=N1+N2-1.

Plot : output y 70 60 amplitude of y 50 40 30 20 10 0 0 1 2 3 samples of y 4 5 6 Page | 46 DSP LAB – 2011/12 .

title('sampled signal'). xa=spline(tt.x2.ww2). n1=t/ts1. fs=100. st=0.xa). m1=min(n1):max(n1).x). tt=m*ts. plot(tt1. m=min(n):max(n). ww2=[min(ww):ww1:max(ww)].xa1). stem(m1. ts=1/fs. x1=sin(2*pi*f*m*ts).x1). figure(3). n=t/ts. x=sin(2*pi*f*t). xa1=spline(ww. figure(2). stem(m.x2). figure(1). x2=sin(2*pi*f*m1*ts1). title('reconstructed signal'). f=10. plot(t. figure(5). figure(4).001. fs1=19. plot(ww2. title('original signal').01:1].tt1). t=[0:0. ww=m1*ts1. Page | 47 DSP LAB – 2011/12 . title('under sampled signal'). ts1=1/fs1. tt1=min(tt):st:max(tt).x1.001. ww1=0.13. MATLAB CODE FOR SAMPLING THEOREM USING SPLINE FUNCTION clc.

2 0.5 -1 0 20 40 60 Page | 48 DSP LAB – 2011/12 .5 -1 0 0.4 0.5 0 -0.8 1 80 100 Figure 2 sampled signal 1 0.Plot : Figure 1 original signal 1 0.6 0.5 0 -0.

5 -1 0 0.8 1 Figure 4 under sampled signal 1 0.6 0.4 0.5 0 -0.Figure 3 reconstructed signal 1 0.5 -1 0 5 10 15 20 Page | 49 DSP LAB – 2011/12 .2 0.5 0 -0.

8 0.4 -0.6 0.8 -1 0 0.9 1 Page | 50 DSP LAB – 2011/12 .1 0.3 0.2 0 -0.4 0.6 -0.2 -0.2 0.7 0.6 0.8 0.Figure 5 1 0.4 0.5 0.

intf). plot(rect). xlabel('t:'). plot(n1. intf=6*sinc(n1*t1/ts).4).29).14. for i=2:length(X1).2. MATLAB CODE FOR SAMPLING THEOREM WITHOUT USING SPLINE FUNCTION clc. subplot(2.1).2.intf). x=cos(2*pi*ts*n).3).2). end length(X1). xlabel('n:'). xlabel('t:'). x2=cos(2*pi*0. X1=[X1.2.x2).x(i)]. title('analog signal'). n2=0:1000. t1=ts/30. subplot(2.zeros(1. ylabel('x(t)'). ylabel('x(n)'). rect=conv(X1. xlabel('n1'). subplot(2. subplot(2. ts=1/fs.x). X1=x(1).001*n2). plot(n. title('sampled signal'). ylabel('x(t)'). n1=-100:100. fs=input('enter the sampling frequency='). plot(n2. title('reconstructed signal'). Output: Enter the Sampling Frequency=25 Page | 51 DSP LAB – 2011/12 . title('sinc function'). n=0:100.2.

5 0 200 400 600 800 -1 1000 0 20 40 t: sinc function 80 100 200 250 reconstructed signal 6 4 4 x(t) 6 2 0 -2 -100 60 n: 2 0 -50 0 n1 50 100 -2 0 50 100 150 t: Page | 52 DSP LAB – 2011/12 .5 0.5 -1 0 -0.5 x(n) x(t) analog signal 1 0 -0.Plot: sampled signal 1 0.

freqz(hn. beta=input('Enter the value of beta='). Page | 53 DSP LAB – 2011/12 . ylabel('Gain in dB'). wc=input('Enter the Digital CutOff Frequency=').1. disp(wn). M=input('Enter the Length of the Filter='). disp(hn).15. grid on.beta). disp('FIR FILTER DESIGN USING KAISER WINDOW'). title('Frequency Response of the FIR Filter'). hn=fir1(M-1.wc. disp('The Unit Sample Response of FIR Filter is h(n)='). xlabel('Normalized Frequency').wn).512). wn=Kaiser(M. FIR FILTER DESIGN USING MATLAB MATLAB CODE: clc. disp('The Kaiser Window Coefficient are as follow'). disp('').

9706 0.9195 0.0224 -0.0614 -0.0277 0.9392 0.2900 0.8166 0.9909 0.8727 0.0142 -0.2900 Columns 17 through 30 0.0224 -0.0133 -0.0142 0.0141 0.9822 0.0028 0.8457 0.9996 0.0895 0.0117 0.9822 0.0141 Page | 54 DSP LAB – 2011/12 .7175 0.7175 The Unit Sample Response of FIR Filter is h(n)= Columns 1 through 16 0.0333 0.0028 -0.7523 0.9563 0.9563 0.8973 0.0895 -0.0495 -0.2097 0.0140 -0.0072 0.0333 0.8727 0.OUTPUT: The Kaiser Window Coefficient are as follow 0.9706 0.8166 0.9996 0.0140 0.9909 0.7854 0.9195 0.0117 -0.8973 0.2097 0.7523 0.7854 0.0495 -0.9392 0.0133 0.9967 0.8457 0.9967 0.0614 -0.0072 -0.0277 -0.

7 0.3 0.4 0.8 0.1 0.2 0.7 Normalized Frequency ( rad/sample) Page | 55 DSP LAB – 2011/12 .1 0.9 1 0 Phase (degrees) -200 -400 -600 -800 -1000 0.PLOT: Frequency Response of the FIR Filter 20 0 Gain in dB -20 -40 -60 -80 -100 0 0.3 0.6 0.9 1 0.8 0.6 Normalized Frequency 0.5 0.2 0 0.4 0.5 0.

a]=bilinear(num. Ws=input('Enter Stop Band Edge Frequenccy in rad/sec=').512.Wn]=buttord(Wp. ylabel('Gain in dB'). [num. Wp=input('Enter the Pass Band Edge Frequency in rad/sec=').'s'). grid on.As. Fs=input('Enter the Sampling Frequency=').Fs).'s').Wn. [n.den. xlabel('Frequency in Hz').den]=butter(n. DIGITAL FILTER DESIGN USING MATLAB MATLAB CODE: clc. As=input('Enter Stop Band Ripple in dB='). Ap=input('Enter the Pass Band Ripple in dB='). freqz(b. OUTPUT: Enter the Pass Band Edge Frequency in rad/sec=1256.a.27 Enter Stop Band Ripple in dB=15 Enter the Sampling Frequency=2000 The Order of the filter is n=3 Page | 56 DSP LAB – 2011/12 .Ap. disp(n). title('Frequency Response of the Filter'). [b.Fs). disp('The Order of the filter is n=').Ws.63 Enter the Pass Band Ripple in dB=3 Enter Stop Band Edge Frequenccy in rad/sec=2513.16.

PLOT: Frequency Response of the Filter 50 Gain in dB 0 -50 -100 -150 -200 0 100 200 300 400 500 600 Frequency in Hz 700 800 900 1000 0 100 200 300 400 500 600 Frequency (Hz) 700 800 900 1000 0 Phase (degrees) -50 -100 -150 -200 -250 -300 Page | 57 DSP LAB – 2011/12 .

5.0} int h[15]={1.0.6.0} for(i=0.j<=m+n-1.0. } Page | 58 DSP LAB – 2011/12 . Linear Convolution Using DSP Processor C-Code: #include<stdio.h> #include<math. int i=0.h> int y[20].j++) y[i]+=x[j]*h[i-j].i<=m+n-1.0. int x[15]={1.i++) { y[i]=0.2.0.5.i<=m+n-1.0.i++) printf(“%d\n”.6. { int m=6.0. int n=6.3.0.3.17.4.y*i+).0.4. } for(i=0.0. main().2. for(j=0.0.

for(i=0.j<n.&h*j+). y[k]+=x[i]*x2[i]. for(i=0.i<n. for(j=0. m=n.i<m.k.i++).j<n.y[30]. } Page | 59 DSP LAB – 2011/12 .a[30].k++) { y[k]=0. scanf(“%d”. Scanf(“%d”.i++) scanf(“%d”.j++) x2[j]=a[j-1].j.h[30].i++) y[0]+=x[i]*a[i].j++).I.i<m. for(i=0. } y[0]=0. }} Printf(“The Circular Convolution is\n”).k<n.i++). x[i]=0.x2[30]. void main() { Printf(“Enter the Length of the first sequence\n”). x2[0]=a[n-1]. Printf(“Enter the second sequence\n”).&x*i+).h> int m.h> #include<math.18. if(m-n!=0) { If (m>n) { for(i=0. a[j]=h[n-j].n.y*i+).x[30].i<n. for(k=1. Printf(“Enter the Length of the second sequence\n”). a[0]=h[0].j++) printf(“%d\t”.j<n.&m). for(j=0. for(j=1. n=m.&n). Printf(“Enter the first sequence\n”). h[i]=0. for(i=0. } for(i=m.i<n.i<n.i++) { a[i]=x2[i]. Scanf(“%d”.j++).temp[30]. Circular Convolution using DSP Processor C-Code: #include<stdio.

n<N.0}.3f\n”.3. float out_real[8]={0. printf(“*%d+%7. float pi=3. sumim=0.n++) { cosine=cos(2*pi*k*n/N).out_real*k+.1412. short x[8]={1.n. DFT Using DSP Processor C-Code: #include<stdio. int i=0. for(k=0. for(n=0. } } Page | 60 DSP LAB – 2011/12 .4.k=0.k<n.0}. simim=0.k.7}.h> void main(void) { short N=8.3f%7.6. float sumre=0. float cosine=0.out_imag*k+). N pt.1.4. sine=sin(2*pi*k*n/N) sumre=sumre+x[n]*cosine.2. sumim=sumim-x[n]*sine. sine=0.h> #include<math. out_imag[k]=sumim.19. out_imag[8]={0.k++) { sumre=0. } out_real[k]=sumre.

j.-6}. main() { int j.y*j+).k.1. float a[order+1]={1.h> #include<math. Impulse Response Using DSP Processor C-Code: #include<stdio.h> #define len3 float y[len]={0. } } Page | 61 DSP LAB – 2011/12 . } if (j<=order) { y[j]=b[j]-sum.j<len.0}. } Printf(“Response*%d+=%f\n”.0. } else { y[j]=-sum.j++) { if (j-k)>=0 sum=sum+(a[k]*y[j-k]).20. for(j=0.sum. float b[order+1]={1}.