Вы находитесь на странице: 1из 139

LAB MANUAL

DIGITAL SIGNAL PROCESSING


LABORATORY
III Year B. Tech. ECE-II SEM

DEPARTMENT OF ELECTRONICS
AND COMMUNICATION
ENGINEERING

VIGNANS INSTITUTE OF TECHNOLOGY &


AERONAUTICAL ENGINEERING
DESHMUKHI(V),VIGNAN HILLS, NALGONDA Dist-508284.

PART-A:INRODUCTION

DSP Lab Manual


MATLAB: MATLAB is a software package for high performance numerical
computation and visualization provides an interactive environment with hundreds of built
in functions for technical computation, graphics and animation. The MATLAB name
stands for MATrix Laboratory
The diagram shows the main features and capabilities of MATLAB.

MATLAB

Graphics
2-D graphics
3-D graphics
Animation

Computations
Linear algebra
Signal processing
Polynomials & interpolation
Quadrature
Solution of ODEs

External interface
Interface with C and
Fortran programs

Toolbox
Signal processing
Statistics
Neural networks

Image processing
Control system
Communications

At its core ,MATLAB is essentially a set (a toolbox) of routines (called m files or


mex files) that sit on your computer and a window that allows you to create new

Dept of ECE

VITAE

DSP Lab Manual


variables with names (e.g. voltage and time) and process those variables with any of
those routines (e.g. plot voltage against time, find the largest voltage, etc).
It also allows you to put a list of your processing requests together in a file and save that
combined list with a name so that you can run all of those commands in the same order at
some later time. Furthermore, it allows you to run such lists of commands such that you
pass in data and/or get data back out (i.e. the list of commands is like a function in most
programming languages). Once you save a function, it becomes part of your toolbox (i.e.
it now looks to you as if it were part of the basic toolbox that you started with).
For those with computer programming backgrounds: Note that MATLAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It
simply reads through each line of the function, executes it, and then goes on to the next
line. (In practice, a form of compilation occurs when you first run a function, so that it
can run faster the next time you run it.)
MATLAB Windows:
MATLAB works with through three basic windows
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
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
Edit window: This is where you write edit, create and save your own programs in files
called M files.
Input-output:

Dept of ECE

VITAE

DSP Lab Manual


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.

Basic Instructions in Mat lab


1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value
10 with an increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 100]
3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose
values are zero
Output= [0 0 0]
5. zeros( 2,4)
Output =

0000
0000

6. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output =
Dept of ECE

11
3

VITAE

DSP Lab Manual


11
11
11
11
7. a = [ 1 2 3]
b = [4 5 6]
a.*b = [4 10 18]
Which is multiplication of individual elements?
i.e. [4X1 5X2 6X3]
8

if C= [2 2 2]
b.*C results in [8 10 12]

9. plot (t, x)
Ifx = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
9
8
7
6
1

2`

10. stem (t,x)

This instruction will display a figure window as shown

Dept of ECE

VITAE

DSP Lab Manual

9
8
7
6
11. Subplot: This function divides the figure window into rows and columns
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1
represent number of the figure

1
(2 2 1)

2
(2,2,2)

3
(2 2 3)

4
( 2 2 4)

Subplot(3, 1, 3)
1 (3, 1, 1)
2 (3, 1, 2)
3 (3, 1, 3)

12 Filter
Syntax:

y = filter(b,a,X)

Description: y = filter(b,a,X) filters the data in vector X with the filter described by
numerator coefficient vector b and denominator coefficient vector a.If a(1) is not equal to
1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error.

Dept of ECE

VITAE

DSP Lab Manual

13. Impz
Syntax: [h,t] = impz(b,a,n)
Description: [h,t] = impz(b,a,n) computes the impulse response of the filter with
numerator coefficients b and denominator coefficients a and computes n samples of the
impulse response when n is

an integer (t = [0:n-1]'). If n is a vector of integers, impz

computes the impulse response at those integer locations, starting the response
computation from 0 (and t = n or t = [0 n]).If, instead of n, you include the empty vector
[] for the second argument, the number of samples is computed automatically by default.
14. Fliplr
Syntax: B = fliplr(A)
Description: B = fliplr(A) returns A with columns flipped in the left-right direction, that
is, about a vertical axis.If A is a row vector, then fliplr(A) returns a vector of the same
length with the order of its elements reversed. If A is a column vector, then fliplr(A)
simply returns A.
15. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the
same operation as multiplying the polynomials whose coefficients are the elements of u
and v.
16.Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a
text string, the string is displayed.Another way to display an array on the screen is to type
its name, but this prints a leading "X=," which is not always desirable.Note that disp does
not display empty arrays.
17.xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.

Dept of ECE

VITAE

DSP Lab Manual

18. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
19.Title
Syntax : title('string')
Description: title('string')

outputs the string at the top and in the center of the current

axes.
20.grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.

Dept of ECE

VITAE

DSP Lab Manual

Experiment 1: To find DFT of given sequence


Aim: To find DFT of given sequence
Theory: Description
Fourier analysis is a family of mathematical techniques, all based on ecomposing signals
into sinusoids. The discrete Fourier transform (DFT) is the family member used with
digitized signals. A signal can be either continuous or discrete, and it can be either
periodic or Aperiodic. The combination of these two features generates the four
categories, described below

Aperiodic-Continuous
This includes, decaying exponentials and the Gaussian curve. These signals extend to
both positive and negative infinity without repeating in a periodic pattern. The Fourier
Transform for this type of signal is simply called the Fourier Transform.

Periodic-Continuous
This includes: sine waves, square waves, and any waveform that repeats itself in a regular
pattern from negative to positive infinity. This version of the Fourier transform is called
the Fourier series.

Aperiodic-Discrete
These signals are only defined at discrete points between positive and negative
infinity,and do not repeat themselves in a periodic fashion. This type of Fourier transform
is called the Discrete Time Fourier Transform.

Periodic-Discrete
These are discrete signals that repeat themselves in a periodic fashion from negative to
positive infinity. This class of Fourier Transform is sometimes called the Discrete Fourier
Series, but is most often called the Discrete Fourier Transform.

Discrete Fourier Transform Computation:


Mathematical Expression to calculate DFT for an input sequence x(n)

Dept of ECE

VITAE

DSP Lab Manual

Matlab Code
clf;
a=[1 1 2 2];
x=fft(a,4);
n=0:3;
subplot(2,1,1);
stem(n,abs(x));
xlabel('time index n');ylabel('Amplitude');
title('amplitude obtained by dft');
grid;
subplot(2,1,2);stem(n,angle(x));
xlabel('time index n'); ylabel('Amplitude');
title('Phase obtained by dft');

Dept of ECE

VITAE

DSP Lab Manual

Dept of ECE

10

VITAE

DSP Lab Manual

Experiment No 2. To find frequency response of LTI system given in


transfer function / difference equation
Aim: To find frequency response of LTI system given in transfer function /
difference equation
% Frequency Response of LTI system using difference equation
clf;
num=input('numerator coefficiuents b = ');
den=input('denominator coefficients a = ');
w = -pi:8*pi/511:pi;
h = freqz(num, den, w);
% Plot the DTFT
subplot(2,1,1)
plot(w/pi,abs(h));grid
title('Magnitude of H')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w/pi,phase(h));grid
title('phase of H')
xlabel('\omega /\pi');
ylabel('phase');

Output
freqresp
numerator coefficiuents b = [2 1]
denominator coefficients a = [1 -0.6]

Dept of ECE

11

VITAE

DSP Lab Manual

Dept of ECE

12

VITAE

DSP Lab Manual

EXPERIMENT NO 3:

Impulse response of a given system

Aim:
To find the impulse response h(n) of the given LTI system whose response y(n) to an
input x(n) is given.
Theory:

Fig.2.1 A LTI system

A discrete time LTI system (also called digital filters) as shown in Fig.2.1 is
represented by
o A linear constant coefficient difference equation, for example,
y[n] a1 y[n 1] a 2 y[n 2] b0 x[n] b1 x[n 1] b2 x[n 2];
o A system function H(z) (obtained by applying Z transform to the
H (z)
difference equation).

Y ( z ) b0 b1 z 1 b2 z 2

X ( z ) 1 a1 z 1 a 2 z 2

Given the difference equation or H(z), the impulse response of the LTI system is
found using filter or impz MATLAB functions.

MATLAB Programs:
Program 1
b=input('numerator coefficiuents b = ');
a=input('denominator coefficients a = ');
n=input('enter length n = ');
[h,t] = impz(b,a,n);
Dept of ECE

13

VITAE

DSP Lab Manual


disp(h);
stem(t,h);
xlabel('samples n ' ,'color' , 'm');
ylabel('amplitude h(n)','color','m');
title('impulse response','color','r');
grid on;
Result:
numerator coefficiuents b = [1]
denominator coefficients a = [1 -0.5]
enter length n = 20
1.0000

0.5000

0.2500

0.1250

0.0625

0.0313

0.0156

0.0078

0.0039

0.0020

0.0010

0.0005

0.0002

0.0001

0.0001

0.0000

0.0000

0.0000

0.0000

0.0000

Dept of ECE

14

VITAE

DSP Lab Manual

Experiment No. 4 Implementation of N point FFT


Aim: To Implement FFT algorithm of a given sequence and to plot magnitude and
phase spectra
Theory:

Discrete Fourier Transform (DFT) is used for performing frequency analysis of


discrete time signals. DFT gives a discrete frequency domain representation
whereas the other transforms are continuous in frequency domain.

The N point DFT of discrete time signal x[n] is given by the equation
N -1

X (k ) x[n]e

j 2kn
N

; k 0,1,2,....N - 1

n 0

Where N is chosen such that N L , where L=length of x[n].

The inverse DFT allows us to recover the sequence x[n] from the frequency
samples.

x[n]

1
N

N 1

x[n]e

j 2kn
N

; n 0,1,2,....N - 1

k 0

X(k) is a complex number (remember e jw=cosw + jsinw). It has both magnitude


and phase which are plotted versus k. These plots are magnitude and phase
spectrum of x[n]. The k gives us the frequency information.

Here k=N in the frequency domain corresponds to sampling frequency (fs).


Increasing N, increases the frequency resolution, i.e., it improves the spectral
characteristics of the sequence. For example if fs=8kHz and N=8 point DFT, then
in the resulting spectrum, k=1 corresponds to 1kHz frequency. For the same fs
and x[n], if N=80 point DFT is computed, then in the resulting spectrum, k=1
corresponds to 100Hz frequency. Hence, the resolution in frequency is increased.

Since N L , increasing N to 8 from 80 for the same x[n] implies x[n] is still the
same sequence (<8), the rest of x[n] is padded with zeros. This implies that there
is no further information in time domain, but the resulting spectrum has higher
frequency resolution. This spectrum is known as high density spectrum

Dept of ECE

15

VITAE

DSP Lab Manual


(resulting from zero padding x[n]). Instead of zero padding, for higher N, if more
number of points of x[n] are taken (more data in time domain), then the resulting
spectrum is called a high resolution spectrum.
Algorithm:
1. Input the sequence for which DFT is to be computed.
2. Input the length of the DFT required (say 4, 8, >length of the sequence).
3. Implement FFT algorithm.
4. Plot the magnitude & phase spectra.
MATLAB Program:
% This programme is for fast fourier transform in matlab.
% Where y is the input argument and N is the legth of FFT . Let
% y = [1 2 3 4 ];
y=input('enter input sequence:');
N= input('size of fft(e.g . 2,4,8,16,32):');
n=length(y);
p=log2(N);
Y=y;
Y=[Y, zeros(1, N - n)];
N2=N/2;
YY = -pi*sqrt(-1)/N2;
WW = exp(YY);
JJ = 0 : N2-1;
W=WW.^JJ;
for L = 1 : p-1
u=Y(:,1:N2);
v=Y(:,N2+1:N);
t=u+v;
S=W.*(u-v);

Dept of ECE

16

VITAE

DSP Lab Manual


Y=[t ; S];
U=W(:,1:2:N2);
W=[U ;U];
N=N2;
N2=N2/2;
end;
u=Y(:,1);
v=Y(:,2);
Y=[u+v;u-v];
Y
subplot(3,1,1)
stem(y);grid
title('input sequence y')
xlabel('n');
ylabel('Amplitude');
subplot(3,1,2)
stem(abs(Y));grid
title('Magnitude of FFT')
xlabel('N');
ylabel('Amplitude');
subplot (3,1,3)
stem(angle(Y));grid
title('phase of FFT')
xlabel('N');
ylabel('phase');
Result:
>> fft1
enter input sequence:[1 2 3 4 5 6 7]
size of fft(e.g . 2,4,8,16,32):8
Y=

Dept of ECE

17

VITAE

DSP Lab Manual


28.0000
-9.6569 + 4.0000i
-4.0000 - 4.0000i
1.6569 - 4.0000i
4.0000
1.6569 + 4.0000i
-4.0000 + 4.0000i
-9.6569 - 4.0000i

Dept of ECE

18

VITAE

DSP Lab Manual

Experiment No. 5 Power Density Spectrum Using MATLAB

Write a MATLAB program to compute Power Density Spectrum of a given signal


Algorithm:
1. Generate a signal
2. find DFT of the signal
3. PSD is given by the formula

y(n) =

x ( k ) x ( k n)

where n = - (N-1) to (N-1)


PSD= |Y(w)|2
Where Y(w) = fft of y(n)
Matlab program
% computation of psd of signal corrupted with random noise
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
figure,plot(1000*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various frequencies, is:
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
figure,plot(f,Pyy(1:257))
title('power spectrum of y');
xlabel('frequency (Hz)');

Dept of ECE

19

VITAE

DSP Lab Manual

Output

Dept of ECE

20

VITAE

DSP Lab Manual

Experiment No. 6 and 7 Design and implementation of FIR filter to


meet given specifications
Aim: To design and implement a FIR filter for given specifications.
Theory:
There are two types of systems Digital filters (perform signal filtering in time domain)
and spectrum analyzers (provide signal representation in the frequency domain). The
design of a digital filter is carried out in 3 steps- specifications, approximations and
implementation.
DESIGNING AN FIR FILTER (using window method):
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the
window.

Step 1: Compute the digital cut-off frequency Wc (in the range - < Wc < , with

corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz,

fs=8000Hz
Wc = 2** fc / fs = 2* * 400/8000 = 0.1* radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is
computed as wc = Wc /

Step 2: Compute the Impulse Response h(n) of the required FIR filter using the
given Window type and the response type (lowpass, bandpass, etc). For example
given a rectangular window, order N=20, and a high pass response, the
coefficients (i.e., h[n] samples) of the filter are computed using the MATLAB
inbuilt command fir1 as

h =fir1(N, wc , 'high', boxcar(N+1));


Dept of ECE

21

VITAE

DSP Lab Manual


Note: In theory we would have calculated h[n]=hd[n]w[n], where hd[n] is the
desired impulse response (low pass/ high pass,etc given by the sinc function) and
w[n] is the window coefficients. We can also plot the window shape as
stem(boxcar(N)).
Plot the frequency response of the designed filter h(n) using the freqz function and
observe the type of response (lowpass / highpass /bandpass).
Method 2:
Given the pass band (wp in radians) and Stop band edge (ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.

Step 1: Select the window depending on the stopband attenuation required.


Generally if As>40 dB, choose Hamming window. (Refer table )

Step 2: Compute the order N based on the edge frequencies as

Transition bandwidth = tb=ws-wp;


N=ceil (6.6*pi/tb);

Step 3: Compute the digital cut-off frequency Wc as

Wc=(wp+ws)/2
Now compute the normalized frequency in the range 0 to 1 for MATLAB
as
wc=Wc/pi;
Note: In step 2 if frequencies are in Hz, then obtain radian frequencies (for computation
of tb and N)

as wp=2*pi*fp/fs, ws=2*pi*fstop/fs, where fp, fstop and fs are the

passband, stop band and sampling frequencies in Hz

Step 4: Compute the Impulse Response h(n) of the required FIR filter using N,
selected window, type of response(low/high, etc) using fir1 as in step 2 of
method 1.

MATLAB IMPLEMENTATION
Dept of ECE

22

VITAE

DSP Lab Manual


FIR1 Function : B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and
returns the filter coefficients in length N+1 vector B. The cut-off frequency Wn must be
between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter B is real
and has linear phase, i.e., even symmetric coefficients obeying B(k) = B(N+2-k), k =
1,2,...,N+1.
If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter
with passband W1 < W < W2. B = FIR1(N,Wn,'high') designs a highpass filter. B =
FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. If Wn is a multi-element vector,
Wn = [W1 W2 W3 W4 W5 ... WN], FIR1 returns an order N multiband filter with bands
0 < W < W1, W1 < W < W2, ..., WN < W < 1.FREQZ Digital filter frequency
response. [H,W] = FREQZ(B,A,N) returns the N-point complex frequency response
vector H and the N-point frequency vector W in radians/sample of the filter whose
numerator and denominator coefficients are in vectors B and A. The

frequency response

is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't
specified, it defaults to 512.
For FIR filter enter A=1 and B = h[n] coefficients. Appropriately choose N as 128, 256,
etc
Width

Window

Transition

Name

Approximate Exact values

Min. Stop band

Matlab

Attenuation

Command

Rectangular

4
M

1.8
M

21db

B= FIR1(N,Wn,boxcar)

Bartlett

8
M

6.1
M

25db

B = FIR1(N,Wn,bartlett)

Hanning

8
M

6.2
M

44db

B = FIR1(N,Wn,hanning)

Hamming

8
M

6.6
M

53db

B= FIR1(N,Wn,hamming)

Blackman

12
M

11
M

Dept of ECE

74db

23

B = FIR1(N,Wn,blackman)

VITAE

DSP Lab Manual


Program:
%Method 2: the following program gives only the design of the FIR filter- for
implementation continue with the next program (after h[n])
%input data to be given: Passband & Stopband frequency
% Data given: Passband ripple & stopband attenuation As. If As>40 dB, Choose
hamming
clear
wpa=input('Enter passband edge frequency in Hz');
wsa= input('Enter stopband edge frequency in Hz');
ws1= input('Enter sampling frequency in Hz');
%Calculate transmission BW,Transition band tb,order of the filter
wpd=2*pi*wpa/ws1;
wsd=2*pi*wsa/ws1;
tb=wsd-wpd;
N=ceil(6.6*pi/tb)
wc=(wsd+wpd)/2;
%compute the normalized cut off frequency
wc=wc/pi;
%calculate & plot the window
hw=hamming(N+1);
stem(hw);
title('Fir filter window sequence- hamming window');
%find h(n) using FIR
h=fir1(N,wc,hamming(N+1));
%plot the frequency response
figure(2);
[m,w]=freqz(h,1,128);
mag=20*log10(abs(m));
plot(ws1*w/(2*pi),mag);

Dept of ECE

24

VITAE

DSP Lab Manual


title('Fir filter frequency response');
grid;
%generate simulated input of 50, 300 & 200 Hz, each of 30 points
n=1:30;
f1=50;f2=300;f3=200;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
%y=conv(h,x);
y=filter(h,1,x);
subplot(2,1,2);
stem(y);
title('output');
Result:
Enter passband edge frequency in Hz100
Enter stopband edge frequency in Hz200
Enter sampling frequency in Hz1000
N = 33
Plots are as in Fig.11.1 and 11.2
Inference:
Notice the maximum stopband attenuation of 53 dB from plot 11.2

Dept of ECE

25

VITAE

DSP Lab Manual


%Design and implementation of FIR filter Method 1
%generate filter coefficients for the given %order & cutoff Say N=33, fc=150Hz,
%fs=1000 Hz, Hamming window
h=fir1(33, 150/(1000/2),hamming(34));
%generate simulated input of 50, 300 & 200 Hz, each of 30 points
n=1:30;
f1=50;f2=300;f3=200;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
%y=conv(h,x);
y=filter(h,1,x);
subplot(2,1,2);
stem(y);
title('output');
Result:
Plots are in Fig.11.3 & 11.4
Notice that freqs below 150 Hz are passed & above 150 are cutoff

Dept of ECE

26

VITAE

DSP Lab Manual

Fig.11.1

Fig.11.3(using filter command)

Fig.11.2

Fig.11.4 (using conv command)

Fig.11.5 Freqs f1=150;f2=300;f3=170;fs=1000;


FIR filter design using Kaiser window:

Dept of ECE

27

VITAE

DSP Lab Manual


disp('FIR filter design using Kaiser window');
M = input ('enter the length of the filter = ');
beta= input ('enter the value of beta = ');
Wc = input ('enter the digital cutoff frequency');
Wn= kaiser(M,beta);
disp('FIR Kaiser window coefficients');
disp(Wn);
hn = fir1(M-1,Wc,Wn);
disp('the unit sample response of FIR filter is hn=');
disp(hn);
freqz(hn,1,512);
grid on;
xlabel('normalized frequency');
ylabel('gain in db');
title('freq response of FIR filter');
Result:
FIR filter design using Kaiser window
enter the length of the filter = 30
enter the value of beta = 1.2
enter the digital cutoff frequency.3
FIR Kaiser window coefficients
0.7175

0.7523

0.7854

0.8166

0.8457

0.8727

0.8973

0.9195

0.9392

0.9563

0.9706

0.9822

0.9909

0.9967

0.9996

0.9996

0.9967

0.9909

0.9822

0.9706

0.9563

0.9392

0.9195

0.8973

0.8727

0.8457

0.8166

0.7854

0.7523

0.7175

the unit sample response of FIR filter is hn=


Columns 1 through 5
0.0141

0.0028 -0.0142 -0.0224 -0.0117

Columns 6 through 10

Dept of ECE

28

VITAE

DSP Lab Manual


0.0133

0.0333

0.0277 -0.0072 -0.0495

Columns 11 through 15
-0.0614 -0.0140

0.0895

0.2097

0.2900

Columns 16 through 20
0.2900

0.2097

0.0895 -0.0140 -0.0614

Columns 21 through 25
-0.0495 -0.0072

0.0277

0.0333

0.0133

0.0028

0.0141

Columns 26 through 30
-0.0117 -0.0224 -0.0142

Fig.11.6.Response of FIR filter designed using Kaiser window

Dept of ECE

29

VITAE

DSP Lab Manual

EXPERIMENT NO 8,9: Design and implementation of IIR filter to


meet given specifications
Aim: To design and implement an IIR filter for given specifications.
Theory:
There are two methods of stating the specifications as illustrated in previous program. In
the first program, the given specifications are directly converted to digital form and the
designed filter is also implemented. In the last two programs the butterworth and
chebyshev filters are designed using bilinear transformation (for theory verification).
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the IIR
filter type (butterworth, cheby1, cheby2).

Step 1: Compute the digital cut-off frequency Wc (in the range - < Wc < , with
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz

Wc = 2** fc / fs = 2* * 400/8000 = 0.1* radians


For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is computed
as wc = Wc /

Step 2: Compute the Impulse Response [b,a] coefficients of the required IIR filter
and the response type (lowpass, bandpass, etc) using the appropriate butter, cheby1,
cheby2 command. For example given a butterworth filter, order N=2, and a high pass
response, the coefficients [b,a] of the filter are computed using the MATLAB inbuilt
command butter as [b,a] =butter(N, wc , 'high');

Method 2:
Given the pass band (Wp in radians) and Stop band edge (Ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.

Step 1: Since the frequencies are in radians divide by to obtain normalized


frequencies to get wp=Wp/pi and ws=Ws/pi

Dept of ECE

30

VITAE

DSP Lab Manual


If the frequencies are in Hz (note: in this case the sampling frequency should be
given), then obtain normalized frequencies as wp=fp/(fs/2), ws=fstop/(fs/2),
where fp, fstop and fs are the passband, stop band and sampling frequencies in Hz

Step 2: Compute the order and cut off frequency as

[N, wc] = BUTTORD(wp, ws, Rp, Rs)

Step 3: Compute the Impulse Response [b,a] coefficients of the required IIR filter
and the response type as [b,a] =butter(N, wc , 'high');

IMPLEMENTATION OF THE IIR FILTER


1. Once the coefficients of the IIR filter [b,a] are obtained, the next step is to
simulate an input sequence x[n], say input of 100, 200 & 400 Hz (with sampling
frequency of fs), each of 20/30 points. Choose the frequencies such that they are
>, < and = to fc.
2. Filter the input sequence x[n] with Impulse Response, to obtain the output of the
filter y[n] using the filter command.
3. Infer the working of the filter (low pass/ high pass, etc).
MATLAB IMPLEMENTATION
BUTTORD Butterworth filter order selection.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Butterworth filter that loses no more than Rp dB in the passband and has at least Rs dB of
attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies,
normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example,
Lowpass: Wp = .1,

Ws = .2

Highpass: Wp = .2,

Ws = .1

Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7]
BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB
frequency") to use with BUTTER to achieve the specifications.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second.
When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD.
BUTTER Butterworth digital and analog filter design.

Dept of ECE

31

VITAE

DSP Lab Manual


[B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and
returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator).
The coefficients are listed in descending powers of z. The cutoff frequency Wn must be
0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. If Wn is a two-element
vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filter with passband W1
< W < W2.

[B,A] = BUTTER(N,Wn,'high') designs a highpass filter. [B,A] =

BUTTER(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].


BUTTER(N,Wn,'s'), BUTTER(N,Wn,'high','s') and BUTTER(N,Wn,'stop','s') design
analog Butterworth filters. In this case, Wn is in [rad/s] and it can be greater than 1.0.
Program (Design & implementation)
%generate filter coefficients for the given %order & cutoff %Say N=2, fc=150Hz,
%fs=1000 Hz, butterworth filter
[b,a]=butter(2, 150/(1000/2));
%generate simulated input of 100, 300 & 170 Hz, each of 30 points
n=1:30;
f1=100;f2=300;f3=170;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
y=filter(b,a,x);
subplot(2,1,2);
stem(y);
title('output');

Dept of ECE

32

VITAE

DSP Lab Manual


Result:
Plot is in Fig. 12.1, which shows that 100 Hz is passed, while 300 is cutoff and 170
has slight attenuation.
Note: If fp,fstp,fs, rp,As are given then use
[N,wc]=buttord(2*fp/fs,2*fstp/fs,rp,As)
[b,a]=butter(N,wc);
If wp & ws are in radians
[N,wc]=buttord(wp/pi,ws/pi,rp,As)
[b,a]=butter(N,wc);
If wc is in radians & N is given
[b,a]=butter(N,wc/pi);
For a bandpass output
wc=[150/(1000/2) 250/(1000/2)];
[b,a]=butter(4, wc);
Plot is in Fig.12.2 where only 170 is passed, while 100 & 300 are cutoff.

Fig.12.1 Low pass IIR filter(butterworth) output


Dept of ECE

33

VITAE

DSP Lab Manual

Fig.12.2 IIR output for bandpass (150-250 Hz)


Programs for designing of IIR filters (for theory practice):
% Butterworth filter: Given data: rp=1, rs=40, w1=800, %w2=1200,ws=3600;
rp=1, rs=40, w1=800, w2=1200,ws=3600;
% Analog frequency
aw1=2*pi*w1/ws;
aw2=2*pi*w2/ws;
% Prewrapped frequency
pw1 = 2*tan(aw1/2);
pw2 = 2*tan(aw2/2);
%Calculate order and cutoff freq
[n,wc]= buttord (pw1,pw2,rp,rs,'s');
% analog filter transfer

Dept of ECE

34

VITAE

DSP Lab Manual


[b,a] = butter(n,wc,'s');
%obtaining the digital filter using bilinear transformation
fs=1;
[num,den]= bilinear(b,a,fs);
%plot the frequency response
[mag,freq1]=freqz(num,den,128);
freq=freq1*ws/(2*pi);
m = 20*log10(abs(mag));
plot(freq,m);
grid;

Result: rp = 1 rs = 40

w1 = 800

w2 = 1200

Fig. 12.2 BUTTERWORTH FILTER

Dept of ECE

35

VITAE

DSP Lab Manual


To design a chebyshev filter for given specifications
%Given data
rp=1,rs=40,w1=800,w2=1200,ws=3600
%Analog frequencies
aw1= 2*pi*w1/ws;
aw2=2*pi*w2/ws;
% Prewrapped frequency assuming T=1/fs
pw1 = 2*tan(aw1/2);
pw2 = 2*tan(aw2/2);
[n,wc]= cheb1ord (pw1,pw2,rp,rs,'s');
[b,a] = cheby1(n,rp,wc,'s');
%obtaining the digital filter using bilinear transformation
fs=1;
[num,den]= bilinear(b,a,fs);
%plot the frequency response
[mag,freq1]=freqz(num,den,128);
freq=freq1*ws/(2*pi);
m = 20*log10(abs(mag));
plot(freq,m);grid;
Result: rp = 1 rs = 40 w1 = 800 w2 = 1200

ws = 360

Fig.12.3 CHEBYSHEV FILTER

Dept of ECE

36

VITAE

DSP Lab Manual


EXPERIMENT NO 10: Generation of sinusoidal wave using recursive difference
equation
Aim: To generate sinusoidal signal using recursive difference equation
Theory:
There exists different techniques to generate a sine wave on a DSP processor.Using a lookup table,
interpolation, polynomials, or pulse width modulation are some of these techniques utilized to generate a
sine wave. When a slightly sufficient processing power is considered, it is possible to utilize another
technique which makes use of an IIR filter.In this technique, a second order IIR filter as shown in Figure 1
is designed to be marginally stable which is an undesirable situation for a normal filtering operation. For
this second order filter to be marginally stable, its poles are located in the unit circle. After choosing the
suitable filter coefficients for the filter to be marginally stable, a unit impulse is applied to the filter as an
input at time t = 0, and then the input is disconnected. Then the filter starts to oscillate with a fixed
frequency.

The difference equation of the second order filter shown in Figure 1 will be:

Dept of ECE

37

VITAE

DSP Lab Manual

Where F0 is the frequency, Fs is the sampling frequency and A is the amplitude of the
sine wave.
Matlab Program
% Generation of sine wave using recursive difference equation or IIR filter
%fs = sampling rate
% t = time in sec
%f0 = frequency
% A = amplitude
A = 2;
t=0.1;
fs = 5000;
f0=50;
length = fs*t;
y = zeros(1,length);
impulse = zeros(1,length);
impulse(1) = 1;
% frequency coefficients
% difference equation of form y[n]= -a1 y[n-1] -a2 y[n-2] + b0 impulse[n]

Dept of ECE

38

VITAE

DSP Lab Manual


% a1 = -2cos(2*pi*f0/fs), a2= 1, b0 = Asin(2*pi*f0/fs)
a1 = -2*cos(2*pi*f0/fs)
a2 = 1;
b0 = A*sin(2*pi*f0/fs)

y(1)= 0;
y(2)= b0;
for i=3:length
y(i)= b0* impulse(i)- a1*y(i-1) - a2* y(i-2);
end
plot (y);
title('Sinusoidal waveform')
xlabel('samples n');
ylabel('y(n)');

Result :

Dept of ECE

39

VITAE

DSP Lab Manual

Experiment No. 11 Generation of DTMF signals


Theory: Dual-tone Multi-Frequency (DTMF) signaling is the basis for voice
communications control and is widely used worldwide in modern telephony to dial
numbers and configure switchboards. It is also used in systems such as in voice mail,
electronic mail and telephone banking.
A DTMF signal consists of the sum of two sinusoids - or tones - with frequencies taken
from two mutually exclusive groups. These frequencies were chosen to prevent any
harmonics from being incorrectly detected by the receiver as some other DTMF
frequency. Each pair of tones contains one frequency of the low group (697 Hz, 770 Hz,
852 Hz, 941 Hz) and one frequency of the high group (1209 Hz, 1336 Hz, 1477Hz) and
represents a unique symbol. The frequencies allocated to the push-buttons of the
telephone pad are shown below:

697Hz
770 Hz
852Hz
941 Hz

Dept of ECE

1209Hz

1336Hz
ABC

1477 Hz
DEF

1
GHI

2
JKL

3
MNO

4
PQRS

5
TUV

6
WXYZ

40

VITAE

DSP Lab Manual

We will right the program to generate and visualize the DTMF tones for all 12 Symbols.
Also we will estimate its energy content using Gortzets Algorithm
The minimum duration of a DTMF signal defined by the ITU standard is 40 ms.
Therefore, there are at most 0.04 x 8000 = 320 samples available for estimation and
detection. The DTMF decoder needs to estimate the frequencies contained in these short
signals.
One common approach to this estimation problem is to compute the Discrete-Time
Fourier Transform (DFT) samples close to the seven fundamental tones. For a DFT-based
solution, it has been shown that using 205 samples in the frequency domain minimizes
the error between the original frequencies and the points at which the DFT is estimated.
At this point we could use the Fast Fourier Transform (FFT) algorithm to calculate the
DFT. However, the popularity of the Goertzel algorithm in this context lies in the small
number of points at which the DFT is estimated. In this case, the Goertzel algorithm is
more efficient than the FFT algorithm.
Plot Goertzel's DFT magnitude estimate of each tone on a grid corresponding to the
telephone pad.
MATLAB Program
% generating all 12 frequencies
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];

Dept of ECE

41

VITAE

DSP Lab Manual


end
end
f'
% Generate the DTMF tones
Fs = 8000;

% Sampling frequency 8 kHz

N = 800;

% Tones of 100 ms

t = (0:N-1)/Fs; % 800 samples at Fs


pit = 2*pi*t;
tones = zeros(N,size(f,2));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
% Plot tone
subplot(4,3,toneChoice),plot(t*1e3,tones(:,toneChoice));
title(['Symbol

"',

symbol{toneChoice},'":

[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'Xlim', [0 25]);
ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone pad', ...
'FitHeightToText', 'on');
% estimation of DTMF tone using Gortzel's Algorithm
Nt = 205;
original_f = [lfg(:);hfg(:)] % Original frequencies
k = round(original_f/Fs*Nt); % Indices of the DFT
estim_f = round(k*Fs/Nt)

Dept of ECE

% Frequencies at which the DFT is estimated

42

VITAE

DSP Lab Manual


tones = tones(1:205,:);
figure,
for toneChoice=1:12,
% Select tone
tone=tones(:,toneChoice);
% Estimate DFT using Goertzel
ydft(:,toneChoice) = goertzel(tone,k+1); % Goertzel use 1-based indexing
% Plot magnitude of the DFT
subplot(4,3,toneChoice),stem(estim_f,abs(ydft(:,toneChoice)));
title(['Symbol

"',

symbol{toneChoice},'":

[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'Xlim', [650 1550]);
ylabel('DFT Magnitude');
if toneChoice>9, xlabel('Frequency (Hz)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.28 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Estimation of the frequencies contained in each tone of the telephone pad
using Goertzel', ...
'FitHeightToText','on');

Output:

Dept of ECE

43

VITAE

DSP Lab Manual

Dept of ECE

44

VITAE

DSP Lab Manual

Experiment No.12: Implementation of Interpolation process


AIM: program to verify the decimation of given sequence.
SOFTWARE: MATLAB 8.2
Signal Processing Toolbox
PROGRAM:
clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%input signal
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fm=20;
fs=500;
t=0.1;
dt=1/fs;
n=0:dt:t;
m=sin(2*pi*fm*n);
subplot(2,1,1);
stem(m);
xlabel('n-->');
ylabel('amplitude');
title('input signal');
%from the original signal interpolation
b=input('enter the length of interpolation factor b= ');
i=interp(m,b);
subplot(2,1,2);
stem(i);
xlabel('n');
ylabel('amplitude');

Dept of ECE

45

VITAE

DSP Lab Manual


title('interpolation from the original signal'); OUTPUT:
enter the length of interpolation factor b= 3

Dept of ECE

46

VITAE

DSP Lab Manual

Experiment No.13: Implementation of Decimation process


AIM: program to verify the decimation of given sequence.
SOFTWARE: MATLAB 8.2
Signal Processing Toolbox
PROGRAM:
clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%input signal
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fm=20;
fs=1000;
t=0.1;
dt=1/fs;
n=0:dt:t;
m=sin(2*pi*fm*n);
subplot(2,1,1);
stem(m);
xlabel('n-->');
ylabel('amplitude');
title('input signal');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%decimation
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
r=input(' enter the length of decimation factor r= ');
d=decimate(m,r);
subplot (2,1,2);
stem(d);
xlabel('n-->');

Dept of ECE

47

VITAE

DSP Lab Manual


ylabel('amplitude');
title('decimation');
OUTPUT:
enter the length of decimation factor b= 3

Dept of ECE

48

VITAE

DSP Lab Manual

Experiment No.14: Implementation of I/D sampling rate converters


AIM: program to implement sampling rate conversion.
SOFTWARE: MATLAB 8.2
Signal Processing Toolbox
PROGRAM:
clc;% clear comand window
clear all; % clear work space
close all; %close all figure windows
%input signal
N=50 ;% no of samples
n=0:1:N-1;
x=sin(2*pi*n/15);% input signal
subplot(3,1,1)
stem(n,x);
xlabel('n');
ylabel('Amplitude');
title('Original Sequence');
%up sampling
L=2;% upsampling factor
x1=[zeros(1,L*N)];
n1=1:1:L*N;
j =1:L:L*N;
x1(j)=x;
subplot(3,1,2)
stem(n1-1,x1);
xlabel('n');
ylabel('Amplitude');
title('Upsampled Sequence');
% down sampling
M=2;

Dept of ECE

49

VITAE

DSP Lab Manual


x2=x(1:M:N);
n2=1:1:N/M;
subplot(3,1,3)
stem(n2-1,x2);
xlabel('n');
ylabel('Amplitude');
title('Downsampled Sequence');
Output waveforms for Sampling Rate Conversion:

Dept of ECE

50

VITAE

DSP Lab Manual

PART B - LIST OF EXPERIMENTS USING DSP PROCESSOR

ARCHITECTURE AND INSTRUCTION SET OF


DSPCHIP-TMS320C5515
Introduction to the TMS320C55x:
The TMS320C55x digital signal processor (DSP) represents the latest generation
of C5000 DSPs from Texas Instruments. The C55x is built on the proven legacy of the
C54x and is source code compatible with the C54x, protecting the customers software
investment. Following the trends set by the C54x, the C55x is optimized for power
efficiency, low system cost, and best-in-class performance for tight power budgets. With
core power dissipation as low as 0.05 mW/MIPS at 0.9V, and performance up to 800
MIPS (400 MHz), the TMS320C55x offers a cost-effective solution to the toughest
challenges in personal and portable processing applications as well as digital
communications infrastructure with restrictive power budgets. Compared to a 120-MHz
C54x, a 300-MHz C55x will deliver approximately 5X higher performance and
dissipate one-sixth the core power dissipation of the C54x. The C55x cores ultra-low
power dissipation of 0.05mW/MIPS is achieved through intense attention to low-power
design and advanced power management techniques. The C55x designers have
implemented an unparalleled level of power-down configurability and granularity
coupled with unprecedented power management that occurs automatically and is
transparent to the user.
The C55x core delivers twice the cycle efficiency of the C54x through a dualMAC

(multiply-accumulate)

architecture

with

parallel

instructions,

additional

accumulators, ALUs, and data registers. An advanced instruction set, a superset to that of
the C54x, combined with expanded busing structure complements the new hardware
execution units. The C55x continues the standard set by the C54x in code density
leadership for lower system cost. The C55x instructions are variable byte lengths ranging
in size from 8 bits to 48 bits. With this scalable instruction word length, the C55x can
reduce control code size per function by up to 40% more than C54x. Reduced control
code size means reduced memory requirements and lower system cost.

Dept of ECE

51

VITAE

DSP Lab Manual

Key Features of the C55x


The C55x incorporates a rich set of features that provide processing efficiency,
low-power dissipation, and ease of use. Some of these features are listed in Table

Overview of the C5515 eZdsp USB Stick


The C5515 eZdsp USB Stick is an evaluation tool for the Texas Instruments
TMS320C5515 Digital Signal Processor (DSP). This USB bus powered tool allows the
user to evaluate the following items:
The TMS320C5515 processor along with its peripherals
The TLV320AIC3204 codec
The Code Composer Studio IDETM software development tools

Dept of ECE

52

VITAE

DSP Lab Manual

Key Features of the C5515 eZdsp USB Stick


The C5515 eZdsp USB Stick has the following features:
Texas Instruments TMS320C5515 Digital Signal Processor
Texas Instruments TLV320AIC3204 Stereo Codec (stereo in, stereo out)
Micro SD connector
USB 2.0 interface to C5515 processor
32 Mb NOR flash
I2C OLED display
5 user controlled LEDs
2 user readable push button switches
Embedded USB XDS100 JTAG emulator
Bluetooth board interface
Expansion edge connector
Power provided by USB interface
Compatible with Texas Instruments Code Composer Studio v4
USB extension cable
C5515 eZdsp USB Stick Block Diagram

Dept of ECE

53

VITAE

DSP Lab Manual


The block diagram of the C5515 eZdsp USB Stick is shown below.

Dept of ECE

54

VITAE

DSP Lab Manual

CODE COMPOSER STUDIO


INTRODUCTION TO CODE COMPOSER STUDIO
Code Composer Studio (CCS or CCStudio) is the integrated development
environment for TI's DSPs, microcontrollers and application processors. CCStudio
includes a suite of tools used to develop and debug embedded applications. It includes
compilers for each of TI's device families, source code editor, project build environment,
debugger, profiler, simulators and many other features. CCStudio provides a single user
interface taking users through each step of the application development flow. Familiar
tools and interfaces allow users to get started faster than ever before and add functionality
to their application thanks to sophisticated productivity tools.
CCStudio version 4 (CCSv4) is based on the Eclipse open source software
framework. CCSv4 is based on Eclipse because it offers an excellent software framework
for development environments a standard framework many embedded software vendors.
CCSv4 combines the advantages of the Eclipse software framework with advanced
embedded debug capabilities from TI resulting in a compelling feature rich development
environment for embedded developers.

Dept of ECE

55

VITAE

DSP Lab Manual

Features
Debugger
CCStudio's integrated debugger has several capabilities and advanced breakpoints
to simplify development. Conditional or hardware breakpoints are based on full C
expressions, local variables or registers. The advanced memory window allows you to
inspect each level of memory so that you can debug complex cache coherency issues.
CCStudio supports the development of complex systems with multiple processors or
cores. Global breakpoints and synchronous operations provide control over multiple
processors and cores.
Profiling
CCStudio's interactive profiler makes it easy to quickly measure code
performance and ensure the efficient use of the target's resources during debug and
development sessions. The profiler allows developers to easily profile all C/C++
functions in their application for instruction cycles or other events such as cache
misses/hits, pipeline stalls and branches.

Dept of ECE

56

VITAE

DSP Lab Manual


Profile ranges can be used to concentrate efforts on high-usage areas of code
during optimization, helping developers produce finely-tuned code. Profiling is available
for ranges of assembly, C++ or C code in any combination. To increase productivity, all
profiling facilities are available throughout the development cycle.
Scripting
Some tasks such as testing need to run for hours or days without user interaction.
To accomplish such a task, the IDE should be able to automate common tasks. CCStudio
has a complete scripting environment allowing for the automation of repetitive tasks such
as testing and performance benchmarking. A separate scripting console allows you to
type commands or to execute scripts within the IDE.
Image Analysis and Visualization
CCStudio has many image analysis and graphic visualization. It includes the
ability to graphically view variables and data on displays which can be automatically
refreshed. CCStudio can also look at images and video data in the native format (YUV,
RGB) both in the host PC or loaded in the target board.
Compiler
TI has developed C/C++ compilers specifically tuned to maximize the processor's
usage and performance. TI compilers use a wide range of classical, application-oriented,
and sophisticated device-specific optimizations that are tuned to all the supported
architectures.
Some of these optimizations include:
Common sub-expression elimination
Software pipelining
Strength Reduction
Auto increment addressing
Cost-based register allocation
Instruction predication
Hardware looping
Function In-lining

Dept of ECE

57

VITAE

DSP Lab Manual


Vectorization
TI compilers also perform program level optimizations that evaluate code
performance at the application level. With the program level view, the compiler is able to
generate code similar to an assembly program developer who has the full system view.
This application level view is leveraged by the compiler to make trade-offs that
significantly increase the processor performance.
The TI ARM and Microcontroller C/C++ compilers are specifically tuned for
code size and control code efficiency. They offer industry leading performance and
compatibility.
Simulation
Simulators provide a way for users to begin development prior to having access to
a development board. Simulators also have the benefit of providing enhanced visibility
into application performance and behavior. Several simulator variants are available
allowing users to trade off cycle accuracy, speed and peripheral simulation, with some
simulators being ideally suited to algorithm benchmarking and others for more detailed
system simulation. Hardware Debugging (Emulation)
TI devices include advanced hardware debugging capabilities. These capabilities include:
IEEE 1149.1 (JTAG) and Boundary Scan
Non-intrusive access to registers and memory
Real-time mode which provides for the debugging of code that interacts with interrupts
that must not be disabled. Real-time mode allows you to suspend background code at
break events while continuing to execute time-critical interrupt service routines.
Multi-core operations such as synchronous run, step, and halt. This includes crosscore
triggering, which provides the ability to have one core trigger other cores to halt.
Advanced Event Triggering (AET) which is available on selected devices, allows a user
to halt the CPU or trigger other events based on complex events or sequences such as
invalid data or program memory accesses. It can non-intrusively measure performance
and count system events (for example, cache events).
CCStudio provides Processor Trace on selected devices to help customers find
previously invisible complex real-time bugs. Trace can detect the really hard to find
bugs race conditions between events, intermittent real-time glitches, crashes from stack

Dept of ECE

58

VITAE

DSP Lab Manual


overflows, runaway code and false interrupts without stopping the processor. Trace is a
completely nonintrusive debug method that relies on a debug unit inside the processor so
it does not interfere or change the applications real-time behavior. Trace can fine tune
code performance and cache optimization of complex switch intensive multi-channel
applications. Processor Trace supports the export of program, data, timing and selected
processor and system events/interrupts. Processor Trace can be exported either to an
XDS560 Trace external JTAG emulator, or on selected devices, to an on chip buffer
Embedded Trace Buffer (ETB).
Real time operating system support
CCSv4 comes with two versions of TI's real time operating system:
DSP/BIOS 5.4x is a real-time operating system that provides pre-emptive multitasking
services for DSP devices. Its services include ISR dispatching, software interrupts,
semaphores, messages, device I/O, memory management, and power management. In
addition, DSP/BIOS 5.x also includes debug instrumentation and tooling, including lowoverhead print and statistics gathering.
BIOS 6.x is an advanced, extensible real-time operating system that supports ARM926,
ARM Cortex M3, C674x, C64x+, C672x, and 28x-based devices. It offers numerous
kernel and debugging enhancements not available in DSP/BIOS 5.x, including faster,
more flexible memory management, events, and priority-inheritance mutexes.
Note: BIOS 6.x includes a DSP/BIOS 5.x compatibility layer to support easy migration
of application source code.
Step 1:
Open the code composer studio (CCSV4) and give a name to workspace and store it in
the default path itself.
Note: dont assign other than default path unless you are familiar with eclipse frame work
based CCSV4

Dept of ECE

59

VITAE

DSP Lab Manual

Step 2:
Project windows overview

Dept of ECE

60

VITAE

DSP Lab Manual

TMS320C6713 DSK CODEC(TLV320AIC23)


Configuration Using Board Support Library
1.0 Unit Objective:
To configure the codec TLV320AIC23 for a talk through program using the board
support library.
2.0 Prerequisites
TMS320C6713 DSP Starter Kit, PC with Code Composer Studio, CRO, Audio
Source, Speakers and Signal Generator.
3.0 Discussion on Fundamentals:
Refer BSL API Module under, help contents TMS320C6713 DSK.
4.0 Procedure
All the Real time implementations covered in the Implementations module
follow code Configuration using board support library.
The board Support Library (CSL) is a collection of functions, macros, and
symbols used to configure and control on-chip peripherals.
The goal is peripheral ease of use, shortened development time,
portability, hardware abstraction, and some level of standardization and
compatibility among TI devices.
BSL is a fully scalable component of DSP/BIOS. It does not require the
use of other DSP/BIOS components to operate.
Source Code: codec.c
Steps:
1. Connect CRO to the Socket Provided for LINE OUT.
2. Connect a Signal Generator to the LINE IN Socket.
3. Switch on the Signal Generator with a sine wave of frequency 500 Hz.
4. Now Switch on the DSK and Bring Up Code Composer Studio on the PC.
5. Create a new project with name XXXX.pjt.
6. From the File Menu new DSP/BIOS Configuration select
dsk6713.cdb and save it as YYYY.cdb and add it to the current project.
7. Add the generated YYYYcfg.cmd file to the current project.
8. Add the given codec.c file to the current project which has the main function
and calls all the other necessary routines.
9. View the contents of the generated file YYYYcfg_c.c and copy the include
header file YYYYcfg.h to the codec.c file.
10. Add
the
library
file
dsk6713bsl.lib
from
the
location
C:\ti\C5400\dsk6713\lib\dsk6713bsl.lib to the current project

Dept of ECE

61

VITAE

DSP Lab Manual


11. Build, Load and Run the program.

12. You can notice the input signal of 500 Hz. appearing on the CRO verifying the
codec configuration.
13. You can also pass an audio input and hear the output signal through the
speakers.
14. You
can
also
vary
the
sampling
frequency
using
the
DSK6713_AIC23_setFreq Function in the codec.c file and repeat the
above steps.
5.0 Conclusion:
The codec TLV320AIC23 successfully configured using the board support
library
and verified.

Dept of ECE

62

VITAE

DSP Lab Manual

codec.c
#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input
channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input
channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel
headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel
headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path
control */
\
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path
control */
\
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down
control */
\
0x0043, /* 7 DSK6713_AIC23_DIGIF
Digital audio
interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate
control */
\
0x0001 /* 9 DSK6713_AIC23_DIGACT
Digital interface
activation */ \
};
/* main() - Main code routine, initializes BSL and generates
tone */
void main()
{
DSK6713_AIC23_CodecHandle
hCodec;
int l_input, r_input,l_output, r_output;

Dept of ECE

63

VITAE

DSP Lab Manual

/* Initialize the board support library, must be called first */


DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
/*set codec sampling frequency*/
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
/* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_input));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, l_input));
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}

EXP.NO: 15
COMPUTATION OF N- POINT DFT OF A GIVEN SEQUENCE
Aim: To compute the N (=4/8/16) point DFT of the given sequence
EQUIPMENTS:

Host (PC) with windows (95/98/Me/XP/NT/2000).

TMS320C5515 DSP Starter Kit (DSK).

Theory:
The N point DFT of discrete time signal x[n] is given by the equation
N -1

X (k ) x[n]e

j 2kn
N

; k 0,1,2,....N - 1

n 0

Dept of ECE

64

VITAE

DSP Lab Manual


Where N is chosen such that N L , where L=length of x[n]. To implement using C

j 2kn
N

program we use the expression

2kn
2kn
j sin

N
N and allot memory

cos

space for real and imaginary parts of the DFT X(k)


Program
//dft.c N-point DFT of sequence read from lookup table
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979
#define N 64
#define TESTFREQ 10000.0
#define SAMPLING_FREQ 64000.0
typedef struct
{
float real;
float imag;
} COMPLEX;
float x1[N],y1[N];
COMPLEX samples[N];
void dft(COMPLEX *x)
{
COMPLEX result[N];
int k,n,i;
for (k=0 ; k<N ; k++)
{
result[k].real=0.0;
result[k].imag = 0.0;
for (n=0 ; n<N ; n++)
{
result[k].real += x[n].real*cos(2*PI*k*n/N) + x[n].imag*sin(2*PI*k*n/N);

Dept of ECE

65

VITAE

DSP Lab Manual


result[k].imag += x[n].imag*cos(2*PI*k*n/N) - x[n].real*sin(2*PI*k*n/N);
}
}
for (k=0 ; k<N ; k++)
{
x[k] = result[k];
}
printf("output");
for (i = 0 ; i < N ; i++) //compute magnitude
{
x1[i] = (int)sqrt(result[i].real*result[i].real + result[i].imag*result[i].imag);
printf("\n%d = %f",i,x1[i]);
}
}
void main() //main function
{
int n;
for(n=0 ; n<N ; n++)
{
y1[n] = samples[n].real = cos(2*PI*TESTFREQ*n/SAMPLING_FREQ);
samples[n].imag = 0.0;
printf("\n%d = %f",n,samples[n].real);
}
printf("real input data stored in array samples[]\n");
printf("\n"); // place breakpoint here
dft(samples); //call DFT function
printf("done!\n");
}
Code Flow:
Step 1 - Select no. of points for DFT(Eg: 64)
Step 2 Generate a sine wave of frequency f (eg: 10 Hz with a sampling rate = No. of

Dept of ECE

66

VITAE

DSP Lab Manual


Points of DFT(eg. 64)) using math library function.
Step 3 - Take sampled data and apply DFT algorithm.
Execution Procedure:

Open CCstudio setup

Go to File Menu , select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select DFT Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)

Give Right Click on Your Dft.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

From Tools select Graph(Dual Time) , give properties and select OK.

Result:
Input Signal:

Output Signal :

Dept of ECE

67

VITAE

DSP Lab Manual

Graph Properties:

Dept of ECE

68

VITAE

DSP Lab Manual

EXP.NO: 16
IMPLEMENTATION OF FFT OF GIVEN SEQUENCE
AIM: To compute the FFT of the given sequence
EQUIPMENTS:
1. Host (PC) with windows (95/98/Me/XP/NT/2000).
2. TMS320C5515 DSP Starter Kit (DSK).
FFT Algorithm
The FFT has a fairly easy algorithm to implement, and it is shown step by step in the list
below. This version of the FFT is the Decimation in Time Method
1. Pad input sequence, of N samples, with Zeros until the number of samples is the
nearest power of two.
e.g. 500 samples are padded to 512 (2^9)
2. Bit reverse the input sequence.
e.g. 3 = 011 goes to 110 = 6
3. Compute (N / 2) two sample DFT's from the shuffled inputs. See "Shuffled Inputs"
4. Compute (N / 4) four sample DFT's from the two sample DFT's. See "Shuffled Inputs"
5. Compute (N / 2) eight sample DFT's from the four sample DFT's. See "Shuffled
Inputs"
6. Until the all the samples combine into one N-sample DFT
PROGRAM:
Main.c
#include "usbstk5515.h"
#include <math.h>
#include <stdio.h>
#define PTS 64 //no of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
short i; //general purpose index variable

Dept of ECE

69

VITAE

DSP Lab Manual


short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer
void main(void)
{
for(i=0;i<PTS;i++)
{
iobuffer[i]=0;
x1[i]=0;
}
printf("\n input");
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants
}
for (i = 0 ; i < PTS ; i++) //swap buffers
{
iobuffer[i] = sin(2*PI*10*i/64.0);/*10- > freq, 64 -> sampling freq*/
printf("\n%d = %f",i,iobuffer[i]);
samples[i].real=0.0;
samples[i].imag=0.0;
}
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
FFT(samples,PTS); //call function FFT.c

Dept of ECE

70

VITAE

DSP Lab Manual


printf("\n output");
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real +
samples[i].imag*samples[i].imag);
printf("\n%d = %f",i,x1[i]);
}
} //end of main
fft.c
#define PTS 64 //# of points for FFT
typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS]; //twiddle constants stored in w
void FFT(COMPLEX *Y, int N) //input sample array, # of points
{
COMPLEX temp1,temp2; //temporary storage variables
int i,j,k; //loop counter variables
int upper_leg, lower_leg; //index of upper/lower butterfly leg
int leg_diff; //difference between upper/lower leg
int num_stages = 0; //number of FFT stages (iterations)
int index, step; //index/step through twiddle constant
i = 1; //log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2; //difference between upper&lower legs
step = (PTS*2)/N; //step between values in twiddle.h
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;

Dept of ECE

71

VITAE

DSP Lab Manual


for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;

Dept of ECE

72

VITAE

DSP Lab Manual


if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
Code Flow:
Step 1 - Select no. of points for FFT(Eg: 64)
Step 2 Generate a sine wave of frequency f (eg: 10 Hz with a sampling rate = No. of
Points of FFT(eg. 64)) using math library function.
Step 3 - Take sampled data and apply FFT algorithm.
Execution Procedure:

Open CCstudio setup

Go to File Menu , select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select FFT Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)

Give Right Click on Your fft.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

From Tools select Graph(Dual Time) , give properties and select OK.

Dept of ECE

73

VITAE

DSP Lab Manual


Result :
Input Signal:

Output Signal:

Dept of ECE

74

VITAE

DSP Lab Manual

EXP.NO: 17
POWER SPECTRUM
Aim: To verify the power spectrum using DSP processor.
Equipments required:
1. Host (PC) with windows (95/98/Me/XP/NT/2000).
2. TMS320C5515 DSP Starter Kit (DSK).
Program:
Main.c
#include "usbstk5515.h"
#include <math.h>
#include <stdio.h>
#define PTS 64 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
void apply_fft(void);
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
float x[PTS];
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer
void main(void)
{
float sum=0.0 ;
int n,k,i;
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); /*Re component of twiddle constants*/

Dept of ECE

75

VITAE

DSP Lab Manual


w[i].imag =-sin(2*PI*i/(PTS*2.0)); /*Im component of twiddle constants*/
}
/****************Input Signal X(n) *************************/
for(i=0;i<PTS;i++)
{
x[i] = sin(2*PI*5*i/PTS);
// Signal x(Fs)=sin(2*pi*f*i/Fs);
samples[i].real=0.0;
samples[i].imag=0.0;
}
/********************Auto Correlation of X(n)=R(t) ***********/
for(n=0;n<PTS;n++)
{
sum=0;
for(k=0;k<PTS-n;k++)
{
sum=sum+(x[k]*x[n+k]); // Auto Correlation R(t)
}
iobuffer[n] = sum;
}
/********************** FFT of R(t) ***********************/
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
FFT(samples,PTS); //call function FFT.c
/******************** PSD ********************/
for (i = 0 ; i < PTS ; i++) //compute magnitude
{

Dept of ECE

76

VITAE

DSP Lab Manual


x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag);
}
}
FFT.c
Refer previous FFT experiment
Code Flow:
Step 1 - Select no. of points for FFT(E.g.: 64)
Step 2 Generate a sine wave of frequency f (e.g.: 10 Hz with a sampling rate = No.
of Points of FFT (e.g. 64)) using math library function.
Step 3 - Compute the Auto Correlation of Sine wave
Step4 - Take output of auto correlation, apply FFT algorithm.
Execution Procedure:
_ Open CCstudio setup
_ Go to File Menu, select Import option.
_ In the Import Window under CCs choose Existing CCS/CCE Eclipse project then next.
_ In Select root Directory Browse for project file where it is located.
_ Select PSD Project folder and Finish it.
_ Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)
_ Give Right Click on Your psd.out file under Binaries and select Load program Option.
_ Now Go to Target select Run.
_ From Tools select Graph(Dual Time and single Time) , give properties and select OK.
Output:

Dept of ECE

77

VITAE

DSP Lab Manual

Dept of ECE

78

VITAE

DSP Lab Manual

EXP.NO: 18
IMPLEMENTATION OF LP FIR FILTER FOR GIVEN SEQUENCE &
IMPLEMENTATION OF HP FIR FILTER FOR GIVEN SEQUENCE
Aim: The aim of this laboratory exercise is to design and implement a Digital FIR Filter
& observe its frequency response. In this experiment we design a simple FIR filter so as
to stop or attenuate required band of frequencies components and pass the frequency
components, which are outside the required band.
EQUIPMENTS:

Host (PC) with windows(95/98/Me/XP/NT/2000).

TMS320C5515 DSP Starter Kit (DSK).

Finite Impulse Response (FIR) Filter: The FIR filters are of non-recursive type, where
by the present output sample is depending on the present input sample and previous input
samples.
The transfer function of a FIR causal filter is given by,
N 1

H ( z )= h ( n ) Z

n=0

Where h(n) is the impulse response of the filter.


The Fourier transform of h(n) is
N 1

H ( e jw ) = h ( n ) e jwn
n=0

In the design of FIR filters most commonly used approach is using windows.
The desired frequency response Hd(ejw) of a filter is periodic in frequency and can be
expanded in Fourier series. The resultant series is given by,

hd ( n )=(1 /2 ) H (e jw )e jwn dw

And known as Fourier coefficients having infinite length. One possible way of obtaining FIR
filter is to truncate the infinite Fourier series at n = [(N-1)/2]
Where N is the length of the desired sequence.
The Fourier coefficients of the filter are modified by multiplying the infinite impulse
response with a finite weighing sequence w(n) called a window.

Where w(n) = w(-n) 0 for |n| [(N-1)/2]


= 0 for |n| > [(N-1)/2]

Dept of ECE

79

VITAE

DSP Lab Manual


After multiplying w(n) with hd(n), we get a finite duration sequence h(n) that satisfies the
desired magnitude response,
h(n) = hd(n) w(n) for |n| [(N-1)/2]
= 0 for |n| > [(N-1)/2]
The frequency response H(ejw) of the filter can be obtained by convolution of Hd(ejw)
and
W(ejw) is given by,

H ( e ) =(1 /2 ) H d (e j )e jw d
jw

H(ejw) = Hd(ejw) * W(ejw).


DESIGNING AN FIR FILTER :
Following are the steps to design linear phase FIR filters Using Windowing Method.
I. Clearly specify the filter specifications.
Eg: Order= 30; Sampling Rate= 8000 samples/sec; Cut off Freq. = 400 Hz.
II. Compute the cut-off frequency Wc
Eg: Wc = 2*pie* fc / Fs= 2*pie* 400/8000= 0.1*pie
III. Compute the desired Impulse Response h d (n) using particular Window.
Eg: b_rect1=fir1(order, Wc , 'high',boxcar(31));
IV. Convolve input sequence with truncated Impulse Response x (n)*h (n).

Dept of ECE

80

VITAE

DSP Lab Manual


FLOW CHART TO IMPLEMENT FIR FILTER:

Coefficients for FIR Low Pass Kaiser filter:


Cutoff freq: 8khz, sampling freq: 24khz
#define N 82 //length of filter
short h[N]= { 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2, 0, 2, -2,
0, 3, -3, 0, 4, -4, 0, 5, -6, 0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2,
0, -2, 2, 0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };
Coefficients for FIR Low Pass rectangular filter:

Dept of ECE

81

VITAE

DSP Lab Manual


Cutoff freq: 8khz, sampling freq: 24khz
#define N 82 //length of filter
short h[N]= { 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2, 0, 2, -2,
0, 3, -3, 0, 4, -4, 0, 5, -6, 0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2,
0, -2, 2, 0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };
Coefficients for FIR Low Pass triangular filter:
Cutoff freq: 8khz, sampling freq: 24khz
#define N 82 //length of filter
short h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -2, 0, 2,
-2, 0, 3, -3, 0, 5, -6, 0, 9, -13, 0, 70, 70, 0, -13, 9, 0, -6, 5, 0, -3, 3, 0, -2, 2, 0, -2, 1, 0, -1,
1,
0, -1, 1, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Coefficients for FIR high Pass Kaiser filter:
Cutoff freq: 4khz, sampling freq: 12khz
#define N 82 //length of filter
short h[N]= { 1, 0, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1, 2,
-1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2, 2,
-3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 0, -1 };
Coefficients for FIR high Pass rectangular filter:
Cutoff freq: 4khz, sampling freq: 12khz
#define N 82 //length of filter
short h[N]= { 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1, 2,
-1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2, 2,
-3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1 };
Coefficients for FIR high Pass triangular filter:
Cutoff freq: 4khz, sampling freq: 12khz
#define N 82 //length of filter
short h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, -1, 1, -1, -1, 1, -1, -1, 2,
-1, -1, 3, -2, -2, 5, -3, -3, 8, -5, -8, 27, -41, 41, -27, 8, 5, -8, 3, 3, -5, 2, 2, -3, 1, 1, -2, 1, 1,
-1, 1, 1, -1, 1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
C-Program:

Dept of ECE

82

VITAE

DSP Lab Manual


Main.c
#include "stdio.h"
#include "usbstk5515.h"
void main( void )
{
/* Initialize BSL */
USBSTK5515_init();
printf( "playing audio ::::: \n" );
while(1)
{
aic3204_test( );
}
}
Aic3204_test.c:
#define AIC3204_I2C_ADDR 0x18
#include "usbstk5515.h"
#include "usbstk5515_gpio.h"
#include "usbstk5515_i2c.h"
#include "stdio.h"
extern Int16 aic3204_tone_headphone( );
extern Int16 aic3204_loop_stereo_in1( );
Int16 AIC3204_rget( Uint16 regnum, Uint16* regval )
{
Int16 retcode = 0;
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = 0;
retcode |= USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 1 );
retcode |= USBSTK5515_I2C_read( AIC3204_I2C_ADDR, cmd, 1 );
*regval = cmd[0];
USBSTK5515_wait( 10 );

Dept of ECE

83

VITAE

DSP Lab Manual


return retcode;
}
Int16 AIC3204_rset( Uint16 regnum, Uint16 regval )
{
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = regval; // 8-bit Register Data
return USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 2 );
}
Int16 aic3204_test( )
{
SYS_EXBUSSEL = 0x6100; // Enable I2C bus
USBSTK5515_I2C_init( ); // Initialize I2C
USBSTK5515_wait( 100 ); // Wait
if ( aic3204_loop_stereo_in1( ) )
return 1;
return 0;
}
aic3204_loop_stereo_in1.c:
#include "stdio.h"
#include "usbstk5515.h"
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define N 82
Int16 data1, data2, data3, data4;
int sample,n,k,l;
Int16 dly0[N];
Int32 lyn,ryn;
/*//hpkaiser12-4
Int16 h[N]= {1, 0, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1,

Dept of ECE

84

VITAE

DSP Lab Manual


2, -1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2,
2, -3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 0, -1 };*/
/*//hprect12-4
Int16 h[N]= { 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1,
2, -1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2,
2, -3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1 };*/
/*//hptrig12-4
Int16 h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, -1, 1, -1, -1, 1, -1, -1, 2,
-1, -1, 3, -2, -2, 5, -3, -3, 8, -5, -8, 27, -41, 41, -27, 8, 5, -8, 3, 3, -5, 2, 2, -3, 1, 1, -2, 1, 1,
-1, 1, 1,-1, 1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0};*/
/*//lpkaiser24-8
Int16 h[N]= {0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1,0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2,0, 2, -2, 0,
3, -3, 0, 4, -4, 0, 5, -6, 0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2, 0,
-2, 2,0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1,0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };*/
/*//lprect24-8
short h[N]= {0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1,0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2,0, 2, -2, 0,
3, -3, 0, 4, -4, 0, 5, -6,0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2, 0,
-2, 2,0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1,0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };*/
/*//lptrig24-8
Int16 h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -2, 0, 2,
-2, 0, 3, -3, 0, 5, -6,0, 9, -13, 0, 70, 70, 0, -13, 9, 0, -6, 5,0, -3, 3, 0, -2, 2, 0, -2, 1, 0, -1, 1,
0, -1, 1, 0, -1, 1, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0};*/
//lpkaiser48-8
Int16 h[N]= {-1, 0, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1,-1, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1, -2, -1,
1, 3, 2, -2, -4, -2, 2, 5, 3, -4,-9, -6, 8, 27, 41, 41, 27, 8, -6, -9, -4, 3,5, 2, -2, -4, -2, 2, 3, 1,
-1, -2, -1, 1,2, 1, -1, -2, -1, 1, 2, 1, -1, -1, -1, 1,1, 1, -1, -1, -1, 1, 1, 1, 0, -1};
Int16 aic3204_loop_stereo_in1( )
{
Int16 j, i = 0;
/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0

Dept of ECE

85

VITAE

DSP Lab Manual


AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Point to page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
AIC3204_rset( 0, 0 ); // Select page 0
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK is set as o/p to AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL CLK
AIC3204_rset( 6, 8 ); // PLL setting: J=8
AIC3204_rset( 7, 15 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0xdc ); // PLL setting: LO_BYTE(D)
AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
AIC3204_rset( 5, 0x91 ); // PLL setting: Power up PLL, P=1 and R=1
AIC3204_rset( 13, 0 ); // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC
oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for decimation
filters 1 to 6
AIC3204_rset( 11, 0x88 ); // Power up NDAC and set NDAC value to 8
AIC3204_rset( 12, 0x82 ); // Power up MDAC and set MDAC value to 2
AIC3204_rset( 18, 0x88 ); // Power up NADC and set NADC value to 8
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 12, 0x08 ); // LDAC AFIR routed to HPL
AIC3204_rset( 13, 0x08 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 64, 0x02 ); // Left vol=right vol
AIC3204_rset( 65, 0x00 ); // Left DAC gain to 0dB VOL; Right tracks Left

Dept of ECE

86

VITAE

DSP Lab Manual


AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 16, 0x06 ); // Unmute HPL , 6dB gain
AIC3204_rset( 17, 0x06 ); // Unmute HPR , 6dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
USBSTK5515_wait( 500 ); // Wait
/* ADC ROUTING and Power Up */
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x34, 0x30 ); // STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 0x37, 0x30 ); // IN2_R to RADC_P through 40 kohmm
AIC3204_rset( 0x36, 3 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 0x39, 0xc0 ); // CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 0x3b, 0 ); // MIC_PGA_L unmute
AIC3204_rset( 0x3c, 0 ); // MIC_PGA_R unmute
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 0x51, 0xc0 ); // Powerup Left and Right ADC
AIC3204_rset( 0x52, 0 ); // Unmute Left and Right ADC
AIC3204_rset( 0, 0 );
USBSTK5515_wait( 200 ); // Wait
/* I2S settings */
I2S0_SRGR = 0x0;
I2S0_CR = 0x8010; // 16-bit word, slave, enable I2C
I2S0_ICMR = 0x3f; // Enable interrupts
/* Play Tone */
for(l=0;l<N;l++)
dly0[l]=0;
for ( i = 0 ; i < 5 ; i++ )
{
for ( j = 0 ; j < 1000 ; j++ )

Dept of ECE

87

VITAE

DSP Lab Manual


{
for ( sample = 0 ; sample < N ; sample++ )
{
/* Read Digital audio input */
data3 = I2S0_W0_MSW_R; // 16 bit left channel received audio data
data1 = I2S0_W0_LSW_R;
data4 = I2S0_W1_MSW_R; // 16 bit right channel received audio data
data2 = I2S0_W1_LSW_R;
while((Rcv & I2S0_IR) == 0); // Wait for interrupt pending flag
lyn=0;
for(k=0;k<N;k++)
{
dly0[(N-1)-k]=dly0[(N-1)-k-1];
dly0[0]=data3;
}
for(k=0;k<N;k++)
lyn+=((h[k])*dly0[k]); //fir low pass filter
data1=lyn>>1;
data2=data1;
/* Write Digital audio input */
I2S0_W0_MSW_W = data1; // 16 bit left channel transmit audio data
I2S0_W0_LSW_W = 0;
I2S0_W1_MSW_W = data2; // 16 bit right channel transmit audio data
I2S0_W1_LSW_W = 0;
while((Xmit & I2S0_IR) == 0); // Wait for interrupt pending flag
}
}
}
/* Disble I2S */
I2S0_CR = 0x00;
return 0;

Dept of ECE

88

VITAE

DSP Lab Manual


}
Execution Procedure:

Open CCstudio setup

Go to File Menu , select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select FIR Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)

Give Right Click on Your fir.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

Observe the audio (Give Input from Stereo in and listen Filtered Output from
Stereo Out).

Dept of ECE

89

VITAE

DSP Lab Manual

EXP.NO: 19
IMPLEMENTATION OF LP IIR FILTER FOR GIVEN SEQUENCE &
IMPLEMENTATION OF HP IIR FILTER FOR GIVEN SEQUENCE
Aim: The aim of this laboratory exercise is to design and implement a Digital IIR Filter
& observe its frequency response. In this experiment we design a simple IIR filter so as
to stop or attenuate required band of frequencies components and pass the frequency
components which are outside the required band
EQUIPMENTS NEEDED:

Host (PC) with windows(95/98/Me/XP/NT/2000).

TMS320C5515 DSP Starter Kit (DSK).

Audio Jack Cable

FLOWCHART FOR IIR IMPLEMENTATION:

Dept of ECE

90

VITAE

DSP Lab Manual


IIR high pass filter coefficients:
#define N 83 //length of filter
Short

h[N]={1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,

3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,
1,3,1,3,1,3,1,3,1,2,1};
IIR low pass filter coefficients:
#define N 83 //length of filter
Shorth[N]={1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,
3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,2,1 };
c-Program:
main.c
#include "stdio.h"
#include "usbstk5515.h"
void main( void )
{
/* Initialize BSL */
USBSTK5515_init();
printf( "playing audio ::::: \n" );
while(1)
{
aic3204_test( );
}
}
Aic3204_test.c:
#define AIC3204_I2C_ADDR 0x18
#include "usbstk5515.h"
#include "usbstk5515_gpio.h"
#include "usbstk5515_i2c.h"
#include "stdio.h"
extern Int16 aic3204_tone_headphone( );
extern Int16 aic3204_loop_stereo_in1( );

Dept of ECE

91

VITAE

DSP Lab Manual


Int16 AIC3204_rget( Uint16 regnum, Uint16* regval )
{
Int16 retcode = 0;
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = 0;
retcode |= USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 1 );
retcode |= USBSTK5515_I2C_read( AIC3204_I2C_ADDR, cmd, 1 );
*regval = cmd[0];
USBSTK5515_wait( 10 );
return retcode;
}
Int16 AIC3204_rset( Uint16 regnum, Uint16 regval )
{
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = regval; // 8-bit Register Data
return USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 2 );
}
Int16 aic3204_test( )
{
SYS_EXBUSSEL = 0x6100; // Enable I2C bus
USBSTK5515_I2C_init( ); // Initialize I2C
USBSTK5515_wait( 100 ); // Wait
if ( aic3204_loop_stereo_in1( ) )
return 1;
return 0;
}
aic3204_loop_stereo_in1.c:
#include "stdio.h"
#include "usbstk5515.h"

Dept of ECE

92

VITAE

DSP Lab Manual


extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define N 83
Int16 data1, data2, data3, data4;
int sample, n, k, l;
Int16 dly0[N];
Int16 dly1[N];
Int32 lyn,lyn0,lyn1;
Int16

h[N]={1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,

3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,
3,1,3,1,3,1,3,1,3,1,2,1 };
Int16 aic3204_loop_stereo_in1 ( )
{
/* Pre-generated sine wave data, 16-bit signed samples */
Int16 j, i = 0;
/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Point to page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
AIC3204_rset( 0, 0 ); // Select page 0
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK is set as o/p to AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL
CLK
AIC3204_rset( 6, 8 ); // PLL setting: J=8
AIC3204_rset( 7, 15 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0xdc ); // PLL setting: LO_BYTE(D)

Dept of ECE

93

VITAE

DSP Lab Manual


AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
AIC3204_rset( 5, 0x91 ); // PLL setting: Power up PLL, P=1 and R=1
AIC3204_rset( 13, 0 ); // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC
oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for decimation
filters 1 to 6
AIC3204_rset( 11, 0x88 ); // Power up NDAC and set NDAC value to 8
AIC3204_rset( 12, 0x82 ); // Power up MDAC and set MDAC value to 2
AIC3204_rset( 18, 0x88 ); // Power up NADC and set NADC value to 8
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 12, 0x08 ); // LDAC AFIR routed to HPL
AIC3204_rset( 13, 0x08 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 64, 0x02 ); // Left vol=right vol
AIC3204_rset( 65, 0x00 ); // Left DAC gain to 0dB VOL; Right tracks Left
AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 16, 0x06 ); // Unmute HPL , 6dB gain
AIC3204_rset( 17, 0x06 ); // Unmute HPR , 6dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
USBSTK5515_wait( 500 ); // Wait
/* ADC ROUTING and Power Up */
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x34, 0x30 ); // STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 0x37, 0x30 ); // IN2_R to RADC_P through 40 kohmm

Dept of ECE

94

VITAE

DSP Lab Manual


AIC3204_rset( 0x36, 3 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 0x39, 0xc0 ); // CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 0x3b, 0 ); // MIC_PGA_L unmute
AIC3204_rset( 0x3c, 0 ); // MIC_PGA_R unmute
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 0x51, 0xc0 ); // Powerup Left and Right ADC
AIC3204_rset( 0x52, 0 ); // Unmute Left and Right ADC
AIC3204_rset( 0, 0 );
USBSTK5515_wait( 200 ); // Wait
/* I2S settings */
I2S0_SRGR = 0x0;
I2S0_CR = 0x8010; // 16-bit word, slave, enable I2C
I2S0_ICMR = 0x3f; // Enable interrupts
/* Play Tone */
for(l=0;l<N;l++)
{
dly0[l]=0;
dly1[l]=0;
}
for ( i = 0 ; i < 5 ; i++ )
{
for ( j = 0 ; j < 1000 ; j++ )
{
for ( sample = 0 ; sample < N ; sample++ )
{
/* Read Digital audio input */
data3 = I2S0_W0_MSW_R; // 16 bit left channel received audio data
data1 = I2S0_W0_LSW_R;
data4 = I2S0_W1_MSW_R; // 16 bit right channel received audio data
data2 = I2S0_W1_LSW_R;
while((Rcv & I2S0_IR) == 0); // Wait for interrupt pending flag

Dept of ECE

95

VITAE

DSP Lab Manual


dly0[sample]=data3;
lyn0=0;
lyn1=0;
for(k=0;k<=sample;k++)
lyn0+=((h[k])*dly0[sample-k]); //fir low pass filter
for(k=1;k<=sample;k++)
lyn1+=((h[k])*dly1[sample-k]); //fir low pass filter
lyn=lyn0-lyn1;
dly1[sample]=lyn;
data1=lyn<<1;
data2=lyn<<1;
/* Write Digital audio input */
I2S0_W0_MSW_W = data1; // 16 bit left channel transmit audio data
I2S0_W0_LSW_W = 0;
I2S0_W1_MSW_W = data2; // 16 bit right channel transmit audio data
I2S0_W1_LSW_W = 0;
while((Xmit & I2S0_IR) == 0); // Wait for interrupt pending flag
}
}
}
/* Disble I2S */
I2S0_CR = 0x00;
return 0;
}
Execution Procedure:

Open CCstudio setup

Go to File Menu , select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select FIR Project folder and Finish it.

Dept of ECE

96

VITAE

DSP Lab Manual

Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)

Give Right Click on Your fir.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

Observe the audio (Give Input from Stereo in and listen Filtered Output from
Stereo Out).

Dept of ECE

97

VITAE

DSP Lab Manual

EXP.NO: 20
GENERATION OF SINUSOIDAL SIGNAL THROUGH FILTERING
Program:
Main.c
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 40 //no of points for FFT
#define PI 3.14159265358979
float output;
float y[40];
void main()
{
int n;
for (n=0; n<PTS; n++)
{
/*y[n]=Ay[n1]+By[n2] A=1.9754 and B=1. Examining the behavior
of this IIR filter by its transfer function as below:
//y[n] = 1.9754y[n1] y[n2] */
if(n<2)
y[n]=sin(2*PI*n/PTS);
else
y[n]=(1.9754*y[n-1])-(y[n-2]);
printf("%f,",y[n]);
}
}
Execution Procedure:

Open CCstudio setup

Go to File Menu , select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then

next.

Dept of ECE

98

VITAE

DSP Lab Manual

In Select root Directory Browse for project file where it is located.

Select sinusoidal through Filtering Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual

procedure from Step 46 to 51)

Give Right Click on Your sin.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

In Tools menu select Graph (single Time) set the properties and watch.

Result:

Graph Proeprties:

Dept of ECE

99

VITAE

DSP Lab Manual

Dept of ECE

100

VITAE

DSP Lab Manual

EXP.NO: 21
GENERATION OF DTMF SIGNALS
Program:
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 256
#define FS 8000 //sampling frequency of 8khz
#define pi 3.14159265358979
int lfg[ ]={697,770,852,941}; // Low frequency group
int hfg[ ]={1209,1336,1477}; // High frequency group
float num[12][PTS];
float t[PTS];
void main()
{
int n,tone_select=0,r=0,c=0;
printf("DTMF Signal Generation:");
for(n=0;n<PTS;n++) {
t[n] = 2*pi*n/FS; }
tone_select=0;
for(r=0;r<4;r++) //loop for selection lfg index
{
for(c=0;c<3;c++) //loop for selection hfg index
{
for(n=0;n<PTS;n++)
{
num[tone_select][n]=sin(lfg[r]*t[n])+sin(hfg[c]*t[n]);
//printf("%d %f \n",n,t[n],num[tone_select][n]);
}
tone_select++;
}

Dept of ECE

101

VITAE

DSP Lab Manual


}
printf("Done");
}
Execution Procedure:

Open CCstudio setup

Go to File Menu, select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select DTMF Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it. (Follow the above given manual
procedure from Step 46 to 51).

Give Right Click on Your dtmf.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

In Tools menu select Graph (single Time) set the properties and watch.

Result:
DTMF 1:

DTMF 2:

Dept of ECE

102

VITAE

DSP Lab Manual

Dept of ECE

103

VITAE

DSP Lab Manual

EXP.NO: 22
IMPLEMENTATION OF DECIMATION PROCESS
Program:
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 256 //no of points for FFT
#define PI 3.14159265358979
float y1[PTS],y2[PTS],y3[PTS];
main()
{
int n,m;
printf("Enter Vaue for Decimation Factor\n");
scanf("%d",&m);
printf("Original signal samples:\n");
for(n=0;n<=PTS;n++) //original signal
{
y1[n]=sin(2*PI*10*(n)/(PTS));
printf("%d, %f\n",n,y1[n]);
}
printf("Decimated signal samples:\n");
for(n=0;n<=PTS;n++) //intrpol
{
y2[n]=sin(2*PI*10*n/(m*PTS));
printf("%d, %f\n",n,y2[n]);
}
} //end of main
Execution Procedure:
Open CCstudio setup
Go to File Menu, select Import option.
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
Dept of ECE

104

VITAE

DSP Lab Manual

In Select root Directory Browse for project file where it is located.

Select Decimation Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it. (Follow the above given manual
procedure from Step 46 to 51).

Give Right Click on Your decimation.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

In Tools menu select Graph (Dual Time) set the properties and watch input signal and
decimated signal.

Result:
Input signal:

Output Signal:

Graph Properties:

Dept of ECE

105

VITAE

DSP Lab Manual

EXP.NO: 23
IMPLEMENTATION OF INTERPOLATION PROCESS
Program:
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 256 //no of points for FFT
#define PI 3.14159265358979
float y1[PTS],y2[PTS],y3[PTS];
main()
{
int n,m;
printf("Enter Vaue for Interpolation Factor\n");
scanf("%d",&m);
printf("Original signal samples:\n");
for(n=0;n<=PTS;n++) //original signal
{
y1[n]=sin(2*PI*10*(n)/(PTS));
printf("%d, %f\n",n,y1[n]);
}
printf("Interpolated signal samples:\n");
for(n=0;n<=PTS;n++) //intrpol
Dept of ECE

106

VITAE

DSP Lab Manual


{
y2[n]=sin(2*PI*10*(m*n)/(PTS));
printf("%d, %f\n",n,y2[n]);
}
}
Execution Procedure:

Open CCstudio setup

Go to File Menu, select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select Interpolation Project folder and Finish it.

Now Connect the DSP Kit to PC and Launch it. (Follow the above given manual
procedure from Step 46 to 51).

Give Right Click on Your interpolation.out file under Binaries and select Load
program Option.

Now Go to Target select Run.

In Tools menu select Graph (Dual Time) set the properties and watch input signal and
decimated signal.

Result :

Input Signal:

Dept of ECE

107

VITAE

DSP Lab Manual

Dept of ECE

108

VITAE

DSP Lab Manual


Output Signal:

Graph Properties:

Dept of ECE

109

VITAE

DSP Lab Manual

EXP.NO: 24
IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER
SYSTEMS
Program:
#include<stdio.h>
#define Order 2
#define Len 5
float h[Len] = {0.0,0.0,0.0,0.0,0.0},sum;
void main()
{
int j, k;
float a[Order+1] = {0.1311, 0.2622, 0.1311};
float b[Order+1] = {1, -0.7478, 0.2722};
for(j=0; j<Len; j++)
{
sum = 0.0;
for(k=1; k<=Order; k++)
{
if ((j-k) >= 0)
sum = sum+(b[k]*h[j-k]);
}
if (j <= Order)
h[j] = a[j]-sum;
else
h[j] = -sum;
printf (" %f ",h[j]);
}
}
Output:
0.131100 0.360237 0.364799 0.174741 0.031373

Dept of ECE

110

VITAE

DSP Lab Manual

FOR FIRST ORDER DIFFERENCE EQUATION.


Program:
#include<stdio.h>
#define Order 1

Dept of ECE

111

VITAE

DSP Lab Manual


#define Len 5
float h[Len] = {0.0,0.0,0.0,0.0,0.0},sum;
void main()
{
int j, k;
float a[Order+1] = {0.1311, 0.2622};
float b[Order+1] = {1, -0.7478};
for(j=0; j<Len; j++)
{
sum = 0.0;
for(k=1; k<=Order; k++)
{
if((j-k)>=0)
sum = sum+(b[k]*h[j-k]);
}
if(j<=Order)
h[j] = a[j]-sum;
else
h[j] = -sum;
printf("%f ", j, h[j]);
}
}
Output:
0.131100 0.360237 0.269385 0.201446 0.150641

Dept of ECE

112

VITAE

DSP Lab Manual

Graph Properties:

Dept of ECE

113

VITAE

DSP Lab Manual

EXP. NO 25
AUDIO APPLICATIONS
Aim: Audio applications such as to plot a time and frequency display of
microphone plus a cosine using DSP. Read a wav file and match with their
respective spectrograms.

Program:
#include <math.h>
#include <stdio.h>
#include "usbstk5515.h"
#define PTS 64
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);
void cosine_plot(void);
Int16 aic3204_test( );
extern Int16 dly0[PTS];
COMPLEX data[PTS],samples[PTS];
COMPLEX w[PTS];
#define PI 3.14159265358979
float x1[PTS],y1[PTS],iobuffer[PTS];
int i;
void main( void )
{
/* Initialize BSL */
USBSTK5515_init();
for (i = 0;i<PTS;i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants
}
printf( "Cosine Plot ::::: \n" );
cosine_plot();

Dept of ECE

114

VITAE

DSP Lab Manual


printf( "playing audio ::::: \n" );
while(1)
{
aic3204_test( );
//for(i=0;i<PTS;i++)
// printf( "%d \n",dly0[i]);
for(i=0;i<PTS;i++)
{
data[i].real = dly0[i];
data[i].imag = 0.0;
}
FFT(data,PTS);
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(data[i].real*data[i].real + data[i].imag*data[i].imag);
printf("\n%d = %f",i,x1[i]);
}
}
}
void cosine_plot()
{
int i;
for (i = 0 ; i < PTS ; i++) //swap buffers
{
iobuffer[i] = cos(2*PI*2*i/64.0);/*10- > freq, 64 -> sampling freq*/
printf("\n%d = %f",i,iobuffer[i]);
samples[i].real=0.0;
samples[i].imag=0.0;
}
for (i = 0 ; i < PTS ; i++) //swap buffers
{

Dept of ECE

115

VITAE

DSP Lab Manual


samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
FFT(samples,PTS); //call function FFT.c
printf("\n output");
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
y1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag);
printf("\n%d = %f",i,x1[i]);
}
}
aic3204_loop_stereo_in1.C

#include "stdio.h"
#include "usbstk5515.h"
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define N 64
Int16 data1, data2, data3, data4;
int sample,n,k,l;
Int16 dly0[N];
Int32 lyn,ryn;
Int16 aic3204_loop_stereo_in1( )
{
// Int16 j, i = 0;
/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Point to page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD

Dept of ECE

116

VITAE

DSP Lab Manual


AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
AIC3204_rset( 0, 0 ); // Select page 0
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK is set as o/p to AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL CLK
AIC3204_rset( 6, 8 ); // PLL setting: J=8
AIC3204_rset( 7, 15 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0xdc ); // PLL setting: LO_BYTE(D)
AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
AIC3204_rset( 5, 0x91 ); // PLL setting: Power up PLL, P=1 and R=1
AIC3204_rset( 13, 0 );// Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC
oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for decimation
filters 1 to 6
AIC3204_rset( 11, 0x88 ); // Power up NDAC and set NDAC value to 8
AIC3204_rset( 12, 0x82 ); // Power up MDAC and set MDAC value to 2
AIC3204_rset( 18, 0x88 ); // Power up NADC and set NADC value to 8
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 12, 0x08 ); // LDAC AFIR routed to HPL
AIC3204_rset( 13, 0x08 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 64, 0x02 ); // Left vol=right vol
AIC3204_rset( 65, 0x00 ); // Left DAC gain to 0dB VOL; Right tracks Left
AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 16, 0x06 ); // Unmute HPL , 6dB gain

Dept of ECE

117

VITAE

DSP Lab Manual


AIC3204_rset( 17, 0x06 ); // Unmute HPR , 6dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
USBSTK5515_wait( 500 ); // Wait
/* ADC ROUTING and Power Up */
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x34, 0x30 ); // STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 0x37, 0x30 ); // IN2_R to RADC_P through 40 kohmm
AIC3204_rset( 0x36, 3 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 0x39, 0xc0 ); // CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 0x3b, 0 ); // MIC_PGA_L unmute
AIC3204_rset( 0x3c, 0 ); // MIC_PGA_R unmute
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 0x51, 0xc0 ); // Powerup Left and Right ADC
AIC3204_rset( 0x52, 0 ); // Unmute Left and Right ADC
AIC3204_rset( 0, 0 );
USBSTK5515_wait( 200 ); // Wait
/* I2S settings */
I2S0_SRGR = 0x0;
I2S0_CR = 0x8010; // 16-bit word, slave, enable I2C
I2S0_ICMR = 0x3f; // Enable interrupts
/* Play Tone */
for(l=0;l<N;l++)
dly0[l]=0;
for ( sample = 0; sample < N ; sample++ )
{
USBSTK5515_waitusec(25);
/* Read Digital audio input */
data3 = I2S0_W0_MSW_R; // 16 bit left channel received audio data
data1 = I2S0_W0_LSW_R;

Dept of ECE

118

VITAE

DSP Lab Manual


data4 = I2S0_W1_MSW_R; // 16 bit right channel received audio data
data2 = I2S0_W1_LSW_R;
while((Rcv & I2S0_IR) == 0); // Wait for interrupt pending flag
// printf("data3.. %d \n",data3);
USBSTK5515_wait(5000);
dly0[sample] = data3;
/* Write Digital audio input */
I2S0_W0_MSW_W = data3; // 16 bit left channel transmit audio data
I2S0_W0_LSW_W = 0;
I2S0_W1_MSW_W = data3; // 16 bit right channel transmit audio data
I2S0_W1_LSW_W = 0;
while((Xmit & I2S0_IR) == 0); // Wait for interrupt pending flag
}
/* Disble I2S */
I2S0_CR = 0x00;
return 0;
}
aic3204_test.c
#define AIC3204_I2C_ADDR 0x18
#include "usbstk5515.h"
#include "usbstk5515_gpio.h"
#include "usbstk5515_i2c.h"
#include "stdio.h"
extern Int16 aic3204_tone_headphone( );
extern Int16 aic3204_loop_stereo_in1( );
Int16 AIC3204_rget( Uint16 regnum, Uint16* regval )
{
Int16 retcode = 0;
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = 0;

Dept of ECE

119

VITAE

DSP Lab Manual


retcode |= USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 1 );
retcode |= USBSTK5515_I2C_read( AIC3204_I2C_ADDR, cmd, 1 );
*regval = cmd[0];
USBSTK5515_wait( 10 );
return retcode;
}
Int16 AIC3204_rset( Uint16 regnum, Uint16 regval )
{
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = regval; // 8-bit Register Data
return USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 2 );
}
Int16 aic3204_test( )
{
SYS_EXBUSSEL = 0x6100; // Enable I2C bus
USBSTK5515_I2C_init( ); // Initialize I2C
USBSTK5515_wait( 100 ); // Wait
if ( aic3204_loop_stereo_in1( ) )
return 1;
return 0;
}
FFT.C

Refer previous FFT experiment


Execution Procedure:

Open CCstudio setup

Go to File Menu , select Import option.

In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.

In Select root Directory Browse for project file where it is located.

Select Audio Project folder and Finish it.

Dept of ECE

120

VITAE

DSP Lab Manual

Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure

from Step 46 to 51)

Give Right Click on Your Audio.out file under Binaries and select Load program
Option.

Now Go to Target select Run.

Observe the audio (Give Input from Stereo in and listen Filtered Output

from Stereo Out).

In Tools menu select Graph (Dual Time) set the properties and watch.

Result:
Cosine time plot

Audio time plot

Dept of ECE

121

VITAE

DSP Lab Manual

Audio time plot

Frequency plot

Cosine time plot

Dept of ECE

122

VITAE

DSP Lab Manual

Cosine Frequency plot

Dept of ECE

123

VITAE

DSP Lab Manual

EXP. NO.26
NOISE REMOVAL
Noise removal programs:
(i)

Add noise above 3kHz and then remove (using adaptive filters)

(ii)

Interference suppression using 400 Hz tone

Program code:
Main.c
#include<usbstk5515.h>
#include<stdio.h>
Int16 aic3204_test( );
void main()
{
USBSTK5515_init();
while(1)
{
aic3204_test();
}
}
aic3204_loop_stereo_in1.c
#include "stdio.h"
#include "usbstk5515.h"
#include<math.h>
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define beta 1.5E-8 /*rate of convergence */
#define N1 30 /*# of coefficients */
#define NS 128 /*# of output sample points*/
#define Fs 8000 /*sampling frequency */
#define pi 3.1415926
//#define DESIRED 1000*sin(2*pi*T*1000/Fs) /*desired signal */

Dept of ECE

124

VITAE

DSP Lab Manual


#define ADDNOISE 1000*sin(2*pi*T*3000/Fs) /*additive noise */
#define REFNOISE 1000*cos(2*pi*T*3000/Fs) /*reference noise*/
Int16 data1, data2, data3, data4;
int sample,n,k,l;
Int16 dly0[NS];
Int32 lyn,ryn;
int I,T;
float W[N1+1];
float Delay[N1+1];
float Y, E, DPLUSN,IO_INPUT[NS],IO_OUTPUT[NS],a[NS],b[NS];
Int16 aic3204_loop_stereo_in1( )
{
// Int16 j, i = 0;
/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Point to page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
AIC3204_rset( 0, 0 ); // Select page 0
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK is set as o/p to AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL CLK
AIC3204_rset( 6, 8 ); // PLL setting: J=8
AIC3204_rset( 7, 15 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0xdc ); // PLL setting: LO_BYTE(D)
AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
AIC3204_rset( 5, 0x91 ); // PLL setting: Power up PLL, P=1 and R=1
AIC3204_rset( 13, 0 );// Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC

Dept of ECE

125

VITAE

DSP Lab Manual


oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for decimation
filters 1 to 6
AIC3204_rset( 11, 0x88 ); // Power up NDAC and set NDAC value to 8
AIC3204_rset( 12, 0x82 ); // Power up MDAC and set MDAC value to 2
AIC3204_rset( 18, 0x88 ); // Power up NADC and set NADC value to 8
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 12, 0x08 ); // LDAC AFIR routed to HPL
AIC3204_rset( 13, 0x08 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 64, 0x02 ); // Left vol=right vol
AIC3204_rset( 65, 0x00 ); // Left DAC gain to 0dB VOL; Right tracks Left
AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 16, 0x06 ); // Unmute HPL , 6dB gain
AIC3204_rset( 17, 0x06 ); // Unmute HPR , 6dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
USBSTK5515_wait( 500 ); // Wait
/* ADC ROUTING and Power Up */
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x34, 0x30 ); // STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 0x37, 0x30 ); // IN2_R to RADC_P through 40 kohmm
AIC3204_rset( 0x36, 3 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 0x39, 0xc0 ); // CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 0x3b, 0 ); // MIC_PGA_L unmute
AIC3204_rset( 0x3c, 0 ); // MIC_PGA_R unmute

Dept of ECE

126

VITAE

DSP Lab Manual


AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 0x51, 0xc0 ); // Powerup Left and Right ADC
AIC3204_rset( 0x52, 0 ); // Unmute Left and Right ADC
AIC3204_rset( 0, 0 );
USBSTK5515_wait( 200 ); // Wait
/* I2S settings */
I2S0_SRGR = 0x0;
I2S0_CR = 0x8010; // 16-bit word, slave, enable I2C
I2S0_ICMR = 0x3f; // Enable interrupts
/* Play Tone */
for(l=0;l<NS;l++)
dly0[l]=0;
for(T=0;T<N1;T++)
{
W[T] = 0.0;
Delay[T] = 0.0;
}
for ( T = 0; T < NS ; T++ )
{ USBSTK5515_waitusec(25);
/* Read Digital audio input */
data3 = I2S0_W0_MSW_R; // 16 bit left channel received audio data
data1 = I2S0_W0_LSW_R;
data4 = I2S0_W1_MSW_R; // 16 bit right channel received audio data
data2 = I2S0_W1_LSW_R;
while((Rcv & I2S0_IR) == 0); // Wait for interrupt pending flag
// printf("data3.. %d \n",data3);
USBSTK5515_wait(5000);
dly0[T] = data3;
Delay[0] = REFNOISE; /*adaptive filters input*/
b[T]=DPLUSN = dly0[T]+ADDNOISE; /*desired + noise, d+n */
Y = 0;

Dept of ECE

127

VITAE

DSP Lab Manual


for(I=0;I<N1;I++)
Y += (W[I] * Delay[I]); /*adaptive filter output */
E = DPLUSN-Y; /*error signal */
for(I=N1;I>0;I--)
{
W[I] = W[I]+(beta*E*Delay[I]); /*update weights */
if (I != 0)
Delay[I] = Delay[I-1]; /*update samples */
}
/* Write Digital audio input */
I2S0_W0_MSW_W = E; // 16 bit left channel transmit audio data
I2S0_W0_LSW_W = 0;
I2S0_W1_MSW_W = E; // 16 bit right channel transmit audio data
I2S0_W1_LSW_W = 0;
while((Xmit & I2S0_IR) == 0); // Wait for interrupt pending flag
}
/* Disble I2S */
I2S0_CR = 0x00;
return 0;
}
/*
void apply_noise()
{
for(T=0;T<NS;T++) //# of output samples
{
a[T] = dly0[T];
IO_OUTPUT[T] = E; //overall output E
IO_INPUT[T]= DPLUSN; // store d + n
printf("%d %f %f\n",T,IO_INPUT[T],IO_OUTPUT[T]);
}
}*/

Dept of ECE

128

VITAE

DSP Lab Manual


And one more .c file same as aic3204_test.c in the above experiment.
Execution Procedure:

Open CCstudio setup


Go to File Menu , select Import option.
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
In Select root Directory Browse for project file where it is located.
Select FIR Project folder and Finish it.
Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure
from Step 46 to 51)
Give Right Click on Your fir.out file under Binaries and select Load program
Option.
Now Go to Target select Run.
Observe the audio (Give Input from Stereo in and listen Filtered Output
from Stereo Out).
INTRODUCTION TO CODE COMPOSER STUDIO
Code Composer is the DSP industry's first fully integrated development
environment (IDE) with DSP-specific functionality. With a familiar environment
liked MS-based C++TM, Code Composer lets you edit, build, debug, profile and
manage projects from a single unified environment. Other unique features
include graphical signal analysis, injection/extraction of data signals via file I/O,
multi-processor debugging, automated testing and customization via a Cinterpretive scripting language and much more.
CODE COMPOSER FEATURES INCLUDE:

IDE
Debug IDE
Advanced watch windows
Integrated editor
File I/O, Probe Points, and graphical algorithm scope probes
Advanced graphical signal analysis
Interactive profiling
Automated testing and customization via scripting
Visual project management system
Compile in the background while editing and debugging
Multi-processor debugging
Help on the target DSP

Dept of ECE

129

VITAE

DSP Lab Manual


Note :
Documents for Reference:
spru509 Code Composer Studio getting started guide.
spru189 TMS320C6000 CPU & Instruction set guide
spru190 TMS320C6000 Peripherals guide
slws106d codec(TLV320AIC23) Data Manual.
spru402 Programmers Reference Guide.
sprs186j TMS320C6713 DSP
Soft Copy of Documents are available at : c:\ti\docs\pdf.

Procedure to work on Code Composer Studio


To create the New Project
Project New (File Name. pjt , Eg: Vectors.pjt)
To Create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib 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
Compile:
To Compile: Project Compile
To Rebuild: Project rebuild,
which will create the final .out executable file.(Eg. Vectors.out).
Procedure to Load and Run program:
Load the program to DSK: File Load program Vectors. out
Dept of ECE

130

VITAE

DSP Lab Manual

To Execute project: Debug Run.

sum.c
# include<stdio.h>
main()
{
int i=0;
i++;
printf("%d",i);
}
To Perform Single Step Debugging:
1. Keep the cursor on the on to the line from where u want to start single
step debugging.(eg: set a break point on to first line int i=0; of your
project.)
To set break point select

icon from tool bar menu.

2. Load the Vectors. out file onto the target.


3. Go to view and select Watch window.
4. Debug Run.
5. Execution should halt at break point.
6. Now press F10. See the changes happening in the watch window.
7. Similarly go to view & select CPU registers to view the changes happening
in CPU registers.
8. Repeat steps 2 to 6.

Dept of ECE

131

VITAE

DSP Lab Manual

Additional Programs:
EXP. NO.:27 LINEAR CONVOLUTION
To Verify Linear Convolution:
Linear Convolution Involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:

x[ ]= Input signal Samples


h[ ]= Impulse response co-efficient.
y[ ]= Convolution output.
n = No. of Input samples
h = No. of Impulse response co-efficient.
Algorithm to implement C or Assembly program for Convolution:
Eg:

x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}

Where: n=4, k=4.

;Values of n & k should be a multiple of 4.


If n & k are not multiples of 4, pad with zeros to make
multiples of 4
r= n+k-1
; Size of output sequence.
= 4+4-1
= 7.

r=
n= 0
1
2
3

0
1
2
x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
x[1]h[0] x[1]h[1] x[1]h[2]
x[2]h[0] x[2]h[1]
x[3]h[0]

Dept of ECE

x[1]h[3]
x[2]h[2] x[2]h[3]
x[3]h[1] x[3]h[2]

132

x[3]h[3]

VITAE

DSP Lab Manual

Output:

y[r] = { 1, 4, 10, 20, 25, 24, 16}.

NOTE: At the end of input sequences pad n and k no. of zeros


EQUIVALENT C PROGRAM TO IMPLEMENT LINEAR CONVOLUTION
#include<stdio.h>
main()
{
int m=4;
/*Length of i/p samples sequence*/
int n=4;
/*Length of impulse response Co-efficients
*/
int i=0,j;
int x[10]={1,2,3,4,0,0,0,0};
/*Input Signal Samples*/
int h[10]={1,2,3,4,0,0,0,0};
/*Impulse Response Coefficients*/
/*At the end of input sequences pad M and N no. of zeros*/
int y[10];
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
Note:
1. To execute the above program follow procedure to work on code
composer studio
To view graphical output follow the above procedure.

OUTPUT:

Dept of ECE

133

VITAE

DSP Lab Manual

EXP. NO.: 28 CIRCULAR CONVOLUTION


Steps for Cyclic Convolution
Steps for cyclic convolution are the same as the usual convolution, except all
index calculations are done "mod N" = "on the wheel"
Dept of ECE

134

VITAE

DSP Lab Manual


Steps for Cyclic Convolution
Step1: Plot f[m] and h[m]

Subfigure 1.1

Subfigure 1.2

Step 2: "Spin" h[m] n times Anti Clock Wise (counter-clockwise) to get h[n-m]
(i.e. Simply rotate the sequence, h[n], clockwise by n steps)

Figure 2: Step 2
Step 3: Pointwise multiply the f[m] wheel and the h[nm] wheel. sum=y[n]
Step 4: Repeat for all 0nN1
Example 1: Convolve (n = 4)

Subfigure 3.1
Subfigure 3.2
Figure 3: Two discrete-time signals to be
convolved.

h[m] =

Dept of ECE

135

VITAE

DSP Lab Manual

Figure 4
Multiply f[m] and sum to yield: y[0] =3

h[1m]

Figure 5
Multiply f[m] and sum to yield: y[1] =5

h[2m]

Figure 6
Multiply f[m] and sum to yield: y[2] =3

h[3m]

Figure 7
Multiply f[m] and sum to yield: y[3] =1

Dept of ECE

136

VITAE

DSP Lab Manual

Program to Implement Circular Convolution


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

Dept of ECE

137

VITAE

DSP Lab Manual


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]);
}
IN PUT:
Eg:
x[4]={3, 2, 1,0}
h[4]={1, 1, 0,0}
OUT PUT

Dept of ECE

y[4]={3, 5, 3,0}

138

VITAE

Вам также может понравиться