You are on page 1of 133

2

LIST OF EXPERIMENTS

S.No EXPERIMENT NAME Pg.No


USING MATLAB
1 Generation of sequences 5
2 Linear and Circular convolution 13
3 Auto Correlation and Cross Correlation 20
4 Frequency Analysis using DFT 22
5 Design of FIR filter using window technique 28
6 Design of IIR filter using Butterworth technique 58
7 Design of IIR filter using Chebyshev-1 technique 70
8 Design of IIR filter using Chebyshev-2 technique 82
9 Decimation and Interpolation 94
DSP PROCESSOR BASED IMPLEMENTATION
10 Study of architecture of Digital Signal Processor 100
11 MAC operation using addressing modes 106
12 Waveform Generation 110
13 Implementation of FIR filter 114
14 Implementation of IIR filter 117
15 Sampling of Input Signals and Display 120

ADDITIONAL EXPERIMENTS
16 Linear Convolution Using TMS320c5515 Processor 123
17 Circular Convolution Using TMS320c5515 Processor 125

18 Decimation And Interpolation 127

19 MAC Operation 132


3
4

Flowchart: IMPULSE FUNCTION

START

GET THE TIME INTERVAL

PLOT THE OUTPUT SEQUENCE, GIVE TITLE,


XLABEL & YLABEL

STOP

Flowchart: STEP FUNCTION

START

GET THE NUMBER OF


SEQUENCES AND TIME INTERVAL

PLOT THE OUTPUT SEQUENCE,


GIVE TITLE, XLABEL & YLABEL

STOP
5

EX.No:1 GENERATION OF SEQUENCES

Aim:
To write a program in MATLAB to generate the following signals
(1) Unit impulse function.
(2) Unit step function.
(3) Unit ramp and exponential function.
(4) Sine and cosine wave function.
(5) Random and correlation sequences.
Software and Hardware Required:
1. Computers installed with MATLAB 7.7(R2008b)
Algorithm: Unit Impulse Function:
(1) Get the time interval.
(2) Give the respective impulse function zeros and ones function.
(3) Subplot and stem the sequence.
(4) Give X-label, Y-label and title.
(5) Stop the program and execute it.
Unit Step Function:
(1) Get the length of the of sequence.
(2) Get the time interval.
(3) Give the matrix using one’s function.
(4) Subplot and stem the sequence.
(5) Give the X- label, Y-label and title.
(6) Stop the program.
6

Flowchart: RAMP FUNCTION


START

GET THE LENGTH OF SEQUENCE


AND TIME INTERVAL

PLOT THE OUTPUT SEQUENCE,


GIVE TITLE, XLABEL & YLABEL

STOP

Flowchart: SINE FUNCTION

START

ENTER THE LENGTH OF SINUSOIDAL


SEQUENCE &NUMBER OF CYCLES

GET THE INTERVAL & OBTAIN SINE WAVEFORMS

PLOT THE OUTPUT SEQUENCE,


GIVE TITLE, XLABEL & YLABEL

STOP
7

Unit Ramp Function:


(1) Get the length of sequence.
(2) Give the time interval.
(3) Subplot and stem the sequence.
(4) Give the xlabel, ylabel and title.
(5) Stop the program.
Sine Function:
(1) Enter the length of sinusoidal sequence.
(2) Enter the number of cycles.
(3) Get the interval and obtain sinusoidal waveform using sine function.
(4) Subplot and plot the sequence.
(5) Give X-label, Y-label and title.
(6) Stop the program.
Random Sequence Function:
(1) Enter the sample length for the random signal.
(2) Use random function and calculate the value of X.
(3) Using stem function plot X
(4) Give X-label, Y-label and title.
(5) Stop the program.
8

Flowchart: COSINE FUNCTION


START

ENTER THE LENGTH OF SINUSOIDAL


SEQUENCE &NUMBER OF CYCLES

GET THE INTERVAL & OBTAIN COSINE


WAVEFORMS

PLOT THE OUTPUT SEQUENCE, GIVE


TITLE, X-LABEL & Y-LABEL

STOP

Flowchart: EXPONENTIAL FUNCTION

START

SET THE EXPONENTIAL FUNCTION

PLOT THE OUTPUT SEQUENCE, GIVE


TITLE, XLABEL & YLABEL

STOP
9

Cosine Function:
(1) Enter the length of sinusoidal sequence.
(2) Enter the number of cycles.
(3) Get the interval and obtain sinusoidal waveform using cosine function.
(4) Subplot and plot the sequence.
(5) Give X-label, Y-label and title.
(6) Stop the program.
Exponential Function:
(1) Set the exponential function.
(2) Plot the exponential sequence in discrete domain.
(3) Give the xlabel, ylabel and title.
(4) Stop the program.

Output:
Enter the n value 4
Enter the length of ramp sequence 4
Enter the length of exponential sequence 4
Enter the ‘a’ value 1
10

OUTPUT WAVEFORMS

a) Unit impulse sequence b) Unit step sequence c) Ramp sequence


d) Exponential sequence e) Sine sequence f) cosine sequence
11

White noise : x=0


1

0.9

0.8

0.7

0.6

0.5

SampleValues
0.4

0.3

0.2

0.1

0
0 10 20 30 40 50 60 70 80 90 100
Samples

OUTPUT WAVEFORM: Random sequence

Program: Generation of Sequences

%Program for the generation of unit impulse sequence


clc;
clear all;
close all;
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
figure();stem(t,y);
ylabel('Amplitude');
xlabel('(a) n');
%Program for the generation of unit step sequence.
n=input('Enter the n value');
t=0:1:n-1;y1=ones(1,n); figure();stem(t,y1);
ylabel('Amplitude');
xlabel('(b) n');
%Program for the generation of ramp sequence
n1=input('Enter the length of ramp sequence');
t=0:n1;
12

figure(); stem(t,t);
ylabel('Amplitude');
xlabel('(c) n');
%Program for the generation of exponential sequence
n2=input('Enter the length of exponential sequence');
t=0:n2;
a=input('Enter the a value');
y2=exp(a*t);
figure();stem(t,y2);
ylabel('Amplitude');
xlabel('(d) n');
%Program for the generation of sine sequence
t=0:.01:pi;
y=sin(2*pi*t);figure(2);
figure();plot(t,y);
ylabel('Amplitude'); xlabel('(e) n');
%Program for the generation of cosine sequence
t=0:.01:pi;
y=cos(2*pi*t);
figure();plot(t,y);
ylabel('Amplitude'); xlabel('(f) n');
%Program for the generation of random sequence
L=100; %Sample length for the random signal
mu=0;
X=rand(L,1)+mu;
figure(); stem(X);
title(['White noise : \mu_x=',num2str(mu)]);
figure(); plot(X); title(['White noise : \mu_x=',num2str(mu),' \sigma^2=',num2str(sigma^2)]);
xlabel('Samples'); ylabel('Sample Values');

Result:
The program for various signals is executed and output is verified using MATLAB.
13

EX.NO:2 LINEAR AND CIRCULAR CONVOLUTION

Aim:
To write a MATLAB program to perform linear and circular convolution.
Software and Hardware Required:
1. Computers installed with MATLAB 7.7(R2008b)
Algorithm: Linear Convolution
(1) Get the first input sequence and its range.
(2) Get the second input sequence and its range.
(3) Convolve the two sequences and assign in ‘Y’
(4) Display the discrete form of ‘Y’.
(5) Give the X-label, Y-label.
(6) Display the result.
Algorithm: Circular Convolution
(1) Start the program.
(2) Get the two input sequence.
(3) Calculate n1=max (n1, n2) where n1 is length of first sequence and n2 is length of
second sequence.
(4) Check if n3 is greater than zero. Calculate ‘h’ or compute ’g’.
(5) Find circular Convolution and display the output.
(6) Stop the program.
14

Flowchart: LINEAR CONVOLUTION

START

GET THE FIRST INPUT


SEQUENCE

GET THE SECOND INPUT


SEQUENCE

CONVOLVE THE TWO SEQUENCES AND STORE THE RESULT

DISPLAY THE DISCRETE FORM


OF ‘Y’

GIVE THE XLABEL, YLABEL,


TITLE

STOP
15

Output: Linear Convolution


Enter the input sequence x(n) [2 4 6 8]
Enter the range of x(n) -2:1
Enter the impulse response h(n) [1 3 5]
Enter the range of h(n) 0:2
Convoluted sequence 2 10 28 46 54 40

Convoluted sequence y(n)


60

50

40
Amplitude

30

20

10

0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3
time axis
16

Program: Linear Convolution

%Program to find the convolution between two sequences


%Here x(n) is taken as[2:5] with range 0:3
%h(n) is taken as[1:3] with range 0:2
clc;
clear all;
close all;
seq1=input('Enter the input sequence x(n)');
n1=input('Enter the range of x(n)');
figure();stem(n1,seq1);
title('input sequence x(n)');
xlabel('time axis');
ylabel('Amplitude');
seq2=input('Enter the impulse response h(n)');
n2=input('Enter the range of h(n)');
figure();stem(n2,seq2);
title('Impulse response h(n)');
xlabel('time axis');
ylabel('Amplitude');
figure();seq=conv(seq1,seq2);
n=(min(n1)+min(n2)):1:(max(n1)+max(n2));
disp('Convoluted sequence=');
disp(seq);
stem(n,seq);
title('Convoluted sequence y(n)');
xlabel('time axis');
ylabel('Amplitude');
17

Flowchart: CIRCULAR CONVOLUTION

START

GET TWO
SEQUENCES
’g’ & ‘h’

N1=LENGTH (g), n2=LENGTH (h)

n=max (n1, n2), n3=n1-n2

IF h= (h, ZEROS (1, n3)


n3>0

g= (g, ZEROS (1,-n3))

y=CCONV (g, h, n)

DISPLAY CONVOLUTED
SEQUENCE

STOP
18

Output: Circular Convolution

Enter the first sequence[ 1 2 3 4 5 6]

Enter the second sequence[ 1 2 3 4 5 6]

The circular convoluted sequence is given by

71 80 83 80 71 56
19

Program: Circular Convolution

clc;
close all;
clear all;
g=input('Enter the first sequence');
subplot(2,2,1);stem(g);
ylabel('Amplitude');xlabel('g(n)');
h=input('Enter the second sequence');
subplot(2,2,2);stem(h);
ylabel('Amplitude');xlabel('h(n)');
n1=length(g);
n2=length(h);
n=max(n1,n2);
n3=n1-n2;
if(n3>0)
h=[h,zeros(1,n3)];
end
if(n3<0)
g=[g,zeros(1,-n3)];
end
y=cconv(g,h,n);
disp('The circular convoluted sequence is given by');
disp(y);
subplot(2,2,3);stem(y);
ylabel('Amplitude');xlabel('output sequence');

Result:

The MATLAB program for Linear and Circular convolution is executed and their waveforms
are plotted.
20

EX.NO:3 AUTO CORRELATION AND CROSS CORRELATION


Aim:
To write the MATLAB program for the given sequence to compute auto correlation and
cross correlation.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm:
Correlation function:
(1) Get two sequences x and y.

(2) Compute auto correlation and cross correlation using xcorr(x), xcorr(x,y)

(3) Display the output using stem command.

(4) Give X-label, Y-label and title.


(5) Stop the program.
%Program for correlation function
x= input(‘enter the first sequence’); y=input(‘enter the second sequence’);
r=xcorr(x); r1=xcorr(x,y);
stem(r); title(‘auto correlation’);
stem(r1); title(‘cross correlation’);

enter the first sequence[1 2 3 4 5]

enter the second sequence [ 1 1 1 1]


cross correlation
14

12

10

-2
1 2 3 4 5 6 7 8 9

Output put wave form: Auto correlation


21

Flowchart: Coerrelation

START

GET THE FIRST INPUT


SEQUENCE

GET THE SECOND INPUT


SEQUENCE

CORRELATE THE TWO SEQUENCES AND STORE THE RESULT

DISPLAY THE DISCRETE FORM


OF ‘Y’

GIVE THE XLABEL, YLABEL,


TITLE

STOP

Result:

The MATLAB program for auto correlation and cross-correlation is executed and their
waveforms are plotted.
22

EX.NO:4 FREQUENCY ANALYSIS USING DFT

Aim:
To write the MATLAB program for the given sequence to compute and plot DFT of
sequence using FFT and IDFT using IFFT.

Software and Hardware Required:


2. Computer installed with MATLAB 7.7(R2008b)

Algorithm: FFT
(1) Start the program
(2) Generate a signal with different frequencies
(3) Plot the input sequence x(n).
(4) Compute DFT of sequence using FFT algorithm.
(5) Display DFT sequence.
(6) Plot the real and imaginary parts.
(7) Use abs command to obtain magnitude plot.
(8) Use angle command to obtain phase plot and plot it.
(9) Stop the program.
Algorithm: IFFT
(1) Start the program
(2) Enter the sequence X(k).
(3) Plot the input sequence X(k).
(4) Compute IDFT of sequence using FFT algorithm.
(5) Display IDFT sequence.
(6) Plot the real and imaginary parts.
(7) Use abs command to obtain magnitude plot.
(8) Use angle command to obtain phase plot and plot it.
(9) Stop the program.
23

Flowchart: COMPUTATION OF FFT


START

ENTER THE SEQUENCE


x (n)

PLOT THE SEQUENCE x


(n)

COMPUTE DFT USING FFT ALGORITHM

DISPLAY THE DFT SEQUENCE

PLOT THE REAL PART

PLOT THE IMAGINARY PART

PLOT THE MAGNITUDE PARTPART USING abs


COMMAND

PLOT THE PHASE PART


USING angle COMMAND

STOP
24

Flowchart: COMPUTATION OF IFFT


START

ENTER THE SEQUENCE


X(k)

PLOT THE SEQUENCE


X(k)

COMPUTE IDFT USING FFT ALGORITHM

DISPLAY THE IDFT


SEQUENCE

PLOT THE REAL PART

PLOT THE IMAGINARY


PART

PLOT THE MAGNITUDE


PART USING abs
COMMAND

PLOT THE PHASE PART


USING angle COMMAND

STOP
25

Program: Computation of FFT

clc;
close all;
clear all;
fs=5000;
ts=1/fs;
length=100000;
t=(0:length-1)*ts;
y= 0.2*cos(2*pi*100*t)+ 0.5*cos(2*pi*500*t)+ 2*sin(2*pi*1000*t);
figure(1);
plot(y(1:100));
title('spectrum of the input signal');
xlabel('time');
ylabel('amplitude');
nfft=2^(nextpow2(length));
z=fft(y,nfft)/length;
f=(fs/2)*linspace(0,1,(nfft/2)+1)
z1=2*abs(z(1:(nfft/2)+1));
figure(2);
plot(f,z1);
title('spectrum of the input signal');
xlabel('frequncy');
ylabel('amplitude');
z2=ifft(z,nfft)*length;
figure(3);
plot(z2(1:100));
title('Input signal recovered');
xlabel('time');
ylabel('amplitude');
26

Output: FFT
Input signal
3

1
amplitude

-1

-2

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

spectrum of the input signal


1.8

1.6

1.4

1.2

1
amplitude

0.8

0.6

0.4

0.2

0
0 500 1000 1500 2000 2500
frequncy
27

Output: IFFT

Input signal recovered


3

1
amplitude

-1

-2

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

Result:

The MATLAB program to compute FFT and IFFT for the given sequence is executed and its
response is plotted successfully.
28

EX.NO:5 DESIGN OF FIR FILTER USING WINDOW TECHNIQUES

(A) RECTANGULAR WINDOW


Aim:

To design and plot the FIR filter using rectangular window technique.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm:

(1) For the given length N, calculate alpha=(N-1)/2 and assign eps=0.001 and cut-off frequency
wc.

(2) Calculate delayed sample response (hd) using sine function.

(3) Calculate the rectangular window coefficient (wr)

(4) Calculate the sample response h (n) as hd*wr.

(5) Calculate the frequency of h (n) and plot it.

(6) Calculate the rectangular window coefficient (wh) using rectangular functions.

(7) Calculate h (n) =hd*wh.

(8) Calculate the frequency and plot it separately for LPF, HPF, BPF and BSF.
29

Flowchart: RECTANGULAR WINDOW


START

GET THE LENGTH OF


SEQUENCE

CALCULATE α=(N-1)/2 AND wc=0.3*pi

CALCULATE THE FILTER COE-FFIECIENT AS( hd)


RECTANGULAR WINDOW COEFFICIENT AS (wr).

CALCULATE FIR FILTER COEFFICIENT h(n)=hd*wr.

FIND FREQUENCY DOMAIN RESPONSE OF h(n).

PLOT THE FREQUENCY


DOMAIN RESPONSE

COMPUTE RECTANGULAR WINDOW COE-FFICIENT


(wh) AND CORRESPONDING FILTER COEFFICIENT

CALCULATE FREQUENCY DOMAIN REPRESENTATION


OF h(n)

PLOT THE FREQUENCY


DOMAIN WITH LABEL

STOP
30

Output:

Rectangular lowpass filter Rectangular high pass filter


1.5 1.5

1 1
Magnitude

Magnitude
0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
Rectangular bandpass filter Rectangular bandstop filter
1.5 1.5

1 1
Magnitude

Magnitude

0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
31

Program: FIR Filter’ Design Using Rectangular Window

%Low pass filter


clc;close all;
clear all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));hold on;
title('Rectangular lowpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%High pass filter
hd1=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr1=boxcar(N);
hn1=hd1.*wr1';
w1=0:.01:pi;
h1=freqz(hn1,1,w1);
subplot(2,2,2);
plot(w/pi,abs(h1));hold on;
title('Rectangular high pass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
32

%Band pass filter


clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-a+e))-sin(wc1*(n-a+e)))./(pi*(n-a+e));
wr=boxcar(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));hold on;
title('Rectangular bandpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%Band stop filter
clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-a+e))-sin(wc2*(n-a+e))+sin(pi*(n-a+e)))./(pi*(n-a+e));
wr=boxcar(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,4);
33

plot(w/pi,abs(h));hold on;
title('Rectangular bandstop filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');

Result:

The program to design and plot the FIR filter response using rectangular window technique
is executed and verified successfully using MATLAB.
34

(B) HAMMING WINDOW

Aim:

To design and plot the FIR filter using hamming window technique.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm:

(i) For the given length N, calculate alpha=(N-1)/2 and assign eps=0.001 and cut-off frequency
wc=0.5*pi.

(ii) Calculate delayed sample response (hd) using sine function.

(iii) Calculate the rectangular window coefficient (wr)

(iv) Calculate the unit sample response h (n) as hd*wr.

(v) Calculate the frequency of h (n) and plot it.

(vi) Calculate the hamming window coefficient (wh) using hamming functions.

(vii) Calculate h (n) =hd*wh.

(viii) Calculate the frequency and plot it separately for LPF, HPF, BPF and BSF.
35

Flowchart: HAMMING WINDOW


START

GET THE LENGTH OF


SEQUENCE

CALCULATE α= (N-1)/2 AND wc=0.5*pi

CALCULATE THE FILTER COE-FFIECIENT AS


(hd) RECTANGULAR WINDOW COEFFICIENT

CALCULATE FIR FILTER COEFFICIENT


h (n) =hd*wr

FIND FREQUENCY DOMAIN RESPONSE OF


h (n)

PLOT THE FREQUENCY


DOMAIN RESPONSE

COMPUTE HAMMING WINDOW COE-FFICIENT


(wh) AND CORRESPONDING FILTER
COEFFICIENT

CALCULATE FREQUENCY DOMAIN


REPRESENTATION OF h (n)

PLOT THE FREQUENCY


DOMAIN WITH LABEL

STOP
36

Output:

Hamming lowpass filter Hamming high pass filter


1.5 1.5

1 1
Magnitude

Magnitude
0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
Hamming bandpass filter Hamming bandstop filter
1.5 1.5

1 1
Magnitude

Magnitude

0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
37

Program: FIR Filter Design Using Hamming Window

%Low pass filter


clc;close all;
clear all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=hamming(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));hold on;
title('Hamming lowpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%High pass filter
hd1=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr1=hamming(N);
hn1=hd1.*wr1';
w1=0:.01:pi;
h1=freqz(hn1,1,w1);
subplot(2,2,2);
plot(w/pi,abs(h1));hold on;
title('Hamming high pass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
38

%Band pass filter


clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-a+e))-sin(wc1*(n-a+e)))./(pi*(n-a+e));
wr=hamming(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));hold on;
title('Hamming bandpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%Band stop filter
clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-a+e))-sin(wc2*(n-a+e))+sin(pi*(n-a+e)))./(pi*(n-a+e));
wr=hamming(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,4);
39

plot(w/pi,abs(h));hold on;
title('Hamming bandstop filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');

Result:
The program to design and plot the FIR filter using Hamming window technique is
executed and output is verified successfully.
40

(C) HANNING WINDOW

Aim:

To design and plot the FIR filter using Hanning window technique.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm:

(1) For the given length N, calculate alpha= (N-1)/2 and assign eps=0.001 and cut-off frequency
wc.

(2) Calculate delayed sample response (hd) using sine function.

(3) Calculate the rectangular window coefficient (wr)

(4) Calculate the unit sample response h (n) as hd*wr.

(5) Calculate the frequency of h (n) and plot it.

(6) Calculate the hamming window coefficient (wh) using hanning functions.

(7) Calculate h (n) =hd*wh.

(8) Calculate the frequency and plot it separately for LPF, HPF, BPF and BSF.
41

Flowchart: HANNING WINDOW START

GET THE LENGTH OF


SEQUENCE

CALCULATE α= (N-1)/2 AND wc=0.3*pi

CALCULATE THE FILTER COE-


FFIECIENT AS (hd) RECTANGULAR
WINDOW COEFFICIENT AS (wr).

CALCULATE FIR FILTER COEFFICIENT


h (n) =hd*wr

FIND FREQUENCY DOMAIN RESPONSE OF


h (n)

PLOT THE FREQUENCY


DOMAIN RESPONSE

COMPUTE HANNING WINDOW COE-FFICIENT


(wh) AND CORRESPONDING FILTER COEFFICIENT

CALCULATE FREQUENCY DOMAIN


REPRESENTATION OF h (n)

PLOT THE FREQUENCY


DOMAIN WITH LABEL

STOP
42

Output:

Hanning lowpass filter Hanning high pass filter


1.5 1.5

1 1
Magnitude

Magnitude
0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
Hanning bandpass filter Hanning bandstop filter
1.5 1.5

1 1
Magnitude

Magnitude

0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
43

Program: FIR Filter’s Design Using Hanning Window

%Low pass filter


clc;close all;
clear all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=hanning(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));hold on;
title('Hanning lowpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%High pass filter
hd1=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr1=hanning(N);
hn1=hd1.*wr1';
w1=0:.01:pi;
h1=freqz(hn1,1,w1);
subplot(2,2,2);
plot(w/pi,abs(h1));hold on;
title('Hanning high pass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
44

%Band pass filter


clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-a+e))-sin(wc1*(n-a+e)))./(pi*(n-a+e));
wr=hanning(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));hold on;
title('Hanning bandpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%Band stop filter
clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-a+e))-sin(wc2*(n-a+e))+sin(pi*(n-a+e)))./(pi*(n-a+e));
wr=hanning(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,4);
45

plot(w/pi,abs(h));hold on;
title('Hanning bandstop filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');

Result:
The program to design and plot the FIR filter using Hanning window technique is
executed and output is verified successfully.
46

(D) BLACKMANN WINDOW

Aim:

To design and plot the FIR filter using Blackmann window technique.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm:

(1) For the given length N, calculate alpha= (N-1)/2 and assign eps=0.001 and cut-off frequency
wc.

(2) Calculate delayed sample response (hd) using sine function.

(3) Calculate the rectangular window coefficient (wr)

(4) Calculate the unit sample response h(n) as hd*wr.

(5) Calculate the frequency of h (n) and plot it.

(6) Calculate the blackmann window coefficient (wh) using hanning functions.

(7) Calculate h (n) =hd*wp.

(8) Calculate the frequency and plot it separately for LPF, HPF, BPF and BSF.
47

Flowchart: BLACKMANN WINDOW


START

GET THE LENGTH


OF SEQUENCE

CALCULATE α= (N-1)/2 AND wc=0.7*pi

CALCULATE THE FILTER COE-FFIECIENT AS


(hd) HANNING WINDOW COEFFICIENT AS
(wn).

CALCULATE FIR FILTER COEFFICIENT


h (n) =hd*wr

FIND FREQUENCY DOMAIN RESPONSE OF h


(n)

PLOT THE FREQUENCY


DOMAIN RESPONSE

COMPUTE BLACKMANN WINDOW COE-FFICIENT (wp)


AND CORRESPONDING FILTER COEFFICIENT

CALCULATE FREQUENCY DOMAIN


REPRESENTATION OF h (n)

PLOT THE FREQUENCY


DOMAIN WITH LABEL

STOP
48

Output:

Blackman lowpass filter Blackman high pass filter


1.5 1.5

1 1
Magnitude

Magnitude
0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
Blackman bandpass filter Blackman bandstop filter
1 1
Magnitude

Magnitude

0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
49

PROGRAM: FIR FILTER’S DESIGN USING BLACKMANN WINDOW

%Low pass filter


clc;close all;
clear all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=blackman(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));hold on;
title('Blackman lowpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%High pass filter
hd1=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr1=blackman(N);
hn1=hd1.*wr1';
w1=0:.01:pi;
h1=freqz(hn1,1,w1);
subplot(2,2,2);
plot(w/pi,abs(h1));hold on;
title('Blackman high pass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
50

%Band pass filter


clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-a+e))-sin(wc1*(n-a+e)))./(pi*(n-a+e));
wr=blackman(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));hold on;
title('Blackman bandpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%Band stop filter
clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-a+e))-sin(wc2*(n-a+e))+sin(pi*(n-a+e)))./(pi*(n-a+e));
wr=blackman(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,4);
51

plot(w/pi,abs(h));hold on;
title('Blackman bandstop filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');

Result:

The program to design and plot the FIR filter using Blackmann window technique is
executed and output is verified successfully.
52

(E) BARTLETT WINDOW

Aim:

To design and plot the FIR filter using Bartlett window technique.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm:

(i) For the given length N, calculate alpha= (N-1)/2 and assign eps=0.001 and cut-off frequency
wc.

(ii) Calculate delayed sample response (hd) using sine function.

(iii) Calculate the rectangular window coefficient (wr)

(iv) Calculate the unit sample response h(n) as hd*wr.

(v) Calculate the frequency of h (n) and plot it.

(vi) Calculate the bartlett window coefficient (wh) using hanning functions.

(vii) Calculate h (n) =hd*wp.

(viii) Calculate the frequency and plot it separately for LPF, HPF, BPF and BSF.
53

Flowchart: BARTLETT WINDOW


START

GET THE LENGTH OF


SEQUENCE

CALCULATE α= (N-1)/2 AND wc=0.7*pi

CALCULATE THE FILTER COE-FFIECIENT AS (hd)


RECTANGULAR WINDOW COEFFICIENT AS
(wn).

CALCULATE FIR FILTER COEFFICIENT


h (n) =hd*wr

FIND FREQUENCY DOMAIN RESPONSE OF


h (n)

PLOT THE FREQUENCY


DOMAIN RESPONSE

COMPUTE BARTLETT WINDOW COE-FFICIENT (wp)


AND CORRESPONDING FILTER COEFFICIENT

CALCULATE FREQUENCY DOMAIN


REPRESENTATION OF h (n)

PLOT THE FREQUENCY


DOMAIN WITH LABEL

STOP
54

Output:

Hillbert using lowpass filter Hillbert using high pass filter


1 1
Magnitude

Magnitude
0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
Hillbert using bandpass filter Hillbert using bandstop filter
1 1
Magnitude

Magnitude

0.5 0.5

0 0
0 0.5 1 0 0.5 1
Normalised frequency\omaga\/pi Normalised frequency\omaga\/pi
55

Program: FIR FILTER’S DESIGN USING BARTLETT WINDOW

%Low pass filter


clc;close all;
clear all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=bartlett(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));hold on;
title('Hillbert using lowpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%High pass filter
hd1=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr1=bartlett(N);
hn1=hd1.*wr1';
w1=0:.01:pi;
h1=freqz(hn1,1,w1);
subplot(2,2,2);
plot(w/pi,abs(h1));hold on;
title('Hillbert using high pass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
56

%Band pass filter


clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-a+e))-sin(wc1*(n-a+e)))./(pi*(n-a+e));
wr=bartlett(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));hold on;
title('Hillbert using bandpass filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');
%Band stop filter
clear all;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
a=(N-1)/2;
e=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-a+e))-sin(wc2*(n-a+e))+sin(pi*(n-a+e)))./(pi*(n-a+e));
wr=bartlett(N);
hn=hd.*wr';
w=0:.01:pi;
h=freqz(hn,1,w);
subplot(2,2,4);
57

plot(w/pi,abs(h));hold on;
title('Hillbert using bandstop filter');
xlabel('Normalised frequency\omega\/pi');
ylabel('Magnitude');

Result:

The program to design and plot the FIR filter using Bartlett window technique is executed
and output is verified successfully.

EX.NO:6 DESIGN OF IIR FILTERS USING BUTTERWORTH TECHNIQUE


58

Aim:

To write a MATLAB program to design Butterworth low pass, high pass, band pass and band
reject filter.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm: Butterworth Low Pass Filter:

(1) Start the program.

(2) Assign the value of α1, fp, fs, and α2.

(3) Perform A=2*fp/f; B=2*fs/f.

(4) Calculate cut off frequency and order of filter using buttord function.

(5) Butterworth function is used to calculate system function.(vi)Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.(viii)Perform m=abs (h)


& an=angle (h).
(7) Stop the program.

Flow Chart: Butterworth Low Pass Filter


59

START

ASSIGN α1, fp, fs, f and α2.

CALCULATE A=2*fp/f; B=2*fs/f.

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER USING BUTTORD FUNCTION

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM m=20*log


(abs (h)), an=angle(h)

DISPLAY BUTTERWORTH LPF RESPONSE

STOP

Flow Chart: Butterworth High Pass Filter


60

START

ASSIGN α1, fp, fs, f and α2.

CALCULATE A=2*fp/f; B=2*fs/f.

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER USING BUTTORD FUNCTION

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY BUTTERWORTH HPF


RESPONSE

STOP

Butterworth High Pass Filter:


61

(1) Start the program.

(2) Assign the value of α1=0.4, fp=400, fs=800,f=200, and α2=30.

(3) Calculate cut off frequency and order of filter using buttord function.

(4) Butterworth function is used to calculate system function.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log (abs (h)) & an=angle (h).

(8) Stop the program.


62

Butterworth Band Pass Filter:

(1) Start the program.

(2) Assign the value of α1=2, α2=20, wp= [0.2*pi, 0.4*pi], ws= [0.1*pi, 0.5*pi].

(3) Calculate cut off frequency and order of filter using buttord function.

(4) Butterworth function is used to calculate system function.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log (abs (h)) & an=angle (h).

(8) Plot phase in radians in y axis and normalized frequency in x-axis.

(9) Stop the program.


63

Flow Chart: Butterworth Band Pass Filter

START

ASSIGN α1, fp, fs, f and α2.

CALCULATE A=2*fp/f; B=2*fs/f.

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER USING BUTTORD


FUNCTION

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h)

DISPLAY BUTTERWORTH BPF


RESPONSE

STOP
64

FLOW CHART: Butterworth Band Stop Filter

START

ASSIGN α1, fp, fs, f and


α2.

CALCULATE A=2*fp/f; B=2*fs/f.

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER USING BUTTORD


FUNCTION

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY BUTTERWORTH BSF


RESPONSE

STOP
65

Butterworth Band Stop Filter:

(1) Start the program.

(2) Assign the value of α1=2, α2=20, wp= [0.2*pi, 0.4*pi], ws= [0.1*pi, 0.5*pi].

(3) Calculate cut off frequency and order of filter using buttord function.

(4) Butterworth function is used to calculate system function.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log (abs (h)) & an=angle (h).

(8) Plot phase in radians in y axis and normalized frequency in x-axis.

(9) Stop the program.


66

OUTPUT:

Enter Pass band attenuation in db=1


Enter Stop band attenuation in db=2
Enter Pass band Frequency in Hz=5
Enter Stop band Frequency in Hz=10
Enter Sampling Frequency in Hz=5000

IIR low pass filter IIR High pass filter


0 0

-100 -20
Gain in db
Gain in db

-200 -40

-300 -60
0 0.5 1 0 0.5 1
Normalised frequency Normalised frequency
IIR Band pass filter IIR Band stop filter
0 0

-20 -20
Gain in db
Gain in db

-40 -40

-60 -60

-80 -80
0 0.5 1 0 0.5 1
Normalised frequency Normalised frequency
67

Program: BUTTERWORTH-IIR FILTER


%Butterworth low pass filter
clc;
close all;
clear all;
alpha=input('Enter Passband attenuation in db=');
alphas=input('Enter Stopband attenuation in db=');
fp=input('Enter Passband Frequency in Hz=');
fs=input('Enter Stopband Frequency in Hz=');
f=input('Enter Sampling Frequency in Hz=');
omp=2*fp/f;
oms=2*fs/f;
[n,wn]=buttord(omp,oms,alpha,alphas);
[b,a]=butter(n,wn);
w=0:0.001:pi;
[h,om]=freqz(b,a,w,'whole');
m=abs(h);
an=angle(h);
subplot(2,2,1);
plot(om/pi,20*log(m));grid on;
title('IIR low pass filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
%Butterworth high pass filter
omp=2*fp/f; oms=2*fs/f;
[n,wn]=buttord(omp,oms,alpha,alphas);
[b,a]=butter(n,wn,'high');
w=0:0.001:pi;
[h,om]=freqz(b,a,w,'whole');
m=abs(h);
an=angle(h);
subplot(2,2,2);
68

plot(om/pi,20*log(m));grid on;
title('IIR High pass filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
%Butterworth band pass filter
wp=[0.2*pi,0.4*pi]; ws=[0.1*pi,0.5*pi];
[n,wn]=buttord(wp/pi,ws/pi,alpha,alphas);
[b,a]=butter(n,wn);
w=0:0.001:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,3);
plot(ph/pi,m);grid on;
title('IIR Band pass filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
%Butterworth band stop filter
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
[n,wn]=buttord(wp/pi,ws/pi,alpha,alphas);
[b,a]=butter(n,wn,'stop');
w=0:0.001:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,4);
plot(ph/pi,m);grid on;
title('IIR Band stop filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
69

Result:
The program to design Butterworth low pass, high pass, band pass and band reject filter is
executed and output is verified successfully.
70

EX.NO:7 DESIGN OF IIR FILTER USING CHEBYSHEV – 1 TECHNIQUE

Aim:

To write a MATLAB program to design chebyshev1 IIR low pass, high pass, band pass and
band reject filter.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm: Chebyshev1 Low Pass Filter:

(1) Start the program.

(2) Assign the value of α1 and α2

(3) Perform w=0.2*pi,ws=0.3*pi.

(4) Calculate cut off frequency and order of filter

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function

(7) Perform m=20*log(abs (h))&an=angle (h).

(8) Stop the program


71

Flowchart: Chebyshev1 Low Pass Filter

START

ASSIGN α1 and α2.

CALCULATE wp=0.2*pi,ws=0.3*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND


PERFORM m=20*log (abs (h)), an=angle(h).

DISPLAY CHEBYSHEV1 LPF RESPONSE

STOP
72

Flow Chart: Chebyshev1 High Pass Filter

START

ASSIGN α1 and α2.

CALCULATE wp=0.2*pi,ws=0.3*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM m=20*log


(abs (h)), an=angle(h).

DISPLAY CHEBYSHEV1 HPF RESPONSE

STOP
73

Chebyshev1 High Pass Filter:

(1) Start the program.

(2) Assign the value of α1 and α2.

(3) Perform w=0.2*pi,ws=0.3*pi.

(4) Calculate cut off frequency and order of filter.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log(abs (h))&an=angle (h).

(8) Display the chebyshev1 high pass filter

(9) Stop the program.


74

Flow Chart: Chebyshev1 Band Pass Filter

START

ASSIGN α1 and α2.

CALCULATE wp=0.2*pi,0.4*pi,ws=0.1*pi,0.5*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND


PERFORM m=20*log (abs (h)),an=angle(h).

DISPLAY CHEBYSHEV1 BPF


RESPONSE

STOP
75

Chebyshev1 Band Pass Filter:

(1) Start the program.

(2) Assign the value of α1 and α2.

(3) Perform w=0.2*pi,0.4*pi,ws=0.1*pi,0.5*pi.

(4) Calculate cut off frequency and order of filter.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log(abs (h))&an=angle (h).

(8) Display the chebyshev1 band pass filter

(9) Stop the program.


76

Flow Chart: Chebyshev1 Band Stop Filter

START

ASSIGN α1 and α2

CALCULATE wp=0.2*pi,0.4*pi,ws=0.1*pi,0.5*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY CHEBYSHEV1 BSF


RESPONSE

STOP
77

Chebyshev1 Band Stop Filter:

(1) Start the program.

(2) Assign the value of α1 and α2.

(3) Perform w=0.2*pi,ws=0.3*pi.

(4) Calculate cut off frequency and order of filter.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log(abs (h))&an=angle (h).

(8) Display the chebyshev1 band stop filter

(9) Stop the program.


78

Output:

Enter Pass band attenuation in db=1

Enter Stop band attenuation in db=5

IIR low pass filter IIR High pass filter


0 0

-100 -100
Gain in db

Gain in db
-200 -200

-300 -300

-400 -400
0 0.5 1 0 0.5 1
Normalised frequency Normalised frequency
IIR Band pass filter IIR Band stop filter
0 0

-50
-50
Gain in db

Gain in db

-100
-100
-150

-200 -150
0 0.5 1 0 0.5 1
Normalised frequency Normalised frequency
79

CHEBYSHEV1-IIR FILTER

Program:

%chebyshev1 low pass filter


clc;
close all;
clear all;
alpha=input('enter passband attenuation in db=');
alphas=input('enter stopband attenuation in db=');
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby1(n,alpha,wn);
w=0:0.001:pi;
[h,om]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,2,1);
plot(om/pi,m);grid on;
title('iir low pass filter');
ylabel('gain in db');
xlabel('normalised frequency');
%chebyshev1 high pass filter
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby1(n,alphas,wn);
w=0:0.001:pi;
[h,om]=freqz(b,a,w);
m=abs(h);
an=angle(h);
subplot(2,2,2);
80

plot(om/pi,20*log(m));grid on;
title('iir high pass filter');
ylabel('gain in db');
xlabel('normalised frequency');
%chebyshev1 band pass filter
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
[n,wn]=cheb1ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby1(n,alpha,wn);
w=0:0.001:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,3);
plot(ph/pi,m);grid on;
title('iir band pass filter');
ylabel('gain in db');
xlabel('normalised frequency');
%chebyshev1 band stop filter
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
[n,wn]=cheb1ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby1(n,alphas,wn,'stop');
w=0:0.001:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,4);
plot(ph/pi,m);grid on;
title('iir band stop filter');
ylabel('gain in db');
xlabel('normalised frequency');
81

RESULT:

The program to design chebyshev1 IIR low pass, high pass, band pass and band reject
filter is executed and output is verified successfully.
82

EX.NO:8 DESIGN OF IIR FILTER USING CHEBYSHEV-2 TECHNIQUE

Aim:

To write a MATLAB program to design chebyshev-2 IIR low pass, high pass, band pass and
band reject filter.

Software and Hardware Required:


1. Computer installed with MATLAB 7.7(R2008b)
Algorithm: Chebyshev-2 Low Pass Filter:

(1) Start the program

(2) Assign the value of α1 and α2

(3) Perform w=0.2*pi,ws=0.3*pi.

(4) Calculate cut off frequency and order of filter.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function

(7) Perform m=20*log(abs (h)) & an=angle (h).

(8) Stop the program.


83

Flow Chart: Chebyshev2 Low Pass Filter

START

ASSIGN α1 and α2

CALCULATE wp=0.2*pi,ws=0.3*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY CHEBYSHEV2 LPF RESPONSE

STOP
84

Flow Chart: Chebyshev2 High Pass Filter

START

ASSIGN α1 and α2.

CALCULATE wp=0.2*pi,ws=0.3*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY CHEBYSHEV2 HPF RESPONSE

STOP
85

Chebyshev2 High Pass Filter:

(1) Start the program.

(2) Assign the value of α1 and α2.

(3) Perform w=0.2*pi,ws=0.3*pi.

(4) Calculate cut off frequency and order of filter.(v)Assign w=0:0.01: pi.

(5) Calculate Z transform using frequency function.

(6) Perform m=20*log(abs (h))&an=angle (h).

(7) Display the chebyshev-2 high pass filter

(8) Stop the program.


86

Flow Chart: Chebyshev2 Band Pass Filter

START

ASSIGN α1 and α2.

CALCULATE wp=0.2*pi,0.4*pi,ws=0.1*pi,0.5*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY CHEBYSHEV2 BPF RESPONSE

STOP
87

Chebyshev2 Band Pass Filter:

(1) Start the program.

(2) Assign the value of α1 and α2.

(3) Perform w=0.2*pi,0.4*pi,ws=0.1*pi,0.5*pi.

(4) Calculate cut off frequency and order of filter.

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log(abs (h))&an=angle (h).

(8) Display the chebyshev-2 band pass filter

(9) Stop the program.


88

Flow Chart: CHEBYSHEV2 BAND STOP FILTER

START

ASSIGN α1 and α2.

CALCULATE wp=0.2*pi,0.4*pi,ws=0.1*pi,0.5*pi

CALCULATE CUT OFF FREQUENCY AND ORDER OF FILTER

ASSIGN w=0:0.01:pi

CALCULATE Z- TRANSFORM USING FREQUENCY FUNCTION AND PERFORM


m=20*log (abs (h)),an=angle(h).

DISPLAY CHEBYSHEV2 BSF RESPONSE

STOP
89

CHEBYSHEV2 BAND STOP FILTER:

(1) Start the program.

(2) Assign the value of α1 and α2.

(3) Perform w=0.2*pi,ws=0.3*pi.

(4) Calculate cut off frequency and order of filter

(5) Assign w=0:0.01: pi.

(6) Calculate Z transform using frequency function.

(7) Perform m=20*log(abs (h))&an=angle (h).

(8) Display the chebyshev-2 band stop filter

(9) Stop the program.


90

Output:

Enter Pass band attenuation in db=1

Enter Stop band attenuation in db=5

IIR low pass filter IIR High pass filter


50 0

0 -50
Gain in db

Gain in db
-50 -100

-100 -150

-150 -200
0 0.5 1 0 0.5 1
Normalised frequency Normalised frequency
IIR Band pass filter IIR Band stop filter
0 50

-20 0
Gain in db

Gain in db

-40 -50

-60 -100
0 0.5 1 0 0.5 1
Normalised frequency Normalised frequency
91

Program: CHEBYSHEV-2 IIR FILTER

%Chebyshev2 low pass filter


clc;
close all;
clear all;
alpha=input('Enter Passband attenuation in db=');
alphas=input('Enter Stopband attenuation in db=');
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb2ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby2(n,alpha,wn);
w=0:0.001:pi;
[h,om]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,2,1);
plot(om/pi,m);grid on;
title('IIR low pass filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
%Chebyshev2 high pass filter
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb2ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby2(n,alphas,wn);
w=0:0.001:pi;
[h,om]=freqz(b,a,w);
m=abs(h);
an=angle(h);
subplot(2,2,2);
92

plot(om/pi,20*log(m));grid on;
title('IIR High pass filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
%Chebyshev2 band pass filter
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
[n,wn]=cheb2ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby2(n,alpha,wn);
w=0:0.001:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,3);
plot(ph/pi,m);grid on;
title('IIR Band pass filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
%Chebyshev2 band stop filter
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
[n,wn]=cheb2ord(wp/pi,ws/pi,alpha,alphas);
[b,a]=cheby2(n,alphas,wn,'stop');
w=0:0.001:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,4);
plot(ph/pi,m);grid on;
title('IIR Band stop filter');
ylabel('Gain in db');
xlabel('Normalised frequency');
93

RESULT:

The program to design chebyshev-2 IIR low pass, high pass, band pass filter is executed
and output is verified successfully.
94

EX.NO:9 DECIMATION AND INTERPOLATION

Aim:

To write a program to compute decimation and interpolation of a given sequence.

Software and Hardware Required:


1. Computers installed with MATLAB 7.7(R2008b)
Algorithm:
Decimation
1. Get the sampling frequency to sample the defined input signal.
2. Give the down sampling factor.
3. Subplot and stem the sequence.
4. Give X-label, Y-label and title.
5. Stop the program and execute it.
Interpolation
1. Get the sampling frequency to sample the defined input signal.
2. Give the up-sampling sampling factor.
3. Subplot and stem the sequence.
4. Give X-label, Y-label and title.
5. Stop the program and execute it.
Program:
DOWN SAMPLING:
clear all;
close all;
clc;
f1=100;
k=1:50;
fs=1000;
M=3; %Down sample by a value
x=sin(2*pi*f1/fs*k); %Input signal
subplot(2,1,1);
stem(x);
95

title(' Input sequence ');


xlabel(' Samples(n) ');
ylabel('Amplitude');
y=downsample(x,M); %TO DOWNSAMPLE
subplot(2,1,2);
stem(y);
title('Input sequence downsampled by a factor M = 3');
xlabel(' Samples(n) ');
ylabel('Amplitude');

UP SAMPLING:
clear all;
close all;
clc;
f1=100;
k=1:10;
fs=1000;
L=4; %Up sample by a value
x=sin(2*pi*f1/fs*k); %Input signal
subplot(2,1,1);
stem(x);
title('Input sequence ');
xlabel(' Samples(n) ');
ylabel('Amplitude');
y=Upsample(x,L); %TO DO UP SAMPLE
subplot(2,1,2);
stem(y); %Draw the graph
xlabel(' Samples(n) ');
ylabel('Amplitude');
title('Input sequence Upsampled by a factor L');

Output:
96

Down sampling:

Up Sampling:
97

Flowchart: Down sampling

START

GET THE SAMPLING FREQUENCY


fs and M

downsample(x,M)

PLOT THE DOWNSAMPLED


RESPONSE

STOP

Flowchart: Up Sampling

START

GET THE SAMPLING


FREQUENCY fs and L

Upsample(x,L)

PLOT THE UP SAMPLED


RESPONSE

STOP
98

Result:

The program for decimation and interpolation is executed and its output is verified
successfully using MATLAB.
99
100

EX.NO:10 STUDY OF ARCHITECTURE OF DIGITAL SIGNAL PROCESSOR

Aim:

To study about the fixed point DSP processor TMS320C5515.

Introduction:

The TMS320C5515 digital-signal processor (DSP) contains a high-performance, low-power


DSP to efficiently handle tasks required by portable audio, wireless audio devices, industrial
controls, software defined radio, fingerprint biometrics, and medical applications. The DSP
consists of the following primary components:
• A C55x CPU and associated memory
• FFT hardware accelerator
• Four DMA controllers and external memory interface
• Power management module
• A set of I/O peripherals that includes I2S, I2C, SPI, UART, Timers, EMIF, 10-bit SAR ADC, LCD
Controller, USB 2.0
Block Diagram:
CPU Core:
The C55x CPU is responsible for performing the digital signal processing tasks required by
the application. In addition, the CPU acts as the overall system controller, responsible for handling
many system functions such as system-level initialization, configuration, user interface, user
command execution, connectivity functions, and overall system control.Tightly coupled to the CPU
are the following components:
 DSP internal memories
 Dual-access RAM (DARAM)
 Single-access RAM (SARAM)
 Read-only memory (ROM)
 FFT hardware accelerator
 Ports and buses.
The CPU also manages/controls all peripherals on the device .
101

Peripherals:
The DSP includes the following peripherals:
• Four direct memory access (DMA) controllers, each with four independent channels.
• One external memory interface (EMIF) with 21-bit address and 16-bit data. The EMIF has
support for mobile SDRAM and non-mobile SDRAM single-level cell (SCL) NAND with 1-bit ECC,
and multi-level cell (MLC) NAND with 4-bit ECC. Two serial busses each configurable to support
one Multimedia Card (MMC) / Secure Digital (SD/SDIO) controller, one inter-IC sound bus (I2S)
interface with GPIO, or a full GPIO interface.
• One parallel bus configurable to support a 16-bit LCD bridge or a combination of an 8-bit LCD
bridge, a serial peripheral interface (SPI), an I2S, a universal asynchronous receiver/transmitter
(UART), and GPIO.
• One inter-integrated circuit (I2C) multi-master and slave interface with 7-bit and 10-bit
addressing modes.
• Three 32-bit timers with 16-bit prescaler; one timer supports watchdog functionality.
• A USB 2.0 slave.
102

• A 10-bit successive approximation (SAR) analog-to-digital converter with touch screen


conversion capability.
• One real-time clock (RTC) with associated low power mode.
System Memory:
The DSP supports a unified memory map (program code sections and data sections can be
mixed and interleaved within the entire memory space) composed of both on-chip and external
memory. The on-chip memory consists of 320KB of RAM and 128KB of ROM. The external
memory interface (EMIF) port provides the means for the DSP to access external memory and
devices including: mobile and non-mobile single data rate (SDR) SDRAM, NOR Flash, NAND
Flash and SRAM. Separate from the program and data space, the DSP also includes a 64K-byte
I/O space for peripheral registers.
System Configuration and Control overview:
The DSP includes system-level registers for controlling, configuring, and reading status of the
device.
These registers are accessible by the CPU and support the following features:
o Device Identification
o Device Configuration
 Pin multiplexing control
 Output drive strength configuration
 Internal pullup and pulldown enable/disable
 On-chip LDO control
o DMA Controller Configuration
o Peripheral Reset
o EMIF and USB Byte Access
Introduction to the Addressing Modes:
The TMS320C55x DSP supports three types of addressing modes that enable
flexible access to data memory, to memory-mapped registers, to register bits, and to I/O space:
1. The absolute addressing mode allows you to reference a location by supplying all or part of an
address as a constant in an instruction.
2. The direct addressing mode allows you to reference a location using an address offset.
103

3. The indirect addressing mode allows you to reference a location using a pointer. Each
addressing mode provides one or more types of operands.
Absolute Addressing Modes:
1. k16 Absolute Addressing Mode
The k16 absolute addressing mode uses the operand *abs16 (#k16), where k16 is a 16-bit
unsigned constant. DPH (the high part of the extended data page register) and k16 are
concatenated to form a 23-bit data-space address. An instruction using this addressing mode
encodes the constant as a 2-byte extension to the instruction. Because of the extension, an
instruction using this mode cannot be executed in parallel with another instruction.
2. k23 Absolute Addressing Mode
The k23 absolute addressing mode uses the *(#k23) operand, where k23 is
a 23-bit unsigned constant. An instruction using this addressing mode encodes the constant as a
3-byte extension to the instruction. . Because of the extension, an instruction using this mode
cannot be executed in parallel with another instruction.
3. I/O Absolute Addressing Mode
The I/O absolute addressing mode uses the *port (#k16) operand, where k16
is a 16-bit unsigned constant. An instruction using this addressing mode encodes the constant as
a 2-byte extension to the instruction. Because of the extension, an instruction using this mode
cannot be executed in parallel with another instruction.
Direct Addressing Modes:
1. DP direct
This mode uses the main data page specified by DPH (high part of the extended data page
register) in conjunction with the data page register (DP). This mode is used to access a memory
location or a memory-mapped register.
2. SP direct
This mode uses the main data page specified by SPH (high part of the extended stack
pointers) in conjunction with the data stack pointer (SP). This mode is used to access stack values
in data memory.
3. Register-bit direct
This mode uses an offset to specify a bit address. This mode is used to access one
register bit or two adjacent register bits.
4. PDP direct
104

This mode uses the peripheral data page register (PDP) and an offset to specify an I/O
address. This mode is used to access a location in I/O space.
Indirect Addressing Modes:
1. AR indirect
This mode uses one of eight auxiliary registers (AR0–AR7) to point to data. The way the
CPU uses the auxiliary register to generate an address depends on whether you are accessing
data space (memory or memory-mapped registers), individual register bits, or I/O space.
2. Dual AR indirect
This mode uses the same address-generation process as the AR indirect addressing
mode. This mode is used with instructions that access two or more data-memory locations.
3. CDP indirect
This mode uses the coefficient data pointer (CDP) to point to data. The way the CPU uses
CDP to generate an address depends on whether you are accessing data space (memory or
memory-mapped registers), individual register bits, or I/O space.
4. Coefficient indirect
This mode uses the same address-generation process as the CDP indirect addressing
mode. This mode is available to support instructions that can access a coefficient in data memory
at the same time they access two other data-memory values using the dual AR indirect
addressing mode.
Circular Addressing:
Circular addressing can be used with any of the indirect addressing modes. Each of the
eight auxiliary registers (AR0–AR7) and the coefficient data pointer can be independently
configured to be linearly or circularly modified as they act as pointers to data or to register bits.
This configuration is done with a bit (ARnLC) in status register ST2_55.
105

Result:
The Block diagram and addressing modes of TMS320C5515 processor is studied.
106

EX.NO:11 MAC OPERATION USING ADDRESSING MODES

Aim
To Study the various addressing mode of TMS320C6745 DSP processor.

Addressing Modes The TMS320C55x DSP supports three types of addressing modes that
enable flexible access to data memory, to memory-mapped registers, to register bits, and to I/O
space:
The absolute addressing mode allows you to reference a location by supplying all or part of an
address as a constant in an instruction.
The direct addressing mode allows you to reference a location using an address offset.
The indirect addressing mode allows you to reference a location using a pointer.
Each addressing mode provides one or more types of operands. An instruction that supports an
addressing-mode operand has one of the following syntax elements listed below.

Baddr - When an instruction contains Baddr, that instruction can access one or two bits in an
accumulator (AC0–AC3), an auxiliary register (AR0–AR7), or a temporary register (T0–T3). Only
the register bit test/set/clear/complement instructions support Baddr. As you write one of these
instructions, replace Baddr with a compatible operand.
Cmem - When an instruction contains Cmem, that instruction can access a single word (16 bits)
of data from data memory. As you write the instruction, replace Cmem with a compatible operand.
Lmem - When an instruction contains Lmem, that instruction can access a long word (32 bits) of
data from data memory or from a memory-mapped registers. As you write the instruction, replace
Lmem with a compatible operand.
Smem - When an instruction contains Smem, that instruction can access a single word (16 bits) of
data from data memory, from I/O space, or from a memory-mapped register. As you write the
instruction, replace Smem with a compatible operand.
Xmem and Ymem - When an instruction contains Xmem and Ymem, that instruction can perform
two simultaneous 16-bit accesses to data memory. As you write the instruction, replace Xmem
and Ymem with compatible operands.
107

Absolute Addressing Modes k16 absolute - This mode uses the 7-bit register called DPH (high
part of the extended data page register) and a 16-bit unsigned constant to form a 23-bit data-
space address. This mode is used to access a memory location or a memory-mapped register.
k23 absolute - This mode enables you to specify a full address as a 23-bit unsigned constant.
This mode is used to access a memory location or a memory-mapped register.
I/O absolute - This mode enables you to specify an I/O address as a 16-bit unsigned constant.
This mode is used to access a location in I/O space.

Direct Addressing Modes DP direct - This mode uses the main data page specified by DPH
(high part of the extended data page register) in conjunction with the data page register (DP). This
mode is used to access a memory location or a memory-mapped register.
SP direct - This mode uses the main data page specified by SPH (high part of the extended stack
pointers) in conjunction with the data stack pointer (SP). This mode is used to access stack values
in data memory.
Register-bit direct - This mode uses an offset to specify a bit address. This mode is used to
access one register bit or two adjacent register bits.
PDP direct - This mode uses the peripheral data page register (PDP) and an offset to specify an
I/O address. This mode is used to access a location in I/O space. The DP direct and SP direct
addressing modes are mutually exclusive. The mode selected depends on the CPL bit in status
register ST1_55: 0 DP direct addressing mode 1 SP direct addressing mode The register-bit and
PDP direct addressing modes are independent of the CPL bit.
Indirect Addressing Modes You may use these modes for linear addressing or circular
addressing.
AR indirect - This mode uses one of eight auxiliary registers (AR0–AR7) to point to data. The way
the CPU uses the auxiliary register to generate an address depends on whether you are
accessing data space (memory or memory-mapped registers), individual register bits,or I/O space.
Dual AR indirect - This mode uses the same address-generation process as the AR indirect
addressing mode. This mode is used with instructions that access two or more data-memory
locations.
CDP indirect - This mode uses the coefficient data pointer (CDP) to point to data. The way the
CPU uses CDP to generate an address depends on whether you are accessing data space
(memory or memory-mapped registers), individual register bits, or I/O space.
108

Coefficient indirect - This mode uses the same address-generation process as the CDP indirect
addressing mode. This mode is available to support instructions that can access a coefficient in
data memory at the same time they access two other data-memory values using the dual AR
indirect addressing mode.
Circular Addressing Circular addressing can be used with any of the indirect addressing modes.
Each of the eight auxiliary registers (AR0–AR7) and the coefficient data pointer (CDP) can be
independently configured to be linearly or circularly modified as they act as pointers to data or to
register bits, see Table 3−10. This configuration is done with a bit (ARnLC) in status register
ST2_55. To choose circular modification, set the bit. Each auxiliary register ARn has its own
linear/circular configuration bit in ST2_55: 0 Linear addressing 1 Circular addressing The CDPLC
bit in status register ST2_55 configures the DSP to use CDP for linear addressing or circular
addressing: 0 Linear addressing 1 Circular addressing You can use the circular addressing
instruction qualifier, .CR, if you want every pointer used by the instruction to be modified circularly,
just add .CR to the end of the instruction mnemonic (for example, ADD.CR). The circular
addressing instruction qualifier overrides the linear/circular configuration in ST2_55.

ADDITION

INP1 .SET 0H
INP2 .SET 1H
OUT .SET 2H
.mmregs
.text Input: Output:
START: Data Memory: Data Memory:
LD #140H,DP A000h 0004h A002h 0008h
RSBX CPL A001h 0004h
NOP
NOP
NOP
NOP
LD INP1,A
ADD INP2,A
STL A,OUT
HLT: B HLT
109

SUBTRACTION
INP1 .SET 0H
INP2 .SET 1H
OUT .SET 2H
.mmregs
.text
START:
LD #140H,DP
RSBX CPL
NOP
NOP
NOP
NOP
LD INP1,A
SUB INP2,A
STL A,OUT
HLT: B HLT

Input: Output:
Data Memory: Data Memory:
A000h 0004h A002h 0002h
A001h 0002h

Result
Thus, the various addressing mode of DSP processor TMS320C5505 was studied.
110

EX.NO:12 WAVE FORM GENERATION

Aim:

To generate sine wave and square wave using TMS320C5515 FIXED POINT DSP KIT.

Software and hardware Required:

1) TMS320C5515 DSP Starter kit.


2) PC with code composer studio v4.
3) CRO

Procedure:

1. Start the code composer IDE.


2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. Connect the TMS320C5515 kit with the PC through USB port and connect the LINEIN and
LINEOUT pins with function generator and CRO respectively.
9. In target menu click RUN icon and observe the output in CRO.
111

Program: SINE WAVE


#include "stdio.h"
#include "usbstk5515.h"
#include "aic3204.h"
#include "PLL.h"
#include "sinewaves.h"
Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
#define SAMPLES_PER_SECOND 48000
#define GAIN_IN_dB 0
unsigned long int i = 0;
void main( void )
{
USBSTK5515_init( );
pll_frequency_setup(100);
aic3204_hardware_init();
aic3204_init();
set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
printf( "Sinewave 1000Hz on left HP output, 1000Hz on right HP output\n\n" );
asm(" bclr XF");
for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
{
aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two
channels.
left_output = generate_sinewave_1(1000, 10000); // Sinewave 1 is 1000 Hz.
right_output = generate_sinewave_2(1000, 10000); // Sinewave 2 is 1000 Hz.
aic3204_codec_write(left_output, right_output);
}
aic3204_disable();
printf( "\n***Program has Terminated***\n" );
SW_BREAKPOINT;
}
112

Program: SQUARE WAVE


#include "stdio.h"
#include "usbstk5515.h"
#include "aic3204.h"
#include "PLL.h"
#define SAMPLES_PER_SECOND 48000
#define GAIN_IN_dB 0
#define table_size 256 //size of table = 256
Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
int data_table[table_size]; //data table array
unsigned long int i = 0;
unsigned int j=0;
void main( void )
{
USBSTK5515_init( );
pll_frequency_setup(100);
aic3204_hardware_init();
aic3204_init();
set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
for(i=0; i<table_size/2; i++) //set 1st half of buffer
data_table[i] = 0x7FFF; //with max value (2^15)-1
for(i=table_size/2; i<table_size; i++) //set 2nd half of buffer
data_table[i] = -0x8000; //with -(2^15)
asm(" bclr XF");
for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
{
aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two
channels.
left_output = data_table[j];
right_output = data_table[j];
aic3204_codec_write(left_output, right_output);
j++;
if(j==table_size)
113

j=0;
}
aic3204_disable();
printf( "\n***Program has Terminated***\n" );
SW_BREAKPOINT;
}

Result:

The sine wave and square waves are generated using TMS320C5515 DSP kit and the
output waveforms are obtained in CRO.
114

EX.NO:13 IMPLEMENTATION OF FIR FILTER

Aim:

To design and plot the FIR filter using TMS320C5515 FIXED POINT DSP KIT.

Software and hardware required:

1) TMS320C5515 DSP Starter kit.


2) PC with code composer studio v4.

Procedure:

1. Start the code composer IDE.


2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. Connect the TMS320C5515 kit with the PC through USB port and connect the LINEIN and
LINEOUT pins with function generator and CRO respectively.
9. In target menu click RUN icon and observe the output in CRO.
115

Program: IMPLEMENTATION OF FIR FILTER


#include "stdio.h"
#include "usbstk5515.h"
#include "aic3204.h"
#include "PLL.h"
#include "FIR_Filters_asm.h"
#include "LEDFlasher.h"
#include "hamming.h"
#include "hanning.h"
#include "kaiser.h"
#include "rectangular.h"
#include "stereo.h"
Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
Int16 mono_input;
#define SAMPLES_PER_SECOND 48000
#define GAIN_IN_dB 30
unsigned long int i = 0;
unsigned int step = 0;
void main( void )
{
USBSTK5515_init( );
pll_frequency_setup(100);
aic3204_hardware_init();
aic3204_init();
set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
asm(" bclr XF");
for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
{
aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two
channels.
mono_input = stereo_to_mono(left_input, right_input);
left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_1000Hz[0], mono_input);
right_output = FIR_filter_asm_2(&Hamming_Low_Pass_Filter_1000Hz[0], mono_input);
aic3204_codec_write(left_output, right_output);
}
aic3204_disable();
printf( "\n***Program has Terminated***\n" );
SW_BREAKPOINT; }
116

Result:

The FIR filter is implemented using TMS320C5515 DSP kit and the output waveforms are
obtained in CRO.
117

EX.NO:14 IMPLEMENTATION OF IIR FILTER

Aim:

To design and plot the IIR filter using TMS320C5515 FIXED POINT DSP KIT.

Software and hardware required:

1) TMS320C5515 DSP Starter kit.


2) PC with code composer studio v4.

Procedure:

1. Start the code composer IDE.


2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. Connect the TMS320C5515 kit with the PC through USB port and connect the LINEIN and
LINEOUT pins with function generator and CRO respectively.
9. In target menu click RUN icon and observe the output in CRO.
118

Program: IMPLEMENTATION OF IIR FILTER

#include "stdio.h"
#include "usbstk5515.h"
#include "aic3204.h"
#include "PLL.h"
#include "stereo.h"
#include "IIR_band_pass_filters.h"
#include "IIR_band_stop_filters.h"
#include "IIR_filters_fourth_order.h"
#include "IIR_low_pass_filters.h"
#include "IIR_high_pass_filters.h"
#include "SweepGenerator.h"

#define SAMPLES_PER_SECOND 48000


#define GAIN_IN_dB 30

Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
Int16 mono_input;

unsigned long int i = 0;


unsigned int Step = 0;

void main( void )


{
/* Initialize BSL */
USBSTK5515_init( );

/* Initialize the Phase Locked Loop in EEPROM */


pll_frequency_setup(100);

/* Initialise hardware interface and I2C for code */


aic3204_hardware_init();

/* Initialise the AIC3204 codec */


aic3204_init();

/* Set sampling frequency in Hz and ADC gain in dB */


set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);

asm(" bclr XF");

for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )


119

aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two


channels.

mono_input = stereo_to_mono(left_input, right_input); // Generate mono signal

/* Low pass filter 1200 Hz */


left_output = fourth_order_IIR_direct_form_I( &IIR_low_pass_600Hz[0], mono_input);
/* High pass filter 1200 Hz */
right_output = fourth_order_IIR_direct_form_I( &IIR_low_pass_600Hz[0], mono_input);

aic3204_codec_write(left_output, right_output);
}

/* Disable I2S and put codec into reset */


aic3204_disable();

SW_BREAKPOINT;

Result:

The IIR and FIR filter is implemented using TMS320C5515 DSP kit and the output
waveforms are obtained in CRO.
120

EX.NO:15 SAMPLING OF INPUT SIGNALS AND DISPLAY

Aim:

To sample and display the input signals using TMS320C5515 FIXED POINT DSP KIT.

Software and hardware Required:

1) TMS320C5515 DSP Starter kit.


2) PC with code composer studio v4.
3) CRO

Procedure:

1. Start the code composer IDE.


2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. Connect the TMS320C5515 kit with the PC through USB port and connect the LINEIN and
LINEOUT pins with function generator and CRO respectively.
9. In target menu click RUN icon and observe the output in CRO.
121

Program: SAMPLING AND DISPLAY


#include “stdio.h”
#include “usbstk5515.h”
#include “aic3204.h”
#include “PLL.h”
#include “stereo.h”
//#include “LEDflasher.h”
Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
Int16 mono_input;
#define SAMPLES_PER_SECOND 48000
/* New. Gain as a #define */
/* Use 30 for microphone. Use 0 for line */
#define GAIN_IN_dB 30
unsigned long int i = 0;
/* New. Variable for step */
unsigned int Step = 0;
void main( void )
{
/* Initialize BSL */
USBSTK5515_init( );
/* Initialize PLL */
pll_frequency_setup(100);
/* Initialise hardware interface and I2C for code */
aic3204_hardware_init();
/* Initialise the AIC3204 codec */
aic3204_init();
/* Setup sampling frequency and 30dB gain
for microphone */
set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
122

/* New. Default to XF LED off */


asm(“ bclr XF”);
for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
{
aic3204_codec_read(&left_input, &right_input);
// Configured for one interrupt per two channels.
Mono_input = stereo_to_mono(left_input, right_input);
left_output = mono_input; // Stereo to mono
right_output = mono_input;
aic3204_codec_write(left_output, right_output);
}
/* Disable I2S and put codec into reset */
aic3204_disable();
printf( “\n***Program has Terminated***\n” );
SW_BREAKPOINT;
}

Result:

The Input signals are sampled, reconstructed and displayed in CRO using TMS320C5515
DSP kit .
123

Additional Experiments

EX.NO:16 LINEAR CONVOLUTION USING TMS320C5515 PROCESSOR

Aim:
To implement the linear convolution using TMS320C5515 FIXED POINT DSP KIT.
Hardware and software required:
1. TMS320C5515 DSP KIT
2. PC with code composer studio v4
3. CRO
Procedure:
1. Start the code composer IDE.
2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. Connect the TMS320C5515 kit with the PC through USB port and connect the LINEIN and
LINEOUT pins with function generator and CRO respectively.
9. In target menu click RUN icon and observe the output in CRO.

Program: Linear convolution

#include "stdio.h"
#include "usbstk5505.h"
#include "PLL.h"
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf("Enter values for i/p\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf ("Enter Values for n \n");
for(i=0;i<n;i++)
scanf("%d",&h[i]);
for(i=m;i<=m+n-1;i++)
124

x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}}
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}

Result:
The Linear convolution is implemented and output is verified using TMS320C5515 DSP kit.
125

EX.NO:17 CIRCULAR CONVOLUTION USING TMS320C5515 PROCESSOR

Aim:
To implement the circular convolution using TMS320C5515 FIXED POINT DSP KIT.
Hardware and software required:
1. TMS320C5515 DSP KIT
2. PC with code composer studio v4
3. CRO
Procedure:
1. Start the code composer IDE.
2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. Connect the TMS320C5515 kit with the PC through USB port and connect the LINEIN and
LINEOUT pins with function generator and CRO respectively.
9. In target menu click RUN icon and observe the output in CRO.

Program: circular convolution


#include "stdio.h"
#include "usbstk5505.h"
#include "PLL.h"
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
126

{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];

/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}

/*displaying the result*/


printf(" the circular convolution is\n");
for(i=0;i<n;i++)

printf("%d \t",y[i]);

Result:
The circular convolution is implemented and output is verified using TMS320C5515 DSP
kit.
127

EX.NO:18 DECIMATION AND INTERPOLATION

Aim:

To write a program to compute decimation and interpolation of a given sequence.

Software and Hardware Required:


2. Computers installed with MATLAB 7.7(R2008b)
Algorithm:
Decimation
6. Get the sampling frequency to sample the defined input signal.
7. Give the down sampling factor.
8. Subplot and stem the sequence.
9. Give X-label, Y-label and title.
10. Stop the program and execute it.
Interpolation
6. Get the sampling frequency to sample the defined input signal.
7. Give the up-sampling sampling factor.
8. Subplot and stem the sequence.
9. Give X-label, Y-label and title.
10. Stop the program and execute it.
Program:
DOWN SAMPLING:
clear all;
close all;
clc;
f1=100;
k=1:50;
fs=1000;
M=3; %Down sample by a value
x=sin(2*pi*f1/fs*k); %Input signal
subplot(2,1,1);
stem(x);
128

title(' Input sequence ');


xlabel(' Samples(n) ');
ylabel('Amplitude');
y=downsample(x,M); %TO DOWNSAMPLE
subplot(2,1,2);
stem(y);
title('Input sequence downsampled by a factor M = 3');
xlabel(' Samples(n) ');
ylabel('Amplitude');

UP SAMPLING:
clear all;
close all;
clc;
f1=100;
k=1:10;
fs=1000;
L=4; %Up sample by a value
x=sin(2*pi*f1/fs*k); %Input signal
subplot(2,1,1);
stem(x);
title('Input sequence ');
xlabel(' Samples(n) ');
ylabel('Amplitude');
y=Upsample(x,L); %TO DO UP SAMPLE
subplot(2,1,2);
stem(y); %Draw the graph
xlabel(' Samples(n) ');
ylabel('Amplitude');
title('Input sequence Upsampled by a factor L');

Output:
129

Down sampling:

Up Sampling:
130

Flowchart: Down sampling

START

GET THE SAMPLING FREQUENCY


fs and M

downsample(x,M)

PLOT THE DOWNSAMPLED


RESPONSE

STOP

Flowchart: Up Sampling

START

GET THE SAMPLING


FREQUENCY fs and L

Upsample(x,L)

PLOT THE UP SAMPLED


RESPONSE

STOP
131

Result:

The program for decimation and interpolation is executed and its output is verified
successfully using MATLAB.
132

EX.NO:19 MAC OPERATION

Aim:

To write a program to perform Multiply and Accumulate operation using TMS320C5515


FIXED POINT DSP KIT.

Software and hardware required:

1) TMS320C5515 DSP Starter kit.


2) PC with code composer studio v4.

Procedure:

1. Start the code composer IDE.


2. Open new CCS Project and add the necessary library files.
3. Select a new source and type the program
4. Save the source file with a file extension .c
5. Go to project menu select the properties option and apply the necessary settings.
6. Apply Build active project in project menu.
7. Go to Launch TI option in target menu and set the general configuration settings about the
target.
8. In target menu click RUN icon and observe the output in console window.

Block Diagram:
133

Program: MAC Operation

/* include the library files of circular / linear convolution library files*/


#include "stdio.h"
#include "usbstk5505.h"
#include "PLL.h"

int A[10],i;
float B[10],a=0;
void main(void)
{

printf("Enter values for i/p A(n):\n");

for(i=0;i<10;i++)
scanf("%d",&A[i]);

printf("Enter Values for i/p B(n) \n");


for(i=0;i<10; i++)
scanf("%f",&B[i]);

for(i=0;i<10;i++)
{
a=a+(A[i]*B[i]);
}
printf("mac result is %f",a);
}

Result:

The MAC operation is implemented using TMS320C5515 DSP kit and the output is obtained
in console window.
134

You might also like