You are on page 1of 51

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)
.



m
m) x(m)h(n 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)
(n).
3
h (n)
2
h (n)
1
h h(n)
VITAM College of Engineering, VSP. Page No. 1
LINEAR CONVOLUTION
EXPT. NO : 1
DATE :
h(n)
h
1
(n) h
1
(n) h
1
(n)
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


1 N
0 m
m) x(m)h(n y(n)
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. Thats 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.
VITAM College of Engineering, VSP. Page No. 2
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]);
}
VITAM College of Engineering, VSP. Page No. 3
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)');
pause
n=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)');
pause
n=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');
pause
n=0:1:N-1;
subplot(2,2,3);
stem(n,y);
title('Response of discrete LTI system');
xlabel('discrete Time n');
ylabel('Amplitude');
VITAM College of Engineering, VSP. Page No. 4
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:
8. VIVA -VOCE QUESTIONS:
What is convolution
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
Which window is preferable to write MATLAB program
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
VITAM College of Engineering, VSP. Page No. 5
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)
.



m
m) x(m)h(n 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)
VITAM College of Engineering, VSP. Page No. 6
CIRCULAR CONVOLUTION
EXPT. NO : 2
DATE :
h(n)
h
1
(n) h
1
(n) h
1
(n)
(n).
3
h (n)
2
h (n)
1
h h(n)
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


1 N
0 m
m) x(m)h(n y(n)
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. Thats 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


1 N
0 m
m) x(m)h(n y(n)
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).
VITAM College of Engineering, VSP. Page No. 7
Finally compute the sum over the range 0 to N1+N2 2.
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]);
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]);
}
VITAM College of Engineering, VSP. Page No. 8
5.2 MATLAB PROGRAM:
x=input('Enter the input sequence x(n)=');
h=input('Enter the impulse response sequence h(n)=');
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)');
pause
subplot(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)');
pause
n=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');
pause
n=0:1:L-1;
subplot(2,2,3);
stem(n,y);
title('Response of discrete LTI System');
xlabel('Discrete Time');
VITAM College of Engineering, VSP. Page No. 9
ylabel('Amplitude');
6. EXPECTED RESULTS:
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:
8. 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.
In MATLAB without using conv command, how to compute the convolution
In MATLAB how to pad the given sequence, to obtain the required length
What is the use of clf command in MATLAB.
What is the use of pause command in MATLAB.
Explain the command subplot(a,b,c)
VITAM College of Engineering, VSP. Page No. 10
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).

1 N
0 n
W
nk
N
x(n) 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).

1 N
0 k
W
nk -
N
X(k)
1
x(n)
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:
VITAM College of Engineering, VSP. Page No. 11
DISCRETE FOURIER TRANSFORM
EXPT. NO : 3
DATE :
#include<stdio.h>
#include<math.h>
#define Pi 3.142857
int 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);
VITAM College of Engineering, VSP. Page No. 12
X=fft(x);
MSX=abs(X);
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');
pause
n=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"');
pause
k=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"');
pause
k=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 :
VITAM College of Engineering, VSP. Page No. 13
Let
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:
7. 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.
How to compute DFT in C .
What is the command used to compute DFT in MATLAB.
Which command is used to compute Magnitude Spectrum in MATLAB.
Which command is used to compute Phase Spectrum in MATLAB
VITAM College of Engineering, VSP. Page No. 14
SUM of SINUSOIDAL SIGNAL GENERATION
EXPT. NO : 4
1. AIM
Write a program in C and MATLAB to generate two sinusoidal signals and its sum.
2. TOOLS REQUIRED :
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
1
ContinuousTimeSignal x(t)
ContinuousTime(t)
A
m
p
l
i
t
u
d
e
VITAM College of Engineering, VSP. Page No. 15
DATE :
Discrete time signals are those for which the signal amplitude is discretely varies with
respect to discrete variation in time.
Example :
0 10 20 30 40 50 60 70 80 90 100
-1
-0.5
0
0.5
1
DiscreteTimeSignal x(n)
DiscreteTime(n)
A
m
p
l
i
t
u
d
e
4. PROCEDURE:
Choose the length (L) of required sine wave.
Select number of cycles (N1) of first sine wave x1(t)
x1(t) = Sin(2 n N1/L)
Select number of cycles (N2) of second sine wave x2(t)
x1(t) = Sin(2 n 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
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++)
VITAM College of Engineering, VSP. Page No. 16
{
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:');
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');
VITAM College of Engineering, VSP. Page No. 17
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(2 tN1/L), and
Second Sinusoidal Signal x2(t) = Sin(2 tN2/L),then
Sum of x1(t) and x2(t) is x(t) = x1(t) + x2(t);
VITAM College of Engineering, VSP. Page No. 18
0 10 20 30 40 50 60 70 80 90 100
-1
0
1
First Signal
DiscreteTime
A
m
p
l
i
t
u
d
e
0 10 20 30 40 50 60 70 80 90 100
-1
0
1
SecondSignal
DiscreteTime
A
m
p
l
i
t
u
d
e
0 10 20 30 40 50 60 70 80 90 100
-2
0
2
SUM=x1+x2Signal
DiscreteTime
A
m
p
l
i
t
u
d
e
7. CONCLUSION:
VITAM College of Engineering, VSP. Page No. 19
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)
Where
x(t) : Input Signal
y(t) : Output signal
X(s) : Input in s-domain
Y(s) : Output in s-domain
I(s) : current through the circuit
1/sC : Capacitive reactance
Loop equation
sC
1
R
X(s)
I(s)
+

VITAM College of Engineering, VSP. Page No. 20


CHARACTERISTICS OF ANALOG LPF/HPF
EXPT. NO : 5
DATE :
(RC Tan ) H(j
and
) RC ( 1
1
) H(j
C R j 1
1
) H(j
.
sRC 1
1
H(s)
.
1 RCs
1
X(s)
Y(s)
.
1 RCs
X(s)
Y(s)
sC
1
.
sC
1
R
X(s)
Y(s)
sC
1
. I(s) Y(s)
1
2


+

+

+

+

+

,
_

+


Characteristics of LPF:
H(j )1
Ideal characteristics
1
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
VITAM College of Engineering, VSP. Page No. 21
x(t) or X(s) I(s) R y(t) or Y(s)
Where
x(t) : Input Signal
y(t) : Output signal
X(s) : Input in s-domain
Y(s) : Output in s-domain
I(s) : current through the circuit
1/sC : Capacitive reactance
Loop equation
sC
1
R
X(s)
I(s)
+

RC) ( Tan ) H(j


and
) RC ( 1
RC
) H(j
C R j 1
RC j
) H(j
.
sRC 1
sRC
H(s)
.
1 RCs
sRC
X(s)
Y(s)
.
1 RCs
sRCX(s)
Y(s)
R .
sC
1
R
X(s)
Y(s)
R . I(s) Y(s)
1
2


+

+

+

+

+

+

Characteristics of HPF:
H(j )1
Ideal characteristics
1
Practical characteristics
VITAM College of Engineering, VSP. Page No. 22
0 c
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 )1
Ideal characteristics
1
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 )1
Ideal characteristics
1
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];
VITAM College of Engineering, VSP. Page No. 23
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);
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:');
VITAM College of Engineering, VSP. Page No. 24
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);
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 :
VITAM College of Engineering, VSP. Page No. 25
Let
Resistor value R = 10K,
Capacitor value C = 10 F
Frequency range L = 100 rad/sec.
0 10 20 30 40 50 60 70 80 90 100
0
0.5
1
Responseof LPF
Frequency
A
m
p
l
i
t
u
d
e
0 10 20 30 40 50 60 70 80 90 100
0
0.5
1
Responseof HPF
Frequency
A
m
p
l
i
t
u
d
e
6. CONCLUSION:
7. VIVA -VOCE QUESTIONS:
VITAM College of Engineering, VSP. Page No. 26
Define filter
Explain different types of filters
Compare analog / digital filters
Explain the operation of RC low pass filter.
Explain the operation of RC high pass filter.
1. AIM
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 approximation
2. 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
VITAM College of Engineering, VSP. Page No. 27
DESIGN OF IIR BUTTERWORTH LPF
EXPT. NO : 6
DATE :
4. DESIGN PROCEDURE:
Following steps were required to design a digital CHEBYSHEV LPF
1. Take the specifications of desired Low Pass Filter
P= 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

,
_

,
_

Tan
2

Tan

BLT

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

,
_

,
_

P
S
2
P
2
S

log
1
A
1
1
A
1
log
2
1
N
4. Calculate the analog cutoff frequency ( C)
5. Determine the analog filter Transfer function Ha(s)
VITAM College of Engineering, VSP. Page No. 28
d perio sampling is T Where
1
A
1
2

Tan
T
2
BLT
1
A
1
T

IIT
2N
1
2
P
P
C
2N
1
2
P
P
C

,
_

,
_

,
_

,
_

,
_

+ +

,
_

,
_

+ +

2N
1) (2k
2sin b Where
s b s

Ha(s) Odd is N If
s b s

Ha(s) Even is N If
k
2
1 - N
1 k
2
C C k
2
2
C
C
C
2
N
1 k
2
C C k
2
2
C
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.

,
_

1
1
1 aT
z 1
z 1
T
2
s BLT
z e 1
1
a s
1
IIT

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
VITAM College of Engineering, VSP. Page No. 29
5. PROGRAM:
5.1 C PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.14
int 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");
}
VITAM College of Engineering, VSP. Page No. 30
printf("\nInput Data for the BUTTERWORTH LPF\n");
printf("Pass Band Frequency\t\tWp = %f rad/sec.",Wp);
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]);
}
}
VITAM College of Engineering, VSP. Page No. 31
5.2 MATLAB PROGRAM:
Wp=input('Enter the PASS band frequency of LPF in rad/sec:');
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);
VITAM College of Engineering, VSP. Page No. 32
6. EXPECTED RESULTS:
Example :
Let
Pass band frequency ( P) = 0.6 rad/sec
Stop band frequency ( S) = 0.9 rad/sec
Gain at Pass band frequency (AP) = 0.8
Gain at Stop band frequency (AS) = 0.2, then
IIT Frequency ratio

,
_

P
S

= 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) =
,
_

+ +

,
_

+ +

,
_

+ 404 . 0 03 . 1
404 . 0
404 . 0 393 . 0
404 . 0
636 . 0
636 . 0
2 2
s s s s s
BLT Frequency ratio

,
_

P
S

= 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) =
,
_

+ +

,
_

+ +

,
_

+ 429 . 0 06 . 1
429 . 0
429 . 0 405 . 0
429 . 0
655 . 0
655 . 0
2 2
s s s s s
7. CONCLUSION:
8. VIVA -VOCE QUESTIONS:
Define IIR filter
Explain different types of IIR filters
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 are two techniques used to obtain digital filter transfer function from analog filter
transfer function.
What is frequency warping?
What is the relation between analog and digital frequency of IIT method.
VITAM College of Engineering, VSP. Page No. 33
What is the relation between analog and digital frequency of BLT method.
1. AIM
Write 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 approximation
4. 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 Filter
P= 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

,
_

,
_

Tan
2

Tan

BLT

IIT
P
S
P
S
P
S
P
S
VITAM College of Engineering, VSP. Page No. 34
DESIGN OF IIR CHEBYSHEV LPF
EXPT. NO : 7
DATE :
3. Decide the order (N) of the filter (Choose greatest & nearest integer)

,
_

,
_

P
S 1 -
2
P
2
S 1 -

Cosh
1
A
1
1
A
1
Cosh
N
4. Calculate the analog cutoff frequency ( C)
5. Determine the analog filter Transfer function Ha(s)

,
_


1
1
1
]
1

,
_

+ +

,
_

+ +

,
_

,
_

,
_

+ +

,
_

,
_

+ +

1
A
1

1
1

1
1

1
2
1
Y
Y c
2N
1) (2k
Cos Y c
2N
1) (2k
Sin 2Y b Where
c s b s
B
c s
B
Ha(s) Odd is N If
c s b s
B
Ha(s) Even is N If
2
P
N
1
2
N
1
2
N
N 0
2 2
N k
N k
2
1 - N
1 k
2
C k C k
2
2
C k
C 0
C 0
2
N
1 k
2
C k C k
2
2
C k
VITAM College of Engineering, VSP. Page No. 35
period sampling is T Where
1
A
1
2

Tan
T
2
BLT
1
A
1
T

IIT
2N
1
2
P
P
C
2N
1
2
P
P
C

,
_

,
_

,
_


( )
Odd is N If 1, Ha(0)
Even is N If ,
1
1
Ha(0)
Take .....), B B (B B get To
2
2 1 0 k


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.

,
_

1
1
1 aT
z 1
z 1
T
2
s BLT
z e 1
1
a s
1
IIT

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.14
int n,N,i,k;
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)
VITAM College of Engineering, VSP. Page No. 36
{
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);
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++)
VITAM College of Engineering, VSP. Page No. 37
{
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 :
Let
Pass band frequency ( P) = 0.6 rad/sec
Stop band frequency ( S) = 0.9 rad/sec
Gain at Pass band frequency (AP) = 0.8
Gain at Stop band frequency (AS) = 0.2, then
IIT Frequency ratio

,
_

P
S

= 1.5
Order of the filter (N) = 3
Analog filter cutoff frequency ( C) = 0.6rad/sec
BLT Frequency ratio

,
_

P
S

= 1.562
Order of the filter (N) = 3
Analog filter cutoff frequency ( C) = 0.619 rad/sec
7. CONCLUSION:
VITAM College of Engineering, VSP. Page No. 38
DESIGN OF FIR LPF USING WINDOWS
EXPT. NO : 8
1. AIM:
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 filter
In 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:
VITAM College of Engineering, VSP. Page No. 39
DATE :
w(n) =
,
_

1 N
2n
Cos 0.5 0.5
; 0 n N 1.
Hamming Window:
w(n) =
,
_

1 N
2n
Cos 0.46 0.54
; 0 n N 1.
Blackman Window: It is defined as
w(n) =
,
_

+
,
_

1 N
4n
Cos 0.08
1 N
2n
Cos 0.5 0.42
; 0 n N 1.
Triangular Window: It is defined as
w(n) =
1 - N
2
1 - N
- n 2
- 1
; 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 Filter
N = Number of samples of desired Low pass filter
C= 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( )
n ,

n ,
) - (n
)) - (n
c
Sin(
c

d e
2
1

d ) Hd(
2
1
hd(n)
j -

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)
VITAM College of Engineering, VSP. Page No. 40
5. Determine the digital filter transfer function H(z) by using z transform

1 N
0 n
n
z h(n) H(z)
6. Finally realize the linear phase digital low pass filter
5. C PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.14
int 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:");
scanf("%f",&Wc);
a=(N-1)/2;
for(n=0;n<N;n++)
{
if(n==a)
hd[n]=Wc/pi;
else
hd[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");
VITAM College of Engineering, VSP. Page No. 41
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");
}
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:
VITAM College of Engineering, VSP. Page No. 42
Example :
Let Number of samples of LPF (N) = 5
Cutoff frequency (wc)= 2 rad/sec, then
Digital FIR low pass filter transfer function for various windows
(a) Rectangular Window
H(z) = - 0.1205 + 0.2896 z
1
+ 0.6369 z
2
+ 0.2896 z
3
0.1205 z
4

(b) Hanning Window
H(z) = 0.1447 z
1
+ 0.6369 z
2
+ 0.1447 z
3

(c) Hamming Window
H(z) = - 0.0096 + 0.1563 z
1
+ 0.6369 z
2
+ 0.1563 z
3
0.0096 z
4

(d) Blackmann Window
H(z) = 0.0983 z
1
+ 0.6369 z
2
+ 0.983 z
3

(e) Triangular Window
H(z) = 0.1448 z
1
+ 0.6369 z
2
+ 0.1448 z
3

7. CONCLUSION:
8. VIVA -VOCE QUESTIONS:
Define IIR filter
What are advantages of IIR Filter over FIR Filter
Explain GIBBS Phenomenon
What is the need of Window technique
Which are raised cosine windows
Which one is Barlett window
How to design FIR Filters
What are characteristics of LPF

VITAM College of Engineering, VSP. Page No. 43
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,
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 filter
In 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:
VITAM College of Engineering, VSP. Page No. 44
DESIGN OF FIR HPF USING WINDOWS
EXPT. NO : 9
DATE :
w(n) =
,
_

1 N
2n
Cos 0.5 0.5
; 0 n N 1.
Hamming Window:
w(n) =
,
_

1 N
2n
Cos 0.46 0.54
; 0 n N 1.
Blackman Window: It is defined as
w(n) =
,
_

+
,
_

1 N
4n
Cos 0.08
1 N
2n
Cos 0.5 0.42
; 0 n N 1.
Triangular Window: It is defined as
w(n) =
1 - N
2
1 - N
- n 2
- 1
; 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 Filter
N = Number of samples of desired High pass filter
C= 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( )
n ,

1
n ,
) - (n
)) - (n
c
Sin( - )) - (n Sin(

d e
-

d e
2
1

d ) Hd(
2
1
hd(n)
C
j -
C
j -

,
_

VITAM College of Engineering, VSP. Page No. 45


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

1 N
0 n
n
z h(n) H(z)
6. Finally realize the linear phase digital low pass filter
5. C PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.14
int 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;
else
hd[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 :
VITAM College of Engineering, VSP. Page No. 46
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");
}
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);
}
VITAM College of Engineering, VSP. Page No. 47
6. EXPECTED RESULTS:
Example :
Let Number of samples of LPF (N) = 5
Cutoff frequency (wc)= 2 rad/sec, then
Digital FIR high pass filter transfer function for various windows
(a) Rectangular Window
H(z) = 0.12 - 0.2891 z
1
+ 0.3631 z
2
- 0.2891 z
3
+ 0.12 z
4

(b) Hanning Window
H(z) = -0.1444 z
1
+ 0.3631 z
2
- 0.1444 z
3

(c) Hamming Window
H(z) = 0.0096 - 0.1560 z
1
+ 0.3631 z
2
- 0.1560 z
3
+0.0096 z
4

(d) Blackmann Window
H(z) = -0.0982 z
1
+ 0.3631 z
2
- 0.982 z
3

(e) Triangular Window
H(z) = -0.1445 z
1
+ 0.3631 z
2
- 0.1445 z
3

7. CONCLUSION:
8, VIVA -VOCE QUESTIONS:
Define IIR filter
What are advantages of IIR Filter over FIR Filter
Explain GIBBS Phenomenon
What is the need of Window technique
Which are raised cosine windows
Which one is Barlett window
How to design FIR Filters
What are characteristics of HPF

VITAM College of Engineering, VSP. Page No. 48
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.
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.
VITAM College of Engineering, VSP. Page No. 49
POWER SPECTRAL DENSITY
EXPT. NO : 10
DATE :
5. PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.14
int 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++)
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));
}
VITAM College of Engineering, VSP. Page No. 50
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:
8. 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
VITAM College of Engineering, VSP. Page No. 51

You might also like