KEMBAR78
DSP Lab Manual 2016 | PDF | Matrix (Mathematics) | Digital Signal Processing
0% found this document useful (0 votes)
73 views113 pages

DSP Lab Manual 2016

DSP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views113 pages

DSP Lab Manual 2016

DSP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 113

DIGITAL SIGNAL PROCESSING LAB

Experiment No: Date:

ADITYA COLLEGE OF ENGINEERING


(Affiliated to J.N.T. University & Approved by A.I.C.T.E, New Delhi).
PUNGANUR ROAD,MADANAPALLE-517325

DEPARTMENT ELECTRONICS & COMMUNICATION ENGINEERING

DIGITAL SIGNAL PROCESSING


LAB MANUAL
III YEAR II SEMESTER (ECE)
Prepared by

P.GANGADHARA REDDY M.Tech.,(Ph.D.)

Assistant Professor, Dept.of E.C.E

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR


B.Tech. III - II Sem.
(13A04608) DIGITAL SIGNAL PROCESSING LAB
Course Objective:
 To design real time DSP systems and real world applications.
 To implement DSP algorithms using both fixed and floating point processors.
 To generate the basis function of different transforms.
Learning Outcome:
 Able to design real time DSP systems and real world applications.
 Able to implement DSP algorithms using both fixed and floating point processors.

The programs shall be implemented in software (Using MATLAB / C programming/


Equivalent) and hardware (Using TEXAS INSTRUMENTS / Analog devices / Motorola /
Equivalent DSP processors).

List of Experiments: (Minimum of 5 experiments are to be conducted from each part)


Software Experiments (PART – A)
1. Generation of random signal and plot the same as a waveform showing all the specifications.
2. Finding Power and (or) Energy of a given signal.
3. Convolution and Correlation (auto and cross correlation) of discrete sequences without using
built in functions for convolution and correlation operations.
4. DTFT of a given signal
5. N – point FFT algorithm
6. Design of FIR filter using windowing technique and verify the frequency response of the
filter.
7. Design of IIR filter using any of the available methods and verify the frequency response of
the filter.
8. Design of analog filters.
Using DSP Processor kits (Floating point) and Code Composure Studio (CCS) (PART – B)
1. Generation of random signal and plot the same as a waveform showing all the specifications.
2. Finding Power and (or) Energy of a given signal.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

3. Convolution and Correlation (auto and cross correlation) of discrete sequences without using
built in functions for convolution and correlation operations.
4. DTFT of a given signal
5. N – point FFT algorithm
6. Design of FIR filter using windowing technique and verify the frequency response of the
filter.
7. Design of IIR filter using any of the available methods and verify the frequency response of
the filter.
8. Design of analog filters.
Equipment/Software Required:
1. Licensed MATLAB software with required tool boxes for 30 users.
2. DSP floating Processor Kits with Code Composure Studio (8 nos.)
3. Function generators
4. CROs
5. Regulated Power Supplies.

LAB INCHARGE HOD-ECE

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

CONTENTS
List of experiments using MATLABPage No.

List of experiments using CCSPage No.

LAB INCHARGE HOD-ECE

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Software Experiments (PART – A)

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Introduction to MATLAB
MATLAB is a powerful high-level programming language for scientific computations.
Itis very easy to learn and use in solving numerically complex engineering problems.some basic
concepts of MATLAB are included here for a quick reviewto facilitateyour understanding of the
programs.The MATLAB name stands for MATrix LABoratory.

MATLAB consists of functions that are either built into the interpreter or available as M-
files,with each containing a sequence of program statements that execute a certain algorithm.A
completely new algorithm can be written as a program containing only a few of thesefunctions
and can be saved as another M-file.

1.Starting MATLAB: To start MATLAB on Windows platforms, by double-clicking the


MATLAB shortcut icon on your Windows desktop.

2.Quitting MATLAB: To end your MATLAB session on Windows platforms, select File ---->
Exit in MATLAB window in the desktop(or) type quit in the Command Window.

MATLAB Windows desktop:

MATLAB works with through three basic windows.

1.Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the MATLAB
prompt
2.Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow
3. Editor window: This is where you write edit, create and save your own programs in files
called M files.
To create or edit an M-file use File---> New (or) File ----> Open, or use the edit function.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

In addition to the above three windows the following were appeared on MATLAB
Windows Desktop

(i) Command History: Statements entered in the Command Window are logged in the
Command History. From the Command History, previously run statements can be viewed,
copied and executed. M-file can be created from selected statements.

(ii) Current Directory Browser and Search Path: MATLAB file operations use the current
directory and the search path as reference points. Any file required to run must either be in the
current directory or on the search path.

(iii) Workspace Browser and Array Editor: The MATLAB workspace consists of the set of
variables (named arrays) built up during a MATLAB session and stored in memory. The
variables can be added to the workspace by using functions, running M-files, and loading saved
workspaces. To delete variables from the workspace, select the variables and select Edit >
Delete.

(iv) Array Editor: Double-click a variable in the Workspace browser, or use open var variable
name, to see it in the Array Editor. Use the Array Editor to view and edit a visual representation
of variables in the workspace.

Input-output:
MATLAB supports interactive computation taking the input from the screen and
flushing, the output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data –type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, charcter strings, structures and cells.There is no
need to declare variables as real or complex, MATLAB automatically sets the variable to be real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are required
for vectors or arrays .we can find the dimensions of an existing matrix or a vector with the size
and length commands.
Where to work in MATLAB?
All programs and commands can be entered either in the
a)Command window
b) As an M file using Matlab editor

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Note: Save all M files in the folder 'work' in the current directory. Otherwise you have to locate
the file during compiling.
For any clarification regarding plot etc, which are built in functions type help topic
i.e. help plot

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

DATA REPRESENTATION IN MATLAB

1. Basic functionalities of MATLAB


 Defining a scalar:x=1
x=
1

 Defining a column vectorv = [1;2;3]


v=
1
2
3
 Defining a row vectorw = [1 0 1]
w=
101
 Transpose a vectorW = w’
W=
1
0
1
 Defining a range for a vectorX = 1:.5:5
X =Columns 1 through 7
1.0000 1.5000 2.0000 2.5000 3.0000 3.50004.0000
Columns 8 through 9
4.5000 5.0000
 Empty vectorY = []
Y=
[]
 Defining a matrixM = [1 2 3; 3 2 1]
M=
123
321

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

 Zero matrixM = zeros(2,3) % 1st parameter is row, 2nd parameter is col.


M=
000
000
 ones matrixm = ones(2,3)
m=
111
111
 The identity matrixI = eye(3)
I=
100
010
001
 Define a random matrix or vectorR = rand(1,3)
R =0.9501 0.2311 0.6068
 Access a vector or matrixR(3)
ans =0.6068
2. Operations on vector and matrices in MATLAB
MATLAB utilizes the following arithmetic operatops;
Addition +
Subtraction -
Multiplication *
Division /
Power Operator ^
Transpose ‘
Some built in functions in MATLAB
abs magnitude of a number (absolute value for real numbers)
angle angle of a complex number, in radians
cos cosine function, assumes argument is in radians
sin sine function, assumes argument is in radians
exp exponential function

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

3. Relational operators in MATLAB


Relational operators: =(equal), ~=3D (not equal), etc.

4. Control Flow in MATLAB


To control the flow of commands, the makers of MATLAB supplied four devices a
programmer can use while writing his/her computer code
• the for loops
• the while loops
• the if-else-end constructions
• the switch-case constructions

Syntax of the for loop is shown below


for k = array
commands
end

The commands between the for and end statements are executed for all %values stored
in the array.
The for loops can be nested
H = zeros(5);
for k=1:5
for l=1:5
H(k,l) = 1/(k+l-1);
end
end

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Syntax of the while loop is


while expression
statements
end

Syntax of the simplest form of if else is


if expression
commands
end
This construction is used if there is one alternative only. Two alternatives require the
construction
if expression
commands (evaluated if expression is true)
else
commands (evaluated if expression is false)
end
If there are several alternatives one should use the following construction
if expression1
commands (evaluated if expression 1 is true)
elseif expression 2
commands (evaluated if expression 2 is true)
elseif …
...
else
commands (executed if all previous expressions evaluate to false)
end

Syntax of the switch-case construction is


switch expression (scalar or string)
case value1 (executes if expression evaluates to value1)

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

commands
case value2 (executes if expression evaluates to value2)
commands
...
otherwise
statements
end
.
5. Creating functions using m-files
Files that contain a computer code are called the m-files.
There are two kinds of m-files: the script files and the function files.
Script files do not take the input arguments or return the output arguments. The function files
may take input arguments or return output arguments.
To make the m-file click on File next select New and click on M-File
from the pull-down menu.
You will be presented with the MATLAB Editor/Debugger screen. Here you will type your code,
can make %changes, etc. Once you are done with typing, click on File, in the MATLAB
Editor/Debugger screen and select Save As… .
Chose a name for your file, e.g., firstgraph.m and click on Save. Make sure that your
file is saved in the directory that is in MATLAB's search path. If you %have at least two
files with duplicated names, then the one that occurs first in MATLAB's search path will
be executed.
To open the m-file from within the Command Window type edit firstgraph %and then
Press Enter or Return key.

6. Graphs in MATLAB
save the script file and the run it
Script file graph1.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

A Summary of MATLAB Commands


We provide below a quick review with a brief description of all MATLAB functions used
in this book. For additional details on these functions, use the help command.
Function Description
abs Computes the absolute value

angle Computes the phase angle in radians


axis Sets manual scaling of axes on plots
blackman Generates the Blackman window coefficients
break Terminates the execution of loops
butter Designs digital and analog Butterworth filters of all four types
buttord buttord Selects the minimum order of the digital or analog Butterworth
transfer function
ceil Rounds to the nearest integer towards +∞
cheb1ord Selects the minimum order of the digital or analog Type 1 Chebyshev
transfer function
cheb2ord Selects the minimum order of the digital or analog Type 2 Chebyshev
transfer function
chebwin Generates the Dolph-Chebyshev window coefficients
cheby1 Designs digital and analog Type 1 Chebyshev filters of all four types
cheby2 Designs digital and analog Type 2 Chebyshev filters of all four types
clc Deletes all objects from the current figure
conj Computes the complex conjugate
conv Performs the multiplication of two polynomials
cos Computes the cosine
decimate Decreases the sampling rate of a sequence by an integer factor
deconv Performs polynomial division
disp Displays text or a matrix on the screen
echo Echoes M-files during execution
ellip Designs digital and analog elliptic filters of all four types
ellipord Selects the minimum order of the digital or analog elliptic transfer function
else Delineates an alternate block of statements inside an if loop
elseif Conditionally executes a block of statements inside an if loop
end Terminates a loop
eps Indicates floating-point relative accuracy
error Displays an error message
exp Computes the exponential
fft Computes the discrete Fourier transform coefficients
filter Filters data with an IIR or FIR filter implemented in the transposed direct
form II structure
filtfilt Performs zero-phase filtering of data

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

fir1 using the windowed Fourier series method


fir2 responses using the windowed Fourier series method
firpm Designs linear-phase FIR filters using the Parks-McClellan
firpmord with the firpm command
fix Rounds towards zero
format Controls the format of the output display
freqs Computes the complex frequency response of an analog transfer function at
specified frequency points
freqz Computes the complex frequency response of a digital transfer function at
specified frequency points
function Used to generate new M-functions
grid Adds or deletes grid lines to or from the current plot
grpdelay Computes the group delay of a digital transfer function at specified
frequency points
gtext Places a text on a graph with the aid of a mouse
hamming Generates the Hamming window coefficients
hann Generates the von Hann window coefficients
help Provides online documentation for MATLAB functions and M-files
hold Holds the current graph
if Conditionally executes statements
ifft Computes the inverse discrete Fourier transform coefficients
imag Determines the imaginary part of a complex number or matrix
impz Computes a specific number of the impulse response coefficients of a
digital transfer function
input Requests data to be supplied by the user
interp Increases the sampling rate of a sequence by an integer factor
inv Determines the inverse of a matrix
kaiser Determines the Kaiser window coefficients
kaiserord Detemines the filter order and the parameter βof a Kaiser window
length Determines the length of a vector
linspace Generates linearly spaced vectors
load Retrieves saved data from the disk
log10 Computes the common logarithm
lookfor Provides keyword search through all help entries
max Detemines the largest element of a vector
min Detemines the smallest element of a vector
NaN Not-a-number
num2str Converts a number to its string representation
ones Generates a vector or a matrix with element values 1
pause Halts execution temporarily until user presses any key
pi Returns the floating-point number nearest to π
plot Generates linear 2-D plots
poly2rc Determines the coefficients in the cascade realization of an IIR allpass
transfer function
rand Generates random numbers and matrices uniformly distributed in the

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

interval (0,1)
randn Generates random numbers and matrices normally distributed with zero
mean and unity variance
real Determines the real part of a complex number or matrix
rem Determines the remainder of a matrix divided by another matrix of same
size
resample Changes the sampling rate of a sequence by a rational number
residue Determines the partial-fraction of a discrete-time transfer function
expressed as a ratio of polynomials in z
return Causes a return to the keyboard or to the invoking function
roots Determines the roots of a polynomial
save Saves workspace variables on a disk
sawtooth Generates a sawtooth wave with a period 2π
sign Implements the signum function
sin Determines the sine
sinc Computes the sinc function of a vector or array
size Returns the matrix dimensions
sqrt Computes the square root
square Generates a square wave with a period 2π
stairs Draws a stairstep graph
stem Plots the data sequence as stems from the x axis terminated with circles for
the data value
subplot Breaks figure window into multiple rectangular panes for the display of
multiple plots
sum Determines the sum of all elements in a vector
title Write specified text on the top of the current plot
what Provides directory listing of files
which Locates functions and files
while Repeats statements an indefinite number of times
who Lists the current variables in the memory
whos Lists the current variables in the memory, their sizes, and whether they
have non-zero imaginary parts
xlabel Write specified text below the x-axis of the current 2-D plot
ylabel Write specified text on the left side of the y-axis of the current 2-D plot
zeros Generates a vector or a matrix with element 0

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Generation of signals
Aim:-To generate the following signals using MATLAB 6.5
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential growing signal
5. Exponential decaying signal
6. Sine signal
7. Cosine signal

Apparatus Required:-System with MATLAB 6.5

Program:
1. Unit impulse signal
clc;
clear all;
close all;
disp('UNIT IMPULSE SIGNAL');
N=input('Enter Number of Samples: ');
n=-N:1:N
x=[zeros(1,N) 1 zeros(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Impulse Response');

Output:-UNIT IMPULSE SIGNAL


Enter Number of Samples: 6

2. Unit step signal


clc;
clear all;
close all;
disp('UNIT STEP SIGNAL');
N=input(' Enter Number of Samples : ');
n=-N:1:N
x=[zeros(1,N) 1 ones(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Response');

Output:-UNIT STEP SIGNAL


Enter Number of Samples : 6

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

3. Unit ramp signal


clc;
clear all;
close all;
disp('UNIT RAMP SIGNAL');
N=input('Enter Number of Samples : ');
a=input('Enter Amplitude : ')
n=0:1:N
x=a*n stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Unit Ramp Response');

Output:-UNIT RAMP SIGNAL


Enter Number of Samples : 6
Enter Amplitude : 20

4. Exponential decaying signal


clc;
clear all;
close all;
disp('EXPONENTIAL DECAYING
SIGNAL');
N=input('Enter Number of Samples : ');
a=0.5 n=0:.1:N
x=a.^n
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Decaying Signal
Response');

Output: - EXPONENTIAL DECAYING SIGNAL


Enter Number of Samples : 6

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

5. Exponential growing signal


clc;
clear all;
close all;
disp('EXPONENTIAL GROWING SIGNAL');
N=input('Enter Number of Samples : ');
a=0.5
n=0:.1:N
x=a.^-n
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Growing Signal Response');

Output:-EXPONENTIAL GROWING SIGNAL


Enter Number of Samples : 6

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

6. Cosine signal
clc;
clear all;
close all;
disp('COSINE SIGNAL');
N=input('Enter Number of Samples : ');
n=0:.1:N
x=cos(n)
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Cosine ignal');
Output:-COSINE SIGNAL
Enter Number of Samples : 16

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

7. Sine signal
clc;
clear all;
close all;
disp('SINE SIGNAL');
N=input('Enter Number of Samples : ');
n=0:.1:N
x=sin(n)
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('sine Signal');
Output:-SINE SIGNAL
Enter Number of Samples : 16

Questions:
1. Define signal?
2. Define Ramp Signal?
3. Define Exponential Signal?
4. Define sine signal?
5. Define impulse signal?
6. Define pulse signal?
7. What are m-files?
8. What are various windows in matlab?
9. Define analog signal?
10. Definde Digital signal?

Result:-Thus the MATLAB program for generation of all basic signals was performed and the
output was verified.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

INFERENCE:

Applications:

(To be filled by faculty)


Marks Remarks:
Category
awarded
Observation

Regularity

Experiment Conduction &


Behavior

Viva-Voce

Record Date of Submission:

Total: Signature of the faculty:

Sum of sinusoidal signals

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Aim: - To write a MATLAB program to find the sum of sinusoidal signals.


Apparatus required: System with MATLAB 6.5.

Program:-
% sum of sinusoidal signals
clc;
clear all;
close all;
tic;
t=0:.01:pi;

%generation of sine signals


y1=sin(t);
y2=sin(3*t)/3;
y3=sin(5*t)/5;
y4=sin(7*t)/7;
y5=sin(9*t)/9;

y = sin(t) + sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 + sin(9*t)/9;


plot(t,y,t,y1,t,y2,t,y3,t,y4,t,y5);
legend('y','y1','y2','y3','y4','y5');
title('generation of sum of sinusoidal signals');
grid;
ylabel('---> Amplitude');
xlabel('---> t');
toc;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Output:-

Questions:
1. Define signal?
2. Define sine signal?
3. How you can generate different sinusoidal signals?
4. Define Discrete-time signal?
5. Define continuous time signal?
6. Define sinusoidal sequences?

Result:-Thus the MATLAB program for sum of sinusoidal signals was performed and the output
was verified.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

INFERENCE:

APPLICATIONS:

(To be filled by faculty)


Marks Remarks:
Category
awarded

Observation

Regularity

Experiment Conduction &


Behavior

Viva-Voce

Record Date of Submission:

Total: Signature of the faculty:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Generation of Random Signal

Aim:- write a MATLAB program to the generation of random signal and plot the same as a
waveform showing all the specifications.

Apparatus Required:-System with MATLAB 7.0

Program:

clc;

clearall;

closeall;

disp('Random SIGNAL');

N=input('Enter Number of matrices: ');

n=1:N

k=randn(n,N)

stem(n,k);

xlabel('Time');

ylabel('Amplitude');

title('Random Signal Response');

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Output:

Questions:
1. Define random signal?
2. Define Deterministic signal?
3. Define syatem?
4. Define linear system?
5. Define LTI system?

Result:-Thus the MATLAB program for the generation of random signal was performed and the
output was verified.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

INFERENCE:

APPLICATIONS:

(To be filled by faculty)


Marks Remarks:
Category
awarded

Observation

Regularity

Experiment Conduction &


Behavior

Viva-Voce

Record Date of Submission:

Total: Signature of the faculty:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Finding Power and Energy of a Given Signal

Aim: - To write a MATLAB program to find power and energy of a given signal

Apparatus Required:-System with MATLAB 7.0

Program:

clc;

T=10; %Total evaluation time

Ts=0.001; %Sampling time => 1000 samples per second

Fs=1/Ts; % Sampling period

t=[0:Ts:T]; %define simulation time

%sample function to calculate energy and power

x=cos(2*pi*100*t)+cos(2*pi*200*t)+sin(2*pi*300*t);

energy=(norm(x)^2)

power = (norm(x)^2)/length(x)

%Plot Power Spectral Density

psd1=spectrum(x,1024);

specplot(psd1,Fs);

output:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Questions:
1. Define Power signal?
2. Define Energy signal?
3. Find the energy of a power signal?
4. Find the power of aa energy signal?
5. Define causal system?

Result:-Thus the MATLAB program for calculating energy and power of a given signal was
performed and the output was verified.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

INFERENCE:

APPLICATIONS:

(To be filled by faculty)


Marks Remarks:
Category
awarded

Observation

Regularity

Experiment Conduction &


Behavior

Viva-Voce

Record Date of Submission:

Total: Signature of the faculty:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

CONVOLUTION and CORRELATION

Aim :To write the Convolution and Correlation (auto and cross correlation) of discrete sequences without
using built in functions for convolution and correlation operations.

% MATLAB program for linear convolution

%linear convolution program

clc;

clear all;

close all;

disp('linear convolution program');

x=input('enter i/p x(n):');

m=length(x);

h=input('enter i/p h(n):');

n=length(h);

x=[x,zeros(1,n)];

subplot(2,2,1), stem(x);

title('i/p sequence x(n)is:');

xlabel('---->n');

ylabel('---->x(n)');grid;

h=[h,zeros(1,m)];

subplot(2,2,2), stem(h);

title('i/p sequence h(n)is:');

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

xlabel('---->n');

ylabel('---->h(n)');grid;

disp('convolution of x(n) & h(n) is y(n):');

y=zeros(1,m+n-1);

for i=1:m+n-1

y(i)=0;

for j=1:m+n-1

if(j<i+1)

y(i)=y(i)+x(j)*h(i-j+1);

end

end

end

subplot(2,2,[3,4]),stem(y);

title('convolution of x(n) & h(n) is :');

xlabel('---->n');

ylabel('---->y(n)');grid;

Output:

Enter the i/p sequence x(n): [ 1 2 3 4 5]

Enter the i/p sequence h(n): [ 1 2 ]

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Convolution 0f x(n) &h(n) is y(n): [ 2 4 7 10 14 10]

Result:

Thus the Linear Convolution is determined successfully by using MATLAB software.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

%circular convolution program


clc;
clear all;
close all;
disp('circular convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p sequence h(n)');
n=length(h);
subplot(2,2,1), stem(x);
title('i/p sequencce x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
subplot(2,2,2), stem(h);
title('i/p sequencce h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('circular convolution of x(n) & h(n) is y(n):');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;
end
y=zeros(1,n);
y(1)=0;
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%ciruclarconv
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)
a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

end
end
end
disp(y);
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y(n)');grid;

OUTPUT:-

Enter the i/p sequence x(n): [ 1 2 3 4 ]

Enter the i/p sequence h(n): [ 1 2 3]

Convolution 0f x(n) &h(n) is y(n): [ 18 16 10 16]

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Thus the Circular Convolution is determined successfully by using MATLAB software.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Autocorrelation And Cross Correlation


Aim: To perform auto- correlation and cross- correlation of given sequences in
MATLAB.

Program:
%Auto Correlation%
x= input (‘Enter any sequence’);
subplot(3,2,1);
stem(x);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Input sequence’);
y=xcorr(x);
subplot(3,2,2);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Auto correlation’);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Program:

%Cross correlation%
x=input(‘Enter any sequence’);
subplot(3,2,1);
stem(x);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Input sequence’);
h=input(‘Enter any sequence’);
subplot(3,2,2);
stem(h);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Impulse sequence’);
y=xcorr(x,h);
subplot(3,2,3);
stem(y);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Cross correlation’);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

QUESTIONS:
1. Define Convolution
2. Define Correlation
3. Give applications of convolution and correlation
4. Define auto-correlation?
5. Define cross-correlation?
6. Define linear convolution?
7. Define circular convolution?
8. Define circular convolution with zero padding?
9. Find the length of the linear convolution sequence?
10. Find the length of the circular convolution sequence

Result:
Thus, the auto- correlation and cross- correlation was performed using
MATLAB

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

INFERENCE:

APPLICATIONS:

(To be filled by faculty)


Marks Remarks:
Category
awarded

Observation

Regularity

Experiment Conduction &


Behavior

Viva-Voce

Record Date of Submission:

Total: Signature of the faculty:

DTFT of a given signal

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Aim: To write a MATLAB program to find the DTFT of a given sequence.

PROGRAM:

% Write a MATLAB program to find the DTFT of a given sequence.


x=input('Enter the sequence : ');
N=length(x);
n=0:N-1
K=0:N-1
wn=exp(-j*2*pi/N);
nK=n'*K;
wNnK=wn.^nK;
df=x*wNnK;
subplot(2,1,1);
%subplot(3,1,1);
stem(x,abs(df));
title('DTFT');
xlabel('K');
ylabel('Magnitude');
subplot(2,1,2);
%subplot(3,1,2);
stem(x,angle(df));
title('DTFT');
xlabel('K');
ylabel('phase');

%Inverse DTFT
wn1=exp(j*2*pi/N);
nK1=n'*K;
wN1nK1=wn1.^nK1;
inversdf=(df*wN1nK1)/N;
subplot(3,1,3);
stem(x,abs(inversdf));
title('Inverse DTFT');
xlabel('N');
ylabel('Magnitude');

OUTPUT: Enter the sequence: [1 2 3 4 5 6 7 8]

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

QUESTIONS:
1. Define DTFT?
2. Define IDTFT?
3. Discuss DTFT pair?
4. Write the symmetry property of DTFT?
5. What is ideal reconstruction filter?
6. What is reconstruction signal?

Result:
Thus, the DTFT Of a given signal was performed successfully by using
MATLAB software

N-Point FFT

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

AIM: To determine the FFT by using MATLAB software.

EQUIPMENTS:

Operating System – Windows XP

Constructor - Simulator

Software - MATLAB 7.5

THEORY:

The Fast Fourier Transform is useful to map the time-domain sequence


into a continuous function of a frequency variable. The FFT of a
sequence {x(n)} of length N is given by a complex-valued sequence X(k).

M nk
−j 2π
X ( k )=∑ x ( n) e n
; 0<k < N −1
k=0
The above equation is the mathematical representation of the DFT. As the
number of computations involved in transforming a N point time domain
signal into its corresponding frequency domain signal was found to be N2
complex multiplications, an alternative algorithm involving lesser
number of computations is opted.

When the sequence x(n) is divided into 2 sequences and the DFT performed
separately, the resulting number of computations would be N2/2

(i.e.)

N
2 N2
2−1 2−1
x ( k )=∑ x (2 n ) W 2Nnk + ∑ x ( 2 n+1 ) W (2
N
n+1 )k

n=0 n=0

Consider x(2n) be the even sample sequences and x(2n+1) be the odd
sample sequence derived form x(n).

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

N2
2−1
∑ x ( 2 n) W 2nk
N
n=0

would result

N2
2−1
∑ x (2 n+1) W (N2 n+1 )k
(N/2)2multiplication’s n=0

an other (N/2)2 multiplication's finally resulting in (N/2)2 + (N/2)2


2 2
N2 N N
+ = Computations
= 4 4 2

Further solving Eg. (2)

N2 N
2−1 2−1 k
x ( k )= ∑ x ( 2 n) W 2nk
N + ∑ x( 2 n+1 ) W (2 nk )
N W
n=0 n=0 N
(9)

N N
2−1 k 2−1
= ∑ x ( 2 n ) W 2Nnk +W ∑ x ( 2 n+1) W (N2 nk)
n=0 N n=0 (10)

Dividing the sequence x (2n) into further 2 odd and even sequences would reduce the
computations.

WN is the twiddle factor

− j2 π
n
=e

nk
W =e
( n )
− j 2π
nk
N

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

W
( K+ )
N
2
=W W
( K+ )
N
2
N N N
(11)

− j2 π − j 2π n
k
n n 2
=e e

−j2π
k
=W kN e n

=W kN (cos π − j sin π )

=W
( K+ )
N
2
=W k (−1)=W
( K+ )
N
2
=W k
N N N N

Employing this equation, we deduce

N2 N
2−1 2−1
x ( k )= ∑ x ( 2 n) W 2nk
N + ∑ x( 2 n+1 ) W N
(2 nk )

n=0 n=0 (13)

N
2−1 K N
N
x ( k + )= ∑ x ( 2 n) W 2Nnk −W ∑ x ( 2 n+1 ) 2−1 W (N2 nk)
2 n=0 N (14)

The time burden created by this large number of computations limits the usefulness of
DFT in many applications. Tremendous efforts devoted to develop more efficient ways of computing
DFT resulted in the above explained Fast Fourier Transform algorithm. This mathematical shortcut
reduces the number of calculations the DFT requires drastically. The above mentioned radix-2
decimation in time FFT is employed for domain transformation.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Dividing the DFT into smaller DFTs is the basis of the FFT. A radix-2 FFT divides the DFT into two
smaller DFTs, each of which is divided into smaller DFTs and so on, resulting in a combination of
two-point DFTs. The Decimation -In-Time (DIT) FFT divides the input (time) sequence into two
groups, one of even samples and the other of odd samples. N/2 point DFT are performed on the
these sub-sequences and their outputs are combined to form the N point DFT.

FIG. 3A.1

The above shown mathematical representation forms the basis of N point FFT and is called theButterfly
Structure.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

FIG. – 8 POINT DIT

%fast fourier transform

clc;

clear all;

close all;

tic;

x=input('enter the sequence');

n=input('enter the length of fft');

%compute fft

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

disp('fourier transformed signal');

X=fft(x,n)

subplot(1,2,1);stem(x);

title('i/p signal');

xlabel('n --->');

ylabel('x(n) -->');grid;

subplot(1,2,2);stem(X);

title('fft of i/p x(n) is:');

xlabel('Real axis --->');

ylabel('Imaginary axis -->');grid;

output:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

QUESTIONS:
1. Define FFT?
2. Define DFT?
3. Discuss DITFFT?
4. Discuss DIFFFT?
5. What is radix-2 FFT?
6. What is radix-4 FFT?
7. What is radix-8 FFT?
8. What is radix-16 FFT?

Result:
Thus, the FFT Of a given signal was performed successfully by using
MATLAB software

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Thus The N-point FFT is performed successfully by using MATLAB software.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

FIR filters

AIM: Design the FIR filter using windowing technique and verify the frequency response of the
Filter by using MATLAB software.

EQUIPMENTS:

Operating System – Windows XP

Constructor - Simulator

Software - MATLAB 7.5

THEORY:

A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system

whose output is based on the weighted summation of a finite number of past inputs.

The coefficients are generated by using FDS (Filter Design Software or Digital filter design package).

FIR – filter is a finite impulse response filter. Order of the filter should be specified.

Infinite response is truncated to get finite impulse response. placing a window of

finite length does this. Types of windows available are Rectangular, Barlett,

Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter.

PROGRAM:

%fir filt design window techniques

clc;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

clear all;

close all;

rp=input('enter passband ripple');

rs=input('enter the stopband ripple');

fp=input('enter passbandfreq');

fs=input('enter stopbandfreq');

f=input('enter sampling freq ');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end

c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');

if(c==1)

y=rectwin(n1);

disp('Rectangular window filter response');

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

end

if (c==2)

y=triang(n1);

disp('Triangular window filter response');

end

if(c==3)

y=kaiser(n1);

disp('kaiser window filter response');

end

%LPF

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);plot(o/pi,m);

title('LPF');

ylabel('Gain in dB-->');

xlabel('(a) Normalized frequency-->');

%HPF

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

m=20*log10(abs(h));

subplot(2,2,2);plot(o/pi,m);

title('HPF');

ylabel('Gain in dB-->');

xlabel('(b) Normalized frequency-->');

%BPF

wn=[wpws];

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);plot(o/pi,m);

title('BPF');

ylabel('Gain in dB-->');

xlabel('(c) Normalized frequency-->');

%BSF

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);plot(o/pi,m);

title('BSF');

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

ylabel('Gain in dB-->');

xlabel('(d) Normalized frequency-->');

OUTPUT:-

Enter passband ripple: 0.02

Enter stopband ripple: 0.01

Enter passband frequency:1000

Enter stopband frequency:1500

Enter sampling frequency :10000

Enter your choice of window function

1.Rectangular 2.Triangular 3.Kaiser

Rectangular window filter response

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Triangular window filter response

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Kaiser window response

QUESTIONS:
1. Define FIR filter?
2. Define IIR filter?
3. Define Kaiser window?
4. Define Rectangular window?
5. Define Triangular window?

Result:
Thus, the FIR filters is verified and implemented successfully by using MATLAB software

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

IIR filters

AIM: . Design the IIR filter using any of the available methods and verify the frequency response
of the filters by using MATLAB software.

EQUIPMENTS:

Operating System – Windows XP

Constructor - Simulator

Software - MATLAB 7.5

THEORY:

The IIR filter can realize both the poles and zeroes of a system because it has arational transfer function, de
scribed by polynomials in z in both the numerator andthe denominator .These filter coefficients are genera
ted using FDS (Filter Design software or Digital Filter design package).

IIR filters can be expanded as infinite impulse response filters. In designing IIRfilters, cutoff frequencies of t
he filters should be mentioned. The order of the filter

can be estimated using butter worth polynomial. That’s why the filters are named as

butter worth filters. Filter coefficients can be found and the response can be plotted.

PROGRAM :

% IIR filters LPF & HPF

clc;

clear all;

close all;

disp('enter the IIR filter design specifications');

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

rp=input('enter the passband ripple');

rs=input('enter the stopband ripple');

wp=input('enter the passband freq');

ws=input('enter the stopband freq');

fs=input('enter the sampling freq');

w1=2*wp/fs;w2=2*ws/fs;

[n,wn]=buttord(w1,w2,rp,rs,'s');

c=input('enter choice of filter 1. LPF 2. HPF \n ');

if(c==1)

disp('Frequency response of IIR LPF is:');

[b,a]=butter(n,wn,'low','s');

end

if(c==2)

disp('Frequency response of IIR HPF is:');

[b,a]=butter(n,wn,'high','s');

end

w=0:.01:pi;

[h,om]=freqs(b,a,w);

m=20*log10(abs(h));

an=angle(h);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

figure,subplot(2,1,1);plot(om/pi,m);

title('magnitude response of IIR filter is:');

xlabel('(a) Normalized freq. -->');

ylabel('Gain in dB-->');

subplot(2,1,2);plot(om/pi,an);

title('phase response of IIR filter is:');

xlabel('(b) Normalized freq. -->');

ylabel('Phase in radians-->');

Output:

Enter the IIR filter design specifications

Enter passband ripple: 0.15

Enter stopband ripple: 60

Enter passband frequency:1500

Enter stopband frequency:3000

Enter sampling frequency :7000

Enter the choice of the Filter 1.LPF 2.HPF

Frequency response of IIR LPF is:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Enter the IIR filter design specifications

Enter passband ripple: 0.15

Enter stopband ripple: 60

Enter passband frequency:1500

Enter stopband frequency:3000

Enter sampling frequency :7000

Enter the choice of the Filter 1.LPF 2.HPF

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Frequency response of IIR HPF is

QUESTIONS:
1. Define FIR filter?
2. Define IIR filter?
3. Define Butterworth filter?
4. Define Chebychev filter?
5.

Result:
Thus, the IIR filters is verified and implemented successfully by using MATLAB software

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Frequency response of Analog LPF/ HPF


Aim:
To Design Chebyshev IIR filter using Matlab

Program:
%LPF%
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
wp=input('enter the pass band frequency');
ws=input('enter the stop band frequency');
fs=input('enter the sampling frequency');
w1=2*(wp/fs);
w2=2*(ws/fs);
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:0.01/pi:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,1);
plot((om/pi),m);
xlabel('time');
ylabel('amplitude');
title('magnitude plot of lpf');
subplot(2,2,2);
plot((om/pi),an);
xlabel('time');
ylabel('amplitude');
title('angle plot of lpf');

LOW PASS FILTER


Enter the pass band ripple=0.5
Enter the stop band ripple=50
Enter the pass band frequency=1500
Enter the stop band frequency=2500
Enter the sampling frequency=7500

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

%HPF%
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
wp=input('enter the pass band frequency');
ws=input('enter the stop band frequency');
fs=input('enter the sampling frequency');
w1=2*(wp/fs);
w2=2*(ws/fs);
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0:0.01/pi:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,1);
plot((om/pi),m);
xlabel('time');
ylabel('amplitude');
title('magnitude plot of hpf');
subplot(2,2,2);
plot((om/pi),an);
xlabel('time');
ylabel('amplitude');

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

title('angle plot of hpf');

HIGH PASS FILTER


Enter the pass band ripple=0.5
Enter the stop band ripple=50
Enter the pass band frequency=1500
Enter the stop band frequency=2500
Enter the sampling frequency=7500

Result:
Thus, the Chebyshev filter was designed using Mat Lab

AIM: To verify the frequency response of analog LPF/ HPF using MATLAB soft ware

EQUIPMENTS:

Operating System – Windows XP

Constructor - Simulator

Software - MATLAB 7.5

THEORY:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Analog Low pass filter & High pass filter are obtained by using butterworth or chebyshev filter with
coefficients are given. The frequency – magnitude plot gives the frequency response of the filter.

PROGRAM:

% IIR filters LPF & HPF

clc;

clear all;

close all;

warning off;

disp('enter the IIR filter design specifications');

rp=input('enter the passband ripple');

rs=input('enter the stopband ripple');

wp=input('enter the passbandfreq');

ws=input('enter the stopbandfreq');

fs=input('enter the sampling freq');

w1=2*wp/fs;w2=2*ws/fs;

[n,wn]=buttord(w1,w2,rp,rs,'s');

c=input('enter choice of filter 1. LPF 2. HPF \n ');

if(c==1)

disp('Frequency response of IIR LPF is:');

[b,a]=butter(n,wn,'low','s');

end

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

if(c==2)

disp('Frequency response of IIR HPF is:');

[b,a]=butter(n,wn,'high','s');

end

w=0:.01:pi;

[h,om]=freqs(b,a,w);

m=20*log10(abs(h));

an=angle(h);

figure,subplot(2,1,1);plot(om/pi,m);

title('magnitude response of IIR filter is:');

xlabel('(a) Normalized freq. -->');

ylabel('Gain in dB-->');

subplot(2,1,2);plot(om/pi,an);

title('phase response of IIR filter is:');

xlabel('(b) Normalized freq. -->');

ylabel('Phase in radians-->');

Output:

Enter the IIR filter design specifications

Enter passband ripple: 1

Enter stopband ripple: 15

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Enter passband frequency:0.2*pi

Enter stopband frequency:0.3*pi

Enter sampling frequency :10

Enter the choice of the Filter 1.LPF 2.HPF

Frequency response of Analog LPF is:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Thus The frequency response of analog LPF/ HPF is performed successfully by using MATLAB
software.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

DSP Processor Experiments(PART – B)

DSP TMS 320C 67XX using CCS

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

1(a)INTRODUCTION TO DSP PROCESSORS

A signal can be defined as a function that conveys information, generally about the state
or behavior of a physical system. There are two basic types of signals viz Analog (continuous
time signals which are defined along a continuum of times) and Digital (discrete-time)..

Remarkably, under reasonable constraints, A continuous time signal can be adequately


represented by samples, obtaining discrete time signals. Thus digital signal processing is an ideal
choice for anyone who needs the performance advantage of digital manipulation along with
today’s analog reality.

Hence a processor which is designed to perform the special operations(digital


manipulations) on the digital signal within very less time can be called as a Digital signal
processor. The difference between a DSP processor, conventional microprocessor and a
microcontroller are listed below.

Microprocessor or General Purpose Processor such as Intel xx86 or Motorola 680xx family

Contains - only CPU

-No RAM

-No ROM

-No I/O ports

-No Timer

Microcontroller such as 8051 family Contains - CPU

- RAM

- ROM

- I/O ports

- Timer &

- Interrupt circuitry

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Some Micro Controllers also contain A/D, D/A and Flash Memory

DSP Processors such as Texas instruments and Analog Devices Contains - CPU

- RAM

-ROM

- I/O ports

- Timer

Optimized for – fast arithmetic

- Extended precision

- Dual operand fetch

- Zero overhead loop

- Circular buffering

The basic features of a DSP Processor are

Feature Use

Fast-Multiply accumulate Most DSP algorithms, including


filtering, transforms, etc. are
multiplication- intensive

Multiple – access memory Many data-intensive DSP operations


architecture require reading a program instruction
and multiple data items during each
instruction cycle for best performance

Specialized addressing modes Efficient handling of data arrays and

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

first-in, first-out buffers in memory

Specialized program control Efficient control of loops for many


iterative DSP algorithms. Fast interrupt
handling for frequent I/O operations.

On-chip peripherals and I/O On-chip peripherals like A/D converters


interfaces allow for small low cost system designs.
Similarly I/O interfaces tailored for
common peripherals allow clean
interfaces to off-chip I/O devices.

1(b) ARCHITECTURE OF 6713 DSP PROCESSOR

This chapter provides an overview of the architectural structure of the TMS320C67xx


DSP, which comprises the central processing unit (CPU), memory, and on-chip peripherals. The
C67xE DSPs use an advanced modified Harvard architecture that maximizes processing power
with eight buses. Separate program and data spaces allow simultaneous access to program
instructions and data, providing a high degree of parallelism. For example, three reads and one
write can be performed in a single cycle. Instructions with parallel store and application-specific
instructions fully utilize this architecture. In addition, data can be transferred between data and
program spaces. Such Parallelism supports a powerful set of arithmetic, logic, and bit-
manipulation operations that can all be performed in a single machine cycle. Also, the C67xx
DSP includes the control mechanisms to manage interrupts, repeated operations, and function
calling.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Fig1 :BLOCK DIAGRAM OF TMS 320VC 6713

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Bus Structure

The C67xx DSP architecture is built around eight major 16-bit buses (four program/data buses
and four address buses):

1. The program bus (PB) carries the instruction code and immediate operands from program
memory.

2. Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU,
data address generation logic, program address generation logic, on-chip peripherals, and data
memory.

3. The CB and DB carry the operands that are read from data memory.

4. The EB carries the data to be written to memory.

5. Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for instruction
execution.

The C67xx DSP can generate up to two data-memory addresses per cycle
using the two auxiliary register arithmetic units (ARAU0 and ARAU1). The PB can carry data
operands stored in program space (for instance, a coefficient table) to the multiplier and adder for
multiply/accumulate operations or to a destination in data space for data move
instructions(MVPD and READA). This capability, in conjunction with the feature of dual-
operand read, supports the execution of single-cycle, 3-operand instructions such as the FIRS
instruction. The C67xx DSP also has an on-chip bidirectional bus for accessing on-chip
peripherals. This bus is connected to DB and EB through the bus exchanger in the CPU interface.
Accesses that use this bus can require two or more cycles for reads and writes, depending on the
peripheral’s structure.

Central Processing Unit (CPU)

The CPU is common to all C67xE devices. The C67x CPU contains:

 40-bit arithmetic logic unit (ALU)


 Two 40-bit accumulators

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

 Barrel shifter
 17 × 17-bit multiplier
 40-bit adder
 Compare, select, and store unit (CSSU)
 Data address generation unit
 Program address generation unit
Arithmetic Logic Unit (ALU)

The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit (ALU)
and two 40-bit accumulators (accumulators A and B). The ALU can also perform Boolean
operations. The ALU uses these inputs:

 16-bit immediate value


 16-bit word from data memory
 16-bit value in the temporary register, T
 Two 16-bit words from data memory
 32-bit word from data memory
 40-bit word from either accumulator
The ALU can also function as two 16-bit ALUs and perform two 16-bit operations
simultaneously.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Fig2 :ALU UNIT

Accumulators

Accumulators A and B store the output from the ALU or the multiplier/adder block. They can
also provide a second input to the ALU; accumulator A can be an input to the multiplier/adder.
Each accumulator is divided into three parts:

o Guard bits (bits 39–32)


o High-order word (bits 31–16)
o Low-order word (bits 15–0)

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Instructions are provided for storing the guard bits, for storing the high- and the low-order
accumulator words in data memory, and for transferring 32-bit accumulator words in or out of
data memory. Also, either of the accumulators can be used as temporary storage for the other.

Barrel Shifter

The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to data memory
(using CB or DB), and a 40-bit output connected to the ALU or to data memory (using EB). The
barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0 to 16 bits on the input
data. The shift requirements are defined in the shift count field of the instruction, the shift count
field (ASM) of status register ST1, or in temporary register T (when it is designated as a shift
count register).The barrel shifter and the exponent encoder normalize the values in an
accumulator in a single cycle. The LSBs of the output are filled with 0s, and the MSBs can be
either zero filled or sign extended, depending on the state of the sign-extension mode bit (SXM)
in ST1. Additional shift capabilities enable the processor to perform numerical scaling, bit
extraction, extended arithmetic, and overflow prevention operations.

Multiplier/Adder Unit

The multiplier/adder unit performs 17 _ 17-bit 2s-complement multiplication with a 40-bit


addition in a single instruction cycle. The multiplier/adder block consists of several elements: a
multiplier, an adder, signed/unsigned input control logic, fractional control logic, a zero detector,
a rounder (2s complement), overflow/saturation logic, and a 16-bit temporary storage register
(T). The multiplier has two inputs: one input is selected from T, a data-memory operand, or
accumulator A; the other is selected from program memory, data memory, accumulator A, or an
immediate value. The fast, on-chip multiplier allows the C54x DSP to perform operations
efficiently such as convolution, correlation, and filtering. In addition, the multiplier and ALU
together execute multiply/accumulate (MAC) computations and ALU operations in parallel in a
single instruction cycle. This function is used in determining the Euclidian distance and in

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

implementing symmetrical and LMS filters, which are required for complex DSP algorithms.

Fig3 :MULTIPLIER/ADDER UNIT

These are the some of the important parts of the processor and you are instructed to go through
the detailed architecture once which helps you in developing the optimized code for the required
application.

1(c) CODE COMPOSER STUDIO

Code composer studio is used to build and debug embedded real time
software applications. Code composer studio setup establishes the interface that allows code
composer studio to communicate with target board or simulator .all windows (except edit
windows) and all toolbars are dockable within the code composer studio environment. hence we
can move and align a window or toolbar t o any portion of code composer studio main window.
we can also move dockable windows and toolbars out of the code composer studio main window
and place them any where on the desktop. all code composer studio windows contain context
menus. to open a context menu right click with in the window. context menus provide a list of
options and/or commands that can be applied to that particular window.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

When program is loaded on to the target r simulator ,the code composer studio
debugger automatically opens a dis-assembly window. the dis-assembly window displays
dis-assembly instructions & symbolic information needed for debugging .for each assembly
language instruction, the dis-assembly window displays dis-assembled instructions. the address
at which the instruction is located, and corresponding opcodes. in addition to this dis-assembled
instructions in dis-assembly window ,the code composer studio debugger enables us to view the
C source code interleaved with dis-assembly code..

We can edit the memory locations’ in any one of the following ways.

1.in the memory window ,double click on the data you which to edit.

2. select the edit memory edit command

Both of these methods open the edit memory dialog box.

Code composer studio represents an advanced signal analysis interface that


enables developers to monitor signal data critically and thoroughly .the new features are useful in
developing applications for communications, wireless, image processing as well as general DSP
applications. the graph menu contains many o-ptions that allow us to be flexible in how we
display the data. We can use a time/frequency graph to view signals in either time/frequency
domain.the memory map tell the code composer studio debugger which areas of memory it can
and cannot access. Typically the amp matches the memory definition in the linker command
file.the watch window allows us to examine and edit variables and C expressions, in the watch
window, we can expand and collapse complex expressions. we can also evaluate terms and
display results in different formats. the quick watch feature allows to quickly adding variables to
the watch window. code composer studio provides integrated program management that is
needed to build a target program or library.

Project Records:--

a)file names of source code and object libraries

b) compiler,assembler and linker options

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

c) include file dependencies

Code composer studio allows to collect execution statistics about the specific areas in the code
which is called profiting.

PROCEDURE:

1.to run the CCS code software go to start programs

Texas instruments and then code composer studio.

2.in the setup code composer select functional little Indian,import,save and quit.

3.go to project, new and give the file name.

4.go to file ,new and source file

5.give or write the code in C language

6.go to file and save it.

7.go to C drive

ti

my projects

name

new name .C and save it.

8.go to project

Add files to project and select the program written

9.go to project and add files to the project

10. go to C drive.

ti

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

C600

cgtolls

lib

rts 6700.lib

11.go to C drive

ti

tutorial

disk 6711

hello 1—C file of type should be linker command file

12. go to command files

Hello.cmd

13. go to, project then compile file

14. go to, project then build

15.Go to file

Load program

Open the file.in the window displayed the 1 st column we have address of memory and in the 2 nd
column opcodes.

16. go to dubug and run the program

17. view

Graphs

Time/frequency

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

CONVOLUTION USING “C”

Convolution and Correlation (auto and cross correlation) of discrete sequences without using
built in functions for convolution and correlation operations.

1.LINEAR CONVOLUTION USING “C”

AIM: To determine the Linear Convolution by writing ‘c’ program using DSP Kit with CCS software.

EQUIPMENT:

Operating System – Windows XP

Constructor- Simulator

Software - PC with 6713 CC studio 3.0 software

Hardware - DSP C67XX.

Cable - USB connecting cable.

Supply - Power Chord.

THEORY

Convolution is a formal mathematical operation, just as multiplication, addition, and


integration. Addition takes two numbers and produces a third number, while convolution
takes two signals and produces a third signal. Convolution is used in the mathematics of many
fields, such as probability and statistics. In linear systems, convolution is used to describe the
relationship between three signals of interest: the input signal, the impulse response, and the
output signal.

In this equation, x1(k), x2 (n-k) and y(n) represent the input to and output from the system at
time n. Here we could see that one of the input is shifted in time by a value everytime it is

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

multiplied with the other input signal. Linear Convolution is quite often used as a method of
implementing filters of various types.

PROCEDURE:-
The following are the steps for the Code Composer Studio:

1. Open Code Composer Studio and make sure DSP kit is Switched ON
2. To create the New Project
Project→ New (File Name. pjt, Eg: Vectors.pjt)

3. To create a Source file


File →New→ Type the code (Save & give file name, Eg: sum.c).

4. To Add Source files to Project


Project→ Add files to Project→ sum.c

5. To Add run time support library file rts.lib file & linker command file Hello.cmd:
Project→ Add files to Project→ rts6700.lib

Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)

Note: Select Object& Library in (*.o,*.l) in Type of files

Project→ Add files to Project→hello.cmd

CMD file- Which is common for all non real time programs.

(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)

Note: Select Linker Command file (*.cmd) in Type of files

6. Compile
To Compile: Project→ Compile

To Rebuild: project → rebuild,

Which will create the final .out executable file. (Eg.Vectors.out).

7. Procedure to Load and Run program:


Load the Program to DSK: File→ Load program →Vectors.out

To Execute project: Debug → Run

8. Observe the output using graph utility


To View the graph graphically: View → Graph →time and frequency

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Precautions:

1) Switch ON the computer only after connecting USB cable and make sure the DSP kit is ON.

2) Perform the diagnostic check before opening code composer studio.

3) All the connections must be tight.

PROGRAM:

#include<stdio.h>
intx[15],h[15],y[15];
main()
{
inti,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 h(n): \n");
for(i=0;i<n;i++)
scanf("%d",&h[i]);
for(i=m;i<=m+n-1;i++)
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]);
}

Output:

enter value for m4

enter value for n4

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Enter values for i/p

1234

Enter Values for n

1234

The Value of output y[0]=1

The Value of output y[1]=4

The Value of output y[2]=10

The Value of output y[3]=20

The Value of output y[4]=25

The Value of output y[5]=24

The Value of output y[6]=16

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Thus the Linear Convolution is determined successfully by writing ‘c’ program and using DSP Kit.

2.CIRCULAR CONVOLUTION USING “C”

AIM: To determine the Circular Convolution by writing ‘c’ program using DSP Kit and using CCS software.

EQUIPMENTS:

Operating System – Windows XP

Constructor - Simulator

Software - PC with 67XX CC studio 3.0 software

Hardware - DSP C67XX Kit.

Cable - USB connecting cable.

Supply - Power Chord.

THEORY

Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is folded and right
shifted before the convolution sum is found. Also note that circular convolution could also be found by taking
the DFT of the two input signals and finding the product of the two frequency domain signals. The Inverse DFT of
the product would give the output of the signal in the time domain which is the circular convolution output. The
two input signals could have been of varying sample lengths. But we take the DFT of higher point, which ever
signals levels to. For eg. If one of the signal is of length 256 and the other spans 51 samples, then we could only
take 256 point DFT. So the output of IDFT would be containing 256 samples instead of 306 samples, which
follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the two inputs. Thus the output
which should have been 306 samples long is fitted into 256 samples. The 256 points end up being a distorted
version of the correct signal. This process is called circular convolution.

PROCEDURE:-
The following are the steps for the Code Composer Studio:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

1. Open Code Composer Studio and make sure DSP kit is Switched ON
2. To create the New Project
Project→ New (File Name. pjt, Eg: Vectors.pjt)

3. To create a Source file


File →New→ Type the code (Save & give file name, Eg: sum.c).

4. To Add Source files to Project


Project→ Add files to Project→ sum.c

5. To Add run time support library file rts.lib file & linker command file Hello.cmd:
Project→ Add files to Project→ rts6700.lib

Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)

Note: Select Object& Library in (*.o,*.l) in Type of files

Project→ Add files to Project→hello.cmd

CMD file- Which is common for all non real time programs.

(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)

Note: Select Linker Command file (*.cmd) in Type of files

6. Compile
To Compile: Project→ Compile

To Rebuild: project → rebuild,

Which will create the final .out executable file. (Eg.Vectors.out).

7. Procedure to Load and Run program:


Load the Program to DSK: File→ Load program →Vectors.out

To Execute project: Debug → Run

8. Observe the output using graph utility


To View the graph graphically: View → Graph →time and frequency

Precautions:

1) Switch ON the computer only after connecting USB cable and make sure the DSP kit is ON.

2) Perform the diagnostic check before opening code composer studio.

3) All the connections must be tight.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

PROGRAM:

/* prg to implement circular convolution */

#include<stdio.h>
intm,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*/
{
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];

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

/*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]);
}

OUTPUT:-

Enter the first sequence

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Enter the second sequence

the circular convolution is

94 110 122 106

Result:

Thus the Circular Convolution is perfomed successfully by writing ‘c’ program and using DSP Kit.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Auto Correlation

Aim: To perform Auto Correlation on signals Using TMS 320 Floating point DSP.
Apparatus: PC with CCS V5

TMS 320C67XX Floating point DSP Kit

Program:

#include<stdio.h>

#include<math.h>

#define PI 3.14

#define PTS 512

void delay1();

void sinewave(float fm1, float fc1, int no, int result);

float x[PTS]; //INPUT ARRAY

float y[PTS];

float z[PTS]; //OUTPUT ARRAY

void main()

int i,j;

for (i = 0 ; i < PTS ; i++)

sinewave(100, 8000, i, 0);

//x[i] = sin(2 * PI * 100 * i / 8000.0);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

y[i]=0.0;

for(i=0 ; i< PTS ; i++)

for(j = 1 ; j < (PTS-i+1) ;j++)

y[i]=y[i]+x[j]*x[j+i-1];

z[i]=y[i]/(PTS);

//printf("\n%f",z[i]);

void sinewave(float fm1, float fc1, int no, int result)

float m;

float n;

delay1();

delay1();

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

m = 6.28 * fm1 * no;

delay1();

delay1();

n = (m / fc1);

delay1();

delay1();

if(result == 0)

delay1();

x[no]= sin(n);

delay1();

delay1();

delay1();

void delay1()

int y=150;

while(y!=0)

y--;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

To generate graph:

For auto correlation

 Generate a sample sine wave as a input named as x.

Final output of auto correlation named as z.

To view input / output graphically,

Go to Tools -> graph -> dual time.

Graph setting & graph as follows.

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

N-Point FFT

Aim: To perform N-Point FFT on Sequences Using TMS 320 Floating point DSP.
Apparatus: PC with CCS V5

TMS 320C67XX Floating point DSP Kit

Program:

#include<stdio.h>

//#include<conio.h>

#include<math.h>

#define PI 3.14

typedef struct

float real,imag;

}com;

void main()

com xx[8],x[8],temp[8],temp1[8],y[8],a[8],b[8],w[4];

int i,j=0;//loop counter variables

// printf("Enter the no of pionts of FFT==");

// scanf("%d", &PTS);

printf("\nEnter values==");

for(i=0;i<8;i++)

scanf("%f",&xx[i].real);

scanf("%f",&xx[i].imag);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

j=0;

for(i=0;i<8;i=i+2)

x[j].real=xx[i].real;

x[j].imag=xx[i].imag;

x[j+1].real=xx[i+4].real;

x[j+1].imag=xx[i+4].imag;

if(i==2)

i=-1;

j=j+2;

for(i=0;i<4;i++)

w[i].real=cos(2*PI*i/8);

w[i].imag=-sin(2*PI*i/8);

for(i=0;i<8;i=i+2)

temp[i].real=x[i].real+x[i+1].real;

temp[i].imag=x[i].imag+x[i+1].imag;

temp[i+1].real=x[i].real-x[i+1].real;

temp[i+1].imag=x[i].imag-x[i+1].imag;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

for(i=2;i<8;i=3*i)

a[i].real=temp[i].real*w[0].real-temp[i].imag*w[0].imag;

a[i].imag=temp[i].real*w[0].imag+temp[i].imag*w[0].real;

a[i+1].real=temp[i+1].real*w[2].real-temp[i+1].imag*w[2].imag;

a[i+1].imag=temp[i+1].real*w[2].imag+temp[i+1].imag*w[2].real;

temp[i].real=a[i].real;

temp[i].imag=a[i].imag;

temp[i+1].real=a[i+1].real;

temp[i+1].imag=a[i+1].imag;

for(i=0;i<6;i++)

temp1[i].real=temp[i].real+temp[i+2].real;

temp1[i].imag=temp[i].imag+temp[i+2].imag;

temp1[i+2].real=temp[i].real-temp[i+2].real;

temp1[i+2].imag=temp[i].imag-temp[i+2].imag;

if(i==1)

i=3;

for(i=4;i<8;i++)

b[i].real=temp1[i].real*w[i-4].real-temp1[i].imag*w[i-4].imag;

b[i].imag=temp1[i].real*w[i-4].imag+temp1[i].imag*w[i-4].real;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

temp1[i].real=b[i].real;

temp1[i].imag=b[i].imag;

for(i=0;i<4;i++)

y[i].real=temp1[i].real+temp1[i+4].real;

y[i].imag=temp1[i].imag+temp1[i+4].imag;

y[i+4].real=temp1[i].real-temp1[i+4].real;

y[i+4].imag=temp1[i].imag-temp1[i+4].imag;

printf("\nFFT values==\n");

for(i=0;i<8;i++)

printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].imag);

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Sine wave Generation

Aim: To generate Sine wave Using TMS 320 Floating point DSP.

Apparatus: PC with CCS V5

TMS 320C67XX Floating point DSP Kit

Program:

#include "VSK_6748.h"

#include <math.h>

#define SPIFLASH_SPI (SPI1)

#define SPIFLASH_SPI0 (SPI0)

#define PI 3.14;

int main(void)

int count; // declare variables

int nSamp;

int fi=1000; //input frequency

short *sin_out,val;

const float fSamp = 100000.0; //sampling frequency

float tSamp;

double ang;

spi_regs_t *spi=SPIFLASH_SPI0;

spi_regs_t *spi1=SPIFLASH_SPI;

uint32_t spi_data1 = spi->SPIDAT1;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

sin_out = (short *)0x80001000; // output buffer

nSamp = fSamp / fi; //no. of samples

tSamp = 1 / fSamp; // sampling time

for (count = 0; count < nSamp; count++)

ang = (2 * 3.14 * fi * tSamp * count); // sine wave generation formula

sin_out[count] = sin(ang) * 2048; // store the value in the array of the address of
sinout.

USTIMER_init(); // timer init

Spi_inti(); // spi init

while(1)

for (count = 0; count < nSamp; count++)

val = sin_out[count]; // copy the sine value to another variable

val += 2048; // increase the amplitude level

spi1->SPIDAT1 = val | 0x1000; // display the sine data via DAC

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Result:

Experiment No: Date:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

N-Point DFT

Aim: To perform N-Point DFT on Sequences Using TMS 320 Floating point DSP.
Apparatus: PC with CCS V5

TMS 320C67XX Floating point DSP Kit

Program:

#include<stdio.h>

#include<math.h>

#define pi 3.14

typedef struct {

float real;

float img;

}com;

void main()

com x[50],y[50],temp[50];

int pofd=0,i,k,n;

float WN,c,s,WK;

for(i=0;i<50;i++) /*make output array value to 0.0*/

y[i].real=0.0;

y[i].img=0.0;

printf("\nEnter the no of points of dft:");

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

scanf("%d",&pofd);

printf("\nEnter the function variables of f(n) to calculate DFT in the complex form (e.g. 3+j4
enter as a 3 4)");

for(i=0;i<pofd;i++)

//scanf("%f%f",&x[i].real,&x[i].img);

scanf("%f",&x[i].real);

scanf("%f",&x[i].img);

WN=(2*pi)/pofd;

for(k=0;k<pofd;k++)

temp[k].real=0.0;

temp[k].img=0.0;

WK=k*WN;

for(n=0;n<pofd;n++) /*DFT calculation*/

c=cos(WK*n);

s=sin(WK*n);

temp[k].real=temp[k].real+(x[n].real*c)+(x[n].img*s);

temp[k].img=temp[k].img+(x[n].img*c)-(x[n].real*s);

y[k].real=1/sqrt(pofd)*temp[k].real;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

y[k].img=1/sqrt(pofd)*temp[k].img;

printf("\nDFT OF GIVEN SIGNAL:-\n"); /*Display values of F[k]*/

for(i=0;i<pofd;i++)

printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].img);

Result:

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

FIR LPF

Aim: FIR LP Using TMS 320 Floating point DSP.


Apparatus: PC with CCS V5

TMS 320C67XX Floating point DSP Kit

Function Generator

CRO

Program:

#include "VSK_6748.h"

#include <math.h>

#define SPIFLASH_SPI (SPI1)

#define SPIFLASH_SPI0 (SPI0)

int main(void)

spi_regs_t *spi=SPIFLASH_SPI0;

spi_regs_t *spi1=SPIFLASH_SPI;

uint32_t spi_data1 = spi->SPIDAT1;

const float Fsamp = 10000;

int Fcut = 1500;

int N = 40;

float Fc = Fcut/Fsamp;

float Wc = 2 * 3.14 * Fc;

int *AdcValue;

int *AdcStore;

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

short AdcOut;

int OutValue,Count,Inc;

float *Hd,*Hm;

float Val;

uint16_t val;

unsigned char *Led;

AdcStore = (int *)0x80012000;

Hd = (float *)0x80010000;

Hm = (float *)0x80011000;

for(Count = -2 * N; Count < 2 * N; Count++)

AdcStore[ Count ] = 0;

Hd[ Count ] = 0;

Hm[ Count ] = 0;

for(Count = -N/2; Count < N/2; Count++)

if(Count == 0)

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

Hd[Count] = 2 * Fc;

else

Val = sin(Wc * Count);

Hd[Count] = Val / (Count * 3.14);

Inc=0;

for(Count = -N/2; Count < N/2; Count++)

Hm[Inc] = Hd[Count];

Inc++;

USTIMER_init();

Spi_inti();

while(1)

Department of ECE,ACEM Page No:…………


DIGITAL SIGNAL PROCESSING LAB
Experiment No: Date:

spi->SPIDAT1 = 0x0000;

while (CHKBIT(spi->SPIBUF, RXEMPTY)) {}

val = (uint16_t)spi->SPIBUF;

*AdcStore = val;

val &= 0x0fff;

val ^= 0x0800;

OutValue = 0;

for(Count = 0; Count < N; Count++)

OutValue += (*(AdcStore + Count) * *(Hm + Count));

for(Count = (N-1); Count >= 0; Count--)

*(AdcStore + Count + 1) = *(AdcStore + Count);

spi1->SPIDAT1 = OutValue | 0x1000;

Result:

Department of ECE,ACEM Page No:…………

You might also like