+ All Categories
Home > Documents > DSP Lab Mannual

DSP Lab Mannual

Date post: 11-Sep-2014
Category:
Upload: aniruddha-rajshekar
View: 148 times
Download: 6 times
Share this document with a friend
Popular Tags:
57
H.S.Prashantha, Dept of TE, PESIT DSP LABORATORY MANUAL Semester : V Sub Code: 06ECL57 Prepared by H.S.Prashantha Assistant Professor Department of Telecommunication PES Institute of Technology Bangalore 1
Transcript
Page 1: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

DSP LABORATORY MANUAL

Semester : V Sub Code: 06ECL57

Prepared by

H.S.Prashantha

Assistant Professor

Department of Telecommunication

PES Institute of Technology

Bangalore

1

Page 2: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

DSP LABORATORY MANUAL

Semester : V Sub Code: 06ECL57

CONTENTSDSP using Matlab1. Verification of sampling theorem.2. Impulse response of a given system.3. Linear convolution of two given sequences.4. Circular convolution of two given sequences.5. Autocorrelation of a given sequence and verification of its properties.6. Cross correlation of a given sequence and verification of its properties7. Solving a given difference equation.8. Computation of N point DFT of a given sequence and to plot magnitude and phase

Spectrum.9. Linear convolution of two given sequences using DFT and IDFT.10. Circular convolution of two given sequences using DFT and IDFT11. Design and implementation of FIR filter to meet given specification.12. Design and implementation of IIR filter to meet given specification.

DSP Experiments using DSP processor1. Linear convolution of two given sequences.2. Circular convolution of two given sequences.3. Computation of N point DFT of a given sequence.4. Realization of an FIR filter (any type) to meet given specification. The input can be a signal

from function generator/speech signal.5. Audio specification such as to plot time and frequency display of microphone plus a cosine

using DSP. Read a wav file and match with their respective spectrograms.6. Noise removal: Add noise above 3KHz and then remove; Interference suppression using 400

Hz ton.7. Impulse response of a given system of a given system of first and second order.

2

Page 3: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

Cycle I

DSP using Matlab1. Verification of sampling theorem.2. Impulse response of a given system.3. Linear convolution of two given sequences.4. Circular convolution of two given sequences.5. Autocorrelation of a given sequence and verification of its properties.6. Cross correlation of a given sequence and verification of its properties7. Solving a given difference equation.

DSP Experiments using DSP processor8. Linear convolution of two given sequences.9. Circular convolution of two given sequences.10. Impulse response of a given system of a given system of first and second order.

Cycle II

DSP using Matlab1. Computation of N point DFT of a given sequence and to plot magnitude and phase

Spectrum.2. Linear convolution of two given sequences using DFT and IDFT.3. Circular convolution of two given sequences using DFT and IDFT4. Design and implementation of FIR filter to meet given specification.5. Design and implementation of IIR filter to meet given specification.

DSP Experiments using DSP processor1. Computation of N point DFT of a given sequence.2. Realization of an FIR filter (any type) to meet given specification. The input can be a signal

from function generator/speech signal.3. Audio specification such as to plot time and frequency display of microphone plus a cosine

using DSP. Read a wav file and match with their respective spectrograms.4. Noise removal: Add noise above 3KHz and then remove; Interference suppression using 400

Hz ton.

3

Page 4: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

Cycle 1

DSP USING MATLAB

MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++ etc. The key features of MATLAB are as follows

High-level language for technical computing Development environment for managing code, files, and data Interactive tools for iterative exploration, design, and problem solving Mathematical functions for linear algebra, statistics, Fourier analysis, filtering,

optimization, and numerical integration 2-D and 3-D graphics functions for visualizing data Tools for building custom graphical user interfaces

MATLAB (MATrix LABoratory) is a special purpose computer program optimized to perform engineering and scientific calculations.

The MATLAB program implements the MATLAB language, and provides a very extensive library of predefined functions to make technical programming tasks easier and more efficient.

The extremely wide variety of functions makes it much easier to solve technical problems in MATLAB than in other languages such as FORTRAN or C.

The advantages of using MATLAB for technical programming are: Ease of use Platform independence Predefined functions Device-independent plotting Graphical User Interface MATLAB Compiler

MATLAB is a huge program, with an incredibly rich variety of functions. There are more than 1000 functions in the basic MATLAB.

The disadvantages of MATLAB are: It is interpreted language, and therefore can execute more slowly than compiled

languages. Cost. (Student version of MATLAB is available for low cost with almost identical

feature) full copy of MATLAB is 5 TO 10 times more expensive than a conventional C or FORTRAN compiler.

The functional unit of data in any MATLAB program is the array. An array is a collection of data values organized into rows and columns.

When MATLAB executes, it can display several types of windows that accept commands or display information. The three most important types of windows are command windows, where commands may be entered: figure windows, which display plots and graphs: and edit/debug windows which permit a user to create and modify MATLAB programs.

The major tools within or accessible from the MATLAB desktop are: The command window : a user can enter interactive commands at the command

prompt (>>) in the command window and they will be executed on the spot. Instead of typing commands directly in the command window, a series of commands may be placed in to a single file and the entire file may be executed by

4

Page 5: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

typing its name in the command window. Such files are called script files. Script files are also called M-Files because they have file extension of “. M”.

The command history window : the command history window displays a list of the commands that a user has entered in the command window.

The launch pad : it is a special tool that collects references to the documentation, demos, and related tools for MATLAB itself and for each toolkit that you own.

The edit/debug window : used to create new M-Files, or to modify existing ones. An edit/debug window is created automatically when you create a new M-File or open an existing one. The edit/debug window is essentially a programming text editor, with the MATLAB languages features highlighted in different colors. Comments in an M-File appear in green, variables and numbers appear in black, character strings appear in red, and language keywords appear in blue.

Figure windows : used to display MATLAB graphics. A figure can be two or three-dimensional plot of data, an image or a GUI.

The MATLAB workspace : it is a collection of all the variables and arrays that can be used by MATLAB when a particular command, M-File, or function is executing. All commands executed in the command window share a common workspace, so they can all share variables. (Clear deletes all variables from the current workspace).

The workspace browser : it provides a graphic display of the same information as whos command, and the display is dynamically updated whenever the contents of workspace change. The workspace browser also allows user to change the contents of any variables in the workspace. (A list of the variables and arrays in the current workspace can be generated with the whos command)

Getting help : by selecting the? Help icon bar from the desktop tool bar, or by typing helpdesk or helpwin in the command window. The other way of obtaining help is by using lookfor command. Help command searches for an exact function name match, whereas the lookfor command searches the quick summary information in each function for a match. Lookfor is slower than help but it improves the chances of getting useful information.

For new users of MATLAB, a few demonstrations may help to give you a feel for its capabilities. To run MATLAB’s built in demonstrations, type demo in the command window, or select “demos” from the launch pad.

The contents of the command window can be cleared at any time using the clc command, and the contents of the current figure window can be cleared at any time using the clf command. The variables in the workspace can be cleared with the clear command. It is a good idea to issue the clear command at the start of each new independent calculation.

Another important command is the abort command. If an m-file appears to be running for too long, it might contain an infinite loop, and it will never terminate. In this case the user can regain the control by typing control-c (^c) in the command window. When MATLAB detects a ^c, it interrupts the running program and returns a command prompt.

After diary command is typed, a copy of all input and most output typed in the command window is echoed in the diary file. The command diary off suspends input in to the diary file, and the command diary on resumes input again.

5

Page 6: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

MATLAB includes a special command (which) to help you to find out just which version of a file is being executed. and where it is located. The format of this command is which functionname, where functionname is the name of the function that you are trying to locate.

The path related function include:

* addpath Add directory to MATLAB search path

* path Display MATLAB search path

* path2rc Add current directory to MATLAB search path

* rmpath Remove directory from MATLAB search path

The functional unit of data in any MATLAB program is the array. An array is a collection of data values organized into rows and columns, and known by a single name.

MATLAB variable is a region of memory containing an array, which is known by a user-specified name. MATLAB variable names must begin with a letter, followed by any combination of letters, numbers, and the underscore( _ ) character. Only the first 31 characters are significant; if more than 31 are used, the remaining characters will be ignored. If two variables are declared with names that only differ in the 32nd character, MATLAB will treat them as same variable.

Spaces cannot be used in MATLAB variable names, underscore letters can be substituted to create meaningful names.

It is important to include a data dictionary in the header of any program that you write. A data dictionary lists the definition of each variable used in a program. The definition should include both a description of the contents of the item and the units in which it is measured.

MATLAB language is case-sensitive. It is customary to use lower-case letters for ordinary variable names.

The most common types of MATLAB variables are double and char. MATLAB is weakly typed language. Variables are not declared in a program before it is

used. MATLAB variables are created automatically when they are initialized. There are three

common ways to initialize variables in MATLAB: Assign data to the variable in an assignment system. Input data into the variable from the keyboard. Read data from a file.

The semicolon at the end of each assignment statement suppresses the automatic echoing of values that normally occurs whenever an expression is evaluated in an assignment statement.

6

Page 7: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

How to invoke MATLAB?*) Double Click on the MATLAB icon on the desktop .*) You will find a Command window where in which you can type the commands and see the output. For example if you type PWD in the command window, it will print current working directory.*)If you want to create a directory type mkdir mydir in the command window, It will create a directory called pes.*) If you want delete a directory type rmdir mydir in the command window.How to open a file in MATLAB?*) Go to File à Newà M-File and clickThen type the program in the file and save the file with an extension of .m. While giving file name we should make sure that given file name should not be a command. It is better to the file name as myconvlution .

How to run a MATLAB file?*) Go to Debugàrun and click

1. Program to Verify Sampling Theorem

% program for verification of sampling theorem

clc; % clears the command windowclear all; % clears the variables declared

t=0:.001:0.1; f1=input ('Enter the input freequency1 = '); f2=input ('Enter the input freequency2 = ');

y=cos(2*pi*f1*t)+cos(2*pi*f2*t); f3=max(f1,f2);

% under samplingfs=f3; %fs = sampling freequencyts=1/fs; tx=0:ts:0.1;m=max(size(tx));ys=cos(2*f1*pi*tx)+cos(2*pi*f2*tx);figure(1);subplot(3,1,1);plot(t,y);grid on;title('The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)');xlabel('Time in seconds');ylabel('Amplitude in volts');subplot(3,1,2);

7

Page 8: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

stem(tx,ys);grid on;title('The sinusoidal signal sampled at fs Hz');xlabel('Time in seconds');ylabel('Amplitude in volts');subplot(3,1,3);plot(tx,ys);grid on;title('The recovered sinusidal sampled at fs Hz');xlabel('Time in seconds');ylabel('Amplitude in volts');

% Right samplingfs=2*f3; %fs = sampling freequencyts=1/fs; tx=0:ts:0.1;m=max(size(tx));ys=cos(2*pi*f1*tx)+cos(2*pi*f2*tx);figure(2);subplot(3,1,1);plot(t,y);grid on;title('The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)');xlabel('Time in seconds');ylabel('Amplitude in volts');subplot(3,1,2);stem(tx,ys);grid on;title('The sinusoidal signal sampled at fs Hz');xlabel('Time in seconds');ylabel('Amplitude in volts');subplot(3,1,3);plot(tx,ys);grid on;title('The recovered sinusidal sampled at fs Hz');xlabel('Time in seconds');ylabel('Amplitude in volts');

% over samplingfs=3*f3; %fs = sampling freequencyts=1/fs; tx=0:ts:0.1;m=max(size(tx));ys=cos(2*pi*f1*tx)+cos(2*pi*f2*tx);figure(3);subplot(3,1,1);

8

Page 9: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

plot(t,y);grid on;title('The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)');xlabel('Time in seconds');ylabel('Amplitude in volts');subplot(3,1,2);stem(tx,ys);grid on;title('The sinusoidal signal sampled at fs Hz');xlabel('Time in seconds');ylabel('Amplitude in volts');subplot(3,1,3);plot(tx,ys);grid on;title('The recovered sinusidal sampled at fs Hz');xlabel('Time in seconds');ylabel('Amplitude in volts');

OUTPUTUnder sampling

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)

Time in seconds

Am

plitu

de in

vol

ts

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10

1

2The sinusoidal signal sampled at fs Hz

Time in seconds

Am

plitu

de in

vol

ts

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10

1

2The recovered sinusidal sampled at fs Hz

Time in seconds

Am

plitu

de in

vol

ts

Right sampling

9

Page 10: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)

Time in seconds

Am

plitu

de in

vol

ts

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The sinusoidal signal sampled at fs Hz

Time in seconds

Am

plitu

de in

vol

ts

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The recovered sinusidal sampled at fs Hz

Time in seconds

Am

plitu

de in

vol

ts

Over sampling

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)

Time in seconds

Am

plitu

de in

vol

ts

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The sinusoidal signal sampled at fs Hz

Time in seconds

Am

plitu

de in

vol

ts

0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1-2

0

2The recovered sinusidal sampled at fs Hz

Time in seconds

Am

plitu

de in

vol

ts

10

Page 11: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

2. Program to find the Impulse response of the system

%To find the Impulse response of a given System%a0*y(n)-a1*y(n-1)+a2*y(n-2)=b0*x(n)+b1*x(n-1)+b2*x(n-2)clc;clear all;b=input('Enter the coefficiants of x(n) in the order x(n),x(n-1)...in the Matrix form = ');a=input('Enter the coefficiants of y(n) in the order y(n),y(n-1)...in the Matrix form = ');n=[-5:20];x=[(n==0)];h=filter(b,a,x)figure(1);subplot(2,1,1);stem(n,x);xlabel('n');ylabel('amplitude');title('impulse sequence');subplot(2,1,2);stem(n,h);xlabel('n');ylabel('amplitude');title('impulse response');

OUTPUTEnter the coefficiants of x(n) in the order x(n),x(n-1)...in the Matrix form = [0.2066 0.4131 0.2066]Enter the coefficiants of y(n) in the order y(n),y(n-1)...in the Matrix form = [1 -0.3695 0.1968]

-5 0 5 10 15 200

0.5

1

n

ampl

itude

impulse sequence

-5 0 5 10 15 20-0.2

0

0.2

0.4

0.6

n

ampl

itude

impulse response

11

Page 12: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

Amplitude= [0 0 0 0 0 0.2066 0.4894 0.3468 0.0318 -0.0565 -0.0271 0.0011 0.0057 0.0019 -0.0004 -0.0005 -0.0001 0.0001 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000]

3. Program to perform linear Convolution of two given sequences

%This program gives the convolution of two sequencesclc;clear all;close all;x1=input('enter the first sequence'); %input of first sequencex2=input('enter the second sequence'); %input of second sequencen1=length(x1);n2=length(x2);N=n1+n2-1;

x1=[x1 zeros(1,N-n1)];x2=[x2 zeros(1,N-n2)];m=[0:1:N-1];

for n=0:N-1 y(n+1)=sum(x2(mod(n-m,N)+1).*x1);end;disp('linear convoluted sequence');y

disp('first sequence');x1disp('second sequence');x2disp('convolved sequence');ysubplot(3,1,1);stem(x1);title('first sequence');xlabel('signal');ylabel('time');

subplot(3,1,2);stem(x2);title('second sequence');xlabel('signal');ylabel('time');

subplot(3,1,3);stem(y);

12

Page 13: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

title('convolved sequence');xlabel('signal');ylabel('time');

Input:x1 = 1 2 3 4 0 0 0second sequencex2 = 1 2 3 4 0 0 0convolved sequencey =

1 4 10 20 25 24 16

1 2 3 4 5 6 70

2

4first sequence

sign

al

time

1 2 3 4 5 6 70

2

4second sequence

sign

al

time

1 2 3 4 5 6 70

20

40convolved sequence

sign

al

time

4. Program to perform Circular Convolution of two given sequences

%This program calculates the circular convolutionclc;clear all;x=input('Input first sequence');h=input('Input second sequence');N1=length(x);N2=length(h);N=max(N1,N2);

13

Page 14: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

x=[x zeros(1,N-N1)];h=[h zeros(1,N-N2)];

for m=1:N y(m)=0; for n=1:N i=m-n+1; if(i<=0) i=N+i; end y(m)=y(m)+x(n)*h(i); endend

disp('first sequence');xdisp('second sequence');hdisp('convolved sequence');yn=0:N-1;subplot(3,1,1);stem(x);title('first sequence');ylabel('signal');xlabel('time');

subplot(3,1,2);stem(h);title('second sequence');ylabel('signal');xlabel('time');

subplot(3,1,3);stem(y);title('convolved sequence');ylabel('signal');xlabel('time');

OUTPUT

Input first sequence [1 2 3 4]Input second sequence [1 2 3 4]

first sequence

14

Page 15: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

x =

1 2 3 4

second sequence

h =

1 2 3 4

convolved sequence

y =

26 28 26 20

1 1.5 2 2.5 3 3.5 40

2

4first sequence

sign

al

time

1 1.5 2 2.5 3 3.5 40

2

4second sequence

sign

al

time

1 1.5 2 2.5 3 3.5 40

20

40convolved sequence

sign

al

time

5. Autocorrelation of a given sequencex=input('enter the sequence');y=xcorr(x,x);figure;subplot(2,1,1);stem(x);ylabel('amplitude');

15

Page 16: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

xlabel('n');subplot(2,1,2);stem(fliplr(y));yylabel('amplitude');xlabel('n');disp('the resultant signal is ');fliplr(y);

Input:Enter the sequence[1 2 3 4]The resultant signal is

y = [ 4 11 20 30 20 11 4]

1 1.5 2 2.5 3 3.5 40

1

2

3

4

ampl

itude

n

1 2 3 4 5 6 70

10

20

30

ampl

itude

n

6. Cross correlation of a given sequenceclc;close all;clear all;x=input('enter the sequence');h=input('enter the second sequence');y=xcorr(x,h);figure;subplot(3,1,1);

16

Page 17: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

stem(x);ylabel('amplitude');xlabel('n');subplot(3,1,2);stem(h);ylabel('amplitude');xlabel('n');subplot(3,1,3);stem(fliplr(y));yylabel('amplitude');xlabel('n');disp('the resultant signal is ');fliplr(y);

Input:enter the sequence[1 2 3 4]enter the second sequence[4 3 2 1]

y =

1.0000 4.0000 10.0000 20.0000 25.0000 24.0000 16.0000

The resultant signal is

1 1.5 2 2.5 3 3.5 40

2

4

ampl

itude

n

1 1.5 2 2.5 3 3.5 40

2

4

ampl

itude

n

1 2 3 4 5 6 70

10

20

30

ampl

itude

n

17

Page 18: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

7. Program to Solve difference equation

%program for solution of difference equation % y(n) -0.5 y(n-1) = x(n) with x(n)=u(n)-u(n-4)b=input('enter the coefficients of x');a=input('enter the coefficients of y');n=[-5:50];x=[(n>=0)]-[(n>4)];figure(1);subplot(2,1,1);stem(n,x);title('input sequence x(n)');xlabel('n');ylabel('x');subplot(2,1,2);y=filter(b,a,x);stem(n,y);title('output sequence y(n)');xlabel('n');ylabel('y');

-10 0 10 20 30 40 500

0.5

1input sequence x(n)

n

x

-10 0 10 20 30 40 500

0.5

1

1.5

2output sequence y(n)

n

y

% y(n) -0.25 y(n-1) -0.125 y(n-2)= x(n) with x(n)=u(n)-u(n-10) and initial condition y(-1)=1, y(-2)=-2

18

Page 19: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

b=input('enter the coefficients of x');a=input('enter the coefficients of y');c=input('enter the initial conditions');n=[-5:50];ic=filtic(b,a,c);

x=[(n>=0)]-[(n>10)]; y=filter(b,a,x,ic);

subplot(2,1,1);stem(n,x);title('input sequence x(n)');xlabel('n');ylabel('x');subplot(2,1,2);

stem(n,y);title('output sequence y(n)');xlabel('n');ylabel('y');

Output:

-10 0 10 20 30 40 500

0.5

1input sequence x(n)

n

x

-10 0 10 20 30 40 500

0.5

1

1.5

2output sequence y(n)

n

y

19

Page 20: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

8. Program to Calculate N point DFT and N point IDFT of the given sequence

%to compute dft of the sequence and plot magnitude and phase spectraclc;clear all;close all; % input sequencexn=input('enter the input sequence');N=input('enter the number of points');

xk=dft(xn,N);

%magnitude of fftmagxk=abs(xk);

%phase of fftphasexk=angle(xk);

k=0:N-1;

subplot(2,1,1); stem(k,magxk); title('fft sequence'); xlabel('frequency'); ylabel('magnitude'); subplot(2,1,2); stem(k,phasexk); title('phase of fft sequence'); xlabel('frequency'); ylabel('phase');

function xk=dft(xn,N)L=length(xn);if(N<L) error('N must be >=L');endx1=[xn zeros(1,N-L)]

for k=0:1:N-1; for n=0:1:N-1; p=exp(-i*2*pi*n*k/N) x2(k+1,n+1)=p; endendxk=x1*x2;

OUTPUT:X=[1 1 1 1 1 1 1 1]N=32

20

Page 21: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

0 5 10 15 20 25 30 350

2

4

6

8fft sequence

frequency

mag

nitu

de

0 5 10 15 20 25 30 35-4

-2

0

2

4phase of fft sequence

frequency

phas

e

%to compute idft of the sequence clc;clear all;close all; % input sequenceXk=input('enter the input sequence');N=length(Xk)

xn=idft(Xk,N);

k=0:N-1;

stem(k,xn); title('ifft sequence'); xlabel('time'); ylabel('amplitude'); disp(xn)

function xn=idft(Xk,N)

for k=0:1:N-1; for n=0:1:N-1; p=exp(i*2*pi*n*k/N) x2(k+1,n+1)=p; endend

21

Page 22: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

xn=(Xk*x2)./N;

9. Linear convolution of two sequences using DFT and IDFTclc;clear all;x=input('Input first sequence');h=input('Input second sequence');n1=length(x);n2=length(h);N=n1+n2-1;

x1=[x zeros(1,N-n1)];x2=[h zeros(1,N-n2)];a=fft(x,N);b=fft(h,N);c=a.*b;d=ifft(c,N);

disp('first sequence');xdisp('second sequence');hdisp('convolved sequence');dn=0:N-1;subplot(3,1,1);stem(x);title('first sequence');ylabel('signal');xlabel('time');

subplot(3,1,2);stem(h);title('second sequence');ylabel('signal');xlabel('time');

subplot(3,1,3);stem(d);title('convolved sequence');ylabel('signal');xlabel('time');Input:x = 1 1 1 1second sequenceh = 1 1 1 1convolved sequence

22

Page 23: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

d = 1.0000 2.0000 3.0000 4.0000 3.0000 2.0000 1.0000

1 1.5 2 2.5 3 3.5 40

0.5

1first sequence

sign

al

time

1 1.5 2 2.5 3 3.5 40

0.5

1second sequence

sign

al

time

1 2 3 4 5 6 70

2

4convolved sequence

sign

al

time

10. Circular convolution of two sequences using DFT and IDFTclc;clear all;x=input('Input first sequence');h=input('Input second sequence');n1=length(x);n2=length(h);N=max(n1,n2);

if N>n1 x1=[x zeros(1,N-n1)];end if N>n2 x2=[h zeros(1,N-n2)]; end a=fft(x,N);b=fft(h,N);c=a.*b;d=ifft(c,N);

disp('first sequence');xdisp('second sequence');hdisp('convolved sequence');dn=0:N-1;

23

Page 24: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

subplot(3,1,1);stem(x);title('first sequence');ylabel('signal');xlabel('time');

subplot(3,1,2);stem(h);title('second sequence');ylabel('signal');xlabel('time');

subplot(3,1,3);stem(d);title('convolved sequence');ylabel('signal');xlabel('time');

Result:Input first sequence[1 2 3]Input second sequence[1 2 3 4]first sequencex = 1 2 3second sequenceh = 1 2 3 4convolved sequenced = 18 16 10 16

24

Page 25: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 30

2

4first sequence

sign

al

time

1 1.5 2 2.5 3 3.5 40

2

4second sequence

sign

al

time

1 1.5 2 2.5 3 3.5 40

10

20convolved sequence

sign

al

time

11. Design and implementation of FIR filters to meet given specifications clear all;close all;clc;%cutoff frequency of low pass response at 0.25 pi and a minimum stopband%attenuation of 39 dB. transition band is 0.2 piwc=0.25*pi;tw=0.2*pi;

%normalize the cutoff frequency and transition widthfcn=wc/pi;twn=tw/pi;

%the required transition width is 39 dB. Choose Hanning window%order of the filterdisp('order of the filter');N=ceil(4/twn)if(rem(N,2)==0);N=N+1;end;

25

Page 26: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

y=hanning(N)disp('fir filter coefficients');

b=fir1(N-1,fcn,y)

disp('frequency response');[H,f]=freqz(b,1,256)H_mag=20*log10(abs(H));plot(f/pi,H_mag);xlabel('frequency in rad/sec');ylabel('gain in dB');

output:

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-140

-120

-100

-80

-60

-40

-20

0

20

frequency in rad/sec

gain

in d

B

%passband edge frequency of 2 kHz, a minimum stopband attenuation of 50 dB%transition band is 0.5 kHzat a sampling frequency of 8 kHz.

fs=8000;%normalizing frequencyfn=fs/2;%passband and stopband frequenciesfp=2000;tw=500;fs=fp+tw;%normalize the cutoff frequency and transition widthfcn=(fp+fs)/(2*fn);twn=tw/fs;%the required transition width is 50 dB. Choose Hamming window%order of the filterdisp('order of the filter');N=ceil(4/twn)if(rem(N,2)==0);N=N+1;end;

26

Page 27: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

y=hamming(N)disp('fir filter coefficients');b=fir1(N-1,fcn,y)disp('frequency response');[H,f]=freqz(b,1,256)H_mag=20*log10(abs(H));plot(f/pi,H_mag);xlabel('frequency in rad/sec');ylabel('gain in dB');

Output:

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-120

-100

-80

-60

-40

-20

0

20

frequency in rad/sec

gain

in d

B

12. Programs to Design IIR filters

% Program to Design the Digital IIR Butterworth Low pass filter using bilinear transformation

clc;clear all;

pb=input('Enter the pass band edge frequency ');sb=input('Enter the stop band edge frequency ');pbr=input('Enter the pass band attenuation ');sbr=input('Enter the stop band attenuation ');

fs= input('Enter the sampling frequency ');

pbrad=pb*2*pi;sbrad=sb*2*pi;

27

Page 28: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

[n,wn]=buttord(pbrad,sbrad,pbr,sbr,'s');[b,a]=butter(n,wn,'s');

[z,p,k]=tf2zp(b,a);[zd,pd,kd]=bilinear(z,p,k,fs);[num,den]=zp2tf(zd,pd,kd);

figure(1);freqz(num,den,512,fs);title('Butter worth freequency response');

[n,wn]=cheb1ord(pbrad,sbrad,pbr,sbr,'s');[b,a]=cheby1(n,pbr,wn,'s');

[z,p,k]=tf2zp(b,a);[zd,pd,kd]=bilinear(z,p,k,fs);[num,den]=zp2tf(zd,pd,kd);

figure(2);freqz(num,den,512,fs);title('Chebychev1 Freequency Response');

[n,wn]=cheb2ord(pbrad,sbrad,pbr,sbr,'s');[b,a]=cheby2(n,sbr,wn,'s');

[z,p,k]=tf2zp(b,a);[zd,pd,kd]=bilinear(z,p,k,fs);[num,den]=zp2tf(zd,pd,kd);

figure(3);freqz(num,den,512,fs);title('Chebychev 2 Freequency Response');

OUTPUTEnter the pass band edge frequency 1500Enter the stop band edge frequency 2000Enter the pass band attenuation 0.5Enter the stop band attenuation 30Enter the sampling frequency 8000

28

Page 29: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

0 500 1000 1500 2000 2500 3000 3500 4000-2000

-1000

0

Frequency (Hz)

Phase (

degre

es)

0 500 1000 1500 2000 2500 3000 3500 4000-500

0

500

Frequency (Hz)

Magnitude (

dB

)Butter worth freequency response

0 500 1000 1500 2000 2500 3000 3500 4000-1000

-500

0

Frequency (Hz)

Phase (

degre

es)

0 500 1000 1500 2000 2500 3000 3500 4000-500

0

500

Frequency (Hz)

Magnitude (

dB

) Chebychev1 Freequency Response

0 500 1000 1500 2000 2500 3000 3500 4000-500

0

500

Frequency (Hz)

Pha

se (

degr

ees)

0 500 1000 1500 2000 2500 3000 3500 4000-100

-50

0

Frequency (Hz)

Mag

nitu

de (

dB) Chebychev 2 Freequency Response

% Program to Disign the Digital IIR Butterworth Low pass filter using impulse invariance method

clc;clear all;

pb=input('Enter the pass band edge frequency ');sb=input('Enter the stop band edge frequency ');

pbr=input('Enter the pass band attenuation in dB ');

29

Page 30: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

sbr=input('Enter the stop band attenuation in dB ');

fs= input('Enetr the sampling frequency ');

pbrad=pb*2*pi;sbrad=sb*2*pi;

[n,wn]=buttord(pbrad,sbrad,pbr,sbr,'s');[b,a]=butter(n,wn,'s');[num,den]=impinvar(b,a,fs);

figure(1);freqz(num,den,512,fs);title('Butter worth frequency response');

[n,wn]=cheb1ord(pbrad,sbrad,pbr,sbr,'s');[b,a]=cheby1(n,pbr,wn,'s');[num,den]=impinvar(b,a,fs);

figure(2);freqz(num,den,512,fs);title('Chebychev1 Frequency Response');

[n,wn]=cheb2ord(pbrad,sbrad,pbr,sbr,'s');[b,a]=cheby2(n,sbr,wn,'s');[num,den]=impinvar(b,a,fs);

figure(3);freqz(num,den,512,fs);title('Chebychev 2 Frequency Response');

30

Page 31: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

DSP KIT TMS306713:Troubleshooting DSK Connectivity

If Code Composer Studio IDE fails to configure your port correctly, perform the following steps:

Test the USB port by running DSK Port test from the start menu

Use StartàProgramsàTexas InstrumentsàCode Composer StudioàCode Composer Studio

C6713 DSK ToolsàC6713 DSK Diagnostic Utilities

The below Screen will appear Selectà StartàSelect 6713 DSK Diagnostic Utility Icon from Desktop The Screen Look like as below Select Start Option Utility Program will test the board After testing Diagnostic Status you will get PASS

If the board still fails to detect

Go to CMOS setupà Enable the USB Port Option

31

Page 32: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

(The required Device drivers will load along with CCS Installation)

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 C-interpretive scripting language and much more.

CODE COMPOSER FEATURES INCLUDE:

IDEDebug IDEAdvanced watch windowsIntegrated editorFile I/O, Probe Points, and graphical algorithm scope probesAdvanced graphical signal analysisInteractive profilingAutomated testing and customization via scriptingVisual project management systemCompile in the background while editing and debuggingMulti-processor debuggingHelp on the target DSP

Procedure to work on Code Composer Studio

1. To create a New Project Project à New (SUM.pjt)

2. To Create a Source file

32

Page 33: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

File à New

type the code (Save & give a name to file, Eg: sum.c).

3. To Add Source files to ProjectProject à Add files to Project à sum.c

33

Page 34: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

4. To Add rts6700.lib file & hello.cmd:

Project à Add files to Project àrts6700.lib Path: c:\CCStudio\c6000\cgtools\lib\rts6700.lib

34

Page 35: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

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

Project à Add files to Project àhello.cmdPath: c:\ti\tutorial\dsk6713\hello1\hello.cmdNote: Select Linker Command file(*.cmd) in Type of files

5. To Compile: Project à Compile File

6. To build or Link: Project à build, Which will create the final executable (.out) file.(Eg. sum.out).

7. Procedure to Load and Run program:Load program to DSK: File à Load program à sum. out

8. To execute project: Debug à Run.

TMS320C6713 is a floating point DSP processor.Basically it is a cisc processor.It has following features*) It can execute eight 32-bit instructions/cycle*) Advanced Very Long Instruction Word DSP core.*) It has eight independent functional units.In which there are 2 ALUs of fixed point, 4 ALUs of Floating and fixed point and 2 multipliers of floating and fixed point.*) Two multi channel audio ports*) 32 bit External memory Interface.DSP Starter kit consists of TMS320C6713 ,CPLD,Flash Memory,SDRAM,Codec.

Code Composer Studio

35

Page 36: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

Code Composer is the Integrated Development Environment(IDE) with DSP specific functionality.Basically code composer studio is a cross compiler.That means the programs written in Higher level languages like ‘C’are converted into processor specific languages.

Procedure to work with code composer studioOpen the code composer studio,make sure DSP Starter Kit(DSK) is turned on.Create a new project as followsGo to Project->new and click on it , give project_name ,Select target as TMS320C67xx.Then save it in C:\CCStudio\MyProjectsThen go Project -> Add Files to Project and click on it , then add the run time support library C:\CCStudio\c6000\cgtools\lib\rts6700.libThen go Project-> Add Files to Project and click on it , then add the linker command file C:\CCStudio\tutorial\dsk6713\hello1\hello.cmdThen compile the program using Project->compile->click Then go to Project -> Rebuild All.Then go to File->Load program -> project_name.out into the DSP Starter kit.How to view graphical output

To view the graphical output go to ViewàGraphàTime/Frequency

1 ‘C’ PROGRAM TO IMPLEMENT LINEAR CONVOLUTION

/* prg to implement linear convolution */#include<stdio.h>

#define LENGHT1 6 /*Lenght of i/p samples sequence*/#define LENGHT2 4 /*Lenght of impulse response Co-efficients */

int x[2*LENGHT1-1]={1,2,3,4,5,6,0,0,0,0,0}; /*Input Signal Samples*/int h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0}; /*Impulse Response Co-efficients*/

int y[LENGHT1+LENGHT2-1];

main(){

int i=0,j;

for(i=0;i<(LENGHT1+LENGHT2-1);i++){y[i]=0;for(j=0;j<=i;j++)

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

}for(i=0;i<(LENGHT1+LENGHT2-1);i++)printf("%d\n",y[i]);

}

36

Page 37: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

PROCEDURE:

Open Code Composer Studio, make sure the DSP kit is turned on.

Start a new project using ‘Project-new ‘ pull down menu, save it in a separate directory(c:\ti\myprojects) with name lconv.pjt.

Add the source files conv.c to the project using ‘Projectàadd files to project’ pull down menu.

Add the linker command file hello.cmd .(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

Compile the program using the ‘Project-compile’ pull down menu or by clicking the shortcut icon on the left side of program window.

Build the program using the ‘Project-Build’ pull down menu or by clicking the shortcut icon on the left side of program window.

Load the program(lconv.out) in program memory of DSP chip using the ‘File-load program’ pull down menu.

To View output graphically Select view à graph à time and frequency.

Configure the graphical window as shown below

37

Page 38: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

38

Page 39: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

2 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];y[k]+=x[i]*x2[i];

} } /*displaying the result*/ printf(" the circular convolution is\n"); for(i=0;i<n;i++)

39

Page 40: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

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

}

PROCEDURE:

Open Code Composer Studio, make sure the DSP kit is turned on.

Start a new project using ‘Project-new ‘ pull down menu, save it in a separate directory(c:\ti\myprojects) with name cir conv.pjt.

Add the source files Circular Convolution.C to the project using ‘Projectàadd files to project’ pull down menu.

Add the linker command file hello.cmd .(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

Compile the program using the ‘Project-compile’ pull down menu or by clicking the shortcut icon on the left side of program window.

Build the program using the ‘Project-Build’ pull down menu or by clicking the shortcut icon on the left side of program window.

Load the program(lconv.out) in program memory of DSP chip using the ‘File-load program’ pull down menu.

DFT USING DSP KIT

#include <stdio.h>#include <math.h>float x[4]={1,3,2,5}; //input only real sequence

main(){float y[16]; //for 8 point DFT to store real & imaginaryfloat w;int n,k,k1,N=8,xlen=4;for(k=0;k<2*N;k=k+2){y[k]=0;y[k+1]=0; //initialize real & imag parts

k1=k/2; //actual k indexfor(n=0;n<xlen;n++)

40

Page 41: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

{w=-2*3.14*k1*n/N; //careful about minus signy[k]=y[k]+x[n]*cos(w);y[k+1]=y[k+1]+x[n]*sin(w);} printf("%f+j%f \n",y[k],y[k+1]);

}}//end of main

Procedure for Real time Programs   :

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. and Vp-p=1.5v

4. Now Switch on the DSK and Bring Up Code Composer Studio on the PC.

5. Create a new project with name codec.pjt.

6. From the File Menu new DSP/BIOS Configuration select “dsk6713.cdb” and save it as “xyz.cdb”

41

Page 42: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

7. Add “xyz.cdb” 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. Add the library file “dsk6713bsl.lib” to the current project

Path à “C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib”

10. Copy files “dsk6713.h” and “dsk6713_aic23.h” from C:\CCStudio\C6000\dsk6713\include and paste it in current project.

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.

42

Page 43: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

5.0 Conclusion: The codec TLV320AIC23 successfully configured using the board support library

and verified.

codec.c

#include "xyzcfg.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; /* 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 */

43

Page 44: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

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);}

USING MATLAB TO DETERMINE FILTER COEFFICIENTS :

Using FIR1 Function on Matlab

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

4. IMPLEMENTATION OF AN FIR FILTER : ALGORITHM TO IMPLEMENT :

We need to realize an advance FIR filter by implementing its difference equation as per the specifications. A direct form I implementation approach is taken. (The filter coefficients are taken as ai as generated by the Matlab program.)

C PROGRAM TO IMPLEMENT FIR FILTER:

fir.c

44

Page 45: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

#include "filtercfg.h"

#include "dsk6713.h"#include "dsk6713_aic23.h"

float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,0.011139,0.010502,-0.000000,-0.018003,-0.033416,-0.031505,0.000000,0.063010,0.144802,0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,-0.031505,-0.033416,-0.018003,-0.000000,0.010502,0.011139,0.005728,0.000000,-0.002423,-0.001591,0.000000 };

static short in_buffer[100];

DSK6713_AIC23_Config config = {\ 0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline 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; Uint32 l_input, r_input,l_output, r_output; /* Initialize the board support library, must be called first */ DSK6713_init(); /* Start the codec */ hCodec = DSK6713_AIC23_openCodec(0, &config); DSK6713_AIC23_setFreq(hCodec, 1); 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));

l_output=(Int16)FIR_FILTER(&filter_Coeff ,l_input); r_output=l_output;

/* Send a sample to the left channel */ while (!DSK6713_AIC23_write(hCodec, l_output));

45

Page 46: DSP Lab Mannual

H.S.Prashantha, Dept of TE, PESIT

/* Send a sample to the right channel */ while (!DSK6713_AIC23_write(hCodec, r_output)); } /* Close the codec */ DSK6713_AIC23_closeCodec(hCodec);}

signed int FIR_FILTER(float * h, signed int x){int i=0;signed long output=0;

in_buffer[0] = x; /* new input at buffer[0] */

for(i=30;i>0;i--)in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */

for(i=0;i<32;i++)output = output + h[i] * in_buffer[i];

return(output);

}

PROCEDURE :

Switch on the DSP board. Open the Code Composer Studio. Create a new project

Project à New (File Name. pjt , Eg: FIR.pjt) Initialize on board codec.

Note: “Kindly refer the Topic Configuration of 6713 Codec using BSL”

Add the given above ‘C’ source file to the current project (remove codec.c source file from the project if you have already added).

Connect the speaker jack to the input of the CRO. Build the program. Load the generated object file(*.out) on to Target board. Run the program Observe the waveform that appears on the CRO screen. Vary the frequency on function generator to see the response of filter.

46


Recommended