Sunteți pe pagina 1din 123

DSP LAB MANUAL

VITS

CONTENTS
S.No 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. Experiment Name Introduction to MATLAB Generation of Different Types of Signals Generation of Sum of Sinusoidal Signals Linear Convolution N-POINT FFT Auto Correlation & Power Density Spectrum To Find Frequency Response of FIR Low Pass /High Pass Filters To find frequency response of IIR low pass / High pass filters Architecture and Instruction Set of DSPCHIP-TMS320C6713 CODE COMPOSER STUDIO Linear Convolution using CC Studio Circular Convolution using CC Studio FIR FILTER DESIGN USING TMS320C6713 DSP PROCESSOR [RECTANGULER/TRIANGULAR/KAISER WINDOW] IIR FILTER DESIGN USING TMS320C6713 DSP PROCESSOR N-POINT Fast Fourier Transform (FFT) To Compute Power Density Spectrum of A Sequence [USING TMS320C6713 DSP PROCESSOR] ADDITIONAL EXPERIEMENTS 1. To Find Frequency Response of Band pass filter using FIR 2. To Find Frequency Response of Band pass filter using IIR 3. To Find Frequency Response of Band reject filter using FIR 4. To Find Frequency Response of Band reject filter using IIR Annexure I Viva Questions 100 76 85 93 Page No. 1 4 8 10 12 15 17 29 32 54 58 63 67

DSP LAB MANUAL

VITS

DSP LAB MANUAL

VITS

EXP.NO: 1

INTRODUCTION TO MATLAB
MATLAB (MATrix LABoratory): MATLAB is a software package for high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include the following Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation. MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-productivity research, development, and analysis. MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow learning and applying specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include Image processing, signal

DSP LAB MANUAL

VITS

processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others.

The main features of MATLAB


1. Advance algorithm for high performance numerical computation ,especially in the Field matrix algebra 2. A large collection of predefined mathematical functions and the ability to define ones own functions. 3. Two-and three dimensional graphics for plotting and displaying data 4. A complete online help system 5. Powerful, matrix or vector oriented high level programming language for individual applications. 6. Toolboxes available for solving advanced problems in several application areas % BASIC OPERATIONS ON MATRICES clc; clear all; close all; % clear the command window %clear the workspace %clear the figure window

% creation of matrices a=[1 2 3;4 5 6;7 8 9] b=[1 1 0;1 2 3;1 5 3] %matrix addition c=a+b % matrix substraction d=a-b %matrix multiplication e=a*b % array multiplication(element by element) f=a.*b % transpose g=a' % inverse matrix h=inv(a)

DSP LAB MANUAL

VITS

%diagonal matrix i=diag(a) %extraction of sub-matrix j1=a(1:2,2:3) j2=a(2:3,1:2) j3=a(2,1:3) j4=a(1:3,3)

DSP LAB MANUAL

VITS

EXP.NO: 2

GENERATION OF DIFFERENT TYPES OF SIGNALS Aim: To generate different types of signals Using MATLAB Software.
EQUIPMENTS:. MATLAB Software

Program: %generation of differnt types of signals clc; % clear the command window clear all; %clear the workspace close all; %clear the command window %generaion of unit impulse n=-10:1:10; y=(n==0) subplot(2,2,1) stem(n,y);grid title('unit impulse'); xlabel('time'); ylabel('Amplitude'); %generaion of unit step n=-10:1:10; y=(n>=0) subplot(2,2,2) stem(n,y);grid title('unit step'); xlabel('time'); ylabel('Amplitude'); %generaion of ramp n=0:1:20; y=n; subplot(2,2,3) stem(n,y); title('discrete ramp'); xlabel('time'); ylabel('Amplitude'); subplot(2,2,4);

DSP LAB MANUAL

VITS

plot(n,y); title('continuous ramp'); xlabel('time'); ylabel('Amplitude'); %generaion of exponential n=0:1:20; y=exp(-.3*n); figure; subplot(2,2,1) stem(n,y); title('discrete exponential'); xlabel('time'); ylabel('Amplitude'); subplot(2,2,2); plot(n,y); title('continuous exponential'); xlabel('time'); ylabel('Amplitude'); %generaion of sinusoidal signal n=0:1:50; y=sin(0.1*pi*n); subplot(2,2,3) stem(n,y); title('discrete sinusoidal signal'); xlabel('time'); ylabel('Amplitude'); subplot(2,2,4); plot(n,y); title('continuous sinusoidal signal'); xlabel('time'); ylabel('Amplitude');

DSP LAB MANUAL

VITS

Generation of signals output:

DSP LAB MANUAL

VITS

DSP LAB MANUAL

VITS

EXP.NO: 3

GENERATION OF SUM OF SINUSOIDAL SIGNALS Aim: To generate sum of sinusoidal signals Using MATLAB Software.
EQUIPMENTS: MATLAB Software

Program: clc; close all; clear all; t=0:0.05:3*pi; x1=sin(t*5);%sine wave with period 5 x2=sin(t*9);%sine wave with period 9 x3=x1+x2;%sum of x1 and x2 subplot(3,1,1); plot(t,x1) xlabel('time'),ylabel('amplitude') title('sin signal-1'); subplot(3,1,2); plot(t,x2) xlabel('time'),ylabel('amplitude') title('sin signal-2'); subplot(3,1,3); plot(t,x3) xlabel('time'),ylabel('amplitude') title('sum of sin signals');

10

DSP LAB MANUAL

VITS

sum of sinusoidal signals output:

11

DSP LAB MANUAL

VITS

EXP.NO: 4

LINEAR CONVOLUTION Aim: To find the out put with linear convolution operation Using MATLAB Software.
EQUIPMENTS: MATLAB Software Theory: 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.

Program: clc; close all; clear all; x=input('enter input sequence'); h=input('enter impulse response'); y=conv(x,h); subplot(3,1,1); stem(x); xlabel('n');ylabel('x(n)'); title('input signal') subplot(3,1,2); stem(h); xlabel('n');ylabel('h(n)'); title('impulse response') subplot(3,1,3); stem(y); xlabel('n');ylabel('y(n)');

12

DSP LAB MANUAL

VITS

title('linear convolution') disp('The resultant signal is'); disp(y) linear convolution output: enter input sequence[1 4 3 2] enter impulse response[1 0 2 1] The resultant signal is 1 4 5 11 10 7 2

13

DSP LAB MANUAL

VITS

EXP.NO: 5

N-POINT FFT Aim: To compute N-point FFT


EQUIPMENTS: MATLAB Software

Theory:
DFT of a sequence

Where N= Length of sequence. K= Frequency Coefficient. n = Samples in time domain. FFT : -Fast Fourier transform . There are Two methods. 1.Decimation in time (DIT FFT). 2. Decimation in Frequency (DIF FFT). Why we need FFT ? The no of multiplications in DFT = N2. The no of Additions in DFT = N(N-1). For FFT. The no of multiplication = N/2 log 2N. The no of additions = N log2 N.

14

DSP LAB MANUAL

VITS

Program: clc; close all; clear all; x=input('enter the sequence'); N=length(x); n=0:1:N-1; y=fft(x,N) subplot(2,1,1); stem(n,x); title('input sequence'); xlabel('time index n----->'); ylabel('amplitude x[n]----> '); subplot(2,1,2); stem(n,y); title('output sequence'); xlabel(' Frequency index K---->'); ylabel('amplitude X[k]------>');

15

DSP LAB MANUAL

VITS

N-point FFT Output: enter the sequence[2 3 1 4] y= 10.0000 1.0000 + 1.0000i -4.0000 1.0000 - 1.0000i

16

DSP LAB MANUAL

VITS

EXP.NO: 6

AUTO CORRELATION & POWER DENSITY SPECTRUM Aim: To compute auto correlation and then find the power density spectrum.
EQUIPMENTS: MATLAB Software Signal Processing Toolbox

Program clc; close all; clear all; x=input('enter the sequence'); N=length(x); n=0:1:N-1; y=xcorr(x,x); subplot(3,1,1); stem(n,x); xlabel(' n----->');ylabel('Amplitude--->'); title('input seq'); subplot(3,1,2); N=length(y); n=0:1:N-1; stem(n,y); xlabel('n---->');ylabel('Amplitude----.'); title('autocorr seq for input'); disp('autocorr seq for input'); disp(y) p=fft(y,N); subplot(3,1,3); stem(n,p); xlabel('K----->');ylabel('Amplitude--->'); title('psd of input'); disp('the psd fun:'); disp(p)

17

DSP LAB MANUAL

VITS

auto correlation & power density spectrum enter the sequence[1 0 1 2] autocorr seq for input 2 1 2 6 2 1 2 the psd fun: Columns 1 through 5 16.0000 -4.0048 - 1.9286i 3.6174 + 4.5361i -0.6126 - 2.6840i -0.6126 + 2.6840i Columns 6 through 7 3.6174 - 4.5361i -4.0048 + 1.9286i

18

DSP LAB MANUAL

VITS

EXP.NO: 7

TO FIND FREQEUNCY RESPONSE OF FIR LOW PASS / HIGH PASS FILTERS Aim: To find frequency response of FIR low pass/ high pass filter.
EQUIPMENTS: MATLAB Software Signal Processing Toolbox %Program for FIR LPF using blackman window n=20; fp=200; fq=300; fs=1000; fn=2*fp/fs; window=blackman(n+1); b=fir1(n,fn,window); [H W]=freqz(b,1,128); subplot(2,1,1); plot(W/pi,abs(H)); title('magnitude response of lpf'); ylabel('gain in db-------->'); xlabel('normalized frequency------>'); subplot(2,1,2); plot(W/pi,angle(H)); title('phase response of lpf'); ylabel('angle-------->'); xlabel('normalized frequency------>');

19

DSP LAB MANUAL

VITS

Result:

window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092 -0.0000 b = 0.0000 -0.0003 -0.0009 -0.0000 -0.0386 -0.0430 0.3999 -0.0000 0.0000 0.2906 0.0101 0.0027 0.0794 0.0101 0.2906

0.0794 -0.0430 -0.0386 0.0027 -0.0009 -0.0003

20

DSP LAB MANUAL

VITS

FIR LOW PASS FILTER DESIGN USING RECTANGLE WINDOW: %Program for FIR LPF using rectangular window n=20; fp=200; fq=300; fs=1000; fn=2*fp/fs; window=rectwin(n+1); b=fir1(n,fn,window); [H W]=freqz(b,1,128); subplot(2,1,1); plot(W/pi,abs(H)); title('magnitude response of lpf'); ylabel('gain in db-------->'); xlabel('normalized frequency------>'); subplot(2,1,2); plot(W/pi,angle(H)); title('phase response of lpf'); ylabel('angle-------->'); xlabel('normalized frequency------>');

21

DSP LAB MANUAL

VITS

RESULT:-

window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092 -0.0000 b= 0.0000 -0.0003 -0.0009 0.0027 0.0101 -0.0000 -0.0386 -0.0430 0.3999 -0.0000 0.0000 0.2906 0.0101 0.0794 0.2906

0.0794 -0.0430 -0.0386 0.0027 -0.0009 -0.0003

22

DSP LAB MANUAL

VITS

FIR LOW PASS FILTER DESIGN USING TRIANGLE WINDOW:

%program for FIR LPF using triangular window n=20; fp=200; fq=300; fs=1000; fn=2*fp/fs; window=triang(n+1); b=fir1(n,fn,window); [H W]=freqz(b,1,128); subplot(2,1,1); plot(W/pi,abs(H)); title('magnitude response of lpf'); ylabel('gain in db-------->'); xlabel('normalized frequency------>'); subplot(2,1,2); plot(W/pi,angle(H)); title('phase response of lpf'); ylabel('angle-------->'); xlabel('normalized frequency------>');

23

DSP LAB MANUAL

VITS

RESULT:-

window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092 -0.0000 b= 0.0000 -0.0003 -0.0009 -0.0000 -0.0386 -0.0430 0.3999 0.2906 0.0027 0.0794 0.0101 0.2906

0.0794 -0.0430 -0.0386 0.0027 -0.0009 -0.0003

-0.0000 0.0101 0.0000

24

DSP LAB MANUAL

VITS

FIR LOW PASS FILTER DESIGN USING HAMMING WINDOW:

%program for FIR LPF using Hamming window n=20; fp=200; fq=300; fs=1000; fn=2*fp/fs; window=hamming(n+1); b=fir1(n,fn,window); [H W]=freqz(b,1,128); subplot(2,1,1); plot(W/pi,abs(H)); title('magnitude response of lpf'); ylabel('gain in db-------->'); xlabel('normalized frequency------>'); subplot(2,1,2); plot(W/pi,angle(H)); title('phase response of lpf'); ylabel('angle-------->'); xlabel('normalized frequency------>');

25

DSP LAB MANUAL

VITS

RESULT:-

window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092 -0.0000 b= 0.0000 -0.0003 -0.0009 -0.0000 -0.0386 -0.0430 0.3999 0.2906 0.0027 0.0794 0.0101 0.2906

0.0794 -0.0430 -0.0386 0.0027 -0.0009 -0.0003

-0.0000 0.0101 0.0000

26

DSP LAB MANUAL

VITS

FIR LOW PASS FILTER DESIGN USING HANNING WINDOW: %program for FIR LPF using hanning window n=20; fp=200; fq=300; fs=1000; fn=2*fp/fs; window=hann(n+1); b=fir1(n,fn,window); [H W]=freqz(b,1,128); subplot(2,1,1); plot(W/pi,abs(H)); title('magnitude response of lpf'); ylabel('gain in db-------->'); xlabel('normalized frequency------>'); subplot(2,1,2); plot(W/pi,angle(H)); title('phase response of lpf'); ylabel('angle-------->'); xlabel('normalized frequency------>');

27

DSP LAB MANUAL

VITS

RESULT:-

window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092 -0.0000 b= 0.0000 -0.0003 -0.0009 -0.0000 -0.0386 -0.0430 0.3999 0.2906 0.0027 0.0794 0.0101 0.2906

0.0794 -0.0430 -0.0386 0.0027 -0.0009 -0.0003

-0.0000 0.0101 0.0000

28

DSP LAB MANUAL

VITS

FIR HIGH PASS FILTER DESIGN USINGBLACK MAN WINDOW:


%program for FIR HPF using blackman window n=20; fp=300; fq=200; fs=1000; fn=2*fp/fs; window=blackman(n+1); b=fir1(n,fn,'high',window); [H W]=freqz(b,1,128); subplot(2,1,1); plot(W/pi,abs(H)); title('mag res of lpf'); ylabel('gain in db-------->'); xlabel('normalized frequency------>'); subplot(2,1,2); plot(W/pi,angle(H)); title('phase res of lpf'); ylabel('angle-------->'); xlabel('normalized frequency------>');

29

DSP LAB MANUAL

VITS

RESULT:

fn= 0.6 window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092 -0.0000 b= 0.0000 0.0003 -0.0009 -0.0027 0.0101 0.0000 -0.0386 0.3999 -0.2906 0.0000 0.0000 0.0430 0.0794 0.0794 -0.2906 0.0430 -0.0386 0.0003

0.0101 -0.0027 -0.0009

30

DSP LAB MANUAL

VITS

EXP.NO: 8

TO FIND FREQEUNCY RESPONSE OF IIR LOW PASS / HIGH PASS FILTERS Aim: To find frequency response of IIR low pass/ high pass filter.
EQUIPMENTS: MATLAB Software

PROGRAM: % IIR filters LPF & HPF clc; clear all; close all; disp('enter the IIR filter design specifications'); rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); wp=input('enter the passband freq'); ws=input('enter the stopband freq'); fs=input('enter the sampling freq'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs,'s'); c=input('enter choice of filter 1. LPF 2. HPF \n '); if(c==1) disp('Frequency response of IIR LPF is:'); [b,a]=butter(n,wn,'low','s'); end if(c==2) disp('Frequency response of IIR HPF is:'); [b,a]=butter(n,wn,'high','s'); end w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); figure,subplot(2,1,1);plot(om/pi,m); title('magnitude response of IIR filter is:'); xlabel('(a) Normalized freq. -->'); ylabel('Gain in dB-->'); subplot(2,1,2);plot(om/pi,an); title('phase response of IIR filter is:'); xlabel('(b) Normalized freq. -->');

31

DSP LAB MANUAL

VITS

ylabel('Phase in radians-->'); OUTPUT: enter the IIR filter design specifications enter the passband ripple.15 enter the stopband ripple60 enter the passband freq1500 enter the stopband freq3000 enter the sampling freq7000 enter choice of filter 1. LPF 2. HPF 1 Frequency response of IIR LPF is:

32

DSP LAB MANUAL

VITS

enter the IIR filter design specifications enter the passband ripple.15 enter the stopband ripple60 enter the passband freq1500 enter the stopband freq3000 enter the sampling freq7000 enter choice of filter 1. LPF 2. HPF 2 Frequency response of IIR HPF is:

33

DSP LAB MANUAL

VITS

EXP.No:9

ARCHITECTURE AND INSTRUCTION SET OF DSPCHIP-TMS320C6713


Aim: To Study the architecture and Instruction set of DSP chips
Features of Highest-Performance Floating-Point Digital Signal Processor Tms320c6713 Enhanced Harvard Architecture VLIW Parallel Architecture Rich Addressing modes Two general purpose Register files (A0-A15 & B0-B15) 32/64- Bit Data Word Rich Instruction set Eight 32-Bit Instructions/Cycle 32/64-Bit Data Word 4.4-, 6.7-ns Instruction Cycle Time 1800 MIPS/1350 MFLOPS Rich Peripheral Set, Optimized for Audio Highly Optimized C/C++ Compiler

34

DSP LAB MANUAL

VITS

TMS320C67x Block Diagram

35

DSP LAB MANUAL

VITS

36

DSP LAB MANUAL

VITS

TMS320C6713 ARCHITECTURE

37

DSP LAB MANUAL

VITS

CPU (DSP Core)

38

DSP LAB MANUAL

VITS

CPU (DSP CORE) CONT

39

DSP LAB MANUAL

VITS

FUNCTIONAL UNITS AND OPERATIONS PERFORMED

40

DSP LAB MANUAL

VITS

INSTRUCTION SET FEATURES

* Single- and Double-Precision Instructions


* Byte-Addressable (8-, 16-, 32-Bit Data) * 8-Bit Overflow Protection * Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization

INSTRUCTION SET

41

DSP LAB MANUAL

VITS

INSTRUCTION SET

ABS (Integer Absolute Value with Saturation):

ADD(U) (Signed or Unsigned Integer Addition Without Saturation)

ADDAB/ADDAH/ADDAW (Integer Addition Using Addressing Mode)

42

DSP LAB MANUAL

VITS

AMR Register

ADDK (Integer Addition Using Signed 16-Bit Constant)

ADD2 Two 16-Bit Integer Adds on Upper and Lower Register Halves

43

DSP LAB MANUAL

VITS

AND (Bitwise AND)

CLR (Clear a Bit Field)

CMPEQ (Integer Compare for Equality):

CMPGT(U) (Signed or Unsigned Integer Compare for Greater Than):

44

DSP LAB MANUAL

VITS

CMPLT(U) (Signed or Unsigned Integer Compare for Less Than):

LDB(U)/LDH(U)/LDW LDB .D2 *+B14[36],B1

MPY(U/US/SU)

45

DSP LAB MANUAL

VITS

MVC (Move Between the Control File and the Register File)

MVK (Move a 16-Bit Signed Constant Into a Register and Sign Extend):

MVKH/MVKLH (Move 16-Bit Constant Into the Upper Bits of a Register)

NEG (Negate (Pseudo-Operation)): NEG (.unit) src, dst NORM (Normalize Integer):

OR (Bitwise OR):

46

DSP LAB MANUAL

VITS

SAT (Saturate a 40-Bit Integer to a 32-Bit Integer): SAT .L2 B1:B0,B5

47

DSP LAB MANUAL

VITS

SET (Set a Bit Field):

SHL (Arithmetic Shift Left):

SHR (Arithmetic Shift Right):

SHRU (Logical Shift Right):

48

DSP LAB MANUAL

VITS

SSHL (Shift Left With Saturation):


SSHL .S1 A0,2,A1

SUB(U) (Signed or Unsigned Integer Subtraction Without Saturation):

EXOR (Exclusive OR):

Floating-Point Instruction Set ABSDP (Double-Precision Floating-Point Absolute Value): ABSDP .S1 A1:A0,A3:A2

49

DSP LAB MANUAL

VITS

ABSSP (Single-Precision Floating-Point Absolute Value):

CMPEQDP (Double-Precision Floating-Point Compare for Equality) CMPEQDP .S1 A1:A0,A3:A2,A4

CMPGTDP (Double-Precision Floating-Point Compare for Greater Than) CMPGTDP (.unit) src1, src2, dst CMPGTDP .S1 A1:A0,A3:A2,A4

MPYDP (Double-Precision Floating-Point Multiply) MPYDP .M1 A1:A0,A3:A2,A5:A4

50

DSP LAB MANUAL

VITS

51

DSP LAB MANUAL

VITS

RCPSP (Single-Precision Floating-Point Reciprocal Approximation)

DPINT (Convert Double-Precision Floating-Point Value to Integer) DPINT .L1 A1:A0,A4

MVD (Move From Register to Register, Delayed)

MVK/MVKL (Move a Signed Constant Into a Register and Sign-Extend)

52

DSP LAB MANUAL

VITS

PACKHL2 (Pack 16 MSB, 16 LSB Into Packed 16-Bit):

Floating Point Addition .text NUM1 .FLOAT -2.5 ; NUM1 .FLOAT 8.6; Start: mvkl NUM1,a7 mvkh NUM1,a7 mvkl NUM2,a8 mvkh NUM2,a8 ldw *a7,a4 ldw *a8,a5 mvkl 90030000h,a3 mvkh 90030000h,a3 addsp a4,a5,a2 stw a2,*a3++ .end Result: 6.1 ; 40C3 3334h

53

DSP LAB MANUAL

VITS

Floating Point Multiplication .text NUM1 .FLOAT -2.5 ; NUM1 .FLOAT 8.6; Start: mvkl NUM1,a7 mvkh NUM1,a7 mvkl NUM2,a8 mvkh NUM2,a8 ldw *a7,a4 ldw *a8,a5 mvkl 90030000h,a3 mvkh 90030000h,a3 addsp a4,a5,a2 stw a2,*a3++ .end Result: 6.1 ; 40C3 3334h

54

DSP LAB MANUAL

VITS

55

DSP LAB MANUAL

VITS

TMS C6713DSK
The 6713 DSK is a low-cost standalone development platform that enables customers to evaluate and develop applications for the TI C67XX DSP family. The DSK also serves as a hardware reference design for the TMS320C6713 DSP. Schematics, logic equations and application notes are available to ease hardware development and reduce time to market. The DSK uses the 32-bit EMIF for the SDRAM (CE0) and daughtercard expansion interface (CE2 and CE3). The Flash is attached to CE1 of the EMIF in 8-bit mode. An on-board AIC23 codec allows the DSP to transmit and receive analog signals. McBSP0 is used for the codec control interface and McBSP1 is used for data. Analog audio I/O is done through four 3.5mm audio jacks that correspond to microphone input, line input, line output and headphone output. The codec can select the microphone or the line input as the active input. The analog output is driven to both the line out (fixed gain) and headphone (adjustable gain) connectors. McBSP1 can be re-routed to the expansion connectors in software. A programmable logic device called a CPLD is used to implement glue logic that ties the board components together. The CPLD has a register based user interface that lets the user configure the board by reading and writing to the CPLD registers. The registers reside at the midpoint of CE1. The DSK includes 4 LEDs and 4 DIPswitches as a simple way to provide the user with interactive feedback. Both are accessed by reading and writing to the CPLD registers. An included 5V external power supply is used to power the board. On-board voltage regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A voltage supervisor monitors the internally generated voltage, and will hold the board in reset until the supplies are within operating specifications and the reset button is released. If desired, JP1 and JP2 can be used as power test points for the core and I/O power supplies. Code Composer communicates with the DSK through an embedded JTAG emulator with a USB host interface. The DSK can also be used with an external emulator through the external JTAG connector.

TMS320C6713 DSP FEATURES

Highest-Performance Floating-Point Digital Signal Processor (DSP): Eight 32-Bit Instructions/Cycle 32/64-Bit Data Word 300-, 225-, 200-MHz (GDP), and 225-, 200-, 167-MHz (PYP) Clock Rates 3.3-, 4.4-, 5-, 6-Instruction Cycle Times 2400/1800, 1800/1350, 1600/1200, and 1336/1000 MIPS /MFLOPS

56

DSP LAB MANUAL

VITS

Rich Peripheral Set, Optimized for Audio Highly Optimized C/C++ Compiler Extended Temperature Devices Available Advanced Very Long Instruction Word (VLIW) TMS320C67x DSP Core Eight Independent Functional Units: Two ALUs (Fixed-Point) Four ALUs (Floating- and Fixed-Point) Two Multipliers (Floating- and Fixed-Point) Load-Store Architecture With 32 32-Bit General-Purpose Registers Instruction Packing Reduces Code Size All Instructions Conditional Instruction Set Features Native Instructions for IEEE 754 Single- and Double-Precision Byte-Addressable (8-, 16-, 32-Bit Data) 8-Bit Overflow Protection Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization L1/L2 Memory Architecture 4K-Byte L1P Program Cache (Direct-Mapped) 4K-Byte L1D Data Cache (2-Way) 256K-Byte L2 Memory Total: 64K-Byte L2 Unified Cache/Mapped RAM, and 192K-Byte Additional L2 Mapped RAM Device Configuration Boot Mode: HPI, 8-, 16-, 32-Bit ROM Boot Endianness: Little Endian, Big Endian 32-Bit External Memory Interface (EMIF) Glueless Interface to SRAM, EPROM, Flash, SBSRAM, and SDRAM 512M-Byte Total Addressable External Memory Space Enhanced Direct-Memory-Access (EDMA) Controller (16 Independent Channels) 16-Bit Host-Port Interface (HPI) Two Multichannel Audio Serial Ports (McASPs) Two Independent Clock Zones Each (1 TX and 1 RX) Eight Serial Data Pins Per Port: Individually Assignable to any of the Clock Zones Each Clock Zone Includes: Programmable Clock Generator Programmable Frame Sync Generator TDM Streams From 2-32 Time Slots Support for Slot Size: 8, 12, 16, 20, 24, 28, 32 Bits Data Formatter for Bit Manipulation Wide Variety of I2S and Similar Bit Stream Formats Integrated Digital Audio Interface Transmitter (DIT) Supports: S/PDIF, IEC60958-1, AES-3, CP-430 Formats

57

DSP LAB MANUAL

VITS

Up to 16 transmit pins Enhanced Channel Status/User Data Extensive Error Checking and Recovery Two Inter-Integrated Circuit Bus (I2C Bus) Multi-Master and Slave Interfaces Two Multichannel Buffered Serial Ports: Serial-Peripheral-Interface (SPI) High-Speed TDM Interface AC97 Interface Two 32-Bit General-Purpose Timers Dedicated GPIO Module With 16 pins (External Interrupt Capable) Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible Package Options: 208-Pin PowerPAD Plastic (Low-Profile) Quad Flatpack (PYP) 272-BGA Packages (GDP and ZDP) 0.13-m/6-Level Copper Metal Process CMOS Technology

3.3-V I/Os, 1.2 -V Internal (GDP & PYP) 3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)

TMS320C6713 DSK Overview Block Diagram

58

DSP LAB MANUAL

VITS

DSK HARDWARE INSTALLATION Shut down and Power off the PC Connect the supplied USB port cable to the board Connect the other end of the cable to the USB port of PC Note: If you plan to install a Microphone, speaker, or Signal generator/CRO these must be plugged in properly Before you connect power to the DSK Plug the power cable into the board Plug the other end of the power cable into a power outlet The user LEDs should flash several times to indicate board is operational When you connect your DSK through USB for the first time on windows loaded PC the new hardware found wizard will come up. So, Install the drivers (The CCS CD contains the require drivers for C5416 DSK). Install the CCS software for C5416 DSK

59

DSP LAB MANUAL

VITS

EXP.No 10:

CODE COMPOSER STUDIO


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: 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

To create a system configuration using a standard configuration file: Step 1: Start CCS Setup by double clicking on the Setup CCS desktop icon. Step 2: select Family Platform Endianness . c67xx simulator little

60

DSP LAB MANUAL

VITS

Step 3: Click the Import button (File import) to import our selection (c67xx_sim.ccs) to the system configuration currently being created in the CCS Setup window. Step 4: Click the Save and Quit button to save the configuration in the System Registry. Step 5: Click the Yes button to start the CCS IDE when we exit CCS Setup. The CCS Setup closes and the CCS IDE automatically opens using the configuration we just created.

61

DSP LAB MANUAL

VITS

PROCEDURE TO WORK ON CODE COMPOSER STUDIO


Step 1: Creating

a New Project From the Project menu, choose New.

In the Project Name field, type the name we want for our project. Each project we create must have a unique name, and Click Finish. The CCS IDE creates a project file called projectname.pjt. This file stores our project settings and references the various files used by our project. The Project Creation wizard window displays.

Step 2: Creating a source file Create a new source file using File new source file pull down menu and save the source file with .c extension in the current project name directory. Save as type: c/c++ source file (*.c*) Path: C:\CCStudio_v3.1\ MyProjects\Project Name\ Step 3: Add files to our project (source file\ library file\ linker file)

62

DSP LAB MANUAL

VITS

Source file: Add the source file in the project using project pull down menu. Files of type: c/c++ source file (*.c*)

Projectadd files to

Path: C:\CCStudio_v3.1\ MyProjects\Project Name\file_name.c Library file: Add the library file in the project using project pull down menu. Files of type: Object and Library Files (*.o*,*.l*) Path: C:\CCStudio_v3.1\ C6000\ cgtools\ lib \ rts6700.lib Linker file: Add the linker file in the project using project pull down menu. Files of type: Linker command Files (*.cmd*,*.lcf*) Path: C:\CCStudio_v3.1\ tutorial\ dsk6711\ hello1 \ hello.cmd Step 4: Building and Running the Program (compile\ Build\ Load Program\ Run) Compile: Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Build: Build the program using the Project-Build pull down menu or by clicking the shortcut icon on the left side of program window. Load Program: Load the program in program memory of DSP chip using the File-load program pull down menu. Files of type:(*.out*) Path: C:\CCStudio_v3.1\ MyProjects\Project Name\ Debug\ Project Name.out Run: Run the program using the Debug-Run pull down menu or by clicking the shortcut icon on the left side of program window. Step 5: observe output using graph
Choose View GraphTime/Frequency.

Projectadd files to

Projectadd files to

In the Graph Property Dialog, change the Graph Title, Start Address, and Acquisition Buffer Size, Display Data Size, DSP Data Type, Auto scale, and Maximum YValue properties to the values.

63

DSP LAB MANUAL

VITS

EXP.No:11

LINEAR CONVOLUTION
AIM: Verify the linear convolution operation Using DSK Code composer studio EQUIPMENTS: TMS 320C6713 Kit. RS232 Serial Cable Power Cord Operating System Windows XP Software CCStudio_v3.1 THEORY: Convolution is a formal mathematical operation, just as multiplication, addition, and integration. Addition takes two numbers and produces a third number, while convolution takes two signals and produces a third signal. Convolution is used in the mathematics of many fields, such as probability and statistics. In linear systems, convolution is used to describe the relationship between three signals of interest: the input signal, the impulse response, and the output signal.

In this equation, x(k), h(n-k) and y(n) represent the input to and output from the system at time n. Here we could see that one of the inputs is shifted in time by a value every time it is multiplied with the other input signal. Linear Convolution is quite often used as a method of implementing filters of various types. ALGORITHM Step 1 Declare three buffers namely Input buffer, Temporary Buffer, Output Buffer. Step 2 Get the input from the CODEC, store it in Input buffer and transfer it to the first location of the Temporary buffer. Step 3 Make the Temporary buffer to point to the last location. Step 4 Multiply the temporary buffer with the coefficients in the data memory and accumulate it with the previous output. Step 5 Store the output in the output buffer. Step 6 Repeat the steps from 2 to 5.

ASSEMBLY PROGRAM TO IMPLEMENT LINEAR CONVOLUTION

conv.asm:
.global _main X .half 1,2,3,4,0,0,0,0 H .half 1,2,3,4,0,0,0,0 .bss Y,14,2 ;input1, M=4 ;input2, N=4 ;OUTPUT, R=M+N-1

64

DSP LAB MANUAL

VITS

;At the end of input sequences pad M and N no. of zeros _main: MVKL MVKH MVKL MVKH MVKL MVKH .S1 X,A4 .S1 X,A4 .S2 H,B4 .S2 H,B4 .S1 Y,A5 .S1 Y,A5 ;POINTER TO X ;POINTER TO H ;POINTER TO Y ;R=M+N-1

MVK .S2 7,B2 ZERO .L1 A7 ZERO .L1 A3 LL2: ZERO .L1 A2 ZERO .L1 A8 LL1: LDH MV SUB LDH NOP 4 MPY ADD ADD CMPLT B NOP 5 .D1 *A4[A8],A6 .S2X A8,B5 .L2 A3,B5,B7 .D2 *B4[B7],B6 .M1X A6,B6,A7 .L1 A8,1,A8 .L1 A2,A7,A2 .L2X B5,A3,B0 .S2 LL1 ;I=0

;MOVE THE VALUE OF RTO B2 FOR DIFFERENT LENGTH OF I/P SEQUENCES

;J=0, for(i=0;i<m+n-1;i++) ; for(j=0;j<=i;j++) ; y[i]+=x[j]*h[i-j];

[B0]

[A2]

STH .D1 A2,*A5[A3] ADD .L1 A3,1,A3 CMPLT .L1X A3,B2,A2 B .S1 LL2 NOP 5 B B3 NOP 5

C PROGRAM TO IMPLEMENT LINEAR CONVOLUTION :


//Linear convolution program in c language using CCStudio #include<stdio.h>

65

DSP LAB MANUAL

VITS

int x[15],h[15],y[15]; main() { int i,j,m,n; printf("\n enter first sequence length m:"); scanf("%d",&m); printf("\n enter second sequence length n:"); scanf("%d",&n); printf("Enter i/p sequence for x(n):\n"); for(i=0;i<m;i++) scanf("%d",&x[i]); printf("Enter i/p sequence for h(n): \n"); for(i=0;i<n; i++) scanf("%d",&h[i]); // padding of zeors for(i=m;i<=m+n-1;i++) x[i]=0; for(i=n;i<=m+n-1;i++) h[i]=0; /* convolution operation */ for(i=0;i<m+n-1;i++) { y[i]=0; for(j=0;j<=i;j++) { y[i]=y[i]+(x[j]*h[i-j]); } } //displaying the o/p printf("Output (Linear Convolution) sequence is:\n "); for(i=0;i<m+n-1;i++) printf("y[%d]=%d\t",i,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 lconv.pjt. Add the source files conv.asm. to the project using Projectadd files to project pull down menu. Add the linker command file hello.cmd.

66

DSP LAB MANUAL

VITS

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

67

DSP LAB MANUAL

VITS

OUTPUT FOR LINEAR CONVOLUTION: enter first sequence length m:4 enter second sequence length n:3 Enter i/p sequence for x(n): 1234 Enter i/p sequence for h(n): 231 Output (Linear Convolution) sequence is: y[0]=2 y[1]=7 y[2]=13

y[3]=19

y[4]=15

y[5]=4

Graph Property Graph LINEAR CONVOLUTION

68

DSP LAB MANUAL

VITS

EXP.No:12

CIRCULAR CONVOLUTION
AIM: To verify the circular convolution operation Using DSK Code composer studio EQUIPMENTS: TMS 320C6713 Kit. RS232 Serial Cable Power Cord Operating System Windows XP Software CCStudio_v3.1 THEORY: Circular convolution is another way of finding the convolution sum of two input signals. It resembles the linear convolution, except that the sample values of one of the input signals is folded and right shifted before the convolution sum is found. Also note that circular convolution could also be found by taking the DFT of the two input signals and finding the product of the two frequency domain signals. The Inverse DFT of the product would give the output of the signal in the time domain which is the circular convolution output. The two input signals could have been of varying sample lengths. But we take the DFT of higher point, which ever signals levels to.. This process is called circular convolution. 0 /

*program to implement circular convolution */

69

DSP LAB MANUAL

VITS

#include<stdio.h> int m,n,x[30],h[30],y[30],i,j, 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) { 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++) 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]; /*folding h(n) to h(-n)*/ /* Pad the smaller sequence with zero*/

70

DSP LAB MANUAL

VITS

} } /*displaying the result*/ printf(" the circular convolution is\n"); for(i=0;i<n;i++) 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 Projectadd 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.

71

DSP LAB MANUAL

VITS

OUTPUT FOR CIRCULAR CONVOLUTION: enter the length of the first sequence 4 enter the length of the second sequence 3 enter the first sequence 1234 enter the second sequence 123 the circular convolution is 18 16 10 16

Graph Property Graph CIRCULAR CONVOLUTION

72

DSP LAB MANUAL

VITS

EXP.No: 13 FIR FILTER (WINDOWING TECHNIQUES) DESIGN USING TMS320C6713 DSP PROCESSOR [RECTANGULER/TRIANGULAR/KAISER WINDOW]
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: TMS 320C6713 Kit. Oscilloscope & Function Generator RS232 Serial Cable Power Cord Operating System Windows XP Software CCStudio_v3.1

THEORY: A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose output is based on the weighted summation of a finite number of past inputs. An FIR transversal filter structure can be obtained directly from the equation for discrete-time convolution.

y ( n) = x ( k ) h( n k ) 0 < n < N 1
k =0

N 1

(1)

In this equation, x(k) and y(n) represent the input to and output from the filter at time n. h(n-k) is the transversal filter coefficients at time n. These coefficients are generated by using FDS (Filter Design Software or Digital filter design package).

73

DSP LAB MANUAL

VITS

FLOW CHART TO IMPLEMENT FIR FILTER: Start

Initialize the DSP Board.

Take a new input in data from the analog in of codec in data Initialize Counter = 0 Initialize Output = 0 , i = 0 Output += coeff[Ni]*val[i] Shift the input value by one

No

Is the loop Cnt = order Yes Output += coeff[0]*data Put the data in val array.

Poll the ready bit, when asserted proceed.

Write the value Output to Analog output of the codec

C PROGRAM TO IMPLEMENT FIR FILTER:

74

DSP LAB MANUAL

VITS

fir.c #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)

75

DSP LAB MANUAL

VITS

{ /* 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)); /* 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:

76

DSP LAB MANUAL

VITS

STEPS TO IMPLEMENT FILTERS Do diagnostic test Open DSKC6713 studio Open new project and give it a name. see whether the project is in C drive or D drive Go to file. Say new and select DSPBIOS configuration Select DSK6713 or DSK6711 whatever is available (double click) Click on configuration window and save Path: C:/ CCStudio_v3.1/myprojects/ project name ProjectAdd files to project Filter type as: configuration file(*.cdb) Configlopen Observe under your project .cdb file under DSP and two configure files under generated files Close configl window Go to file say new/source file/copy paste the filter program onto untitled window The filter program is on desktop in programs for 6713 File/save/your project/file type is c source file and give a name to the file and say save After saving the file add to the project/the file name i.e the saved file and say save. Add command file to the project Project Add files to project Path:CCStudio_v3.1/myprojects/ our project name Files of type: Linker command Files (*.cmd*,*.lcf*) Add library file to the project Project Add files to project Path: CCStudio_v3.1\C6000\dsk6713\lib\dsk6713bsl.lib Files of type: Object and Library Files (*.o*,*.l*) Add header file to the project Open configlcfg-c.c(under generated files)/ Copy #include configlcfg.h (close) and paste it to our program Remove filter.h file Go to project/ add files to project Path: CCStudio_v3.1\C6000\dsk6713 Files of type: All files Select include/copy the first two header files(dsk 6713,dsk6713_aic23) and paste in our project i.e Path: CCStudio_v3.1/myprojects/ our project name Save Building and Running the Program (compile\ Build\ Load Program\ Run) Compile: Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window.

77

DSP LAB MANUAL

VITS

Build: Build the program using the Project-Build pull down menu or by clicking the shortcut icon on the left side of program window. Load Program: Load the program in program memory of DSP chip using the File-load program pull down menu. Files of type:(*.out*) Path: C:\CCStudio_v3.1\ MyProjects\Project Name\ Debug\ Project Name.out Run: Run the program using the Debug-Run pull down menu or by clicking the shortcut icon on the left side of program window.

78

DSP LAB MANUAL

VITS

RESULT: FREQUENCY RESPONSE High Pass FIR filter(Fc= 800Hz).

Low Pass FIR filter (Fc=1000Hz)

79

DSP LAB MANUAL

VITS

Model 2: c program to implement FIR Filter


#include<stdio.h> #include<math.h> #define pi 3.1415 int n,N,c; float wr[64],wt[64]; void main() { printf("\n enter no. of samples,N= :"); scanf("%d",&N); printf("\n enter choice of window function: 1.rect 2. triang \n c= :"); scanf("%d",&c); printf("\n elements of window function are:"); switch(c) { case 1: for(n=0;n<=N-1;n++) { wr[n]=1; printf(" \n wr[%d]=%f",n,wr[n]); } break; case 2: for(n=0;n<=N-1;n++) { wt[n]=1-(2*(float)n/(N-1)); printf("\n wt[%d]=%f",n,wt[n]); } break; } }

80

DSP LAB MANUAL

VITS

Output for FIR Filter Rectangular Window

enter no. of samples,N= :64 enter choice of window function:1.rect 2. triang c= 1

Graph Property Graph FIR FILTER RECTANGULAR WINDOW


Output for FIR Filter Triangular Window

enter no. of samples,N= :64 enter choice of window function:1.rect 2. triang c=2

Graph Property Graph FIR FILTER TRIANGULAR WINDOW

81

DSP LAB MANUAL

VITS

EXP. No:14

IIR FILTER DESIGN USING TMS320C6713 DSP PROCESSOR


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: TMS 320C6713 Kit. Oscilloscope & Function Generator RS232 Serial Cable Power Cord Operating System Windows XP Software CCStudio_v3.1 INTRODUCTION GENERAL CONSIDERATIONS: In the design of frequency selective filters, the desired filter characteristics are specified in the frequency domain in terms of the desired magnitude and phase response of the filter. In the filter design process, we determine the coefficients of a causal IIR filter that closely approximates the desired frequency response specifications. IMPLEMENTATION OF DISCRETE-TIME SYSTEMS: Discrete time Linear Time-Invariant (LTI) systems can be described completely by constant coefficient linear difference equations. Representing a system in terms of constant coefficient linear difference equation is its time domain characterization. In the design of a simple frequencyselective filter, we would take help of some basic implementation methods for realizations of LTI systems described by linear constant coefficient difference equation. BACKGROUND CONCEPTS: An Infinite impulse response (IIR) filter possesses an output response to an impulse which is of an infinite duration. The impulse response is "infinite" since there is feedback in the filter, that is if you put in an impulse ,then its output must produced for infinite duration of time. The IIR filter can realize both the poles and zeroes of a system because it has a rational transfer function, described by polynomials in z in both the numerator and the denominator:

82

DSP LAB MANUAL

VITS

H ( z)

b a
k =1 k =0 N

z k
(1)

Z k
N

The difference equation for such a system is described by the following:

y ( n ) = bk x ( n k ) +
k =0

a
k =1

y (n k )

(2)

M and N are order of the two polynomials bk and ak are the filter coefficients. These filter coefficients are generated using FDS (Filter Design software or Digital Filter design package). ALGORITHM TO IMPLEMENT: We need to realize the Butter worth band pass IIR filter by implementing the difference equation y[n] = b0x[n] + b1x[n-1]+b2x[n-2]-a1y[n-1]-a2y[n-2] where b0 b2, a0-a2 are feed forward and feedback word coefficients respectively [Assume 2nd order of filter].These coefficients are calculated using MATLAB.A direct form I implementation approach is taken. Step 1 - Initialize the McBSP, the DSP board and the on board codec. Kindly refer the Topic Configuration of 6713Codec using BSL Step 2 - Initialize the discrete time system , that is , specify the initial conditions. Generally zero initial conditions are assumed. Step 3 - Take sampled data from codec while input is fed to DSP kit from the signal generator. Since Codec is stereo , take average of input data read from left and right channel . Store sampled data at a memory location. Step 4 - Perform filter operation using above said difference equation and store filter Output at a memory location . Step 5 - Output the value to codec (left channel and right channel) and view the output at Oscilloscope. Step 6 - Go to step 3.

83

DSP LAB MANUAL

VITS

LOWCHART FOR IIR IMPLEMENTATION: Start

Initialize the DSP Board.

Set initial conditions of discrete time system by making x[0]-x[2] and y[0]y[2] equal to zeros and a0-a2,b0-b2 with MATLAB filter coefficients

Take a new input and store it in x[0]. Do y[-3] = y[-2],y[-2]=y[-1] and Y[-1] = output . x[-3] = x[-2], x[-2]=x[-1] x[-1]=x[0] Poll for ready bit Poll the ready bit, when asserted output = x[0]b0+x[-1]b1+ x[-2]b2 - y[-1]a1 - y[-2]a2

proceed.
Write output to analog i/o.

Stop

F.1 : Flowchart for implementing IIR filter.

84

DSP LAB MANUAL

VITS

C PROGRAM TO IMPLEMENT IIR FILTER


#include "filtercfg.h" #include "dsk6713.h" #include "dsk6713_aic23.h" const signed int filter_Coeff[] = { //12730,-12730,12730,2767,-18324,21137 //312,312,312,32767,-27943,24367 //1455,1455,1455,32767,-23140,21735 //9268,-9268,9268,32767,-7395,18367 7215,-7215,7215,32767,5039,6171, }; /* Codec configuration settings */ DSK6713_AIC23_Config config = { \
0x0017, 0x0017, 0x00d8, 0x00d8, 0x0011, 0x0000, 0x0000, 0x0043, 0x0081, 0x0001 /* 0 DSK6713_AIC23_LEFTINVOL /* 1 DSK6713_AIC23_RIGHTINVOL /* 2 DSK6713_AIC23_LEFTHPVOL /* 3 DSK6713_AIC23_RIGHTHPVOL /* 4 DSK6713_AIC23_ANAPATH /* 5 DSK6713_AIC23_DIGPATH /* 6 DSK6713_AIC23_POWERDOWN /* 7 DSK6713_AIC23_DIGIF /* 8 DSK6713_AIC23_SAMPLERATE /* 9 DSK6713_AIC23_DIGACT Left line input channel volume */ \ Right line input channel volume */\ Left channel headphone volume */ \ Right channel headphone volume */\ Analog audio path control */ \ Digital audio path control */ \ Power down control */ \ Digital audio interface format */ \ Sample rate control */ \ Digital interface activation */ \

/*HP 2500 */ /*LP 800 */ /*LP 2500 */ /*HP 4000*/ /*HP 7000*/

}; /* * 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); DSK6713_AIC23_setFreq(hCodec, 3); while(1)

85

DSP LAB MANUAL

VITS

/* 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=IIR_FILTER(&filter_Coeff ,l_input); r_output=l_output; /* Send a sample to the left channel */ while (!DSK6713_AIC23_write(hCodec, l_output)); /* Send a sample to the right channel */ while (!DSK6713_AIC23_write(hCodec, r_output));

} /* Close the codec */ DSK6713_AIC23_closeCodec(hCodec); } signed int IIR_FILTER(const signed int * h, signed int x1) { static signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be static */ static signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be static */ int temp=0; temp = (short int)x1; /* Copy input to temp */ x[0] = (signed int) temp; /* Copy input to x[stages][0] */ temp = ( (int)h[0] * x[0]) ; /* B0 * x(n) */ temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */ temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */ temp += ( (int)h[2] * x[2]); /* B2 * x(n-2) */ temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */ temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */ temp -= ( (int)h[5] * y[2]); /* A2 * y(n-2) */ /* Divide temp by coefficients[A0] */ temp >>= 15; if ( temp > 32767 ) { temp = 32767; } else if ( temp < -32767)

86

DSP LAB MANUAL

VITS

{ temp = -32767; } y[0] = temp ; /* Shuffle values along one place for next time */ y[2] = y[1]; /* y(n-2) = y(n-1) */ y[1] = y[0]; /* y(n-1) = y(n) */ x[2] = x[1]; /* x(n-2) = x(n-1) */ x[1] = x[0]; /* x(n-1) = x(n) */ /* temp is used as input next time through */ return (temp<<2); }

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. 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 using F5. Observe the waveform that appears on the CRO screen.

87

DSP LAB MANUAL

VITS

RESULT:

88

DSP LAB MANUAL

VITS

MODEL 2:C PROGRAM TO IMPLEMENT IIR FILTER


#include<stdio.h> #include<math.h> int i,w,wc,c,N; float H[100]; float mul(float, int); void main() { printf("\n enter order of filter "); scanf("%d",&N); printf("\n enter the cutoff freq "); scanf("%d",&wc); printf("\n enter the choice for IIR filter 1. LPF 2.HPF "); scanf("%d",&c); switch(c) { case 1: for(w=0;w<100;w++) { H[w]=1/sqrt(1+mul((w/(float)wc),2*N)); printf("H[%d]=%f\n",w,H[w]); } break; case 2: for(w=0;w<=100;w++) { H[w]=1/sqrt(1+mul((float)wc/w,2*N)); printf("H[%d]=%f\n",w,H[w]); } break; }} float mul(float a,int x) { for(i=0;i<x-1;i++) a*=a; return(a); }

89

DSP LAB MANUAL

VITS

OUTPUT FOR IIR FILTER LPF

enter order of filter 2 enter the cutoff freq 50 enter the choice for IIR filter 1. LPF 2.HPF: 1

Graph Property Graph IIR FILTER LOW PASS FILTER


OUTPUT FOR IIR FILTER HPF

enter order of filter 2 enter the cutoff freq 50 enter the choice for IIR filter 1. LPF 2.HPF: 2

Graph Property Graph IIR FILTER HIGH PASS FILTER

90

DSP LAB MANUAL

VITS

EXP.No:16 N-POINT FAST FOURIER TRANSFORM (FFT)


AIM: To find the DFT of a sequence using FFT algorithm. EQUIPMENTS: TMS 320C6713 Kit. Oscilloscope & Function Generator RS232 Serial Cable Power Cord Operating System Windows XP Software CCStudio_v3.1

THEORY:
The Fast Fourier Transform is useful to map the time-domain sequence into a continuous function of a frequency variable. The FFT of a sequence {x(n)} of length N is given by a Complex-valued sequence X (k).

X ( k ) = x ( n) e
k =0

j 2

nk n

;0 < k < N 1

The above equation is the mathematical representation of the DFT. As the number of computations involved in transforming a N point time domain signal into its corresponding frequency domain signal was found to be N2 complex multiplications, an alternative algorithm involving lesser number of computations is opted. When the sequence x(n) is divided into 2 sequences and the DFT performed separately, the resulting number of computations would be N2/2. (i.e.)
N2 21 N2 21

( x(k ) = x(2n) WN2 nk + x(2n + 1) WN2 n+1) k n =0 n =0

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

x ( 2n )
n =0

2 WN nk

(N/2)2multiplications

x(2n + 1)
n =0

N2 21

( WN2 n+1) k

91

DSP LAB MANUAL

VITS

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


N2 N2 N2 + = Computations 4 4 2

Further solving Eg. (2)


N2 21 N 21 k

x ( k ) = x( 2n) W
n =0

2 nk N

+ x(2n + 1) W
n =0

( 2 nk ) N

W
N

= x ( 2 n) W
n =0

N 21

2 nk N

( + W x(2n + 1) WN2 nk ) N n =0

N 21

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

=e W W

j 2 n j 2 nk n

nk N

=e

N K+ 2 N

= WN W e
j 2 n n 2

N K+ 2 N

=e

j 2 k n

=W

k N

j 2 k n

k = WN (cos j sin )

92

DSP LAB MANUAL

VITS

=W

N K+ 2 N

k = WN (1)

=W

N K+ 2 N

k = WN

Employing this equation, we deduce


N2 21 N 21

( x(k ) = x(2n) WN2 nk + x(2n + 1) WN2 nk ) (13) n =0 n =0 N 21

K N 2 nk ( x( k + ) = x( 2n) WN W x( 2n + 1) 21 WN 2 nk ) (14) 2 n =0 N

The time burden created by this large number of computations limits the usefulness of DFT in many applications. Tremendous efforts devoted to develop more efficient ways of computing DFT resulted in the above explained Fast Fourier Transform algorithm. This mathematical shortcut reduces the number of calculations the DFT requires drastically. The above mentioned radix-2 decimation in time FFT is employed for domain transformation. Dividing the DFT into smaller DFTs is the basis of the FFT. A radix-2 FFT divides the DFT into two smaller DFTs, each of which is divided into smaller DFTs and so on, resulting in a combination of two-point DFTs. The Decimation -In-Time (DIT) FFT divides the input (time) sequence into two groups, one of even samples and the other of odd samples. N/2 point DFT are performed on the these sub-sequences and their outputs are combined to form the N point DFT.

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

93

DSP LAB MANUAL

VITS

ALGORITHM
sample the input (N) of any desired frequency. Convert it to fixed-point format and scale the input to avoid overflow during manipulation. Step 2 Declare four buffers namely real input, real exponent, imaginary exponent and imaginary input. Step 3 Declare three counters for stage, group and butterfly. Step 4 Implement the Fast Fourier Transform for the input signal. Step 5 Store the output (Real and Imaginary) in the output buffer. Step 6 Decrement the counter of butterfly. Repeat from the Step 4 until the counter reaches zero. Step 7 If the butterfly counter is zero, modify the exponent value. Step 8 Repeat from the Step 4 until the group counter reaches zero. Step 9 If the group counter is zero, multiply the butterfly value by two and divide the group value by two. Step 10 Repeat from the Step 4 until the stage counter reaches zero. Step 11 Transmit the FFT output through line out port. PROGRAM fft256.c #include <math.h> #define PTS 64 #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 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 main() { 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 { Step 1

//# of points for FFT

94

DSP LAB MANUAL

VITS

iobuffer[i] = sin(2*PI*10*i/64.0);/*10- > freq, 64 -> sampling freq*/ 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

for (i = 0 ; i < PTS ; i++) //compute magnitude { x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); } } //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;

95

DSP LAB MANUAL

VITS

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

96

DSP LAB MANUAL

VITS

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 FFT.pjt. Add the source files fft256.c and fft.C in the project using Projectadd files to project pull down menu. Add the linker command file hello.cmd. Add the rts file 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. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

97

DSP LAB MANUAL

VITS

GRAPHS

Graph Property FFT INPUT

Graph

Graph Property FFT OUTPUT

Graph

98

DSP LAB MANUAL

VITS

EXP.No:16 TO COMPUTE POWER DENSITY SPECTRUM OF A SEQUENCE [USING TMS320C6713 DSP PROCESSOR]
AIM: To find the PSD of a sequence. EQUIPMENTS: TMS 320C6713 Kit. Oscilloscope & Function Generator RS232 Serial Cable Power Cord Operating System: Windows XP Software: CCStudio_v3.1 INTRODUCTION: The total or the average power in a signal is often not of as great an interest. We are most often interested in the PSD or the Power Spectrum. We often want to see is how the input power has been redistributed by the channel and in this frequency-based redistribution of power is where most of the interesting information lies. The total area under the Power Spectrum or PSD is equal to the total avg. power of the signal. The PSD is an even function of frequency or in other words. To compute PSD: The value of the auto-correlation function at zero-time equals the total power in the signal. To compute PSD we compute the auto-correlation of the signal and then take its FFT. The auto-correlation function and PSD are a Fourier transform pair. (Another estimation method called period gram uses sampled FFT to compute the PSD.). E.g.: For a process x(n) correlation is defined as:

R ( Ex n ) =( x + ) { )n ( }

=lim

1 N + ) ( nxn ( x ) N n= 1

Power Spectral Density is a Fourier transform of the auto correlation.

S ( = (R ( )) lim R ( ) ) FT = e
N

N 1

= N 1 +

R () = FT ( )) S1( =

S ( d ) e 2

ALGORITHM TO IMPLEMENT PSD:

99

DSP LAB MANUAL

VITS

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 - Compute the Auto Correlation of Sine wave . Step4 - Take output of auto correlation, apply FFT algorithm . Step 4 - Use Graph option to view the PSD. Step 5 - Repeat Step-1 to 4 for different no. of points & frequencies.

C PROGRAM TO IMPLEMENT PSD: PSD.c: /************************************************************* * FILENAME * Non_real_time_PSD.c * DESCRIPTION * Program to Compute Non real time PSD * using the TMS320C6711 DSK. *************************************************************** * DESCRIPTION * Number of points for FFT (PTS) * x --> Sine Wave Co-Efficients * iobuffer --> Out put of Auto Correlation. * x1 --> use in graph window to view PSD /*===========================================================*/ #include <math.h> #define PTS 128 #define PI 3.14159265358979 //# of points for FFT

typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); float iobuffer[PTS]; float x1[PTS],x[PTS]; short i; short buffercount = 0; short flag = 0; float y[128]; COMPLEX w[PTS]; COMPLEX samples[PTS]; main() { float j,sum=0.0 ; //FFT prototype //as input and output buffer //intermediate buffer //general purpose index variable //number of new samples in iobuffer //set to 1 by ISR when iobuffer full //twiddle constants stored in w //primary working buffer

100

DSP LAB MANUAL

VITS

int n,k,i,a; 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*/ } /****************Input Signal X(n) *************************/ for(i=0,j=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; FFT(samples,PTS); //imag components = 0 //call function FFT.c

/******************** PSD ********************/ for (i = 0 ; i < PTS ; i++) { //compute magnitude

101

DSP LAB MANUAL

VITS

x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); } } FFT.c: #define PTS 128 //# of points for FFT //end of main

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; //indexof 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// 512 for (i = 0;i < num_stages; i++) //for N-point FFT { index = 0; 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;

102

DSP LAB MANUAL

VITS

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

103

DSP LAB MANUAL

VITS

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 PSD.pjt. Add the source files PSD.c and FFT.c in the project using Projectadd files to project pull down menu. Add the linker command file hello.cmd . Add the rts file 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. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

104

DSP LAB MANUAL

VITS

RESULTS

Graph Property PSD INPUT

Graph

Graph Property PSD OUTPUT

Graph

105

DSP LAB MANUAL

VITS

ADDITIONAL EXPERIMENTS

106

DSP LAB MANUAL

VITS

EXP.NO: 1 TO FIND FREQEUNCY RESPONSE OF BAND PASS FILTER UISNG FIR Aim: To find frequency response of Band pass filter using FIR. EQUIPMENTS: MATLAB Software, CCS Studio PROGRAM:
MATLAB CODE

fs = 20000; % sampling rate F = [3000 4000 6000 8000]; % band limits A = [0 1 0]; % band type: 0='stop', 1='pass' dev = [0.0001 10^(0.1/20)-1 0.0001]; % ripple/attenuation spec [M,Wn,beta,typ] = kaiserord(F,A,dev,fs); % window parameters b = fir1(M,Wn,typ,kaiser(M+1,beta),'noscale'); % filter design

107

DSP LAB MANUAL

VITS

C CODE #include <math.h> #include "st_i.h" #include "btrworth.h" int st_bandpass_getopts (eff_t effp, int n, char **argv) { butterworth_t butterworth = (butterworth_t)effp->priv; if (n != 2) { st_fail("Usage: bandpass FREQUENCY BANDWIDTH"); return (ST_EOF); } st_butterworth_start (effp); if (!(sscanf (argv [0], "%lf", &butterworth->frequency))) { st_fail("bandpass: illegal frequency"); return (ST_EOF); } if (!(sscanf (argv [1], "%lf", &butterworth->bandwidth))) { st_fail("bandpass: illegal bandwidth"); return (ST_EOF); } return (ST_SUCCESS); } int st_bandpass_start (eff_t effp) { butterworth_t butterworth = (butterworth_t) effp->priv; double c; double d; c = 1.0 / tan (M_PI * butterworth->bandwidth / effp->ininfo.rate); d = 2 * cos (2 * M_PI * butterworth->frequency / effp->ininfo.rate); butterworth->a [0] = 1.0 / (1.0 + c); butterworth->a [1] = 0.0;

108

DSP LAB MANUAL

VITS

butterworth->a [2] = -butterworth->a [0]; butterworth->b [0] = -c * d * butterworth->a [0]; butterworth->b [1] = (c - 1.0) * butterworth->a[0]; return (ST_SUCCESS); } RESULT:

Figure : Magnitude response of the FIR bandpass filter designed by the window method.

EXP.NO: 2 TO FIND FREQEUNCY RESPONSE OF BAND PASS FILTER UISNG IIR Aim: To find frequency response of Band pass filter using IIR. EQUIPMENTS: MATLAB Software, CCS Studio PROGRAM:
MATLAB CODE

109

DSP LAB MANUAL

VITS

%steps of designing a digital filter implied in the called functions: % step 1: estimate the minimum order of the filter from specifications % step 2: get analog, pre-warped frequencies % step 3: convert to low-pass prototype estimate % step 4: Get n-th order analog lowpass prototype with desired filter characters % step 5: Transform to lowpass, bandpass, highpass, or bandstop of desired Wn % step 6: Use Bilinear transformation to find discrete equivalent: clear all; format; Fs = 100000; %sampling frequency(Hz). Wp = [20500 23500]/(Fs/2); %passband edge frequency normalised by Fs/2. Ws = [19000 25000]/(Fs/2); %stopband edge frewquency normalised by Fs/2. Rp = 0.25; %passband attenuation in dB. Rs = 45; %stopband attenuation in Db ctype = 4; %character of filter ftype = 'bandpass'; %type of filter if ctype==1 [n,Wn]=buttord(Wp,Ws,Rp,Rs); [b,a]=butter(n,Wn,ftype); elseif ctype==2 [n,Wn]=cheb1ord(Wp,Ws,Rp,Rs); [b,a]=cheby1(n,Rp,Wn,ftype); elseif ctype==3 [n,Wn]=cheb2ord(Wp,Ws,Rp,Rs); [b,a]=cheby2(n,Rs,Wn,ftype); elseif ctype==4

110

DSP LAB MANUAL

VITS

[n,Wn]=ellipord(Wp,Ws,Rp,Rs); [b,a]=ellip(n,Rp,Rs,Wn,ftype); end %Output the result disp('Numerator coefficients (in descending powers of z):'); disp(b); disp('Denominator coefficients (in descending powers of z):'); disp(a); freqz(b,a,1024,Fs); ======================================================= function Impinv %Impulse invariance method of anolog-to-digital filter conversion %a,b -- s-plane coefficients %az,bz -- digital filter coefficients clear all; b = 1; a = [1.84496 1.920675 1]; [bz,az]=impinvar(b,a) %get z-plane coefficients using impulse Inv. freqz(bz,az,1024); C CODE
#include <math.h> #include <string.h> #include "st_i.h" /* Private data for Bandpass effect */ typedef struct bandstuff { float center; float width; double A, B, C; double out1, out2; short noise; /* 50 bytes of data, 52 bytes long for allocation purposes. */ } *band_t; /* * Process options */ int st_band_getopts(eff_t effp, int n, char **argv) { band_t band = (band_t) effp->priv;

111

DSP LAB MANUAL

VITS

band->noise = 0; if (n > 0 && !strcmp(argv[0], "-n")) { band->noise = 1; n--; argv++; } if ((n < 1) || !sscanf(argv[0], "%f", &band->center)) { st_fail("Usage: band [ -n ] center [ width ]"); return (ST_EOF); } band->width = band->center / 2; if ((n >= 2) && !sscanf(argv[1], "%f", &band->width)) { st_fail("Usage: band [ -n ] center [ width ]"); return (ST_EOF); } return (ST_SUCCESS); } /* * Prepare processing. */ int st_band_start(eff_t effp) { band_t band = (band_t) effp->priv; if (band->center > effp->ininfo.rate/2) { st_fail("Band: center must be < minimum data rate/2\n"); return (ST_EOF); } band->C = exp(-2*M_PI*band->width/effp->ininfo.rate); band->B = -4*band->C/(1+band->C)* cos(2*M_PI*band->center/effp->ininfo.rate); if (band->noise) band->A = sqrt(((1+band->C)*(1+band->C)-band->B * band->B)*(1-band->C)/(1+band->C)); else band->A = sqrt(1-band->B*band->B/(4*band->C))*(1-band->C); band->out1 = band->out2 = 0.0; return (ST_SUCCESS); } /* * Processed signed long samples from ibuf to obuf. * Return number of samples processed. */

112

DSP LAB MANUAL

VITS

int st_band_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, st_size_t *isamp, st_size_t *osamp) { band_t band = (band_t) effp->priv; int len, done; double d; st_sample_t l; len = ((*isamp > *osamp) ? *osamp : *isamp); /* yeah yeah yeah registers & integer arithmetic yeah yeah yeah */ for(done = 0; done < len; done++) { l = *ibuf++; d = (band->A * l - band->B * band->out1) - band->C * band->out2; band->out2 = band->out1; band->out1 = d; *obuf++ = d; } *isamp = len; *osamp = len; return(ST_SUCCESS); } /* * Do anything required when you stop reading samples. * Don't close input file! */ int st_band_stop(eff_t effp) { return (ST_SUCCESS); /* nothing to do */ }

113

DSP LAB MANUAL

VITS

RESULT

114

DSP LAB MANUAL

VITS

EXP.NO: 3 TO FIND FREQEUNCY RESPONSE OF BAND REJECT FILTER UISNG FIR Aim: To find frequency response of Band reject filter using FIR. EQUIPMENTS: MATLAB Software PROGRAM:
MATLAB CODE

%IIR Chebyshev type-I bandstop filter clc;clear all;close all; rp=input('enter the passband ripple '); rs=input('enter the stopband ripple '); wp=input('enter the passband frequency '); ws=input('enter the stopband frequency '); fs=input('enter the sampling frequency '); w1=2*wp/fs; w2=2*ws/fs; [n]=cheb1ord(w1,w2,rp,rs); wn=[w1 w2]; [b,a]=cheby1(n,rp,wn,'stop'); w=0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1); plot(om/pi,m); ylabel('Gain in dB--->'); xlabel('Normalised frequency--->'); title('CHEBYSHEV TYPE-I BAND STOP MAGNITUDE RESPONSE'); subplot(2,1,2); plot(om/pi,an); ylabel('Phase in radians--->'); xlabel('Normalised frequency--->'); title('CHEBYSHEV TYPE-I BAND STOP PHASE RESPONSE'); SAMPLE INPUTS enter the passband ripple 0.25 enter the stopband ripple 40 enter the passband frequency 2500

115

DSP LAB MANUAL

VITS

enter the stopband frequency 2750 enter the sampling frequency 7000 RESULT

116

DSP LAB MANUAL

VITS

EXP.NO: 4 TO FIND FREQEUNCY RESPONSE OF BAND REJECT FILTER UISNG IIR Aim: To find frequency response of Band reject filter using IIR. EQUIPMENTS: MATLAB Software PROGRAM:
MATLAB CODE %IIR Butterworth bandstop filter clc;clear all;close all; rp=input('enter the passband ripple '); rs=input('enter the stopband ripple '); wp=input('enter the passband frequency '); ws=input('enter the stopband frequency '); fs=input('enter the sampling frequency '); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); wn=[w1,w2]; [b,a]=butter(n,wn,'stop'); w=0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1); plot(om/pi,m);

117

DSP LAB MANUAL

VITS

ylabel('Gain in dB--->'); xlabel('Normalised frequency--->'); title('BUTTERWORTH BANDSTOP MAGNITUDE RESPONSE'); subplot(2,1,2); plot(om/pi,an); ylabel('Phase in radians--->'); xlabel('Normalised frequency--->'); title('BUTTERWORTH BANDSTOP PHASE RESPONSE'); SAMPLE INPUTS enter the passband ripple .4 enter the stopband ripple 46 enter the passband frequency 1100 enter the stopband frequency 2200 enter the sampling frequency 6000 RESULT

118

DSP LAB MANUAL

VITS

VIVA QUESTIONS GENERATION OF SINUSOIDAL SIGNAL QUESTIONS


1. what is the difference between sin & cos signals? 2. What is meant by signal? 3. What is the difference between time domain & frequency domain signal? 4. What is the difference between periodic & a periodic signal. 5. What is the difference between orthogonal and orthonormal signals? 6. What is the need for Fourier series & Fourier transform? 7. What is the difference between discrete & digital signals? 8. What is the difference between even signal & odd signal? 9. What is the difference between power signal & energy signal? 10. What is the difference between amplitude scaling & time scaling of a signal? 11. What is the difference between deterministic & random signal?

LINEAR CONVOLUTION QUESTIONS


1. What is the requirement for convolution?. 2. What is the difference between convolution & correlation? 3. What is meant by impulse response? 4. Is it possible to represent any discrete time signal in terms of impulses? If yes, represent by using example. 5. Draw the h(2n-k) & h(n-2k) for the following sequence h(n) = { 4 3 2 1} assume (i) k= 3 (ii) k =5. 6. Write the expressions for LTI system convolution formula & causal LTI system convolution formula. 7. What us the length of linear convolution if length of input & impulse responses are N1 & N2 respectively? 8. What is the difference between continuous and discrete convolution?

CIRCULAR CONVOLUTION QUESTIONS

119

DSP LAB MANUAL

VITS

1. Why we need circular convolution? 2. What is the difference between circular & linear convolution? 3. What is the length of output sequence after circular convolution if the lengths of input & impulse responses are M1 & M2 respectively? 4. State the circular convolution property of DFT? 5. Where we required convolution property? 6. What does zero padding mean? Where we required this concept? 7. What is difference between linear shifting & circular shifting of signal? Show with example. 8. What is difference between linear & circular folding of signal? Show with example. 9. What is the advantage with sectioned convolution?.

FAST FOURIER TRANSFORMS QUESTION


1. What is the difference between continuous time & discrete time Fourier transform? 2. What is the condition for convergence of Fourier transform? 3. What is the difference between discrete Time Fourier Transform (DTFT)& DFT? 4. What is the difference between Z transform & DFT? 5. State convolution property of the DFT? Where we could use the convolution property? 6. State Parsevals theorem.? 7. State correlation property of the DFT.? 8. What is the difference between radix 2 & radix4 FFT algorithms? 9. Why we need FFT?. 10. What is the difference between decimation in time (DIT FFT) & Decimation in frequency(DIFFFT) algorithms? 11. What is meant by in-place computation in DIF & DIF algorithms? 12. Which properties are used in FFT to reduce no of computations?

FIR FILTER QUESTIONS


1. What are the advantages of FIR as compared to IIR?

120

DSP LAB MANUAL

VITS

2. How many types of FIR design methods are used in real time?. 3. What is meant by Gibbs Phenomenon? Where we found such type of effect in FIR filters? 4. What are the advantages& disadvantages of Rectangular window FIR filter as compared to remaining window techniques? 5. Which window technique having less peak amplitude of side lobe as compared to all? 6. What do you understand by linear phase responce? 7. To design all types of filters what would be the expected impulse response? 8. What are the properties of FIR filter?. 9. How the zeros in FIR filter is located? 10. What are the desirable characteristics of the window? 11. What are the specifications required to design filter

IIR FILTER QUESTIONS


1. What is meant by IIR filter? 2. What is the difference between recursive & non-recursive systems? 3. Write the difference equation for IIR system. 4. What are the mapping techniques in IIR filter design? Discuss the advantage & disadvantages of them. 5. What are IIR analog filters? What are the advantages & disadvantages of them? 6. What is the disadvantage in impulse invariance method? 7. What does warping effect mean? Where we found this effect? How can we eliminate warping effect 8. Explain the pole mapping procedure of Impulse invariant & bilinear transformation method. 9. For given same specification which difference we found in Butter worth & Tchebyshev filter. 10. What is the difference between type I & type II Tchebyshev filters?. 11. Where the poles are located for Butter worth & Tchedbyshev filters? 12. What is meant by spectral transformation? 13. Why we need spectral transformation in IIR filter?

121

DSP LAB MANUAL

VITS

POWER SPECTRUM DENSITY QUESTION


1. What is the difference between correlation & auto correlation function? 2. What is the difference between PSD & ESD? 3. What is the unit for energy density spectrum? 4. What is the formula for PSD of a function? 5. Same power density spectrum signals always have same magnitude & phase spectrums Is above statement true (or) False: Justify your answer. 6. If we know the impulse response of the system, the How can you find output signal power density from the input signal? 7. What is the unit for power density spectrum? 8. What is the relation between auto correlation & PSD of a function?

DSP PROCESSORS QUESTIONS


1. How many types of DSP processors are available in the market? 2. TMS 320C6X, C stands for what? 3. What are the features of TMS 320C6X processor? 4. What is meant by VLIW architecture? Why we required in DSP processor? 5. How many functional units are in TMS 320C6X DSP processor? 6. What is meant by Circular addressing mode how is it useful for DSP? 7. Which instruction is used to move 16 bit constant in to the upper bits of a register? 8. What is the difference between Von Neumann architecture & Harvard architecture? 9. Which architecture is used in DSP processor? 10. How many instructions can we execute per cycle in TMS320C6X DSP processor? 11. What are the applications for the TMS320 DSPs? 12. Which soft ware tool is required to compile and run the DSP assembly program ? 13. What is the difference between full version Code composer studio &DSK CCS?

122

DSP LAB MANUAL

VITS

123

S-ar putea să vă placă și