Top Banner
INDEX S.NO NAME OF THE EXPERMENT PAGE.NO 1) Linear Convolution of two Sequences. 2 - 6 2) Circular Convolution of two Sequences. 7 - 11 3) Discrete Fourier Transform. 12 - 15 4) Sinusoidal signal generation and its Sum. 16 - 20 5) Characteristics of analog LPF &HPF. 21 - 27 6) Design of IIR BUTTERWORTH LPF. 28 - 34 7) Design of IIR CHEBYSHEV LPF. 35 - 40 8) Design of FIR Low Pass Filter using all windows. 41 - 46 9) Design of FIR High Pass Filter using all windows. 47 - 52 10) Power Density Spectrum of a sequence. 53 - 55 Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 1
69
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dsplab Manuals

INDEX

S.NO NAME OF THE EXPERMENT PAGE.NO

1) Linear Convolution of two Sequences. 2 - 6

2) Circular Convolution of two Sequences. 7 - 11

3) Discrete Fourier Transform. 12 - 15

4) Sinusoidal signal generation and its Sum. 16 - 20

5) Characteristics of analog LPF &HPF. 21 - 27

6) Design of IIR BUTTERWORTH LPF. 28 - 34

7) Design of IIR CHEBYSHEV LPF. 35 - 40

8) Design of FIR Low Pass Filter using all windows. 41 - 46

9) Design of FIR High Pass Filter using all windows. 47 - 52

10) Power Density Spectrum of a sequence. 53 - 55

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 1

Page 2: Dsplab Manuals

1. AIM :

Write a program in C and MATLAB to compute the response of a discrete LTI

system with input sequence x(n) and impulse response h(n) by using linear

convolution. Verify the same on TMS320C6711 DSP kit.

2. COMPONENTS & TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,

2.2 Full version CCS s/w,

2.3 DSK 6711 s/w,

2.4 MATLAB s/w.

3. THEORY:Convolution is a special operation, operated between two signals and which

includes the following operations.

Folding.

Shifting.

Multiplication.

Addition

Convolution sum is useful to obtain the response of discrete LTI system with

input x(n) and impulse response h(n).

x(n) y(n)

.

It is also used to compute the impulse response of cascaded discrete LTI

system with individual systems having impulse responses h1(n), h2(n), h3(n).

x(n) y(n)

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 2

h(n)

h1(n) h1(n) h1(n)

LINEAR CONVOLUTIONEXPT. NO : 1

DATE :

Page 3: Dsplab Manuals

To obtain the response, we have two types of convolutions.

Linear Convolution.

Circular Convolution.

Linear convoluted sequence y(n) between x(n) with duration N1and h(n) with

duration N2 is defined as

Where N = N1+N2 –1 is the duration of convoluted sequence y(n).

DFT does not support linear convolution, because of x(n) and h(n) are of

different durations. That’s why we can go for circular convolution.

4. COMPUTATIONAL ALGORITHM:Following steps were required to compute the response of discrete LTI system

with input x(n) and impulse response h(n)

Keep the input sequence x(m) as it is and fold the impulse response

h(m).

Shift the folded version sequence, h(-m) by n units to get h(n-m).

Multiply the input sequence x(m) and h(n-m).

Compute the sum over wide range.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 3

Page 4: Dsplab Manuals

5. PROGRAM:5.1 C PROGRAM:

#include<stdio.h>int x[20],h[20],y[20],N1,N2,n,m;void main(){

printf("Enter the length of input sequence x(n)\t:N1=");scanf("%d",&N1);

printf("Enter the length of impulse response h(n)\t:N2=");scanf("%d",&N2);

printf("Enter %d samples for input sequence x(n):\n",N1);for(n=0;n<N1;n++)scanf("%d",&x[n]);

printf("Enter %d samples for impulse response h(n):\n",N2);for(n=0;n<N2;n++)scanf("%d",&h[n]);

printf("Input sequence \nx(n)=");for(n=0;n<N1;n++)printf("\t%d",x[n]);

printf("\nImpulse Response \nh(n)=");for(n=0;n<N2;n++)printf("\t%d",h[n]);

for(n=0;n<N1+N2-1;n++){

y[n]=0;for(m=0;m<=n;m++)y[n]=y[n]+x[m]*h[n-m];

}

printf("\nResponse of LT1 system is\ny(n)=");for(n=0;n<N1+N2-1;n++)printf("\t%d",y[n]);

}

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 4

Page 5: Dsplab Manuals

5.2 MATLAB PROGRAM:x=input('Enter the input sequence x(n)=');h=input('Enter the impulse response h(n)=');y=conv(x,h);N1=length(x);N2=length(h);N=length(y);

disp('Input Sequence x(n)::');disp(x);disp('Impulse Response h(n)::');disp(h);disp('Output of discrete LTI system is');disp(y);

disp('press "ENTER" for input sequence x(n)');pausen=0:1:N1-1;subplot(2,2,1);stem(n,x);title('Input sequence x(n)');xlabel('discrete Time n');ylabel('Amplitude');

disp('press "ENTER" for impulse Response h(n)');pausen=0:1:N2-1;subplot(2,2,2);stem(n,h);title('Impulse Response h(n)');xlabel('discrete Time n');ylabel('Amplitude');

disp('press "ENTER" for Response of the system');pausen=0:1:N-1;subplot(2,2,3);stem(n,y);title('Response of discrete LTI system');xlabel('discrete Time n');ylabel('Amplitude');

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 5

Page 6: Dsplab Manuals

6. EXPECTED RESULTS:Example :

Let

Input sequence x(n) = [1, 2, 3, 4], and

Impulse response h(n) = [5, 6, 7, 8, 9], then

Expected response of the LTI system is y(n) = [5, 16, 34, 60, 70, 70, 59, 36]

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

9. VIVA -VOCE QUESTIONS:

What is the need of convolution

Why DFT does not support Linear Convolution.

How to obtain the response of discrete LTI system from Linear Convolution

In MATLAB which command is used to plot the discrete sequence

Write the logic in C, to compute the convolution

What are different steps required to execute the DSP program in CCS.

How to create project in CCS.

What are different files to be added for project, to execute the program

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 6

Page 7: Dsplab Manuals

1. AIM:

Write a program in C and MATLAB to compute the response of a discrete LTI

system with input sequence x(n) and impulse response h(n) by using Circular

convolution. Verify the same on TMS320C6711 DSP kit, MATLAB.

2. TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,

2.2 Full version CCS s/w,

2.3 DSK 6711 s/w,

2.4 MATLAB s/w.

3. THEORY:Convolution is a special operation, operated between two signals and which

includes the following operations.

Folding.

Shifting.

Multiplication.

Addition

Convolution sum is useful to obtain the response of discrete LTI system with

input x(n) and impulse response h(n).

x(n) y(n)

.

It is also used to compute the impulse response of cascaded discrete LTI

system with individual systems having impulse responses h1(n), h2(n), h3(n).

x(n) y(n)

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 7

CIRCULAR CONVOLUTIONEXPT. NO : 2

DATE :

h(n)

h1(n) h1(n) h1(n)

Page 8: Dsplab Manuals

To obtain the response, we have two types of convolutions.

Linear Convolution.

Circular Convolution.

Linear convoluted sequence y(n) between x(n) with duration N1and h(n) with

duration N2 is defined as

Where N = N1+N2 –1 is the duration of convoluted sequence y(n).

DFT does not support linear convolution, because of x(n) and h(n) are of

different durations. That’s why we can go for circular convolution.

DFT supports only circular convolution, because of x(n) and h(n) are equal

durations. Circular convoluted sequence y(n) between x(n) and h(n) with equal

duration N is defined as

In this case if x(n) and h(n) are of different durations, then zero padding is

required to obtain the response of discrete LTI system.

4. COMPUTATION:Following steps are required to compute the response of discrete LTI system

with input x(n) and impulse response h(n)

Convert the input sequence x(n) duration N1 to N1+N2 –1 by padding with

N2 –1 number of zeros.

Convert the impulse response sequence h(n) duration N2 to N1+N2 –1 by

padding with N1 –1 number of zeros

Keep the input sequence x(m) as it is and fold the impulse response h(m).

Shift the folded version sequence, h(-m) by n units to get h(n-m).

Multiply the input sequence x(m) and h(n-m).

Finally compute the sum over the range 0 to N1+N2 –2.

5. PROGRAM:5.1 C PROGRAM:

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 8

Page 9: Dsplab Manuals

#include<stdio.h>int x[20],h[20],y[20],N1,N2,n,m;void main(){

printf("Enter the length of input sequence x(n)\t:N1=");scanf("%d",&N1);

printf("Enter the length of impulse response h(n)\t:N2=");scanf("%d",&N2);

printf("Enter %d samples for input sequence x(n):\n",N1);for(n=0;n<N1;n++)scanf("%d",&x[n]);

printf("Enter %d samples for impulse response h(n):\n",N2);for(n=0;n<N2;n++)scanf("%d",&h[n]);

for(n=N1;n<N1+N2-1;n++)x[n]=0;

for(n=N2;n<N1+N2-1;n++)h[n]=0;

printf("Input sequence after zero paddind \nx(n)=");for(n=0;n<N1+N2-1;n++)printf("\t%d",x[n]);

printf("\nImpulse Response after zero paddind \nh(n)=");for(n=0;n<N1+N2-1;n++)printf("\t%d",h[n]);

for(n=0;n<N1+N2-1;n++){

y[n]=0;for(m=0;m<N1+N2-1;m++)y[n]=y[n]+x[m]*h[n-m];

}

printf("\nResponse of LT1 system is\ny(n)=");for(n=0;n<N1+N2-1;n++)printf("\t%d",y[n]);

}

5.2 MATLAB PROGRAM:x=input('Enter the input sequence x(n)=');h=input('Enter the impulse response sequence h(n)=');

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 9

Page 10: Dsplab Manuals

N1=length(x);N2=length(h);L=N1+N2-1;n=0:1:L-1;

zpx=[x zeros(1,L-N1)];disp('Input sequence after zero padding:: x(n):');disp(zpx);zph=[h zeros(1,L-N2)];disp('Impulse Response after zero padding::y(n):');disp(zph);

X=fft(zpx);H=fft(zph);

y=ifft(X.*H);disp('Response of discrete LTI System::y(n):');disp(y);

disp('Press "ENTER" for zero padded x(n)');pausesubplot(2,2,1);stem(n,zpx);title('Inpuit sequence after zero padding');xlabel('Discrete Time');ylabel('Amplitude');

disp('Press "ENTER" for zero padded h(n)');pausen=0:1:L-1;subplot(2,2,2);stem(n,zph);title('Impulse response after zero padding');xlabel('Discrete Time');ylabel('Amplitude');

disp('Press "ENTER" for Responseof the system');pausen=0:1:L-1;subplot(2,2,3);stem(n,y);title('Response of discrete LTI System');xlabel('Discrete Time');ylabel('Amplitude');

6. EXPECTED RESULTS:

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 10

Page 11: Dsplab Manuals

Example :

Let

Input sequence x(n) = [1, 2, 3, 4], and

Impulse response h(n) = [5, 6, 7, 8, 9], then

Zero padded input sequence zpx(n) =[1, 2, 3, 4, 0, 0, 0, 0]

Zero padded impulse response zph(n) =[5, 6, 7, 8, 9, 0, 0, 0]

Expected response of the LTI system is y(n) = [5, 16, 34, 60, 70, 70, 59, 36]

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

9. VIVA -VOCE QUESTIONS:

In what way Linear Convolution is different from Circular Convolution.

Why zero padding is required in circular convolution.

How to obtain the response of discrete LTI system from circular convolution

How to obtain the circular convolution through DFT & IDFT.

Why DFT supports only circular convolution.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 11

DISCRETE FOURIER TRANSFORMEXPT. NO : 3

Page 12: Dsplab Manuals

1.AIM

Write a program in C and MATLAB to compute the Discrete Fourier Transform

of a given discrete sequence x(n). Verify the same on TMS320C6711 DSP kit,

MATLAB.

2. TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,

2.2 Full version CCS s/w,

2.3 DSK 6711 s/w,

2.4 MATLAB s/w.

3. THEORY:Following are the different transforms used to obtain required frequency domain representation of any given time domain representation.

Laplace Transform. Fourier Transform. Z Transform. Discrete Fourier Transform.

Laplace transform is used for only continuous time signals and Z transform is used for only discrete time signals. Fourier transform is used for both continuous and discrete time signals. The DFT is used to convert N-point discrete time sequence x(n) to an N-point frequency domain sequence X(k).

where k is ranging from 0 to N – 1.

The IDFT is used to convert N-point frequency domain sequence X(k) to an N-point time domain sequence x(n).

where n is ranging from 0 to N – 1.

To compute DFT from above formulae is very difficult, if number of points(N) increases, to over come this problem we can for Fast Fourier Transform(FFT). The FFT is a method or algorithm is used to compute DFT with reduced number of calculations(Complex additions & Complex multiplication).

4. PROGRAM:4.1 C PROGRAM:

#include<stdio.h>

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 12

DATE :

Page 13: Dsplab Manuals

#include<math.h>#define Pi 3.142857int x[20],N,n,k;float XReP[20],XImP[20],X[20],MSofX[20],PSofX[20];void main(){

printf("Enter the length of discrete sequence x(n):N=");scanf("%d",&N);printf("Enter the discrete sequence x(n):\n");for(n=0;n<N;n++)scanf("%d",&x[n]);

for(k=0;k<N;k++){

XReP[k]=0;XImP[k]=0;for(n=0;n<N;n++){

XReP[k]=XReP[k]+x[n]*cos(2*Pi*n*k/N);XImP[k]=XImP[k]+x[n]*sin(2*Pi*n*k/N);

}MSofX[k]=sqrt(XReP[k]*XReP[k]

+XImP[k]*XImP[k]);XImP[k]=-XImP[k];PSofX[k]=atan(XImP[k]/XReP[k]);

}printf("\nDiscrete sequence x(n)=");for(n=0;n<N;n++)printf("\t%d",x[n]);

printf("\nDFT sequence X(K)=");for(k=0;k<N;k++){if(XImP[k]>0)printf("\n%f-%fi",XReP[k],XImP[k]);else printf("\n%f+%fi",XReP[k],-XImP[k]);}

printf("\nMagnitude Spectrum of X(K)\t=");for(k=0;k<N;k++)printf("\t %f",MSofX[k]);printf("\nPhase Spectrum of X(K)\t=");for(k=0;k<N;k++)printf("\t %f ",PSofX[k]); }

4.2 MATLAB PROGRAM:x=input('Enter the discrete sequence x(n)::');N=length(x);X=fft(x);MSX=abs(X);

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 13

Page 14: Dsplab Manuals

PSX=angle(X);

disp('Discrete time sequence x(n)::');disp(x);disp('DFT of x(n)= X(K)is');disp(X);disp('Magnitude Spectrum of X(K)is ');disp(MSX);disp('Phase Spectrum of X(K)is ');disp(PSX);

disp('press "ENTER" for given sequence');pausen=0:1:N-1;subplot(2,2,1);stem(n,x);title('Discrete Time Sequence');xlabel('discrete Time n');ylabel('Amplitude');

disp('For Magnitude Spectrum press "ENTER"');pausek=0:1:N-1;subplot(2,2,2);stem(k,MSX);title('Magnitude Spectrum of X(K)');xlabel('discrete Time k');ylabel('Magnitude');

disp('For Phase Spectrum press "ENTER"');pausek=0:1:N-1;subplot(2,2,3);stem(k,PSX);title('Phase Spetrum of X(K)');xlabel('discrete Time k');ylabel('Phase');

5. EXPECTED RESULTS:Example :

Let

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 14

Page 15: Dsplab Manuals

Discrete time sequence x(n) = [1, 2, 3, 4], then

DFT of x(n) X(k) = [10, -2+2 i, -2, -2 -2i]

Magnitude Spectrum of X(K)is X(k) = [10, 2.8284, 2, 2.8284]

Phase Spectrum of X(K)is in radians X(k) = [0, 2.3562, 3.1416, -2.3562]

6. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

7. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

8. VIVA -VOCE QUESTIONS:

How to obtain Discrete Fourier Transform of a sequence x(n) What is Fast Fourier Transform What are different types of FFT algorithms Explain clearly how computational efficiency increases through FFT How to compute IDFT through FFT How to obtain response of the system from FFT.

1. AIM

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 15

SUM of SINUSOIDAL SIGNAL GENERATIONEXPT. NO : 4

DATE :

Page 16: Dsplab Manuals

Write a program in C and MATLAB to generate two sinusoidal signals and its

sum. Verify the same on TMS320C6711 DSP kit, MATLAB.

2. TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,

2.2 Full version CCS s/w,

2.3 DSK 6711 s/w,

2.4 MATLAB s/w.

3. THEORY:A signal can be defined as a physical quantity, which varies with respect to

one or more independent variables. Mathematically signal can be defined as a

function, which varies with respect to time and conveys some information.

Information may be temperature, Voltage, Current, Power etc. Based on

variation of amplitude of a signal, signals are classified into two categories.

Continuous Time Signals

Discrete Time Signals

Continuous time signals are those for which the signal amplitude is

continuously varies with respect to continuous variation in time.

Example :

0 20 40 60 80 100-1

0

1Continuous Time Signal x(t)

Continuous Time (t)

Am

plitu

de

Discrete time signals are those for which the signal amplitude is discretely

varies with respect to discrete variation in time.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 16

Page 17: Dsplab Manuals

Example :

0 10 20 30 40 50 60 70 80 90 100-1

-0.5

0

0.5

1Discrete Time Signal x(n)

Discrete Time (n)

Am

plitu

de

4. PROCEDURE: Choose the length (L) of required sine wave.

Select number of cycles (N1) of first sine wave x1(t)

x1(t) = Sin(2n N1/L)

Select number of cycles (N2) of second sine wave x2(t)

x1(t) = Sin(2n N1/L)

Finally add x1(t) and x2(t)

5. PROGRAM:5.1 C PROGRAM:

#include<stdio.h>#include<math.h>#define pi 3.14159

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 17

Page 18: Dsplab Manuals

int t,L,N1,N2;float x[1000],x1[1000],x2[1000];void main(){

printf("Enter the Length of required SIN wave");scanf("%d",&L);printf("Enter Number of Cycles of First SIN wave");scanf("%d",&N1);printf("Enter Number of Cycles of Second SIN wave");scanf("%d",&N2);

for(t=0;t<=L;t++){

x1[t]=sin(2*pi*t*N1/L);x2[t]=sin(2*pi*t*N2/L);x[t]=x1[t]+x2[t];

}

printf("First Sine Wave Amplitudes over the range 0 to %d\n",L);for(t=0;t<=L;t++)printf("x1[%d]=%f\n",t,x1[t]);

printf("Second Sine Wave Amplitudes over the range 0 to %d\n",L);

for(t=0;t<=L;t++)printf("x2[%d]=%f\n",t,x2[t]);

printf("SUM = x1(t)+x2(t) over the range 0 to %d\n",L);for(t=0;t<=L;t++)printf("x[%d]=%f\n",t,x[t]);

}

5.2 MATLAB PROGRAM:L=input('Enter the length of sine wave:');N1=input('Enter number of cycles of First Sine Wave:');N2=input('Enter number of cycles of Second Sine Wave:');

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 18

Page 19: Dsplab Manuals

n=0:1:L-1;

x1=sin(2*n*pi*N1/L);x2=sin(2*n*pi*N2/L);x=x1+x2;

disp('For First Sine Wave press ENTER');pause;subplot(3,1,1);stem(n,x1);title('First Signal');xlabel('Discrete Time');ylabel('Amplitude');

disp('For Second Sine Wave press ENTER');pause;subplot(3,1,2);stem(n,x2);title('Second Signal');xlabel('Discrete Time');ylabel('Amplitude');

disp('For the SUM of x1(t)and x2(t)press ENTER');pause;subplot(3,1,3);stem(n,x);title('SUM=x1+x2 Signal');xlabel('Discrete Time');ylabel('Amplitude');

6. EXPECTED RESULTS:Example :

Let

First Sinusoidal Signal x1(t) = Sin(2tN1/L), and

Second Sinusoidal Signal x2(t) = Sin(2tN2/L),then

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 19

Page 20: Dsplab Manuals

Sum of x1(t) and x2(t) is x(t) = x1(t) + x2(t);

0 10 20 30 40 50 60 70 80 90 100-1

0

1First Signal

Discrete Time

Am

plitu

de

0 10 20 30 40 50 60 70 80 90 100-1

0

1Second Signal

Discrete Time

Am

plitu

de

0 10 20 30 40 50 60 70 80 90 100-2

0

2SUM=x1+x2 Signal

Discrete Time

Am

plitu

de

7. CONCLUSION:

Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 20

CHARACTERISTICS OF ANALOG LPF/HPFEXPT. NO : 5

DATE :

Page 21: Dsplab Manuals

1. AIM:

Write a program in C and MATLAB to obtain the frequency response of simple

analog RC low pass and high pass filters. Verify the same on TMS320C6711

DSP kit, MATLAB.

2. TOOLS REQUIRED : TMS 320C 6711 Kit,

Full version CCS s/w,

DSK 6711 s/w,

MATLAB s/w.

3. THEORY:Filter is a frequency selective device, which allows only specified band of frequencies of a input signal and attenuate all other unwanted frequencies of input signal. Based on the frequency response of the filter, filters are classified into four types.

1. Low Pass Filter (LPF)2. High Pass Filter (HPF)3. Band Pass filter (BPF)4. Band Stop Filter/Band Elimination Filter/Band Reject Filter

(BSF/BEF/BRF)

3.1 Low Pass Filter: Low pass filter allows only low frequencies of input signal and attenuate all other high frequencies of input signal. A simple RC low pass filter shown below

R

x(t) or X(s) I(s) C y(t) or Y(s)

Wherex(t) : Input Signaly(t) : Output signalX(s) : Input in s-domainY(s) : Output in s-domainI(s) : current through the circuit1/sC : Capacitive reactance

Loop equation

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 21

Page 22: Dsplab Manuals

Characteristics of LPF:

H(j)

Ideal characteristics1

Practical characteristics

0 c

Where c is cut-off frequency

3.2 High Pass Filter: High pass filter allows only high frequencies of input signal and attenuate all other low frequencies of input signal. A simple RC high pass filter shown below

C

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 22

Page 23: Dsplab Manuals

x(t) or X(s) I(s) R y(t) or Y(s)

Wherex(t) : Input Signaly(t) : Output signalX(s) : Input in s-domainY(s) : Output in s-domainI(s) : current through the circuit1/sC : Capacitive reactance

Loop equation

Characteristics of HPF:

H(j)

Ideal characteristics1

Practical characteristics

0 c

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 23

Page 24: Dsplab Manuals

3.3 Band Pass Filter: Band pass filter allows only a certain band of frequencies and attenuate all other unwanted frequencies of input signal.

Characteristics of BPF:

H(j)

Ideal characteristics1

Practical characteristics

0 c1 c2

3.4 Band Stop Filter: Band stop filter allows entire band of frequencies of input signal, except a certain band of input signal.

Characteristics of BSF:

H(j)

Ideal characteristics1

Practical characteristics

0 c1 c2

4. PROGRAM:

4.1 C PROGRAM:#include<stdio.h>#include<math.h>int W,L;float R,C,K,P,LpfH[1000],HpfH[1000];void main(){

printf("Enter the Resistor value of Filter in Kilo ohms:");scanf("%f",&R);printf("Enter the Capacitor value of Filter in micro Farads:");scanf("%f",&C);

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 24

Page 25: Dsplab Manuals

printf("Enter the Range of frequency response:");scanf("%d",&L);

printf("Analog simple RC Filter\n");printf("Resistance (R) = %f Kilo Ohms\n",R);printf("Capacitor (C) = %f micro Farads\n",C);

R=1000*R;C=C/1000000;

for(W=0;W<=L;W++){

K=W*R*C;P=K*K;LpfH[W]=1/sqrt(1+P);HpfH[W]=K/sqrt(1+P);

}

printf("Magnitude spectrum values of LPF\n");for(W=0;W<=L;W++)printf("\nH(%d) = %f", W,LpfH[W]);

printf("Magnitude spectrum values of HPF\n");for(W=0;W<=L;W++)printf("\nH(%d) = %f", W,HpfH[W]);

}

4.2 MATLAB PROGRAM:disp('Input data for Simple RC Analog LPF:');R=input('Enter the Resistance value of LPF in Kilo Ohms:');C=input('Enter the Capacitor value of LPF in micro Faradays:');L=input('Enter the Frequency Range:');

R=1000*R;C=C/1000000;W=0:1:L;k=W*R*C;ks=k.*k;S=sqrt(1+ks);

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 25

Page 26: Dsplab Manuals

MSofLPF=S.^-1;MSofHPF=k.*(S.^-1);

disp('Amplitude of Magnitude Spectrum of LPF');disp(MSofLPF);disp('Amplitude of Magnitude Spectrum of HPF');disp(MSofHPF);

subplot(2,1,1);plot(W,MSofLPF);title('Response of LPF');xlabel('Frequency');ylabel('Amplitude');subplot(2,1,2);plot(W,MSofHPF);title('Response of HPF');xlabel('Frequency');ylabel('Amplitude');

5. EXPECTED RESULTS:Example :

LetResistor value R = 10K,Capacitor value C = 10 FFrequency range L = 100 rad/sec.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 26

Page 27: Dsplab Manuals

0 10 20 30 40 50 60 70 80 90 1000

0.5

1Response of LPF

Frequency

Am

plitu

de

0 10 20 30 40 50 60 70 80 90 1000

0.5

1Response of HPF

Frequency

Am

plitu

de

6. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

7. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

8. VIVA -VOCE QUESTIONS:

Define filter Explain different types of filters Compare analog / digital filters Explain the operation of RC low pass / high pass filter.

1. AIM

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 27

DESIGN OF IIR BUTTERWORTH LPF EXPT. NO : 6

DATE :

Page 28: Dsplab Manuals

Write a program in C and MATLAB to design IIR BUTTERWORTH low pass filter for the given specifications pass band frequency, stop band frequency, gain at pass band frequency and gain at stop band frequency. Verify the same on TMS 320 C 6711 DSP kit, MATLAB.

2. TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,2.2 Full version CCS s/w,2.3 DSK 6711 s/w, 2.4 MATLAB s/w.

3. THEORY:The filters designed by considering all the infinite samples of impulse response are called IIR filters. It is a discrete time system that is designed to pass the spectral contents of the input signal in a specified band of frequencies. There are so many approximation solutions to design digital filters, among them popular approximations

1. BUTTERWORTH approximation2. CHEBYSHEV approximation

Here. First we have to design analog filters, then by using transformation techniques we can obtain digital filter transfer function. There are two types of transformation techniques.

1. Impulse Invariant Transformation 2. Bilinear Transformation

4. DESIGN PROCEDURE:Following steps were required to design a digital CHEBYSHEV LPF

1. Take the specifications of desired Low Pass FilterP = Pass band frequency corresponding to the analog filter frequency P

S = Stop band frequency corresponding to the analog filter frequency S

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 28

Page 29: Dsplab Manuals

AP = Gain at Pass band frequency P

AS = Gain at Stop band frequency S

2. Choose either Impulse Invariant or Bilinear Transformation(IIT/BT) and calculate the frequency ratio

3. Decide the order (N) of the filter (Choose greatest & nearest integer)

4. Calculate the analog cutoff frequency (C)

5. Determine the analog filter Transfer function Ha(s)

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 29

Page 30: Dsplab Manuals

6. Determine the Digital filter transfer function H(z) from analog filter transfer function Ha(s), may be from impulse invariant or bilinear transformation by using the following formulae.

7. Finally realize the digital system by a suitable structure(a) Direct Form – I Realization.(b) Direct Form – I Realization (Canonic Form Realization).(c) Parallel Form Realization.(d) Cascade Form Realization

5. PROGRAM:5.1 C PROGRAM:

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 30

Page 31: Dsplab Manuals

#include<stdio.h>#include<math.h>#define pi 3.14int n,N,i,k;float A,Ap,As,Wp,Ws,W21,N1,Wc,b[10],bk;void main(){

printf("Enter Pass band frequency of LPF in rad/sec :");scanf("%f",&Wp);printf("Enter Stop band frequency of LPF in rad/sec:");scanf("%f",&Ws);printf("Enter the gain at Pass band frequency %f rad/sec :",Wp);scanf("%f",&Ap);printf("Enter the gain at Stop band frequency %f rad/sec:",Ws);scanf("%f",&As);

printf("\nSelect the required transformation\n");printf("1. Impulse Invariant Transformation\n");printf("2. Bilinear Transformation\n");printf("\nEnter 1 or 2: ");scanf("%d",&i);

switch(i){

case 1 :printf("\nYou are selected Impulse Invariant

method");W21=Ws/Wp;A=(1/(As*As)-1)/(1/(Ap*Ap)-1);N1=log(A)/(2.0*log(W21));N=N1+1.0;Wc=Wp/pow((1/(Ap*Ap)-1),1.0/(2.0*N));

break;

case 2 :printf("\nYou are selected Bilinear Transformation

");W21=tan(Ws/2)/tan(Wp/2);A=(1/(As*As)-1)/(1/(Ap*Ap)-1);N1=log(A)/(2.0*log(W21));N=N1+1.0;Wc=2*tan(Wp/2)/pow((1/(Ap*Ap)-1),1.0/(2.0*N));

break;

default:printf("Sorry, Your selection is wrong");

}

printf("\nInput Data for the BUTTERWORTH LPF\n");printf("Pass Band Frequency\t\tWp = %f rad/sec.",Wp);

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 31

Page 32: Dsplab Manuals

printf("\nStop Band Frequency\t\tWs = %f rad/sec.",Ws);printf("\nGain at Pass Band Frequency\tAp = %f",Ap);printf("\nGain at Stop Band Frequency\tAs = %f",As);

printf("\n\nRequired Results of BUTTERWORTH LPF");printf("\nFrequency ratio\t\t\tW21\t=%f",W21);printf("\nOrder of the Filter\t\tN\t=%d",N);printf("\nAnalog cutoff frequency\t Wc\t=%f rad/sec.",Wc);

if(N%2==0){

printf("\nOrder of the BUTTERWORTH LPF is Even");printf("\nTransfer function of BUTTERWORTH Filter is");printf("\nHa(s)=PI(Wc*Wc/(s*s+bk*Wc*s+Wc*Wc))");printf("\nWhere bk=2*sin((2k-1)pi/2N), k=1,2,...N/2\n");

for(k=1;k<=N/2;k++)b[k]=2*sin((2*k-1)*pi/(2*N));for(k=1;k<=N/2;k++)printf("\nb%d=%f",k,b[k]);

}if(N%2==1){

printf("\nOrder of the BUTTERWORTH LPF is Odd");printf("\nTransfer function of BUTTERWORTH Filter is");printf("\nHa(s)=[Wc/(s+Wc)]

PI[Wc*Wc/(s*s+bk*Wc*s+Wc*Wc)]");printf("\nWhere bk=2*sin((2k-1)pi/2N), k=1,2,...(N-1)/2\n");

for(k=1;k<=(N-1)/2;k++)b[k]=2*sin((2*k-1)*pi/(2*N));for(k=1;k<=(N-1)/2;k++)printf("\nb%d=%f",k,b[k]);

}}

5.2 MATLAB PROGRAM:Wp=input('Enter the PASS band frequency of LPF in rad/sec:');

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 32

Page 33: Dsplab Manuals

Ws=input('Enter the STOP band frequency of LPF in rad/sec:');Ap=input('Enter the GAIN at pass band frequency:');As=input('Enter the GAIN at stop band frequency:');

Apdb=20*log10(Ap);Asdb=20*log10(As);[N,Wc]=buttord(Wp,Ws,Apdb,Asdb);[num,den]=butter(N,Wc,'low');disp('Order of the Filter = ');disp(N);disp('Analog Cutoff frequency of the filter = ');disp(Wc);disp('Numerator coefficients of H(z)');disp(num);disp('Denomminator coefficients of H(z)');disp(den);freqz(num,den);

6. EXPECTED RESULTS:Example :

Let

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 33

Page 34: Dsplab Manuals

Pass band frequency (P) = 0.6 rad/secStop band frequency (S) = 0.9 rad/secGain at Pass band frequency (AP) = 0.8Gain at Stop band frequency (AS) = 0.2, then

IIT Frequency ratio = 1.5

Order of the filter (N) = 5

Analog filter cutoff frequency (C) = 0.636 rad/sec

Coefficients (bk) = (b1, b2) = 0.618, 1.617

Analog filter Transfer function

Ha(s) =

BLT Frequency ratio = 1.562

Order of the filter (N) = 5

Analog filter cutoff frequency (C) = 0.655 rad/sec

Coefficients (bk) = (b1, b2) = 0.618, 1.617

Analog filter Transfer function

Ha(s) =

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

9. VIVA -VOCE QUESTIONS:

Compare IIR / FIR filters Compare BUTTERWORTH / CHEBYSHEV filter. What are conditions for an analog filter to be stable and causal. What are conditions for a digital filter to be stable and causal. What is frequency warping?

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 34

DESIGN OF IIR CHEBYSHEV LPFEXPT. NO : 7

DATE :

Page 35: Dsplab Manuals

1. AIMWrite a program in C and MATLAB to design IIR CHEBYSHEV low pass filter for the given specifications pass band frequency, stop band frequency, gain at pass band frequency and gain at stop band frequency. Verify the same on TMS 320 C 6711 DSP kit, MATLAB.

2. TOOLS REQUIRED : TMS 320C 6711 Kit,Full version CCS s/w,DSK 6711 s/w, MATLAB s/w.

3. THEORY:The filters designed by considering all the infinite samples of impulse response are called IIR filters. It is a discrete time system that is designed to pass the spectral contents of the input signal in a specified band of frequencies. There are so many approximation solutions to design digital filters, among them popular approximations

3. BUTTERWORTH approximation4. CHEBYSHEV approximation

Here. First we have to design analog filters, then by using transformation techniques we can obtain digital filter transfer function. There are two types of transformation techniques.

1. Impulse Invariant Transformation 2. Bilinear Transformation

4. DESIGN PROCEDURE:Following steps were required to design a digital CHEBYSHEV LPF

1. Take the specifications of desired Low Pass FilterP = Pass band frequency corresponding to the analog filter frequency P

S = Stop band frequency corresponding to the analog filter frequency S

AP = Gain at Pass band frequency P

AS = Gain at Stop band frequency S

2. Choose either Impulse Invariant or Bilinear Transformation(IIT/BT) and calculate the frequency ratio

3. Decide the order (N) of the filter (Choose greatest & nearest integer)

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 35

Page 36: Dsplab Manuals

4. Calculate the analog cutoff frequency (C)

5. Determine the analog filter Transfer function Ha(s)

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 36

Page 37: Dsplab Manuals

6. Determine the Digital filter transfer function H(z) from analog filter transfer function Ha(s), may be from impulse invariant or bilinear transformation by using the following formulae.

7. Finally realize the digital filter by a suitable structure(e) Direct Form – I Realization.(f) Direct Form – I Realization (Canonic Form Realization).(g) Parallel Form Realization.(h) Cascade Form Realization

5. C PROGRAM:#include<stdio.h>#include<math.h>#define pi 3.14int n,N,i,k;

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 37

Page 38: Dsplab Manuals

float A,Ap,As,Wp,Ws,W21,N1,Wc,b[10],bk,a,Y,YN,c[10],ck,c0;void main(){

printf("Enter Pass band frequency of LPF in rad/sec :");scanf("%f",&Wp);printf("Enter Stop band frequency of LPF in rad/sec:");scanf("%f",&Ws);printf("Enter the gain at Pass band frequency %0.2f rad/sec :",Wp);scanf("%f",&Ap);printf("Enter the gain at Stop band frequency %0.2f rad/sec:",Ws);scanf("%f",&As);

printf("\nSelect the required transfermation\n");printf("1. Impulse Invariant Transfermation\n");printf("2. Bilinear Transfermation\n");printf("\nEnter 1 or 2: ");scanf("%d",&i);

switch(i){

case 1 :printf("\nYou are selected Impulse Invariant method");W21=Ws/Wp;A=sqrt((1/(As*As)-1)/(1/(Ap*Ap)-1));N1=log(A+sqrt(A*A-1))/log(W21+sqrt(W21*W21-1));N=N1+1.0;Wc=Wp/pow((1/(Ap*Ap)-1),1/(2*N));

break;

case 2 :printf("\nYou are selected Bilinear Transformation ");W21=tan(Ws/2)/tan(Wp/2);A=sqrt((1/(As*As)-1)/(1/(Ap*Ap)-1));N1=log(A+sqrt(A*A-1))/log(W21+sqrt(W21*W21-1));N=N1+1.0;Wc=2*tan(Wp/2)/pow((1/(Ap*Ap)-1),1/(2*N));

break;

default:printf("Sorry, Your selection is wrong");

}

printf("\nInput Data for the CHEBYSHEV LPF\n");printf("Pass Band Frequency\t\tWp = %0.3f rad/sec.",Wp);printf("\nStop Band Frequency\t\tWs = %0.3f rad/sec.",Ws);printf("\nGain at Pass Band Frequency\tAp = %0.3f",Ap);printf("\nGain at Stop Band Frequency\tAs = %0.3f",As);

printf("\n\nRequired Results of CHEBYSHEV LPF");printf("\nFrequency ratio\t\t\tW21\t=%0.3f",W21);

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 38

Page 39: Dsplab Manuals

printf("\nOrder of the Filter\t\tN\t=%d",N);printf("\nAnalog cutoff frequency\t Wc\t=%0.3f rad/sec.",Wc);

a=sqrt(1/(Ap*Ap)-1);Y=sqrt((1/(a*a))+1)+(1/a);YN=(pow(Y,1/N)-pow(Y,-1/N));c0=YN;printf("\nYN=%f",YN);

if(N%2==0){

printf("\nOrder of the CHEBYSHEV LPF is Even");printf("\nTransfer function of CHEBYSHEV Filter is");printf("\nHa(s)=PI(Bk*Wc*Wc/(s*s+bk*Wc*s+ck*Wc*Wc))");printf("\nWhere bk=2*YN*sin((2k-1)pi/2N), k=1,2,...N/2\n");printf("\nWhere ck=YN*YN+Cos2((2k-1)pi/2N), k=1,2,...N/2\n");printf("\nWhere c0=YN\n");printf("\nWhere YN=\n");for(k=1;k<=N/2;k++){

c[k]=YN*YN+pow((cos((2*k-1)*pi/(2*N))),2);b[k]=2*YN*sin((2*k-1)*pi/(2*N));

}for(k=1;k<=N/2;k++){

printf("\nb%d=%f",k,b[k]);printf("\nc%d=%f",k,c[k]);

}}if(N%2==1){

printf("\nOrder of the CHEBYSHEV LPF is Odd");printf("\nTransfer function of CHEBYSHEV LPF Filter is");printf("\nHa(s)=[Wc/(s+Wc)]

PI[Wc*Wc/(s*s+bk*Wc*s+Wc*Wc)]");printf("\nWhere bk=2*sin((2k-1)pi/2N), k=1,2,...(N-1)/2\n");

for(k=1;k<=(N-1)/2;k++)b[k]=2*sin((2*k-1)*pi/(2*N));for(k=1;k<=(N-1)/2;k++)printf("\nb%d=%f",k,b[k]);

}}

6. EXPECTED RESULTS:Example :

LetPass band frequency (P) = 0.6 rad/secStop band frequency (S) = 0.9 rad/sec

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 39

Page 40: Dsplab Manuals

Gain at Pass band frequency (AP) = 0.8Gain at Stop band frequency (AS) = 0.2, then

IIT Frequency ratio = 1.5

Order of the filter (N) = 3

Analog filter cutoff frequency (C) = 0.6rad/sec

BLT Frequency ratio = 1.562

Order of the filter (N) = 3

Analog filter cutoff frequency (C) = 0.619 rad/sec

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

1. AIM:

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 40

DESIGN OF FIR LPF USING WINDOWSEXPT. NO : 8

DATE :

Page 41: Dsplab Manuals

Write a program in C and MATLAB to design FIR Low pass filter for a given cutoff frequency and number of samples. Verify the same on TMS320C6711 DSP kit, MATLAB.

2. TOOLS REQUIRED : TMS 320C 6711 Kit,Full version CCS s/w,DSK 6711 s/w, MATLAB s/w.

3. THEORY:The filters designed by using finite number of samples of impulse response are called IIR filters. Low pass filter allows only low frequency signals and attenuate all other high frequency signals. Magnitude response of FIR low pass filter as shown

Hd(e j)

1 Ideal

Practical

- -C 0 C

For a distortion less filter, we have to choose constant magnitude and linear phase over required range.

Hd(e j ) = e -j ; -C C.

= 0 ; - -C & C

Where = (N – 1)/2 and N is Number of samples of desired filterIn general, desired filter impulse response contains infinite number of samples. From infinite number we have to choose finite number of samples by using windowing techniques. Different windowing techniques are

Rectangular Window: w(n) = 1; 0 n N – 1.

Hanning Window:

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 41

Page 42: Dsplab Manuals

w(n) = ; 0 n N – 1.

Hamming Window:

w(n) = ; 0 n N – 1.

Blackman Window: It is defined as

w(n) = ; 0 n N – 1.

Triangular Window: It is defined as

w(n) = ; 0 n N – 1.

Characteristics of FIR Filters: Only N samples of impulse response are considered. The impulse response can be directly converted to digital filter transfer

function. The digital filter can be directly designed to achieve the desired

specifications. These are linear phase filters.

4. DESIGN PROCEDURE:Following steps were required to design FIR LPF

1. Take the specifications of desired Low Pass FilterN = Number of samples of desired Low pass filterC = cutoff frequency of desired Low pass filter

2. Choose frequency response of the desired Low pass filter

Hd(e j ) = e -j ; -C C.

= 0 ; - -C & C

3. By using inverse Fourier Transform, obtain the desired filter impulse response hd(n) from desired frequency response Hd()

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 42

Page 43: Dsplab Manuals

4. Convert infinite number of samples of hd(n) into finite number of samples by using window w(n)

h(n) = hd(n) . w(n)

5. Determine the digital filter transfer function H(z) by using z transform

6. Finally realize the linear phase digital low pass filter

5. C PROGRAM:#include<stdio.h>#include<math.h>#define pi 3.14int N,a,n,i;float Wc,hd[20],W[20],h[20];void main(){

printf("DESIGN OF LPF USING WINDOW TECHNIQUES\n");printf("\nEnter Required number of Samples(ODD) of LPF:");scanf("%d",&N);printf("\nEnter the cutoff frequency in rad/sec:");

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 43

Page 44: Dsplab Manuals

scanf("%f",&Wc);

a=(N-1)/2;for(n=0;n<N;n++){

if(n==a)hd[n]=Wc/pi;

elsehd[n]=sin(Wc*(n-a))/(pi*(n-a));

}

printf("\nSelect the WINDOWING Technique");printf("1. Rectangular Window\n");printf("2. Hanning Window\n");printf("3. Hamming Window\n");printf("4. Blackman Window\n");printf("5. Triangular Window\n");

printf("\nEnter 1 or 2 or 3 or 4 or 5: ");scanf("%d",&i);

switch(i){case 1 :

printf("\nYou are selected Rectangular Window");for(n=0;n<N;n++)W[n]=1;

break;

case 2 :printf("\nYou are selected Hanning Window");for(n=0;n<N;n++)W[n]=0.5-0.5*cos((2*n*pi)/(N-1));

break;

case 3 :printf("\nYou are selected Hamming Window");for(n=0;n<N;n++)W[n]=0.54-0.46*cos((2*n*pi)/(N-1));

break;

case 4 :printf("\nYou are selected Blackman Window");for(n=0;n<N;n++)W[n]=0.42-0.5*cos((2*n*pi)/(N-1))+0.08*cos((4*n*pi)/(N-1));

break;

case 5 :printf("\nYou are selected Triangular Window");

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 44

Page 45: Dsplab Manuals

for(n=0;n<N;n++)W[n]=1.0-(2.0*abs(n-(N-1)/2.0)/(N-1));

break;

default:printf("Sorry, Your selection is wrong");

}

for(n=0;n<N;n++)h[n]=hd[n]*W[n];printf("\nNumber of samples of LPF :N = %d",N);printf("\nCutoff frequency of LPF :Wc = %0.2f rad/sec",Wc);printf("\nConstant :a = %d",a);

printf("\nImpulse Response of Desired Filter\n");for(n=0;n<N;n++)printf("\nhd[%d] = %0.4f",n,hd[n]);printf("\nSamples of Window\n");for(n=0;n<N;n++)printf("\nW[%d] = %0.4f",n,W[n]);printf("\nImpulse Response of FIR Digital LPF\n");for(n=0;n<N;n++)printf("\nh[%d] = %0.4f",n,h[n]);

printf("\nH(z)=%0.3f",h[0]);for(n=1;n<N;n++)printf("+%0.3fzpow-%d",h[n],n);

}

6. EXPECTED RESULTS:Example :

Let Number of samples of LPF (N) = 5Cutoff frequency (wc)= 2 rad/sec, then

Digital FIR low pass filter transfer function for various windows

(a) Rectangular WindowH(z) = - 0.1205 + 0.2896 z –1 + 0.6369 z –2 + 0.2896 z –3 – 0.1205 z –4

(b) Hanning WindowH(z) = 0.1447 z –1 + 0.6369 z –2 + 0.1447 z –3

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 45

Page 46: Dsplab Manuals

(c) Hamming WindowH(z) = - 0.0096 + 0.1563 z –1 + 0.6369 z –2 + 0.1563 z –3 – 0.0096 z –4

(d) Blackmann WindowH(z) = 0.0983 z –1 + 0.6369 z –2 + 0.983 z –3

(e) Triangular WindowH(z) = 0.1448 z –1 + 0.6369 z –2 + 0.1448 z –3

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

9. VIVA -VOCE QUESTIONS:

What are advantages of IIR Filter over FIR Filter Explain GIBBS Phenomenon What is the need of Window technique Which are raised cosine windows How to design FIR Filters What are characteristics of LPF

1. AIM:Write a program in C and MATLAB to design FIR High pass filter for a given cutoff frequency and number of samples. Verify the same on TMS320C6711 DSP kit, MATLAB.

2. TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,2.2 Full version CCS s/w,

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 46

DESIGN OF FIR HPF USING WINDOWSEXPT. NO : 9

DATE :

Page 47: Dsplab Manuals

2.3 DSK 6711 s/w, 2.4 MATLAB s/w.

3. THEORY:The filters designed by using finite number of samples of impulse response are called IIR filters. High pass filter allows only high frequency signals and attenuate all other low frequency signals. Magnitude response of FIR high pass filter as shown

Hd(e j)

1 Ideal

Practical

- -C 0 C

For a distortion less filter, we have to choose constant magnitude and linear phase over required range.

Hd(e j ) = e -j ; - -C & C .

= 0 ; -C C

Where = (N – 1)/2 and N is Number of samples of desired filterIn general, desired filter impulse response contains infinite number of samples. From infinite number we have to choose finite number of samples by using windowing techniques. Different windowing techniques are

Rectangular Window: w(n) = 1; 0 n N – 1.

Hanning Window:

w(n) = ; 0 n N – 1.

Hamming Window:

w(n) = ; 0 n N – 1.

Blackman Window: It is defined as

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 47

Page 48: Dsplab Manuals

w(n) = ; 0 n N – 1.

Triangular Window: It is defined as

w(n) = ; 0 n N – 1.

Characteristics of FIR Filters: Only N samples of impulse response are considered. The impulse response can be directly converted to digital filter transfer

function. The digital filter can be directly designed to achieve the desired

specifications. These are linear phase filters.

4. DESIGN PROCEDURE:Following steps were required to design FIR HPF

1. Take the specifications of desired High Pass FilterN = Number of samples of desired High pass filterC = cutoff frequency of desired High pass filter

2. Choose frequency response of the desired High pass filter

Hd(e j ) = e -j ; - -C & C .

= 0 ; -C C

3. By using inverse Fourier Transform, obtain the desired filter impulse response hd(n) from desired frequency response Hd()

4. Convert infinite number of samples of hd(n) into finite number of samples by using window w(n)

h(n) = hd(n) . w(n)

5. Determine the digital filter transfer function H(z) by using z transform

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 48

Page 49: Dsplab Manuals

6. Finally realize the linear phase digital low pass filter

5. C PROGRAM:#include<stdio.h>#include<math.h>#define pi 3.14int N,a,n,i;float Wc,hd[20],W[20],h[20];void main(){

printf("DESIGN OF HPF USING WINDOW TECHNIQUES\n");printf("\nEnter Required number of Samples(ODD) of HPF:");scanf("%d",&N);printf("\nEnter the cutoff frequency in rad/sec:");scanf("%f",&Wc);

a=(N-1)/2;for(n=0;n<N;n++){if(n==a)

hd[n]=1-Wc/pi;

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 49

Page 50: Dsplab Manuals

elsehd[n]=(sin(pi*(n-a))-sin(Wc*(n-a)))/(pi*(n-a));

}

printf("\nSelect the WINDOWING Technique");printf("1. Rectangular Window\n");printf("2. Hanning Window\n");printf("3. Hamming Window\n");printf("4. Blackman Window\n");printf("5. Triangular Window\n");

printf("\nEnter 1 or 2 or 3 or 4 or 5: ");scanf("%d",&i);

switch(i){

case 1 :printf("\nYou are selected Rectangular Window");for(n=0;n<N;n++)W[n]=1;

break;

case 2 :printf("\nYou are selected Hanning Window");for(n=0;n<N;n++)W[n]=0.5-0.5*cos((2*n*pi)/(N-1));

break;

case 3 :printf("\nYou are selected Hamming Window");for(n=0;n<N;n++)W[n]=0.54-0.46*cos((2*n*pi)/(N-1));

break;

case 4 :printf("\nYou are selected Blackman Window");for(n=0;n<N;n++)W[n]=0.42-0.5*cos((2*n*pi)/(N-1))+0.08*cos((4*n*pi)/(N-1));

break;

case 5 :printf("\nYou are selected Triangular Window");for(n=0;n<N;n++)W[n]=1.0-(2.0*abs(n-(N-1)/2.0)/(N-1));

break;

default:printf("Sorry, Your selection is wrong");

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 50

Page 51: Dsplab Manuals

}

for(n=0;n<N;n++)h[n]=hd[n]*W[n];printf("\nNumber of samples of HPF :N = %d",N);printf("\nCutoff frequency of HPF :Wc = %0.2f rad/sec",Wc);printf("\nConstant :a = %d",a);

printf("\nImpulse Response of Desired Filter\n");for(n=0;n<N;n++)printf("\nhd[%d] = %0.4f",n,hd[n]);printf("\nSamples of Window\n");for(n=0;n<N;n++)printf("\nW[%d] = %0.4f",n,W[n]);printf("\nImpulse Response of FIR HPF\n");for(n=0;n<N;n++)printf("\nh[%d] = %0.4f",n,h[n]);

printf("\nH(z)=%0.3f",h[0]);for(n=1;n<N;n++)printf("+%0.3fzpow-%d",h[n],n);

}

6. EXPECTED RESULTS:Example :

Let Number of samples of LPF (N) = 5Cutoff frequency (wc)= 2 rad/sec, then

Digital FIR high pass filter transfer function for various windows

(a) Rectangular WindowH(z) = 0.12 - 0.2891 z –1 + 0.3631 z –2 - 0.2891 z –3 + 0.12 z –4

(b) Hanning WindowH(z) = -0.1444 z –1 + 0.3631 z –2 - 0.1444 z –3

(c) Hamming WindowH(z) = 0.0096 - 0.1560 z –1 + 0.3631 z –2 - 0.1560 z –3 +0.0096 z –4

(d) Blackmann WindowH(z) = -0.0982 z –1 + 0.3631 z –2 - 0.982 z –3

(e) Triangular Window

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 51

Page 52: Dsplab Manuals

H(z) = -0.1445 z –1 + 0.3631 z –2 - 0.1445 z –3

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

9. VIVA -VOCE QUESTIONS:

What are advantages of IIR Filter over FIR Filter Explain GIBBS Phenomenon What is the need of Window technique Which are raised cosine windows How to design FIR Filters What are characteristics of HPF

1. AIM :

Write a program in C and MATLAB to compute power spectral density of given

sequence x(n). Verify the same on TMS320C6711 DSP kit.

2. COMPONENTS & TOOLS REQUIRED : 2.1 TMS 320C 6711 Kit,

2.2 Full version CCS s/w,

2.3 DSK 6711 s/w,

2.4 MATLAB s/w.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 52

POWER SPECTRAL DENSITYEXPT. NO : 10

DATE :

Page 53: Dsplab Manuals

3. THEORY:Spectrum is a Latin word for image. Auto correlation function(ACF) is a

measure of similarity between a signal and time delayed version of the same signal.

Cross correlation function(CCF) is a measure of similarity between a signal and time

delayed version of the different signal. Frequency domain representation of a ACF of

non-periodic signal is known as Energy Spectral Density(ESD). Frequency domain

representation of a ACF of periodic signal is known as Power Spectral Density(PSD).

For a non-periodic signals ESD & ACF forms Fourier transformable pairs. For a

periodic signals PSD & ACF forms Fourier transformable pairs.

4. COMPUTATIONAL ALGORITHM:

1. Compute ACF of a given sequence x(n)2. Compute PSD through ACF.

5. PROGRAM:#include<stdio.h>#include<math.h>#define pi 3.14int x[20],ACF[20],N,n,m,w;float PSD[200];void main(){

printf("Enter the length of discrete sequence x(n)\t:N=");scanf("%d",&N);

printf("Enter %d samples for discrete sequence x(n):\n",N);for(n=0;n<N;n++)scanf("%d",&x[n]);

for(n=0;n<N;n++){ACF[n]=0;for(m=0;m<N;m++)

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 53

Page 54: Dsplab Manuals

ACF[n]=ACF[n]+x[m]*x[m-n];}

for(w=0;w<N;w++){PSD[w]=0;for(n=1;n<N;n++)PSD[w]=PSD[w]+2.0*ACF[n]*cos(w*n);PSD[w]=ACF[0]+PSD[w];}

printf("Given discrete sequence \nx(n)=");for(n=0;n<N;n++)printf("\t%d",x[n]);

printf("\nACF of given discrete sequence x(n) is \nACF[n]=");for(n=-(N-1);n<N;n++)printf("\t%d",ACF[abs(n)]);printf(", where -%d<=n<=%d",(N-1),(N-1));

printf("\nPSD of Given discrete sequence x(n)\n PSD(w)=");for(w=-(N-1);w<N;w++)printf("\t%0.2f",PSD[abs(w)]);printf(", where -%d<=w<=%d",(N-1),(N-1));

}

6. EXPECTED RESULTS:Example :

Let

Discrete sequence x(n) = [1, 2, 3, 4], then

ACF of x(n) ACF(n) = [4, 11, 20, 30, 20, 11, 4], and

PSD of x(n) PSD(w) = [4.24, 6.66, 34.54, 100, 34.54, 6.66, 4.24], and

7. CONCLUSION:Program is executed successfully and results are obtained as per the expected values.

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 54

Page 55: Dsplab Manuals

8. PRECAUTIONS: Don’t open any other folders or files. Don’t delete any file or folder without informing the system administrator or lab

in-charge. Shutdown the system before leaving the lab.

9. VIVA -VOCE QUESTIONS:

Define spectrum

How to compute magnitude and phase spectrum

Compare ESD & PSD

In what way ESD and ACF are related

In what way PSD and ACF are related

What are properties of ACF

Compare convolution and correlation

Lakireddy Balireddy College of Engineering, Mylavaram – 521 230. Page No. 55