DSP Labmanual

61
Sr. No. Title of Assignment 1. Write a C program to generate samples of sine, square, exponential & random signals at specified sampling frequency and signal parameters. 2. Find the output of a given system for given input sequence using linear convolution. 3. Find the output of a given system described by given difference equation & initial conditions for given input sequence. 4. Find circular convolution of a given two sequences 5. Write a program to accept pole zero location to generate pole zero plot, all possible ROC’s. 6. Write a program to plot the magnitude & phase response of a given system. 7. Find N pt DFT/IDFT of given complex sequence x (n)/x (k). 8. Compute circular convolution using DFT/IDFT. 9. Implement 8 pt Radix-2 DIT FFT algorithm 10. Find DFT using Goertzel algorithm. 11. Find the Fourier Transform of various windows functions; plot the magnitude & phase functions. 12. Design a DT IIR Butterworth filter for given specifications using bilinear transformation. 13 Study of ADSP 21xx Series DSP Processor

Transcript of DSP Labmanual

Page 1: DSP Labmanual

Sr. No. Title of Assignment

1.Write a C program to generate samples of sine, square, exponential & random signals at specified sampling frequency and signal parameters.

2. Find the output of a given system for given input sequence using linear convolution.

3.Find the output of a given system described by given difference equation & initial conditions for given input sequence.

4. Find circular convolution of a given two sequences

5.Write a program to accept pole zero location to generate pole zero plot, all possible ROC’s.

6. Write a program to plot the magnitude & phase response of a given system.

7. Find N pt DFT/IDFT of given complex sequence x (n)/x (k).

8. Compute circular convolution using DFT/IDFT.

9. Implement 8 pt Radix-2 DIT FFT algorithm

10. Find DFT using Goertzel algorithm.

11.Find the Fourier Transform of various windows functions; plot the magnitude & phase functions.

12.Design a DT IIR Butterworth filter for given specifications using bilinear transformation.

13 Study of ADSP 21xx Series DSP Processor

Assignment No.1

Title of Assignment:

Write a C program to generate samples of sine, cos, square, exponential & Random signals as specified sampling frequency & signal parameters.

Relevant Theory / Literature Survey:

Signal: A signal is the entity that carries information. Signal can be electric or non-electric. Electric signal carry information with electric current. Non-electric signals are

Page 2: DSP Labmanual

sound waves that carry information with air pressure. Standard signals are 1.Sine wave 2.Cos wave 3.Exponential 4.Random 5.Square Sampling of Analog signal: Sampling Theorem states that a continuous time signal can be completely represented in it’s samples and recovered back if Fs >=2W where Fs: Sampling frequencyW: maximum frequency present in the signal. There are many ways to sample analog signal. we are concerned only about periodic and uniform sampling. X(n) = Xa ( nT ) - <n <

Where X(n) is the discrete time signal obtained by taking samples of the analog signal Xa(t) at every T seconds. The time interval T between successive samples is called the sampling period or sampling interval & it’s reciprocal 1/T = Fs is called as sampling frequency (Hz). Periodic sampling establishes a relationship between the time variable t & n of continuous time & discrete time signals respectively. These variables are linearly related through the sampling period T or equivalently through the sampling rate Fs=1/T as

t=nT=n/Fs. -------1

As consequence of above equation there exists a relationship between the frequency variable F for analog signal & the frequency f for discrete time signal. To establish this relationship consider an analog sinusoidal signal of the form

Xa(t)=Acos(2Ft+) ---------2

Which when sampled periodically at rete Fs=1/T samples per sec, so

Xa(nT)=x(n)= Acos(2Fnt+) =Acos(2nF/Fs+) ------3

Comparing equation 3 & 1 we note that the frequency variable F & f are linearly related as f=F/Fs -------4

Example:

Page 3: DSP Labmanual

Consider the analog signal Xa(t)=3cos 100t

a) Determine the minimum sampling rate required to avoid aliasing.b) Suppose that the signal is sampled at rate Fs = 200 Hz what is the discrete time

signal obtained after sampling.c) Suppose that the signal is sampled at rate Fs = 75 Hz what is the discrete time

signal obtained after sampling.d) What is the frequency 0 < F < Fs/2 of a sinusoidal that yields samples identical to

those obtained in part c

Solution:

a. the frequency of the signal is F = 50 Hz hence the minimum sampling rate required to avoid aliasing is Fs = 100 Hz.

b. If the signal is sampled at rate Fs = 200 Hz what is the discrete time signal is

X(n) = 3 cos 100n/200 = 3 cos n/2

c. If the signal is sampled at rate Fs = 75 Hz what is the discrete time signal is

X(n) = 3 cos 100n/75 = 3 cos 4n/3 = 3 cos (2–2/3) = 3 cos 2n/3

d. for the sampling rate of Fs = 75 Hz we have F = f*Fs= 75 fthe frequency of sinusoidal in part c is f=1/3 hence F= 25 Hzclearly the sinusoidal signal

ya(t) = 3cos 2 f * t 3cos 50t sampled at fs = 75 Hz yields identical samples hence F = 50Hz is an alias of F= 25 Hz for the sampling rate Fs = 75 Hz.

Design Analysis / Implementation Logic:

Algorithm:

1. Display the menu on screen & prompt the user to enter which wave to be displayed. 2. To display sine wave use the amplitude, frequency, sampling frequency & the shift given by the user & using formula Amp*sin(2 ft) draw the sampled sin wave. 3. To display shifted wave use Amp*sin(2Ft+) where is shift value. 4. Similarly for cos wave repeat step 2 only formula will be Amp*cos(2ft) & draw the cos wave. 5. To display Exponential wave use Exp function & draw exponential wave.

Page 4: DSP Labmanual

6. To display Random wave use rand function & draw random wave. 7. To display square wave assume arbitrary sampling rate & display square wave.

Testing:

Input: Amplitude, frequency, Sampling frequency of the wave to be generated.

Output: Sin wave, cos wave, exponential wave, random wave& square wave.

Conclusion:

In this way we can generate samples of sine, cos, square, exponential & Random signals.

Assignment No. 2

Title of Assignment:

Find the output of a given system for a given input using their linear Convolution.

Relevant Theory / Literature Survey:

To determine the response of any relaxed linear system to any input signal. First we denote the response y(n, k) of the system to the input unit sample sequence n=k by the special symbol h(n, k) for - <k< i.e. Y(n, k)=h(n, k)=T[(n-k)]

Where n is the time index & k is the parameter showing location of input pulse. If the impulse at the input is scaled by an amount Ck=x(k) then response of the system is correspondingly scaled output i.e.

Ckh(n, k)=x(k)*h(n, k)

Page 5: DSP Labmanual

If the input is the arbitrary signal x(n) i.e. represented as sum of weighted impulse i.e. x(n)= x(k)* (n, k) k=-then the response of system to x(n) is the corresponding sum of weighted outputs i.e.

y(n)=T[x(n)]=T[ x(k)* (n, k) k=- =T[….+x(-2)* (n+2)+x(-1)* (n+1)+x(0)* (1)+x(1)* (n-1)+-----]as output of system is linear =T{ x(-2)* (n+2)}+T{ x(-1)* (n+1)}+T{ x(0)* (1)}+-----

we know that y(n)=T[a x(n)] =aT[x(n)] y(n)=----+x(-2) T{(n+2)}+x(-1)T{(n+1)}+x(0)T{(1)}+----- = x(k)* T[ (n, k)] k=- T[ (n)] =h(n)But as our system is shift Invariant = T[ (n- k)]=h(n-k) (since k is constant) y(n)= x(k)* h(n-k) k=-

This is the convolution sum, which is called as linear convolution.

Properties of Convolution:

1.Commutative: Convolution satisfies commutative property

Y(n)=x(n)*h(n)=h(n)*x(n)

i.e. y(n)= x(k)* h(n-k) k=-

y(n)= h(n-k)*x(k) k=-

Page 6: DSP Labmanual

Are same

2.Associative:

[x(n)*h1(n)]*h2(n)=x(n)*[h1(n)*h2(n)]

3.Distributive: x(n)*[h1(n)+h2(n)]=x(n)*h1(n)+x9n)*h2(n)

That means two LTI systems connected in parallel can be replaced by a single system with h(n)=h1(n)+h2(n)

4.Casuality: System is said to be casual if it’s output at time n depends only on present & past inputs. Consider LTI system at time n

y(n)= h(n-k)*x(k) k=-We can divide the sum into two sets one having present & other having future values of input.

-1 = y(n)= h(n-k)*x(k) + y(n)= h(n-k)*x(k) k=0 k=-

y(n)=[x(0)*h(n)+x(1)*h(n-1)+x(2)*h(n-3)+-----+x(-2)*h(n+2)+---]

h(n)=T[(n)] h(n)=0 n<0

LTI system is casual if and only if it’s impulse response is zero for negative values.

5. System is BIBO (bounded input bounded output) if and only if it’s output sequence y(n) is bounded for every bounded input x(n). Example: Obtain linear Convolution of the following two sequences x(n)={1,2,3,1} , h(n)={1,2,1,-1}

Page 7: DSP Labmanual

we know convolution theorem

y(n)= x(k)* h(n-k) k=-

we can write as x(k)={1,2,3,1} , h(k)={1,2,1,-1}

as we want h(-k) we have to fold the signal h(k)

The lower limit for y is : 0+-1=-1 upper limit for y is 3+2=5

therefore 5 n=-1 y(-1)= x(k)*h(-1-k) k=-1 =x(0)*h(-1) =1*1 =1

5 n=0 y(-1)= x(k)*h(-k) k=-1 =x(0)*h(0)+x(1)*h(-1) =1*2+2*1 =4

5 n=1 y(-1)= x(k)*h(1-k) k=-1 =x(0)*h(1)+x(1)*h(0)+x(2)*h(-1) =1*1+2*2+3*1 =8

5 n=2 y(-1)= x(k)*h(2-k) k=-1 =x(0)*h(2)+x(1)*h(1)+x(2)*h(0)+x(3)*h(-1) =1*-1+2*1+3*1+1*1 =8

5

Page 8: DSP Labmanual

n=3 y(-1)= x(k)*h(3-k) k=-1 =x(1)*h(2)+x(2)*h(1)+x(3)*h(0) =2*-1+3*1+1*2 =3

5 n=4 y(-1)= x(k)*h(4-k) k=-1 =x(2)*h(2)+x(3)*h(1) =3*-1+1*1 =-2

5 n=5 y(-1)= x(k)*h(5-k) k=-1 =x(3)*h(2) =1*-1 =-1 Therefore y(n)={1,4,8,8,3,-2,-1}

Design Analysis / Implementation Logic:

Algorithm:

1. Accept the lower & upper limits for sample x.2. According to limits accept the values of the sample at various points from the user

& maintain index of zero.3. Similarly for the sample h accepts the limits & according to the limits accept the

values from the user.4. Plot the graphs according to the given data.5. For calculating h(-k) fold the sequence h(k).6. To fold the signal interchange the values on left side of zero index with right side

values.7. Lower & upper limits of sample y is given by adding lower limits of both the

samples x & h and upper limits of both the samples.8. For every value of y(n) we have to shift h(k) by h(n-k) & multiply this shifted

sample with sample x. The overall sum of this loop is the value for y(n).9. After getting all the values of sample y plot the graph for y(n).

Page 9: DSP Labmanual

Testing:

Input: - Upper & lower limits for sample x & h. - Values of the sample i.e. x(n) & h(n).

Output: Convolution of sample x(n)& h(n) i.e. Y(n).

Conclusion:

In this way we can find the linear Convolution of any two sequences.

Assignment No. 3

Title of Assignment:

Find the output of a given system described by given difference equation & initial conditions for given input sequence.

Relevant Theory / Literature Survey:

There are 2 methods to obtain solution for given coefficient difference equation

1. Direct method2. Indirect method

Indirect method is based on z transform Direct method is easy and suitable for obtaining the solution

In direct method it assumed that it contains 2 parts of solution1. Homogeneous/complimentary solution i.e. yn (n)2. Particular solution i.e. yp (n) The total solution given as y (n)=yn (n)+yp (n)

Page 10: DSP Labmanual

Homogeneous solution of difference equation

N N Y (n) = - ak* y (n-k) + bk * x (n-k) ------1 K=1 k=0

In the first term limits are k=1 to N changing limits to k=0 to N

N N - ak* y (n-k) = a0* y(n) + ak * y (n-k) K=1 k=1

N N - ak* y (n-k) = a0* y(n) + ak * y (n-k) ----2 K=1 k=0

Putting this value in equation 1

N N Y (n) =a0*y(n) - ak* y (n-k) + bk * x (n-k)

K=0 k=0

Assume a0=1 then,

N N Y (n) = y(n) - ak* y (n-k) + bk * x (n-k)

K=0 k=0

N N ak* y (n-k) = bk * x (n-k) -------3

K=0 k=0

We will obtain the homogeneous solution by assuming input x(n)=0

Since x(n) = 0 , x(n-k) = 0 thus equation 3 becomes

N ak* y (n-k) = 0 -------4

K=0

Assume equation in the form of exponential homogeneous solution

[yh(n)] = rⁿReplace n by n-k [yh(n-k)] = r ⁿ-k

Page 11: DSP Labmanual

Putting this values in equation 4

N ak * rⁿ-k = 0 -------4

K=0

Expanding the summation we get

A0 rⁿ + a1 rⁿ-1 + a2 rⁿ-2 +---------+ aNrⁿ-N=0We assume that a0=1 then, rⁿ + a1 rⁿ-1 + a2 rⁿ-2 +……….+ aNrⁿ-N=0

we take rⁿ-N common

rⁿ-N[rⁿ * r-ⁿ+N + a1 rⁿ-1 * r-ⁿ+N + a2 rⁿ-2 * r-ⁿ+N +……….+ aN]=0

rⁿ-N[rⁿ + a1 rⁿ-1 + a2 rⁿ-2 +……….+ aN]=0

The term inside the bracket is called as characteristic polynomial of the system. This polynomial has N roots, which can be real or complex valued. Case 1: roots are distinct Yh(n)=c1*r1ⁿ+c2 *r2ⁿ+cNrNⁿ

Here c1,c2,……cn are constants

Case 2: multiple roots

Yh(n) = c1*r1ⁿ + c2*n*r1ⁿ+c3n2 r1ⁿ+………..+cNrN

Example:

a [k] = {1,1} , b[k]= {2,2} , x(n) = {1, 2}

for n=0

N ak y(n-k)

K=1 = a[1]*y[-1]+a[2]*y[-2] = 1*0+0*0 =0

N ak x(n-k)

Page 12: DSP Labmanual

K=0 = b[0]*x[0]+b[1]*x[-1] = 2*1+2*0 =2

As N N Y (n) = - ak* y (n-k) + bk * x (n-k) K=1 k=0

So y(0) = 2-0 = 2

for n=1

N ak y(n-k)

K=1 = a[1]*y[0]+a[2]*y[1] = 1*2+0*0 =2

N ak x(n-k)

K=0 = b[0]*x[1]+b[1]*x[0] = 2*2+2*1 =6

As N N Y (n) = - ak* y (n-k) + bk * x (n-k) K=1 k=0

So y(1) = 6-2 = 4

y(n) = {2,4}

Page 13: DSP Labmanual

Design Analysis / Implementation Logic:

Algorithm:

1. Accept number of coefficients for a[k].2. Accept the coefficients. 3. Accept number of coefficients for b[k].4. Accept the coefficients. 5. Accept the input sequence x(n) from user.6. Calculate y(n) using the following formula

N N Y (n) = - ak* y (n-k) + bk * x (n-k) K=1 k=0

7. Calculate two summations differently and add them to get the final result.

Testing:

Input: No. of coefficients of ak denoted as N Values of a1,a2,a3 ……. No. of coefficients of bk denoted as M Values of b1,b2,b3 ……. No . of samples of x(n) denoted as L Values of x(0),x(1)………

Assumptions: –The no. of samples computed for y(n) are same as no. of input samples i.e. L. –All initial conditions are zero.

Output: samples of y(n).

Conclusion:

In this way we can find the solution of linear constant coefficient difference equation.

Assignment No. 4

Title of Assignment:

Page 14: DSP Labmanual

Find circular convolution of a given two sequences.

Relevant Theory / Literature Survey:

If x(n) & h(n) are periodic with period N then

N-1 N-1 x(k)* h(n-k) = x(n-k)* h(k) k=0 k=0 Where x(k) and h(k) are the DFT’s of length N signals corresponding to one period of (n) & h(n) respectively.

Proof:

If Y(k) = x(k) * h(k) then N-1 -kn y(n)=1/N H(k)* X(k)* Wn k=0

N-1 N-1 (-n)k y(n)=1/N H(k)* X()* Wn k=0 =0

N-1 N-1 (-n)k y(n)= X() 1/N H(k)* Wn =0 k=0

N-1 y(n)= X() * h(n- ) =0

When computing all the sequence shifts involved are circular. Product of two DFT actually corresponds to the circulation convolution in time domain.Circular convolution in time domain is equivalent to liner convolution.Since x(n) and h(n) has a period N and has to be specified only for 0≤n≤N-1 then

N-1 y(n)= x() * h(n- ) =0

N-1 N-1 = x() * h(n- ) + x() * h(n- +N) =0 =n+1

Page 15: DSP Labmanual

for 0<=n<=n-1

Which can be rewritten in a compact form as N-1 y(n) = X() * h((n- ))mod N

=0

= x(n) * h(n)

Where and mod N represents the remainder for integer division of by N

We can write it in more compact form

y0) h(0) h(N-1)……..h(1) x(0) y(1) h(1) h(0) …… h(2) x(1)

. = . . .. . . .

y(n-1) h(N-1) h(N-2) h(0) x(N-1)

Each row in the matrix is a circular right shift of the previous.

Example:

Obtain circular convolution of

x(n) = {1,1,1,1,-1,-1,-1,-1} h(n) = {0,1,2,3,4,3,2,1}

We know that y(n) = x(n) * h(n)

y(0) 1 –1 –1 –1 –1 1 1 1 0 y(1) 1 1 –1 –1 –1 –1 1 1 1 y(2) 1 1 1 –1 –1 –1 –1 1 2 y(3) = 1 1 1 1 –1 –1 –1 –1 3 y(4) –1 1 1 1 1 –1 –1 –1 4 y(5) –1 –1 1 1 1 1 –1 –1 3 y(6) –1 –1 –1 1 1 1 1 –1 2 y(7) –1 –1 –1 -1 1 1 1 1 1

hence y(m) = {-4,8,-8,-4,4,8,8,4}

Design Analysis / Implementation Logic:

Page 16: DSP Labmanual

Algorithm:

1. Accept from user the no. of samples in the sequence.2. accept the sequence x(n).3. Accept the sequence h(n).4. using the formula calulate the output sample y(n).5. display the calculated values of y(n).

Testing:

Input: - Input Sequences x(n) & h(n).

Output: Circular Convolution of sample x(n) & h(n) i.e. Y(n).

Conclusion:

In this way we can find the circular convolution of a given two sequences.

Assignment No. 5

Title of Assignment:

Write a program to accept pole zero locations to generate pole zero plot & all possible ROC’s.

Relevant Theory / Literature Survey:

We know that the system function H(z) can be represented as

H(z)= (z-z1)(z-z2)(z-z3)

Page 17: DSP Labmanual

(z-p1)(z-p2)(z-p3)

Here z1, z2, z3 etc. are zeroes of the system and p1, p2, p3 are poles of the system. The poles and zeroes can have complex variable. The coefficient of numerator and denominator are obtained separately. Let us consider the polynomial having zeroes

N(z) = (z-z1)(z-z2)(z-z3)(z-z4)

z1,z2,z3,z4 can have complex values in z plane

z1=r1 ejw , z2=r2 ejwz, z3=r3 ejwz, z4=r4 ejwz

Here r1 is magnitude of z1 i.e. z = r & w1 is angle of z1 z = w1

N1Z1– [(z– r1 ejw1)(z– r2 ejwz)(z– r3 ejwz) (z– r4 ejwz) – z2–(r ejw1+ r2 ejwz)z+r1r2 ej(w1+w2)][z2–(r3ejw3+r4 r4 ejw4)z+r3r4 ej(w3+w4)]

In above equation coefficient of z3z2z1z0 we obtained from the coefficients are nothing but coefficients b0b1b2b3

b0 = always z4 coefficient b1 = coefficient of z3

b2 = coefficient of z2

b4 = coefficient of z0

Example:

y(n)= x(n)+3x(n-1)+3x(n-2)+x(n-3)Plot pole-zero diagram assuming y(n)=0 for n<0 find the value of y(n) for n=0,1,2,3,4,5 for x(n) = (n)

The given difference equation is in the form of y(z) = x(z)+3z-1x(z)+3z-2x(z)+z-3x(z) = (1+3 z-1+3 z-2+ z-3) x(z)

y(z)/x(z) = (1+3 z-1+3 z-2+ z-3)

Making power of z +ve in above equation with h(z) = y(z)/x(z)

h(z) = z3+3z2+3z+1/z3

= (z+1)3/z3

Thus h(z) has 3 zeroes at z= –1 and 3 poles at z=0 the pole zero diagram isIm(z)

+j : 3 poles

Page 18: DSP Labmanual

3 zeroesRe(z)

-1 1

-j

From equation we can write

y(z) = (1+3 z-1+3 z-2+ z-3) x(z)

The i/p is x(n)= (n) hence x(z) = 1

The above equation becomes

y(z) = (1+3 z-1+3 z-2+ z-3)

Taking inverse Z transform of y(z) we get

y(n) = (n) + 3(n-1)+3(n-2)+ (n-3)

Putting value of n from 0 to 5

y(0) = (0) + 3(-1)+3(-2)+ (-3) = 1+0+0+0 = 1

y(1) = (1) + 3(0)+3(-1)+ (-2) = 0+3(1)+0+0 = 3

y(2) = (2) + 3(1)+3(0)+ (-1) = 0+0+3(1)+0 = 3

y(3) = (3) + 3(2)+3(1)+ (0) = 0+0+0+1 = 1

y(4) = (4) + 3(3)+3(2)+ (1) = 0+0+0+0 = 0

y(5) = (5) + 3(4)+3(3)+ (2) = 0+0+0+0 = 0 Design Analysis / Implementation Logic:

Algorithm:

1. Declare the necessary variables.2. Accept real of imaginary values of zeroes.3. Accept real of imaginary values of poles.4. Using differential equation calculate the values of poles & zeroes.5. Plot poles & zeroes using graphics

Page 19: DSP Labmanual

Testing:

Input: two input sequences i.e. x(n) & y(n).

Output: poles & zeroes of transfer function.

Conclusion:

In this way we can generate pole zero plot.

Assignment No. 6

Title of Assignment:

Write a program to plot magnitude & phase response of a given system.

Relevant Theory / Literature Survey:

Fourier Transform: The frequency range for discrete time signals is unique over the interval (- ,) or (0, 2).a discrete time signal of fundamental period N can consist of frequency components separated by 2/N radians or f=1/N cycles.

The Fourier series for discrete time periodic signal: Suppose that we are given a period sequence x(n) with period N, i.e. x(n) = x(n+N) for all n. the Fourier series representation for x(n) consist of harmonically related exponential function.

ej2kn/N k=0,1,…….N-1and is expressed as

N-1 x(n) = ck ej2kn/N ………….1

k=0

Where the {ck} are the coefficients in the series representation, to derive the Fourier coefficients we use the following formula

Page 20: DSP Labmanual

N-1 ej2kn/N = N k=0,+N,–N,+2N,–2N ………….1.1 n=0

from the application of the geometric summation formula:

N-1 an = N a =1 n=0 1-aN/1-a a !=1 ……………1.2

The expression for Fourier coefficient ck can be obtained by multiplying both the sides of above equation by the exponential e–j2n/N and summing the product from m=0 to n=N-1 thus

N-1 N-1 N-1 x(n) e–j2n/N = ck ej2(k-)n/N……………..1.3

n=0 n=0 n=0

if we perform summation over n first the right hand side of above equation we obtain

N-1 ej2(k-)n/N = N k-=0,+N,–N,+2N,–2N …………1.4 n=0 0 otherwise

where we have made use of 1.1 therefore the R.H.S. reduces to Nc and hence N-1C = 1/N x(n) ej2n/N =0,1,2,…….N-1 …………1.5 n=0

thus we have the desired expression for the Fourier coefficients in terms of signal x(n)

Synthesis equation: N-1 x(n) = ck ej2(k-)n/N

n=0

Analysis equation:

N-1 ck = 1/N x(n) e-j2(k-)n/N

n=0

The Fourier transform of discrete time aperiodic signal:

The Fourier transform of a fini9te energy discrete time signal x(n) is defined as

Page 21: DSP Labmanual

x(n) = x(n) e-jwn ……………..2 n=-

x(w) is decomposition of x(n) into it’s frequency components x(w) is periodic with period 2 i.e. x(w+2) = x(n) ej(w+2k)n

n= - = x(n) e-jwn e-j2kn

n= -

= x(n) e-jwn = x(w) ………………2.1

n= -

From the decomposition of Fourier transform x(w) of the sequence x(n) given by equation 2, we observe that x(w) has the form of a Fourier series .let us evaluate sequence x(n) from x(w). multiply both the sides of eq. 2 by ejwm and integrate over the interval (–,) thus we have

x(w) ejwm dw .= [ x(n) e-jwn ]. e-jwn dw ………………2.2– – n= -

The input part of 2.2 can be evaluated if we can interchange the order of summation & integration. The interchange is possible if N xN(w) = x(n) e-jwn

n = –N Converges uniformly to x(w) as N

Let us assume that the series converges, so

ejw(m-n) dw = 2 m=n – 0 mn

consequently

x(n) ejw(m-n) dw = 2 x(m) m=n …………..2.3 n= – 0 mn

Page 22: DSP Labmanual

by considering 2.2 & 2.3 we obtain desired result x(n) = 1/2 X(w) ejwn dw –

Synthesis equation inverse transform x(n) = 1/2 X(w) ejwn dw 2

Analysis equation direct transform x(w) = 1/2 x(n) e–jwn

n=–

Example: Obtain F.T. of x(t) = e–at u(t)

Solution: we know that u(t) ranges from 0 to

x(w) = x(t) e–jwt dt n=–

x(w) = e–at e–jwt dt n=–

= e–t(a+jw) dt n=– = [1/-(a+jw) e–t(a+jw)] = 1/a+jw

Assuming a = 2

w 1/sqrt (a2+w2) –tan–1 (w/a)

-w 0 90-2 35 450 2 02 35 -45 0 -90

Page 23: DSP Labmanual

Magnitude plot

2

– –2

Phase plot

. 90

– –2 –2 w

–90

Design Analysis / Implementation Logic:

Algorithm: 1. Accept the input sequence x(n). 2. Calculate Fourier transform using the formula x(t) e-jwt over the range -2 to 2 where x(t) is original input sequence. 3. To calculate amplitude plot take square root of square of imaginary & real part. 4. To calculate frequency plot take inverse tan of the division of real & imaginary part.

Page 24: DSP Labmanual

Testing:

Input: input sequence x(n).

Output: magnitude & phase plot of the sequence x(n).

Conclusion:

In this way we can plot magnitude & phase response of a given system.

Assignment No. 7

Title of Assignment:

Find N-point DFT/IDFT of given complex sequence x (n)/x (k).

Relevant Theory / Literature Survey:

Discrete Fourier Transform:

The DFT of a finite duration sequence x(n) is obtained by sampling the Fourier transform X(ejw) at N equally spaced points over the interval 0≤w ≤2 with a spacing of 2/N. The DFT denoted by x(k) is defined as

X (k) = X (ejw) w=2k/N 0≤k ≤N-1

The Fourier transform X (e^jw) is periodic in w, with period 2 and its inverse Fourier transform is equal to discrete-time sequence x (n). we know that when a continuous time signal is sampled with sampling time T, the spectrum of resulting discrete time sequence becomes a periodic function of frequency with period 2/T similarly when X(e^jw) is sampled with sampling period 2/N the corresponding discrete time sequence xp(n ) becomes periodic in time with period N.

Where xp(n) = x (n-N ) =-

Thus the periodic sequence xp (n) corresponding to x(k) for k=0 to N-1 obtained by

Page 25: DSP Labmanual

sampling X(e^jw) in the interval 0 to 2 is formed from x(n) by adding together an infinite number of shifted replicas of x(n). let us consider an example in which sequence x(n) is of length L=9 and the value of the frequency spectrum of x(n) taking 10 sampling points (i.e. N>L) over the interval 2 we obtain a periodic sequence xp(n) in which the delayed replicas of x(n) do not overlap and one periodic of the periodic sequence xp(n) is recognizable as x(n).below in fig. c the same sequence is used but the value of N is equal to 7 (i.e. N<L). in this case the replicas of x(n) overlap and one period of xp(n) is not identical to x(n). this is a form of time-domain aliasing which is due to under sampling of Fourier transform of x(n). From above discussion we find that the sequence x(n) cant be recovered from xp(n) when the no. of sampling points ⁿ is less the length of sequence L. if N>L, x(n) can be recovered through the relation.

X (n) = xp (n) 0≤n ≤N-1 = 0 otherwise

a) Finite duration sequence x(n) of length L=9.b) Periodic sequence xp (n) corresponding to sampling Fourier transform of x(n)

with N=10.c) Periodic sequence xp(n) corresponding to sampling F.T. of x(n) with N=7.

Let x(n) is a casual , finite duration sequence containing L samples, then it’s F.T. given by

L-1 x(ejw) = x (n ) e ^-jwn ……………..2

n=0

if we sample x(ejw) at N equally spaced points over 0≤w ≤2 we obtain

L-1 x(k) = x(ejw) w=2K/N = x (n ) e -j2k/N ………….3

n=0 Since time domain aliasing occurs in N <L to prevent it we increase duration of x(n) from L to N samples by appending appropriate number of zeros, which is zero padding. Since zero valued elements contribute nothing to sum of eq. 3 can be written as

L-1 x(k) = x (n ) e -j2k/N 0≤w ≤2 n=0

Which is called N-point DFT.Since xp(n) is periodic extension of x(n) with period ⁿ,it can be expressed in Fourier series expansion.

Page 26: DSP Labmanual

N-1 xp(n) = 1/N xp (k ) ej2kn/N ………………4 k=0

we already know that D.F series coefficients xp(k) of periodic sequence xp(n) is itself a periodic sequence with period N. the DFT x(k) is related to DFS coefficients xp(k) by

x(k) = xp(k) 0≤k ≤N-1 = 0 otherwise …………5

substituting eq 1 & 5 in 4 then

N-1 x(n) = 1/N x (k ) e j2kn/N

k=0

Which is called IDFT thus

DFT N-1 x(k) = x (n ) e-j2kn/N 0≤k ≤N-1 …………6 n=0

IDFT N-1 x(n) = 1/N x (k ) e j2kn/N 0≤n ≤N-1 …………7 n=0

we can represent

X(k) = DFT [x(n)] x(n) = IDFT [X(k)]

Example: Find the DFT of sequence x(n) = {1,1,0,0}

Len N =L=4We have

N-1 x(k) = x (n ) e-j2kn/N k=0,1,…….N-1 n=0

3 x(0) = x (n ) = x(0)+x(1)+x(2)+x(3)

n=0 = 1+1+0+0 =2

Page 27: DSP Labmanual

3

x(1) = x (n ) * e-jn./2 = x(0)+x(1)*e^-j./2+ x(2)*e^-j.+x(3)* e^-j3./2 n=0 = 1+cos /2-jsin /2 =1-j 3

x(2) = x (n ) * e-jn = x(0)+x(1)*e^-j.+ x(2)*e^-j2.+x(3)* e^-j3. n=0 = 1+cos -jsin =1-1 =0 3

x(3) = x (n ) * e-j3n/2.= x(0)+x(1)*e^-j3/2.+x(2)*e^-j3.+x(3)* e^-j9/2. n=0 = 1+cos 3/2-jsin 3/2 =1+j

x(k) = {2,1-j,0,1+j}

Find IDFT of X (k) = {4,1-j,-2,1+j}

N-1 x(n) = 1/N x (k ) e j2kn/N n=0

1 1 1 1 1 1 1 1W= 1 –j -1 j w* = 1 j -1 -j

1 -1 1 -1 1 -1 1 -1 1 j -1 -j 1 -j -1 j

1 1 1 1 4 Xn=1/4 1 –j -1 j 1-j

1 -1 1 -1 -2 1 j -1 -j 1+j

4 Xn=1/4 8

0 4

x (n) = {1, 2, 0, 1}Design Analysis / Implementation Logic:

Algorithm:

Page 28: DSP Labmanual

1. Accept the input sequence x (n) from user for which DFT has to tb derive2. To determine DFT accept the N point i.e. how much pt DFT is to compute.3. now starting from n=0 to N-1 we have to find the DFT of given sequence using the

formula N-1 x(k) = x (n ) e -j2kn/N k=0,1,…….N-1 n=0

4. Similarly for IDFT we have to accept the input sequence X(k) from user.5. Also accept the N point to compute IDFT.6. Now starting from k=0 to N-1 we have to find the IDFT of given sequence using the

formula N-1 x(n) = 1/N x (k ) ej2kn/N n=0,1,……….N-1 n=0

Testing:

Input sequence x (n) for calculating DFT Input sequence x (k) for calculating IDFT

Output: DFT of sequence x (n) IDFT of sequence x (k)

Conclusion:

In this way we can find N-point DFT/IDFT of given complex sequence x (n)/x (k).

Assignment No. 8

Title of Assignment:

Compute circular convolution of a given two sequences using DFT & IDFT.

Relevant Theory / Literature Survey:

The multiplication of two DFT’s is equivalent to the circular convolution of their

Page 29: DSP Labmanual

sequences in time domain.

DFT DFTIf x1(n) X1(k) and x2(n) X2(k) then N N DFT x1(n) * x2(n) X1(k)*X2(k) N

Proof: Consider two discrete time sequences x1(n & x2(n). the DFT of x1(n) & x2(n) is expressed as

N-1 X1(k) = x1(n) * e–j2kn/N k= 0,1,……….N-1 …………..1 n=0

N-1 X2(k) = x2(n) * e–j2k/N k= 0,1,……….N-1 …………..2 =0

now the multiplication of two DFT x1(k) & x2(k)

Y(k) = X1(k) * X2(k)………….3

Let IDFT of Y(k) be y(m) then using IDFT

N-1 Y(m) = 1/N y(k) * ej2km/N ………..4 k=0

Using equation 3 & 4 we can write

N-1 Y(m) = 1/N X1(k) * x2(k) * ej2km/N ………..4 k=0

Putting the values of X1(k) & X2(k) from 1 & 2 in equation 4 N-1 N-1 N-1 Y(m) = 1/N [ x1(n)*e–j2kn/N] [ x2() * e–j2k/N] ej2km/N ………..5 k=0 n=0 =0

Rearranging the terms

N-1 N-1 N-1 Y(m) = 1/N x1(n) x2()[ e–j2k/N * e–j2knn/N * ej2km

Page 30: DSP Labmanual

n=0 =0 k=0

e–j2k(m-n-)/N = [e–j2(m-n-)/N]k ………………6

N-1we know that ak = N a=1 k=0 1-aN/1-a a1

case I: a=1 if (m-n-) is multiple of N which means (m-n-)= N,2N,3N then

a = ej2 = ej2(2) = ej2(3) =1

Thus when (m-n-) is multiple of N then according to equation 7 the third summation equals to N

Case II: when a1 That means if (m-n-) is not multiple of N then according to equation 7

N-1 ak = 1-aN/1-a k=0

Now N-1 (ej2(m-n-))k = 1– ej2(m-n-)/1- ej2(m-n-)/N

k=0

Here m, n, are integers thus ej2(m-n-) = –1 alwaysThe R.H.S. becomes 0 when a1 So to get the result of equation 7 we have to consider the condition a = 1. That means when (m-n-) is multiple of N for this condition we have the result of summation equals to N thus

N-1 N-1 Y(m) = 1/N x1(n) x2() * N n=0 =0 N-1 N-1 Y(m) = x1(n) x2() ……………8 n=0 =0

we have obtained equation 8 for the condition (m-n-) is multiple of N this is expressed as (m-n-) = –p*N ………………9

Page 31: DSP Labmanual

Where p is an integer & an integer can be +ve or –ve. For the simplicity we have considered –ve integer now from 9 we get

= m–n+p*N

Putting this value in equation 8

N-1 Y(m) = x1(n) x2(m–n+pN) ……………10 n=0 =0 we are not considering the 2nd summation in 8 because in terms of and exponential terms is absent. Now the term x2(m–n+pN) indicates a periodic sequence with period N. we know if sequence is periodic & it is delayed then it can be represented as

x2(m–n+pN) = x2((m–n))N m=0,1,………..N-1

The sequence x2(n) is shifted circularly hence this type of circulation is called circular convolution. Example:

Obtain circular convolution of

x(n) = {1,1,1,1,-1,-1,-1,-1} h(n) = {0,1,2,3,4,3,2,1}

We know that y(n) = x(n) * h(n)

y(0) 1 –1 –1 –1 –1 1 1 1 0 y(1) 1 1 –1 –1 –1 –1 1 1 1 y(2) 1 1 1 –1 –1 –1 –1 1 2 y(3) = 1 1 1 1 –1 –1 –1 –1 3 y(4) –1 1 1 1 1 –1 –1 –1 4 y(5) –1 –1 1 1 1 1 –1 –1 3 y(6) –1 –1 –1 1 1 1 1 –1 2 y(7) –1 –1 –1 –1 1 1 1 1 1

hence y(m) = {-4,8,-8,-4,4,8,8,4}

find the circular convolution of given samples using DFT & IDFT.

x(n) = {1,1,1,1} h(n) = {5,6,7,8}

first we will compute DFT of x(n) & h(n)

Page 32: DSP Labmanual

X4=W4 * x(n)

1 1 1 1 1 1 -j -1 j 1 X4 = 1 -1 1 -1 1 1 j -1 -j 1

X4 = {4,0,0,0}

1 1 1 1 5 W4 = 1 -j -1 j 6 1 –1 1 –1 7 1 j -1 –j 8

H4 = {26,-2+2j,-2,-2-2j}

Now we have to multiply X4 with H4

result of multiplication is {104,0,0,0}

now compute IDFT

XN = ¼ 1 1 1 1 104 1 j -1 -j 0 1 -1 1 -1 0 1 -j -1 j 0

x(n) = {26,26,26,26}

Design Analysis / Implementation Logic:

Algorithm:

6. Accept from user the no. of samples in the sequence.7. accept the sequence x(n).8. Accept the sequence h(n).9. calculate the DFT’s of two sequences separately using real part = real1 * real2 – (img1*img2) img part = img1 * real2 – (real1*img2)

Page 33: DSP Labmanual

this should be done for all values10. calculate the IDFT of this calculated sample values.11. the result of IDFT is circular convolution.

Testing:

Input: - Input Sequences x(n) & h(n).

Output: Circular Convolution of sample x(n) & h(n).

Conclusion:

In this way we can calculate circular convolution of two sequences using DFT & IDFT

Assignment No. 9

Title of Assignment:

Implement 8-point Radix-2 DIT FFT algorithm

Page 34: DSP Labmanual

Relevant Theory / Literature Survey:

Radix-2 decimation in time domain algorithm (DIT FFT). Decimation means to break into parts. Thus DIT indicates dividing the sequence in time domain.

First stage: Let x(n) be input sequence containing ‘N’ samples now we divide x(n) into even & odd sequences. Hence x(n) = f1(m) +f2 (m)………….1

Here f1(m) = x(2n) m=0,1,……(N/2)-1 ………2 F2(m) = x(2n+1) m=0,1,……… (N/2)-1 …….3

I/p sequence has N samples so decimation f1(m) & f2(m) will contain N/2 samples.

Now according to definition of DFT

N-1 X(k) = x(n) * Wkn

N ………………4

n=0we can write X(k) = x1(n) * Wkn

N + x(n) WknN …….5

n even n odd

we put n=2m in even sequence & n=2m+1 in odd sequence. Both sequence contain N/2 samples so, (N/2)-1 (N/2)-1 X(k) = x(2m) * W2km

N + x(2m+1) Wk(2m+1)N ………….6

m=0 m=0

x(2m) is even sequence so it is f1(m) & x(2m+1) is odd so it is f2(m) we also know W2

N = WN/2

(N/2)-1 (N/2)-1 X(k) = f1(m) * (W2

N)km + WkN f2(m) (W2

N) km

………….7 m=0 m=0

Now using W2N = WN/2

(N/2)-1 (N/2)-1 X(k) = f1(m) * (WN/2)km + Wk

N f2(m) (WN/2) km

………….8 m=0 m=0

Comparing this with definition of DFT

Page 35: DSP Labmanual

X(k) = f1(k) + WkN f2(k) k= 0,1,…..N-1 …………..9

Now we will consider for 8-point DFT

Here F1(k) is N/2 pt DFT of f1(m) & F2(k) is N/2 point DFT of f2(m). That means F1(k) & F2(k) are 4-point DFT’s Equation 9 indicates F2(k) is multiplied by Wk

N & added with f1(k) to obtain 8-point DFT. Now F1(k) & F2(k) are 4-point (N/2) DFT.they are periodic with period N/2.using periodic property of DFT we write,

F1(k+N/2) = F1(k)………. 10 F2(k+N/2) = F2(k)………. 11

Replacing k by k+N/2 in equation 9

X(k+N/2) = F1(k+N/2) + Wk+N/2N F2(k+N/2) …………..12

Wk+N/2

N = –WkN

X(k+N/2) = F1(k+N/2) – Wk+N/2N F2(k+N/2) …………..13

Using equation 10 & 11 we get

X(k+N/2) = F1(k) + WkN F2(k) …………..14

Using equation 9 & 14 we can obtain combined N-point DFT

X(k) = F1(k) + WkN F2(k) ………….k=0,1,………N/2-1…….15

X(k+N/2) = F1(k) – WkN F2(k) ………k=0,1,……….N/2-1……….16

For 8-point DFT equation 15 & 16 varies from 0 to 3

Therefore X(0) = F1(0) + W0N F2(0)

X(1) = F1(1) + W1N F2(1)

X(2) = F1(2) + W2N F2(2) ………..17

X(3) = F1(3) + W3N F2(3)

X(0+4) = X(4) = F1(0) - W0N F2(0)

X(1+4) = X(5) = F1(1) - W1N F2(1)

X(2+4) = X(6) = F1(2) - W2N F2(2) ………….18

X(3+4) = X(7) = F1(3) - W3N F2(3)

Second stage of decimation: In first stage we obtained the sequence of length N/2 i.e. 8-point DFTWe can further decimate f1(m) into even & odd samplesLet g11(n) = f1(2m) & g12(n) = f1(2m+1)Here m & n ranges from 0 to N/4 –1

Page 36: DSP Labmanual

Similar to equation 15 & 16

F1(k) = G11(k) + WkN/2 G12(n) k=0,1,……N/4-1 ……..19

F1(k+ N/4) = G11(k) + WkN/2 G12(k) k=0,1,……N/4-1 ……..20

Thus for N=8 we have the range for k=0 to k=1 here G11(k) is DFT of g11(n) and G12(k) is DFT of g12(n) using equation 19 F1(0) = G11(0) + W0

N/2 G12(0) F1(1) = G11(1) + W1

N/2 G12(1) ………..21

Similarly from equation 20

F1(0+8/4) = F1(2)= G11(0) – W0N/2 G12(0)

F1(1+8/4) = F1(3)= G11(1) – W1N/2 G12(1)………….22

Here the values of k are 0 & 1 that means it is 2-point DFT.thus equation 21 & 22 shows we can obtain 4-point DFT by containing two 2-point DFT’s.

Hereg11(n) = f1(2m)=x(4n) = {x(0),x(4)}g12(n) = f1(2m+1)=x(4n+2) = {x(2),x(6)}

Similarly g21(n) = f2(2m)=x(4n+1) = {x(1),x(5)}g22(n) = f2(2m+1)=x(4n+3) = {x(3),x(7)}

Computation of 2-point DFT The definition of DFT

N-1 X(k) = x(n) * Wkn

N k=0,1,……..N-1 ………………A n=0Using this equation consider first block of DFT

x(0) G11(0)g11(n) g11(0) 2-Point G11(k) wher k = 0 &1where n is 0,1 x(4) DFT G11(1) g11(1)

here i/p sequences are g11(0) & g11(1) .we denote as g11(n) where 0 to 1 ,G11(k) is DFT of g11(n).

1

Page 37: DSP Labmanual

G11(k) = g11(n) * Wkn2 k=0,1 ………………B

n=0

this Is 2-point DFT so we have to put N=2 putting values of k we get

G11(0) = g11(0) +g11(1) ……….CG11(1) = g11 (0) –g11(1) ……….D

Using c & d we can represent in FFT butterfly structure

g11(0) –1 – - x(0) G11(0)

g11(1) G11(1) x(4) –1 +

we know that W02 = 1 so we can modify c& d as

G11(0) = g11(0) + W02g11(1) ……….E

G11(1) = g11 (0) – W02g11(1) ……….F

Thus the modified butterfly structure is

g11(0) –1 – - x(0) G11(0)

g11(1) W02 G11(1)

x(4) –1 +

similarlly for other 2-point DFT we can draw this structure

Example: Find X(k) using DIFFT. X(n)= {-1,0,2,0,-4,0,2,0}

s1(n) represents o/p of stage1 & s2(n) represents o/p of stage2. W0

8 = e0=1 W1

8 = e-j/4= 0.707–j0.707 W2

8 = e-j/2= –j W3

8 = e-j3/4= 0.707–j0.707

Page 38: DSP Labmanual

Output of stage1

S1(0) = x(0) + W08 x(4) = –1+(–4) = –5

S1(1) = x(0) – W08 x(4) = –1–1(–4) = 3

S1(2) = x(2) + W08 x(6) = 2+1(2) = 4

S1(3) = x(2) – W08 x(6) = 2–1(2) = 0

S1(4) = x(1) + W08 x(5) = 0+1(0) = 0

S1(5) = x(1) – W08 x(5) = 0-1(0) = 0

S1(6) = x(3) + W08 x(7) = 0

S1(7) = x(3) – W08 x(7) = 0–1 = 0

Output of stage2

S2(0) = s1(0) + W08 s1(2) = –5+(–4) = –1

S2(1) = s1(1) + W28 s1(3) = 3-j(0) = 3

S2(2) = s1(0) – W08 s1(2) = –5–1(4) = –9

S2(3) = s1(1) – W28 s1(3) = 3+j(0) = 3

S2(4) = s1(4) + W08 s1(6) = 0+1(0) = 0

S2(5) = s1(5) + W28 s1(7) = 0–j(0) = 0

S2(6) = s1(4) – W08 s1(6) = 0–1(0) = 0

S2(7) = s1(5) – W28 s1(2) = 0+j(0) = 0

Final output X(0) = s2(0) + W0

8 s2(4) = –1+1(0) = –1 X(1) = s2(1) + W1

8 s2(5) = 3+(0.707–j0.707)0 = 3 X(2) = s2(2) + W2

8 s2(6) = –9–j(0) = –9 X(3) = s2(3) + W3

8 s2(7) = 3+(–0.707–j0.707)0 = 3 X(4) = s2(0) – W0

8 s2(4) = –1–1(0) = –1 X(5) = s2(1) – W1

8 s2(5) = 3–1(0) = 3 X(6) = s2(2) – W2

8 s2(6) = –9+j(0) = –9 X(7) = s2(3) – W3

8 s2(7) = 3+(–0.707–j0.707) 0= 3

X(k) = {–1,3,–9,3,–1,3,–9,3}

Design Analysis / Implementation Logic:

Algorithm:

12. Accept the sequence x(n) from user.13. use bit revarsal for input sample & according to that rearrange the input.14. in first loop calculate the twiddle factors.

Page 39: DSP Labmanual

15. find the 2-point DFT using the butterfly technique 16. continue step 4 for the 8 samples.17. use the o/p of step 5 as the input & find the 4-point DFT.18. similarlly to find 8-point DFT i.e. final o/p use the o/p of step 6 as the input &

find DFT.19. Display the output.

Testing:

Input: - Input Sequences x(n)

Output: DIT FFT of x(n) i.e. x(k).

Conclusion:

In this way we can Implement 8-point Radix-2 DIT FFT algorithm

Assignment No. 10

Title of Assignment:

Implement DFT using Goertzel Algorithm

Relevant Theory / Literature Survey:

A linear filtering approach for computation of DFT:The FFT algorithm takes N points of input data and produces an output sequence of N points corresponding to DFT of the input data. The radix-2 FFT algorithm performs the computation of the DFT in (N/2)* log2 N multiplications of Nlog2N additions for an N-point sequence. There are some applications where only a selected number of values of DFT are desired but the entire DFT is not required. In such cases the FFT algorithm may no longer be efficient than a direct computation of the desired number of values of the DFT is less than log2N, a direct computation of the desired values is more efficient.

Page 40: DSP Labmanual

The direct computation of DFT can be formulated as a linear filtering operation on the input data sequence. As the linear filter takes the form of parallel bank of resonators where each resonator selects one of the frequency wk=2k/n where k = 0,1,………..N-1 corresponding to the N frequencies in the DFT. The Goertzel Algorithm: The algorithm exploits the periodicity of the phase factors {W k

n} and allows us to express the computation of the DFT as a linear filtering operation. Consider the factor W –kN

N

W -kN

N= e-j2/N(-kN) = ej2k

= 1 always.Definition of N-pt DFT N-1

X(n) = x (m)* WkmN

M=0Multiply above equation by w –kN

N

N-1 X(k) = x (m)* W –k(N-m)

N

m=0Let us consider the LTI system as shown in the fig. Which has input x(n)

O/p sequence I/p sequence y(n) X(n)

Let the unit sample response of this system can be given as,

hk(n)=W–knN

Linear convolution is given as, yk(n)= x(m)* hk(n-m) m=-

yk(n)= x(m)* W–k(n-m)

N

m=-

N-1 yk(n)= x(m)* W–k(n-m)

N

m=-

Unit Sample processhk(n)=W–kn

N u(n)

Page 41: DSP Labmanual

yk(n) = x(m)* W–k(n-m)N

n=N m=-

Example:

Find the DFT of sequence {0,1,2,3} at pt 1 using Goertzel algorithm.

N-1 We know that X(k) = x (m)* W –k(N-m)

N ……..1 m=0

Now x(n) is given as {0,1,2,3} N=4.

We can represent the equation 1 in terms of linear convolution

N-1 yk(n)= x(m)* hk(n-m) hk(n)=W–k(n-m)

N * u(n-m) m=-

Now using k=1 in equation 1Splitting W in terms of cos & sin

Real x(1) = x(0)*cos (2*3.14*0*(0-4)/4)+x(1)* cos (2*3.14*1*(1-4)/4)+ x(2)* cos (2*3.14*2*(2-4)/4)+ x(3)* cos (2*3.14*3*(3-4)/4) =0+0+(-2)+0 = -2 Img x(1) = x(1)*sin (2*3.14*0*(0-4)/4)+x(1)* sin (2*3.14*1*(1-4)/4)+ x(2)* sin (2*3.14*2*(2-4)/4)+ x(3)* sin (2*3.14*3*(3-4)/4) =0+(-1)+0+3 = 2

So DFT of x(n) at pt 1 is {-2+2j}.

Page 42: DSP Labmanual

Design Analysis / Implementation Logic:

Algorithm:

1. Accept the no. of i/p sample i.e. N from user according to that accept input sample x(n).2. Accept the point at which the DFT is to calculate i.e. K.3. Compute the linear convolution over the range n=9 to N-1 for x(n)* W –k(N-m)

N

4. As twiddle factor involves real & imaginary we can separate the real & imaginary Terms for calculation,

N-1 N-1 x(m)* real + j x(m)* img m=0 m=0

5. This will give the DFT at that particular point.6. Display the final answer.

Testing:

Input: input sequence x(n) & the pt at which the DFT is to be calculate

Output: DFT of the sequence x(n).

Conclusion:

In this way we can calculate the DFT of any sequence using Goertzel algorithm.

Assignment No. 11

Title of Assignment:

Page 43: DSP Labmanual

Find the Fourier transform of various windows function.

Relevant Theory / Literature Survey:

Finite impulse response (FIR) filter design using window.Let us consider that the filter which is to be designed have the frequency response Hd(w). This is also called desired frequency response. We know that Hd(w) is Fourier transform of hd(n) i.e. Hd(w) = hd(n) * e–jwn ……… 1

n=0

and hd can be obtained by equation taking inverse Fourier transform of Hd(w) i.e.

Hd(w) = 1/2 Hd(w) * ejwn ------- 2

– Generally this is the desired unit sample response. Unit sample response obtained by equation 2 is infinite in duration. Since we are designing a finite impulse response filter the length of hd(n) is truncated to length m. this is equivalent to multiplying hd(n) by window sequence w(n). This can be best explained by considering a particular type of window sequence. Rectangular window for FIR filter design The rectangular window wr(n) is define as

wr(n) = 1 for n= 0,1,……..m-1 ……… 3 0 otherwise

The unit sample response of FIR filter is obtained by wR(n) i.e. h(n) = hd(n) * wR(n) ………….. 4

From equation 3 putting for wR(n) in above equation

h(n) = hd(n) for n= 0,1,……..n-1 ………5 0 otherwise

wR(n) acts like window for hd(n)

Now consider the Fourier T of rectangular window

m-1 HR(w) = HR(n) * e–jwn ……… 6

Page 44: DSP Labmanual

n=0

Here we can use

N2 ak = aN1-aN2-1/1-a ……….. 8

k=N1

Equation 7 becomes

wR(w) = 1– e–jwm/1- e–jw

Let us rearrange above equation as,

wR(w) = 1– e–jwm/1– e–jw

= e–jwm/2 * ejwm/2– e–jwm/2 * ejwm/2 / e–jw/2 * ejw/2– e–jw/2 * ejw/2

= e–jwm/2 [ ejwm/2- e–jwm/2]/ e–jw/2 [ ejw/2- e–jw/2]

we know that ej– e–j = 2 sin hence the equation

wR(w) = 1– e–jwm/2 * 2 sin(wm/2)/1– e–jw * 2 sin(w/2) = e–jwm(m-1/2) * Sin (wm/2)/sin(w/2) ……. 10

the polar form of wR(w) is given as wR(w) e–j<wr(w)

wR(w) = sin(wm/2)/sin(w/2)

Commonly used window function

Name Time domain sequence W(n) n m–1

Rectangle 1Barlett triangle 1–2 n-(m-1)/zBlackman 0.42-0.5 cos2n/m-1+0.08 cos4n/m-1Hamming 0-.54-0.46 cos2n/m-1Hannimg ½ (1-cos2n/m-1)

Design Analysis / Implementation Logic:

Algorithm:

Page 45: DSP Labmanual

1. Accept the length of window (m) from user.2. Accept the type of window.3. Using the standard formula calculate the coefficients of that window.4. Calculate the Fourier transform of window coefficient. Use step /640 while

calculating.5. Display magnitude & phase of window.

Testing:

Input: length of the window

Output: coefficient of various windows. Fourier transform of various window coefficient. Magnitude & phase of window.

Conclusion:

In this way we can obtain the Fourier transform of various windows function.

Assignment No. 12

Title of Assignment:

Design a DT IIR Butterworth filter for given specification using Bilinear Transformation.

Relevant Theory / Literature Survey:

The magnitude squared response of the butterworth filter (w pass) is given as

m0 (-z) 2 = 1/1+(N/2c)2n

Here N is order of frequency of butterworth of Rc = 3dB coefficient or critical frequency.

Page 46: DSP Labmanual

Steps to design butterworth filter are as follows

Assumption: Ap & As are passband & stopband edges wp & ws are passband & stopband frequencies.

Step 1: redefine specification for equivalent analog butter using BLT. = 2/T tan w/z Here 2/t is assumed to be 1

Step 2: calculate the order in ‘N’ filter by using relation

N= ½ [wg[1/Ap2 –1] / [1/Ap

2 –1] wg(-zs/p) N= ½ log [100.1AsdB –1/ 100.1/ApdB –1] log [s/p] Step 3: determine cutoff frequencies of equivalent analog filter is rc

c = tan wc/z Assume z/T= 1

Step 4: calculate poles of Ha(s) by full equation ps = (ej(N+2k/j/2N)

Step 5: organize the poles of pk as complex conjugate pairs i.e. s1 & s1* , s1 & s2*

Step 6: calculate system function of analog filter by full equation

Ha(s) = cn

(s-s1)(s- s1*) (s- s2) (s- s2

*)

Step 7: system function of digital filter by bilinear transformation can be obtained by

H(z) = p10(s) s = 1-z-1/1+z-1

These are important steps in design of IIR butterworth filter by bilinear transformation.Design Analysis / Implementation Logic:

Algorithm:

1. Accept the order of filter 2. Accept the cutoff frequency of digital filter wc.

3. Calculate average = tan (cutoff frequency /2)

Page 47: DSP Labmanual

4. Calculate the value of first N/2 poles.5. Calculate real part using = ((N/2 * 2*+1) * Pi) / (N*N) Real = -1* omega (cos ())

6. Calculate complex conjugate no.7. Display value f coefficients.

Testing:

Input: order of filter Cutoff frequency of digital filter.

Output: coefficients of digital filter.

Conclusion:

In this way we can Design a Butterworth filter for given specification using Bilinear Transformation