0% found this document useful (0 votes)
87 views

DSP LCDK USER_MANUAL_V3

The TMS320C6748 LCDK Kit User Manual provides detailed information on the features, installation procedures, and programming examples for the TMS320C6748 DSP Starter Kit, which is designed for practical learning in Digital Signal Processing. It includes instructions for using Code Composer Studio for both non-real-time and real-time projects, as well as various DSP algorithms such as convolution, FFT, and image processing. The manual also outlines system requirements, hardware connections, and programming examples to facilitate user understanding and application development.

Uploaded by

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

DSP LCDK USER_MANUAL_V3

The TMS320C6748 LCDK Kit User Manual provides detailed information on the features, installation procedures, and programming examples for the TMS320C6748 DSP Starter Kit, which is designed for practical learning in Digital Signal Processing. It includes instructions for using Code Composer Studio for both non-real-time and real-time projects, as well as various DSP algorithms such as convolution, FFT, and image processing. The manual also outlines system requirements, hardware connections, and programming examples to facilitate user understanding and application development.

Uploaded by

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

STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

TMS320C6748 LCDK KIT


USER MANUAL

STARCOM INFORMATION TECHNOLOGY LTD


#88, Times Square, M.G Road, Bangalore - 560 032
[email protected]
www.starcomacademic.com

1
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

CONTENTS

 DSP STARTER KIT BOARD FEATURES


 INSTALLATION PROCEDURE
 PROCEDURE TO WORK ON CODE COMPOSER STUDIO(NON-REALTIME)
 PROGRAM TO GENERATE SINEWAVE
 PROGRAM TO IMPLEMENT LINEAR & CIRCULAR CONVOLUTION
 PROGRAM TO IMPLEMENT DFT & IDFT
 PROGRAM TO IMPLEMENT FFT & IFFT
 PROGRAM TO IMPLEMENT INTERPOLATION & DECIMATION
 PROGRAM TO IMPLEMENT POWER SPECTRAL DENSITY(PSD)

 PROCEDURE TO WORK ON CODE COMPOSER STUDIO (REALTIME)


 PROGRAM TO IMPLEMENT LOOPBACK
 PROGRAM TO GENERATE SINE ,SQUARE & RAMP WAVE
 PROGRAM TO IMPLEMENT FIR
 PROGRAM TO IMPLEMENT IIR
 PROGRAM TO IMPLEMENT ADAPTIVE FILTER

 PROCEDURE & PROGRAM TO IMPLEMENT IMAGE PROCESSING

 PROCEDURE TO GENERATE FILTER COEFFICIENTS USING MATLAB

 PROCEDURE TO WORK ON ASSEMBLY PROGRAMS

2
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

TMS320C6748 LCDK
Kit Contents:

 TMS320C6748 Hardware Board


 Power Card(5VDC)
 XDS 100v2/3JTAG Emulator
 USB Cable
 User Manual & Example Programs(Soft Copy)

Description:
The TMS320C6748 DSP Starter kit (LCDK) is a low cost development tool development for practically
learning Theoretical Concepts of Digital Signal Processing. DSP Algorithms used in Applications such as
Speech Processing, Audio Processing, Image Processing and Digital Communication can be explored
practically. The low-cost DSP Kit will also speed and ease development of real-time DSP programs with the
help of Code Composer Studio Software A complete Integrated Development Environment (IDE), an efficient
optimizing C/C++ compiler assembler, linker, debugger, and an advanced editor with Code Maestro™ technology
for faster code creation, data visualization, a profiler and a flexible project manager

The TMS320C6748 DSP Starter Kit does not have an onboard emulator. An external emulator from
TI (such as the XDS100, XDS200,XDS510, XDS560) or a third-party will be required to start
development.

3
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

The C674x DSP core of C6000 processor family is a low-power applications processor and it consumes
less power than other members of the TMS320C6000™ platform of DSPs

The DSP core uses a 2-level cache-based architecture. The level 1 program cache (L1P) is a 32- KB direct
mapped cache, and the level 1 data cache (L1D) is a 32-KB 2-way, set-associative cache. The level 2
program cache (L2P) consists of a 256-KB memory space that is shared between program and data space.
L2 memory can be configured as mapped memory, cache, or combinations of the two. Although the DSP
L2 is accessible by the ARM9 and other hosts in the system, an additional 128KB of RAM shared
memory is available for use by other hosts without affecting DSP performance.

Processor

 TI TMS320C6748 DSP Application Processor


 456-MHz C674x Fixed/Floating Point DSP
 On-Chip RTC

4
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Memory

 128 MByte DDR2 SDRAM


 128 MByte 16-bit wide NAND FLASH
 1 Micro SD/MMC Slot
Interfaces

 One mini-USB Serial Port (on-board serial to USB)


 One Fast Ethernet Port (10/100 Mbps) with status LEDs
 One USB Host port (USB 1.1)
 One SATA Port (3Gbps)
 One LCD Port
 One Leopard Imaging Camera Sensor Input (36-pin ZIP connector)
 Three AUDIO Ports (1 LINE IN-J55 & 1 LINE OUT-J56 & 1 MIC IN-J57)
 14-pin JTAG header (No onboard emulator; external emulator is required)

TMS320C6748 DSP Features

 Highest-Performance Floating-Point Digital Signal Processor (DSP):


 Eight 32-Bit Instructions/Cycle
 32/64-Bit Data Word
 375/456-MHz C674x Fixed/Floating-Point
 Up to 3648/2746 C674x MIPS/MFLOPS
 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 64 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
 67x cache memory.
5
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 32K-Byte L1P Program Cache (Direct-Mapped)


 32K-Byte L1D Data Cache (2-Way)
 256K-Byte L2 unified Memory RAM\Cache.
 Real-Time Clock With 32 KHz Oscillator and Separate Power Rail.
 Three 64-Bit General-Purpose Timers
 Integrated Digital Audio Interface Transmitter (DIT) Supports:
 S/PDIF, IEC60958-1, AES-3, CP-430 Formats
 Up to 16 transmit pins
 Enhanced Channel Status/User Data
 Extensive Error Checking and Recovery
 Two Inter-Integrated Circuit Bus (I2C Bus™) .
 3 64-Bit General-Purpose Timers (each configurable as 2 32-bit timers)
 Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module
 IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible
 3.3-V I/Os, 1.2 -V Internal (GDP & PYP)
 3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)
 Two Serial Peripheral Interfaces (SPI) Each With Multiple Chip-Selects
 Two Multimedia Card (MMC)/Secure Digital Card Interface with Secure Data I/O (SDIO) Interfaces
 One Multichannel Audio Serial Port.
 Two Multichannel Buffered Serial Ports

TOP VIEW OF TMS320C6748 LCDK Board

6
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

INSTALLATION
SYSTEM REQUIREMENTS:
Recommended system requirements Minimum system requirements
Processor 1.5GHz
PENTIUM OR HIGHER
RAM 4GB or above 1GB
Free Disk Space 4GB 4GB
Operating System Microsoft windows 8/7/XP -DO-

SOFTWARE INSTALLATION:
 CCSv6 or Higher(http://processors.wiki.ti.com/index.php/Download_CCS)
Version 6 or higher is recommended
 C64XPLUS-IMGLIB (http://www.ti.com/tool/sprc264)

HARDWARE REQUIREMENTS:
 Kit connected with 5V power supply
 USB cable connected with PC and JTAG emulator.
 Double sided stereo cable and speakers/ear phones (For Audio processing)
 Stereo cables, Function generator and CRO (For signal filtering applications)

Connecting Board with XDS100v3 Emulator

Note: Connect XDS100v3 emulator as shown in above picture prior to power up the board

Note: Ensure Installation of Emulator Driver (Green LED on Emulator Indicates, Driver Installed). Otherwise
install drivers manually from Drivers Folder

7
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

General Procedure to work on Code Composer Studio V6 for


non-real time projects Using target:
NR1. Launch CCS
Launch the CCS v6 icon from the Desktop or goto All Programs -> Texas Instruments -> CCSv6

NR2. Choose the location for the workspace, where your project will be saved.

NR3. Creating a New Project:


 Go to File  New  CCS Project.

 Specify the name of the project in the space provided e g., Project Name: TEST
Specify the “Device” properties as shown in the figure below
8
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Optional: choose the Linker command file: as


“linker_dsp.cmd” (Browse from Supporting files
folder given at the time of installation)
.
Click Finish

 Type your C Code and save.

9
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

NR5. BUILD
Build the program to check your code.

Go to

Project  Build project.

If your code doesn’t have any errors and warnings, a message will be printed in the console window that
“**** Build Finished ****”

Problems window display errors or warnings, if any.

NR6. DEBUG
10
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

After successful Build, connect the kit with the system using the JTAG emulator and
power the kit.
Click the Debug as shown in the below figure.

It will redirect to the Debug perspective automatically.

NR7. RUN
Wait until the program loaded to the hardware automatically.
Now you can run the code, by selecting Run-> Resume.

Once you run the program the output will be printed in the Console Window.

We can also double click on the Console Window to view it on full screen.

11
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

SINE WAVE GENERATION


Procedure to create a simple non-real time project - Sine wave Generation:

#include <stdio.h>
#include <stdio.h>
#include<math.h>
#include<math.h>
#define FREQ 500
float m[128];
main() #define FREQ 500
{ float m[128];
int i=0;
main()
for(i=0;i<127;i++)
{ {
m[i]=30000*sin(2*3.14*FREQ*i/8000);
int i=0;
printf("%f\n",m[i]);
for(i=0;i<127;i++)
}
}
{
m[i]=sin(2*3.14*FREQ*i/24000);
printf("%f\n",m[i]); }}

Once you run the program, 128 no’s of sine samples has been printed in the Console Window.

To view the values in graph


Go to

Tools  Graph Single Time

12
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 Set the Graph Properties as shown in the

Picture

Buffer size: 128 (No. of samples)

DSP Data Type: 32-Bit floating point

Sampling Rate Hz: 8000

Start Address: m

Display Data Size: 128

Click: Ok

Graph will be plotted as shown below:

13
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

RANDOM WAVE GENERATION

#include<stdio.h>
#include<math.h>
#define PI 3.14
#define PTS 128
float x[PTS];
float y[PTS];
float z[PTS];
float n[PTS];

void main()
{
int i,j;
for (i = 0 ; i < PTS ; i++)
{
x[i] = sin(2*PI*i*20/128.0);
y[i]=0.0;
n[i]=x[i] + rand() * 10 ; //rand function to generate random signal
}
}

14
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

LINEAR CONVOLUTION
To Verify Linear Convolution:

Linear Convolution involves the following operations.


1. Folding
2. Multiplication
3. Addition
4. Shifting

These operations can be represented by a Mathematical Expression as follows:

x[ ]= Input signal Samples


h[ ]= Impulse response co-efficient.
y[ ]= Convolution output.
n = No. of Input samples
h = No. of Impulse response co-efficient.

Algorithm to implement ‘C’ or Assembly program for Convolution:

Eg: x[n] = {1, 2, 3, 4}


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

Where: n=4, k=4. ; If n & k are not equal pad with zero’s

r= n+k-1 ; Size of output sequence.


= 4+4-1
= 7.

15
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

1st Shift
H[n]= 4 3 2 1 0 0 0 /* H[n] is Folded */

X[n]= 0 0 0 1 2 3 4

Y[0]= x[0]*H[0]

2nd Shift
H[n]= 4 3 2 1 0 0 0

X[n]= 0 0 0 1 2 3 4

Y[1]= x[0]*H[1]+X[1]*H[0]

3rd Shift
H[n]= 4 3 2 1 0 0

X[n]= 0 0 0 1 2 3 4

Y[2]= x[0]*H[2]+X[1]*H[1]+X[2]*H[0]

4th Shift
H[n]= 4 3 2 1 0 0

X[n]= 0 0 0 1 2 3 4

Y[3]= x[0]*H[3]+X[1]*H[2]+X[2]*H[1]+X[3]*H[0]

5th Shift
H[n]= 4 3 2 1 0

X[n]= 0 0 0 1 2 3 4

Y[4]= X[1]*H[3]+X[2]*H[2]+X[3]*H[1]
16
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

6th Shift
H[n]= 4 3 2 1

X[n]= 0 0 0 1 2 3 4

Y[5]=X[2]*H[3]+X[3]*H[2]

7th Shift
H[n]= 4 3 2 1

X[n]= 0 0 0 1 2 3 4

Y[6]=X[3]*H[3]

NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s

PROGRAM: LINEAR.C

#include<stdio.h>
#include<stdio.h>
#define LENGHT1 6 /*Lenght of i/p samples sequence*/
#define LENGHT2 4 /*Lenght of impulse response Co-efficients */
#define LENGHT1 6 /*Lenght of i/p samples sequence*/
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 Coefficients*/
int y[LENGHT1+LENGHT2-1];
#define LENGHT2 4 /*Lenght of impulse response Co-efficients */
main()
{ x[2*LENGHT1-1]={1,2,3,4,5,6,0,0,0,0,0}; /*Input Signal Samples*/
int
int i=0,j;
for(i=0;i<(LENGHT1+LENGHT2-1);i++)
int
{ h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0}; /*Impulse Response Coefficients*/
y[i]=0;
for(j=0;j<=i;j++)
int y[LENGHT1+LENGHT2-1];
y[i]+=x[j]*h[i-j];
}
main()
for(i=0;i<(LENGHT1+LENGHT2-1);i++)
printf("%d\n",y[i]);}
{

int i=0,jProcedure:

17
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Follow steps 1-7.

To view the values in graph


Go to

Tools  Graph Single Time

Set the Graph Properties as shown

Buffer size: 10

DSP Data Type: 32-Bit Signed Integer

Start Address: y

Display Data Size: 10

Data Plot Style: bar

Click: Ok

The graph has been plotted as shown below.

18
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

DFT and IDFT


DFT of a discrete time signal transforms the signal in time domain into frequency domain signal.

DFT EQUTION:

The sequence of N complex numbers x0, ..., xN−1 is transformed into another sequence of N complex
numbers according to the DFT formula:

Note:

1 It is periodic. (i.e. it goes round and round the circle !!)


2 That the vectors are symmetric
3 The vectors are equally spaced around the circle

The inverse discrete Fourier transform (IDFT) is given by:

19
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

C. PROGRAM TO IMPLEMENT DFT.

#include<stdio.h>
#include<stdio.h>
#include<math.h>
#include<math.h>
int N,k,n,i;
int N,k,n,i;
float pi=3.1416,sumre=0, sumim=0,out_real[8]={0.0}, out_imag[8]={0.0};
float
int pi=3.1416,sumre=0,
x[32]; sumim=0,out_real[8]={0.0}, out_imag[8]={0.0};
void
int main(void)
x[32];
{ main(void)
void
{printf(" enter the length of the sequence\n");
scanf("%d",&N);
printf(" enter theenter
printf(" length the
of thesequence\n");
sequence\n");
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&x[i]);
printf(" enter the sequence\n");
for(k=0;k<N;k++)
for(i=0;i<N;i++)
{
scanf("%d",&x[i]);
sumre=0;
for(k=0;k<N;k++)
sumim=0;
{
for(n=0;n<N;n++)
sumre=0;
{
sumim=0;
sumre=sumre+x[n]* cos(2*pi*k*n/N);
sumim=sumim-x[n]* sin(2*pi*k*n/N);
for(n=0;n<N;n++)
}
{out_real[k]=sumre;
out_imag[k]=sumim;
sumre=sumre+x[n]* cos(2*pi*k*n/N);
printf("X([%d])=\t%f\t+\t%fi\n",k,out_real[k],out_imag[k]);
sumim=sumim-x[n]*
}
sin(2*pi*k*n/N);
}}

PROCEDURE
Follow steps 1-7.
Once you run the program. Console window will ask for length of sequence. Enter the length.

Now it will ask for sequence. Enter the sequence.

DFT of the given input will appear in console window as shown below.
20
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

21
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

FAST FOURIER TRANSFORMS (FFT)

The DFT Equation

Twiddle Factor

Where N = number of samples. If we take an 8 bit sample sequence we can


represent the twiddle factor as a vector in the unit circle. e.g.

Note that

1 It is periodic. (i.e. it goes round and round the circle !!)


2 That the vectors are symmetric
3 The vectors are equally spaced around the circle.

22
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Why the FFT?


If you look at the equation for the Discrete Fourier Transform you will see that it is quite
complicated to work out as it involves many additions and multiplications involving complex
numbers. Even a simple eight sample signal would require 49 complex multiplications and 56
complex additions to work out the DFT. At this level it is still manageable; however a realistic
signal could have 1024 samples which requires over 20,000,000 complex multiplications and
additions. As you can see the number of calculations required soon mounts up to unmanageable
proportions.

The Fast Fourier Transform is a simply a method of laying out the computation, which is much
faster for large values of N, where N is the number of samples in the sequence. It is an ingenious
way of achieving rather than the DFT's clumsy P^2 timing.

The idea behind the FFT is the divide and conquer approach, to break up the original N point
sample into two (N / 2) sequences. This is because a series of smaller problems is easier to solve
than one large one. The DFT requires (N1)^2 complex multiplications and N(N1) complex
additions as opposed to the FFT's approach of breaking it down into a series of 2 point samples
which only require 1 multiplication and 2 additions and the recombination of the points which is
minimal.

For example Seismic Data contains hundreds of thousands of samples and would take months to
evaluate the DFT. Therefore we use the FFT.

FFT Algorithm

The FFT has a fairly easy algorithm to implement, and it is shown step by step in the list below.
Thjis version of the FFT is the Decimation in Time Method

1. Pad input sequence, of N samples, with ZERO's until the number of samples is the
nearest power of two.

e.g. 500 samples are padded to 512 (2^9)

2. Bit reverses the input sequence.

e.g. 3 = 011 goes to 110 = 6

3. Compute (N / 2) two sample DFT's from the shuffled inputs.

See "Shuffled Inputs"

4. Compute (N / 4) four sample DFT's from the two sample DFT's.

See "Shuffled Inputs"

5. Compute (N / 2) eight sample DFT's from the four sample DFT's.


23
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

See "Shuffled Inputs"

6. Until the all the samples combine into one N sample DFT

Shuffled Inputs

The process of decimating the signal in the time domain has caused the INPUT samples to be re-
ordered. For an 8 point signal the original order of the samples is

0, 1, 2, 3, 4, 5, 6, 7

But after decimation the order is

0, 4, 2, 6, 1, 5, 3, 7

At first it may look as if there is no order to this new sequence, BUT if the numbers are

represented as binary a patter soon becomes apparent.

What has happened is that the bit patterns representing the sample number has been reversed. This
new sequence is the order that the samples enter the FFT.

24
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

C. PROGRAM TO IMPLEMENT FFT.

#define PI 3.14159265358979
#include
typedef struct<math.h>
{float real,imag;} COMPLEX;
#define PTS 64 //# of points for FFT
#define PI 3.14159265358979
void FFT(COMPLEX *Y, int n); //FFT prototype
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
float x1[PTS];
short i; //intermediate bufferpurpose index variable
//general
short buffercount=0; //number of new samples in iobuffer
short
shorti; //general
flag = purpose
0; index variable
//set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
short buffercount
COMPLEX = 0; //number of new samples
samples[PTS]; in iobuffer
//primary working buffer
main()
short
{ flag = 0; //set to 1 by ISR when iobuffer full
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
COMPLEX w[PTS]; //twiddle constants stored in w
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle
constantssamples[PTS]; //primary working buffer
COMPLEX
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle
constants
main()
}
{ for (i = 0 ; i < PTS ; i++) //swap buffers
{
foriobuffer[i]
(i = 0 ; i<PTS=; 30000*sin(2*PI*10*i/64.0);
i++) // set up twiddle constants in w //*10- > freq, 64 ->
sampling freq*/
samples[i].real=0.0;
{ samples[i].imag=0.0;
}
w[i].real
for (i==cos(2*PI*i/(PTS*2.0));
0 ; i < PTS ; i++)//Re component
//swap buffersof twiddle constants
{
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im
samples[i].real=iobuffer[i]; component
//buffer withof twiddle
new dataconstants
}
} for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
forFFT(samples,PTS);
(i = 0 ; i < PTS ; i++)//call
//swap buffers
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);
iobuffer[i] = sin(2*PI*10*i/64.0);/*10- > freq, 64 -> sampling freq*/
}
} //end of main
samples[i].real=0.0;
samples[i].imag=0.0;
}

25
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

//FFT FUNCTION
{ void FFT(COMPLEX *Y, int N) //input sample array, # of points
{
COMPLEX temp1,temp2; //temporary storage variables
samples[i].real=iobuffer[i]; //buffer with new data
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
for
i (i
= =1;
0 ;//log(base2)
i < PTS ; i++) of N points= # of stages
do
samples[i].imag
{ = 0.0; //imag components = 0
num_stages +=1;
FFT(samples,PTS); //call function FFT.c
i = i*2;
for (i = 0 ;(i!=N);
}while i < PTS ; i++) //compute magnitude
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
{ = sqrt(samples[i].real*samples[i].real+ samples[i].imag*samples[i].imag);
x1[i]
index = 0;
} for (j = 0; j < leg_diff; j++)
{
} for
//end(upper_leg
of main = 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;
//FFT FUNCTION
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
void FFT(COMPLEX *Y,=inttemp2.real*(w[index]).real
(Y[lower_leg]).real N) //input sample array, # of points
-temp2.imag*(w[index]).imag
{
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
COMPLEX temp1,temp2; //temporary storage variables
+temp2.imag*(w[index]).real;
int i,j,k; //loop counter variables
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
} upper_leg, lower_leg; //index of upper/lower butterfly leg
int
index += step;
} leg_diff; //difference between upper/lower leg
int
leg_diff = leg_diff/2;
step
int *= 2; = 0; //number of FFT stages (iterations)
num_stages
}
j index,
int = 0; step; //index/step through twiddle constant
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
i = 1; //log(base2) of N points= # of stages
k = N/2;
dowhile
{
(k <= j)

j = j - k;
k = k/2;
}
{ j = j + k;

26
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

i if (i<j)
= i*2;
{
temp1.real = (Y[j]).real;
}while (i!=N);
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
leg_diff = N/2; //difference between upper&lower legs
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
step = (PTS*2)/N;
(Y[i]).imag //step between values in twiddle.h
= temp1.imag;
}}
for (i = 0;i < num_stages; i++) //for N-point FFT
return;
}
{

Procedure:

Follow steps 1-7.


To view results goto view->watch.
In watch window type the variable name to which you want to view results.

1. Set the graph properties as shown in figure.

The graph has been plotted as shown below.

27
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

INTERPOLATION AND DECIMATION OF SINE WAVE


Interpolation
Increase the sampling rate of a discrete-time signal. Higher sampling rate preserves fidelity.

The primary reason to interpolate is simply to increase the sampling rate at the output of one system so
that another system operating at a higher sampling rate can input the signal.

In this section the increase of the sample rate by an integer factor L is described. In the following we refer
to this process as interpolation.

28
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

If we increase the sample rate of a signal we can preserve the full signal content according to the
sampling theorem. After the interpolation the signal spectrum repeats only at multiples of the new sample
rate L. fs. The interpolation is accomplished by inserting L-1 zeros between successive samples (zero-
padding) and using an (ideal) lowpass filter with

29
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Decimation
Reduce the sampling rate of a discrete-time signal. Low sampling rate reduces storage and
computation requirements.

The most immediate reason to decimate is simply to reduce the sampling rate at the output of one system
so a system operating at a lower sampling rate can input the signal. But a much more common motivation
for decimation is to reduce thecost of processing: the calculation and/or memory required to implement a
DSP system generally is proportional to the sampling rate, so the use of a lower sampling rate usually
results in a cheaper implementation

To decrease the sample rate by an integer factor M (decimation) we must first band-limit the signal to
fs/(2.M) by the lowpass filter Hm to comply with sampling theorem and keep only every Mth sample. As
a result, we loose all signal content above half the target sampling frequency fs/M.

30
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

//interpolation & decimation .c

#include<stdio.h>
#include<math.h>
#define FREQ 500
int tb=2; //sampling rate multiplier for interpolated signal
float tx[128]; //to store sine(input) wave Signal
float ty[256]; // to store Interpolated signal
float x[256],y[256]; //to store decemated Signal
void main()
{
int txx,ti,tc,td;
int a,b,d;
int i,j,z,g;
int tj,tcc,tz;
int ta=128;

for(i=0;i<127;i++)
{
tx[i]=30000*sin(2*3.14*FREQ*i/8000); //generating sine wave
printf("%f\n",tx[i]);
}
//Interpolation
tc = tb - 1;
txx = 0;
for (ti=1;ti<=ta;ti++)
{
ty[ti+txx] = tx[ti];
tcc = ti+txx;

tz = ti;
for (tj = 1 ; tj<=tc ;tj++)
{
ty[tcc+1] = 0; //adding zeros in between samples
ti = ti+1;
tcc = tcc+1;
}
txx = tcc-tz;
ti = ti-tc;
}
td = ta*tb; //Length of interpolated signal
for(ti=1;ti<=td;ti++)
{
printf("\n The Value of output ty[%d]=%f",ti,ty[ti]);
}
//Decimation
b=2; //Sampling rate divider for decimated signal
j=1;
for (g=1;g<=128;g++)
{
y[g] = ty[j];
j = j+b;
printf("%f\n",y[g]);
}
}
31
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

INPUT SINE WAVE

INTERPOLATION OUTPUT

DECEMATION OUTPUT

32
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

FSK
As its name suggests, a frequency shift keyed transmitter has its frequency shifted by the message.
Although there could be more than two frequencies involved in an FSK signal, in this experiment the
message will be a binary bit stream, and so only two frequencies will be involved. The word ‘keyed’
suggests that the message is of the ‘on-off’ (mark-space) variety, such as one (historically) generated by a
morse key, or more likely in the present context, a binary sequence. The output from such a generator is
illustrated in Figure 1 below

Conceptually, and in fact, the transmitter could consist of two oscillators (on frequencies f1 and f2), with
only one being connected to the output at any one time. This is shown in block diagram form in Figure 2
below.

Unless there are special relationships between the two oscillator frequencies and the bit clock there will
be abrupt phase discontinuities of the output waveform during transitions of the message.

33
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

#include<stdio.h>
#include<math.h>
#define TIME 336 //length of FSK signal
#define PI 3.14

float fh[TIME],fl[TIME],FSK[TIME];
int input_string[8],scale_data[TIME];

void main()
{

int i,j,k,l;
printf("\nEnter your digital data string in the form of 1 & 0s\n");
for(i=0;i<8;i++) //data in binary format
scanf("%d",&input_string[i]);
k=0;
for(k=0;k<TIME;k++)
{
for(j=0;j<8;j++)
{
for(i=0;i<21;i++)
{
scale_data[k]=input_string[j]; // Scaling input data
k++;
}
}
}
for(i=0;i<TIME;i++)
{
fh[i]=sin(2*PI*2000*i/10000);//high frequency
fl[i]=sin(2*PI*1000*i/10000);//low frequency
}

//assigning high frequency to bit 1


k=0;
for(l=0;k<TIME;l++)
{
for(i=0;i<8;i++)
{
if(input_string[i]==1)
{
for(j=0;j<21;j++)
{
FSK[k]=fh[j];
k++;
}
}
else
//assigning low frequency to bit 0

{
if(input_string[i]==0)
{
for(j=0;j<21;j++)
{
FSK[k]=fl[j];
k++;
34
}}}}}}
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

INPUT SEQUENCE

35
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

INPUT SEQUENCE

FSK WAVE

36
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

CACULATION OF POWER AND ENERGY OF SAMPLES


Energy of Samples

#include<stdio.h>
int main()
{
int num,i,j,x[32];
long int sum=0;
printf("\nEnter the number of samples: ");
scanf("%d",&num);
printf("\nEnter samples: ");
for(j=0;j<num;j++)
scanf("%d",&x[j]);
for(i=0;i<=num;i++)
{
sum+=x[i]*x[i];

}
printf("\n the energy of above samples is\n %d",sum);
return 0;
}

Power of Samples

#include<stdio.h>
int main(){
int num,i,j,x[32];
float num1;
long int sum=0;
printf("\nEnter the number of samples: ");
scanf("%d",&num);
printf("\nEnter samples: ");
for(j=0;j<num;j++)
scanf("%d",&x[j]);
for(i=0;i<=num;i++)
{
sum+=x[i]*x[i];
}
num=num*2;
num++;
num1 = sum / (float) num;
printf("\n the Average power of above samples is\n %.2f",num1);
return 0; 37
}
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

POWER SPECTRUM
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( )  E{x(n) x(n   )}


1 N
 lim  x(n) x(n   )
N  N
n 1

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

N 1
S ( )  FT ( R( ))  lim
N 


 N 1
Rˆ ( )e  j

1
R( )  FT 1 ( S ( ))   S ( )e d
j

2

ALGORITHM TO IMPLEMENT PSD:

 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.
38
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 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 --> Output of Auto Correlation.
* x1 --> use in graph window to view PSD
/*===========================================================*/
#include <math.h>
#define PTS 128 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS],x[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
float y[128];
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer
main()
{
float j,sum=0.0 ;
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;
}

39
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

/********************Auto Correlation of X(n)=R(t) ***********/


sum=sum+(x[k]*x[n+k]);
for(n=0;n<PTS;n++) // Auto Correlation R(t)
{
} sum=0;
for(k=0;k<PTS-n;k++)
iobuffer[n]
{ = sum;
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
/******************** FFT of R (t) ***********************/
{ for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i];
samples[i].real=iobuffer[i]; //buffer with //buffer
new datawith new data
}
} for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
for (i = 0 ; i < PTS ; i++)
FFT(samples,PTS); //call function FFT.c
/******************** PSD ********************/
samples[i].imag = 0.0; //imag components = 0
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
FFT(samples,PTS); //call function FFT.c
x1[i] = sqrt(samples[i].real*samples[i].real samples[i].imag*samples[i].imag);
}
/******************** PSD ********************/
}
for//end
(i = 0of; main
i < PTS ; i++) //compute magnitude

x1[i] = sqrt(samples[i].real*samples[i].real
/*FFT*/
#define PTS 128 //# of points for FFT
+ samples[i].imag*samples[i].imag);
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
}{//end of main
COMPLEX temp1,temp2; //temporary storage variables
int i,j,k; //loop counter variables
/*FFT*/
int upper_leg, lower_leg; //index of upper/lower butterfly leg
/*int leg_diff; //difference between upper/lower leg
int num_stages = 0;
#define PTS 128 //# of points for FFT of FFT stages (iterations)
//number
int index, step; //index/step through twiddle constant
i = 1;
typedef //log (base2)
struct {float of N points=
real,imag;} COMPLEX; # 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

40
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

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
int leg_diff; //difference between upper/lower - (Y[lower_leg]).real;
leg
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real
int num_stages = 0; //number = temp2.real*(w[index]).real
of FFT stages (iterations)
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
int index, step; //index/step
(Y[upper_leg]).real = through twiddle constant
temp1.real;
(Y[upper_leg]).imag = temp1.imag;}
i = 1; //log(base2) of N points= # of stages
index += step;
}do
leg_diff = leg_diff/2;
step
{ *= 2;}
j = 0;
for (i = 1;
num_stages i < (N-1); i++)
+=1;
//bit reversal for re sequencing data
{k = N/2;
i = i*2;
while (k <= j)
{}while (i!=N);
j = j - k;
kleg_diff
= k/2; = N/2; //difference between upper&lower legs
}
jstep
= =j (PTS*2)/N;
+ k; //step between values in twiddle.h// 512
if (i<j)
{for (i = 0;i < num_stages; i++) //for N-point FFT
temp1.real = (Y[j]).real;
temp1.imag
{ = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag
index = 0; = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
for (j = 0; j < leg_diff; j++)
}}
return;
{
}
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;


41
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Procedure:

1. Follow steps 1-7.


2. Run the program to see the results.
To view results goto view->watch.
In watch window type the variable name to which you want to view results.
3. Set the graph properties as shown in figure. To view the result use graph utility

Set the graph properties as shown in figure.

The graph has been plotted as shown below.

42
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

GENERAL PROCEDURE FOR WORKING WITH THE REAL TIME


PROJECTS USING C6748 LCDK:
AUDIO PLAYBACK
1.0 Unit Objective:

To configure the codec AIC3106 for a talk through program using the board support library.

2.0 Prerequisites

C6748LCDK, PC with Code Composer Studio, CRO, Audio Source, Speakers, headphone and Signal
Generator.

3.0 Procedure

• All the Real time implementations covered in the Implementations module follow code
Configuration using board support library.
• The board Support Library (CSL) is a collection of functions, macros, and symbols used to
configure and control on-chip peripherals.
• The goal is peripheral ease of use, shortened development time, portability, hardware abstraction,
and some level of standardization and compatibility among TI devices.
 Connect one end of a stereo cable to the LINE IN(J55) of the kit and other end to PC (or function
generator).
 Connect the headphone (or CRO) to the LINE OUT(J56) of the kit.
 Connect the power supply to the board.
 Connect the External JTAG XDS100v3 with board and PC.

General Steps For Real Time Programs:


R1. Create project.

 Goto File ->new->CCS project and enter the details as done in NR3 but only change in “is
Advanced Settings” choose the Linker command file: as “linker_dsp.cmd” (Browse from Supporting
files folder given at the time of installation)

43
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

R2. Create source file to write code.

In source file type (or copy) the following code.

// L138_loop_intr.c
//

#include "L138_LCDK_aic3106_init.h"

interrupt void interrupt4(void) // interrupt service routine


{
uint32_t sample;

sample = input_sample(); // read L + R samples from ADC


output_sample(sample); // write L + R samples to DAC
return;
}

int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}

Once the program is written, save it.

R3. Now add the following library files and supporting files of codec to your project.

 To add files goto Project-> Add files.

44
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 Follow the path given below to add the required files:

1. Supporting files\evmomapl138_bsl.lib

2. Supporting files \L138_LCDK_aic3106_init.h

3. Supporting files \L138_LCDK_aic3106_init.c

4. Supporting files \vectors_intr.asm

R4. Right click on the project name and choose “Show Build Settings..” -> Build-> C6000 Compiler->
Include Options -> Click “Add” as shown in the figure.

 Now Click File system -> supporting files->bsl->inc->OK.

45
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

R5. Build Project, Load and Resume the project.

After clicking the Resume option, play the music now. You can hear the song from the headphone
without any noise.

Alternatively you can also connect function generator to the LINE IN and CRO to the LINE OUT.
At this time you can observe same wave appearing on the CRO which is given in function generator.
Thus the CODEC is verified.

You can also try changing the sampling frequency, gain of the codec.

Note: if you want to play loop signal only in right channel then change the 6th line to
output_right_sample(sample);

If you want to play loop signal only in left channel then change the 6th line to

output_left_sample(sample);

46
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Creating ECO Effect

// L138_echo_intr.c
//

#include "L138_LCDK_aic3106_init.h"
#define GAIN 0.6
#define BUF_SIZE 16000

int16_t input,output,delayed;
int16_t buffer[BUF_SIZE];
int i = 0;

interrupt void interrupt4(void) // interrupt service routine


{
input = input_right_sample();
delayed = buffer[i];
output = delayed + input;
buffer[i] = input + delayed*GAIN;
i = (i+1)%BUF_SIZE;
output_right_sample(output);
return;
}

int main(void)
{
int i;

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


{
buffer[i] = 0;
}
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_MIC_INPUT);
while(1);
}

Procedure:
 After successful generation of .out file connect the Target to Host PC run program

 Connect the MIC to MIC INPUT (J57)

 Connect loud speaker to LINE OUT By giving input to MIC observe the output in loud speaker

47
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Creating DELAY

// L138_delay_intr.c
//

#include "L138_LCDK_aic3106_init.h"
#define BUF_SIZE 24000

uint16_t input,output,delayed;
uint16_t buffer[BUF_SIZE];
int i = 0;

interrupt void interrupt4(void) // interrupt service routine


{
input = input_left_sample();
delayed = buffer[i];
output = delayed + input;
buffer[i] = input;
i = (i+1)%BUF_SIZE;
output_right_sample(output);
return;
}

int main(void)
{
int i;

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


{
buffer[i] = 0;
}
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_MIC_INPUT);
while(1);
}

Procedure:
 Follow the same procedure as ECO program

48
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Advance Discrete Time Filter Design (FIR)

Finite Impulse Response Filter


DESIGNING AN FIR FILTER:

Following are the steps to design linear phase FIR filters Using Windowing Method.

I. Clearly specify the filter specifications.


Eg: Order = 30;
Sampling Rate = 8000 samples/sec
Cut off Freq. = 400 Hz.

II. Compute the cut-off frequency Wc


Eg: Wc = 2*pi* fc / Fs
= 2*pi* 400/8000
= 0.1*pi

III. Compute the desired Impulse Response h d (n) using particular Window
Eg: b_rect1=fir1(order, Wc , 'high',boxcar(31));

IV. Convolve input sequence with truncated Impulse Response x (n)*h (n)

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

49
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

If Wn is a multi-element vector,
Wn = [W1 W2 W3 W4 W5 ... WN],
FIR1 returns an order N multiband filter with bands
0 < W < W1, W1 < W < W2, ..., WN < W < 1.
B = FIR1(N,Wn,'DC-1') makes the first band a passband.
B = FIR1(N,Wn,'DC-0') makes the first band a stopband.

For filters with a passband near Fs/2, e.g., highpass


and bandstop filters, N must be even.

By default FIR1 uses a Hamming window. Other available windows,


including Boxcar, Hanning, Bartlett, Blackman, Kaiser and Chebwin
can be specified with an optional trailing argument. For example,
B = FIR1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4.
B = FIR1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window.

By default, the filter is scaled so the center of the first pass band
has magnitude exactly one after windowing. Use a trailing 'noscale'
argument to prevent this scaling, e.g. B = FIR1(N,Wn,'noscale'),
B = FIR1(N,Wn,'high','noscale'), B = FIR1(N,Wn,wind,'noscale').

50
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Matlab Program to generate ‘FIR Filter-Low Pass’ Coefficients using FIR1

% FIR Low pass filters using rectangular, triangular and kaiser windows
% sampling rate - 8000
order = 30;
cf--> contains set of cut-off frequencies[Wc ]

% cutoff frequency - 500


b_rect1=fir1(order,cf(1),boxcar(31)); Rectangular
b_tri1=fir1(order,cf(1),bartlett(31)); Triangular
b_kai1=fir1(order,cf(1),kaiser(31,8)); Kaisar [Where 8-->Beta Co-efficient]

% cutoff frequency - 1000


b_rect2=fir1(order,cf(2),boxcar(31));
b_tri2=fir1(order,cf(2),bartlett(31));
b_kai2=fir1(order,cf(2),kaiser(31,8));

% cutoff frequency - 1500


b_rect3=fir1(order,cf(3),boxcar(31));
b_tri3=fir1(order,cf(3),bartlett(31));
b_kai3=fir1(order,cf(3),kaiser(31,8));

fid=fopen('FIR_lowpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');

fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');

fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_lowpass_rectangular.txt');

51
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:

Cutoff -500Hz
float b_kai1[31]={-0.000019,-0.000170,-0.000609,-0.001451,-0.002593,-0.003511,-
0.003150,0.000000,0.007551,0.020655,0.039383,0.062306,0.086494,0.108031,0.122944,
0.128279,0.122944,0.108031,0.086494,0.062306,0.039383,0.020655,0.007551,0.000000,
-0.003150,-0.003511,-0.002593,-0.001451,-0.000609,-0.000170,-0.000019};

Cutoff -1000Hz
float b_kai2[31]={-0.000035,-0.000234,-0.000454,0.000000,0.001933,0.004838,0.005671,
-0.000000,-0.013596,-0.028462,-0.029370,0.000000,0.064504,0.148863,0.221349,0.249983,
0.221349,0.148863,0.064504,0.000000,-0.029370,-0.028462,-0.013596,-0.000000,0.005671,
IMPLEMENTATION OF AN FIR FILTER :
0.004838,0.001933,0.000000,-0.000454,-0.000234, -0.000035};
ALGORITHM TO IMPLEMENT :
Cutoff -1500Hz
float b_kai3[31]={-0.000046,-0.000166,0.000246,0.001414,0.001046,-0.003421,-0.007410,
0.000000,0.017764,0.020126,-0.015895,-0.060710,-0.034909,0.105263,0.289209,0.374978,
We need to realize an advance FIR filter by implementing its difference equation as per the specifications.
0.289209,0.105263,-0.034909,-0.060710,-0.015895,0.020126,0.017764,0.000000,-0.007410,
A-0.003421,0.001046,0.001414,0.000246,-0.000166,
direct form I implementation approach is taken.-0.000046};
(The filter coefficients are taken as ai as generated by
the Matlab program.)

T.2 :Matlab generated Coefficients for FIR Low Pass Rectangular filter

Cutoff -500Hz
float b_rect1[31]={-0.008982,-0.017782,-0.025020,-0.029339,-0.029569,-0.024895,
-0.014970,0.000000,0.019247,0.041491,0.065053,0.088016,0.108421,0.124473,0.134729,
0.138255,0.134729,0.124473,0.108421,0.088016,0.065053,0.041491,0.019247,0.000000,
-0.014970,-0.024895,-0.029569,-0.029339,-0.025020,-0.017782,-0.008982};

Cutoff -1000Hz
float b_rect2[31]={-0.015752,-0.023869,-0.018176,0.000000,0.021481,0.033416,0.026254,-0.000000,-
0.033755,-0.055693,-0.047257,0.000000,0.078762,0.167080,0.236286,0.262448,
0.236286,0.167080,0.078762,0.000000,-0.047257,-0.055693,-0.033755,-0.000000,0.026254,
0.033416,0.021481,0.000000,-0.018176,-0.023869,-0.015752};

Cutoff -1500Hz
float b_rect2[31]={-0.020203,-0.016567,0.009656,0.027335,0.011411,-0.023194,-0.033672,
0.000000,0.043293,0.038657,-0.025105,-0.082004,-0.041842,0.115971,0.303048,0.386435,
0.303048,0.115971,-0.041842,-0.082004,-0.025105,0.038657,0.043293,0.000000,-0.033672,
-0.023194,0.011411,0.027335,0.009656,-0.016567,-0.020203};

T.3 : Matlab generated Coefficients for FIR Low Pass Triangular filter

52
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Cutoff -500Hz
float b_tri1[31]={0.000000,-0.001185,-0.003336,-0.005868,-0.007885,-0.008298,-0.005988,
0.000000,0.010265,0.024895,0.043368,0.064545,0.086737,0.107877,0.125747,0.138255,
0.125747,0.107877,0.086737,0.064545,0.043368,0.024895,0.010265,0.000000,-0.005988,
-0.008298,-0.007885,-0.005868,-0.003336,-0.001185,0.000000};

Cutoff -1000Hz
float b_tri2[31]={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};

Cutoff -1500Hz
float b_tri3[31]={0.000000,-0.001104,0.001287,0.005467,0.003043,-0.007731,-0.013469,
0.000000,0.023089,0.023194,-0.016737,-0.060136,-0.033474,0.100508,0.282844,0.386435,
0.282844,0.100508,-0.033474,-0.060136,-0.016737,0.023194,0.023089,0.000000,-0.013469,
-0.007731,0.003043,0.005467,0.001287,-0.001104,0.000000};

53
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

MATLAB Program to generate ‘FIR Filter-High Pass’ Coefficients using FIR1


% FIR High pass filters using rectangular, triangular and kaiser windows
% sampling rate - 8000
order = 30;

cf=[400/4000,800/4000,1200/4000]; ;cf--> contains set of cut-off frequencies[Wc]

% cutoff frequency - 400


b_rect1=fir1(order,cf(1),'high',boxcar(31));
b_tri1=fir1(order,cf(1),'high',bartlett(31));
b_kai1=fir1(order,cf(1),'high',kaiser(31,8)); Where Kaiser(31,8)--> '8'defines the value of 'beta'.

% cutoff frequency - 800


b_rect2=fir1(order,cf(2),'high',boxcar(31));
b_tri2=fir1(order,cf(2),'high',bartlett(31));
b_kai2=fir1(order,cf(2),'high',kaiser(31,8));

% cutoff frequency - 1200


b_rect3=fir1(order,cf(3),'high',boxcar(31));
b_tri3=fir1(order,cf(3),'high',bartlett(31));
b_kai3=fir1(order,cf(3),'high',kaiser(31,8));

fid=fopen('FIR_highpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');

fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');

54
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

T.1 : MATLAB generated Coefficients for FIR High Pass Kaiserfilter:

Cutoff -400Hz
float b_kai1[31]={0.000050,0.000223,0.000520,0.000831,0.000845,-0.000000,-0.002478,
-0.007437,-0.015556,-0.027071,-0.041538,-0.057742,-0.073805,-0.087505,-0.096739,
0.899998,-0.096739,-0.087505,-0.073805,-0.057742,-0.041538,-0.027071,-0.015556,
-0.007437,-0.002478,-0.000000,0.000845,0.000831,0.000520,0.000223,0.000050};

Cutoff -800Hz
float b_kai2[31]={0.000000,-0.000138,-0.000611,-0.001345,-0.001607,-0.000000,0.004714,
0.012033,0.018287,0.016731,0.000000,-0.035687,-0.086763,-0.141588,-0.184011,0.800005,
-0.184011,-0.141588,-0.086763,-0.035687,0.000000,0.016731,0.018287,0.012033,0.004714,
IMPLEMENTATION OF AN FIR FILTER :
-0.000000,-0.001607,-0.001345,-0.000611,-0.000138,0.000000};
ALGORITHM TO IMPLEMENT :
Cutoff -1200Hz
float b_kai3[31]={-0.000050,-0.000138,0.000198,0.001345,0.002212,-0.000000,-0.006489,
-0.012033,-0.005942,0.016731,0.041539,0.035687,-0.028191,-0.141589,-0.253270,0.700008,
need to realize an advance FIR filter by implementing its difference equation as per the specifications. A
-0.253270,-0.141589,-0.028191,0.035687,0.041539,0.016731,-0.005942,-0.012033,-0.006489,
direct form I implementation approach is taken. (The filter coefficients are
-0.000000,0.002212,0.001345,0.000198,-0.000138,-0.000050};

T.2 :MATLAB generated Coefficients for FIR High Pass Rectangular filter

Cutoff -400Hz
float b_rect1[31]={0.021665,0.022076,0.020224,0.015918,0.009129,-0.000000,-0.011158,
-0.023877,-0.037558,-0.051511,-0.064994,-0.077266,-0.087636,-0.095507,-.100422,0.918834,
-0.100422,-0.095507,-0.087636,-0.077266,-0.064994,-0.051511,-0.037558,-0.023877,
-0.011158,-0.000000,0.009129,0.015918,0.020224,0.022076,0.021665};

Cutoff -800Hz
float b_rect2[31]={0.000000,-0.013457,-0.023448,-0.025402,-0.017127,-0.000000,0.020933,
0.038103,0.043547,0.031399,0.000000,-0.047098,-0.101609,-0.152414,-0.188394,0.805541,
-0.188394,-0.152414,-0.101609,-0.047098,0.000000,0.031399,0.043547,0.038103,0.020933,
-0.000000,-0.017127,-0.025402,-0.023448,-0.013457,0.000000};

Cutoff -1200Hz
float b_rect3[31]={-0.020798,-0.013098,0.007416,0.024725,0.022944,-0.000000,-0.028043,
-0.037087,-0.013772,0.030562,0.062393,0.045842,-0.032134,-0.148349,-0.252386,0.686050,
-0.252386,-0.148349,-0.032134,0.045842,0.062393,0.030562,-0.013772,-0.037087,-0.028043,
-0.000000,0.022944,0.024725,0.007416,-0.013098,-0.020798};

55
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

T.3 : MATLAB generated Coefficients for FIR High Pass Triangular


filter

Cutoff -400Hz
float b_tri1[31]={0.000000,0.001445,0.002648,0.003127,0.002391,-0.000000,-0.004383,
-0.010943,-0.019672,-0.030353,-0.042554,-0.055647,-0.068853,-0.081290,-0.092048,
0.902380,-0.092048,-0.081290,-0.068853,-0.055647,-0.042554,-0.030353,-0.019672,
-0.010943,-0.004383,-0.000000,0.002391,0.003127,0.002648,0.001445,0.000000};

Cutoff -800Hz
float b_tri2[31]={0.000000,-0.000897,-0.003126,-0.005080,-0.004567,-0.000000,0.008373,
0.017782,0.023225,0.018839,0.000000,-0.034539,-0.081287,-0.132092,-0.175834,0.805541,
-0.175834,-0.132092,-0.081287,-0.034539,0.000000,0.018839,0.023225,0.017782,0.008373,
-0.000000,-0.004567,-0.005080,-0.003126,-0.000897,0.000000};

Cutoff -1200Hz
float b_tri3[31]={0.000000,-0.000901,0.001021,0.005105,0.006317,-0.000000,-0.011581,
-0.017868,-0.007583,0.018931,0.042944,0.034707,-0.026541,-0.132736,-0.243196,0.708287,
-0.243196,-0.132736,-0.026541,0.034707,0.042944,0.018931,-0.007583,-0.017868,-0.011581,
-0.000000,0.006317,0.005105,0.001021,-0.000901,0.000000};

56
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

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[N-i]*val[i]

Shift the input value by one

No
Is the loop
Cnt = order

Poll the ready bit, when


asserted proceed. Yes

Output += coeff[0]*data

Put the ‘data’ in ‘val’ array.

Write the value ‘Output’ to


Analog output of the codec
57
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

C PROGRAM TO IMPLEMENT FIR FILTER:


#include "L138_LCDK_aic3106_init.h"
#define N 31 //number of coefficients

float h[N]={-0.01348909363, -0.01021953207,-0.005696943495,2.920240591e-18, 0.006732751615,


0.01430734433, 0.02248182334, 0.03097631037, 0.03948523849, 0.04769114777,
0.05527933314, 0.06195262074, 0.06744547188, 0.0715367198, 0.0740602687,
0.07491308451, 0.0740602687, 0.0715367198, 0.06744547188, 0.06195262074,
0.05527933314, 0.04769114777, 0.03948523849, 0.03097631037, 0.02248182334,
0.01430734433, 0.006732751615,2.920240591e-18,-0.005696943495, -0.01021953207,
-0.01348909363}; //LPF-2KHz-Rectangular designed for Sampling rate of 48Khz*/

float x[N]; // filter delay line

interrupt void interrupt4(void)


{
short i;
float yn = 0.0;

x[0] = (float)(input_right_sample()); // input from ADC


for (i=0 ; i<N ; i++) // compute filter output
yn += h[i]*x[i];
for (i=(N-1) ; i>0 ; i--) // shift delay line
x[i] = x[i-1];
output_right_sample((int16_t)(yn)); // output to DAC
return;
}

int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
} // end of main()

PROCEDURE:

 After successful generation of .out file connect target to host PC


 Connect signal generator to LINE INPUT with 1Vp-p Sine Wave frequency is set according to
filter co-efficient
 Connect CRO to LINE OUT with volt/div at 1 and time/div at 5msec

Note: Select FS_8000_HZ, to use filter coefficients from tables T.1, T.2, T.3

58
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

MATLAB GENERATED FREQUENCY RESPONSE


High Pass FIR filter(Fc= 800Hz).

Low Pass FIR filter

(Fc=1000Hz)

59
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

ADVANCE DISCRETE TIME FILTER DESIGN (IIR)


IIR filter Designing Experiments
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 it’s time domain characterization. In the design of a simple frequency–selective
filter, we would take help of some basic implementation methods for realizations of LTI systems
described by linear constant coefficient difference equation.

UNIT OBJECTIVE:
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.

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, which is if you
put in an impulse, then its output must produced for infinite duration of time.

PREREQUISITES:
 Concept of discrete time signal processing.
 Analog filter design concepts.
 TMS320C6748 Architecture and instruction set.

EQUIPMENTS NEEDED:
 Host (PC).
 TMS320C6748 DSP Kit.
 Oscilloscope and Function generator.

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
60
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

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 McASP, the DSP board and the on board codec.

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

FLOWCHART FOR IIR IMPLEMENTATION:


61
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

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]
output = x[0]b0+x[-1]b1+x[-2]b2 - y[-1]a1 - y[-2]a2
and Y[-1] = output .

x[-3] = x[-2], x[-2]=x[-1]

x[-1]=x[0]

Poll for ready bit Write ‘output’ to analog i/o.

Poll the ready bit, when


Stop
asserted proceed.

MATLAB PROGRAM TO GENRATE FILTER CO-EFFICIENTS

62
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

% IIR Low pass Butterworth and Chebyshev filters


% sampling rate – 24000Hz
order = 2;
cf=[2500/12000,8000/12000,1600/12000];

% cutoff frequency - 2500


[num_bw1,den_bw1]=butter(order,cf(1));
[num_cb1,den_cb1]=cheby1(order,3,cf(1));

% cutoff frequency - 8000


[num_bw2,den_bw2]=butter(order,cf(2));
[num_cb2,den_cb2]=cheby1(order,3,cf(2));

fid=fopen('IIR_LP_BW.txt','wt');
fprintf(fid,'\t\t-----------Pass band range: 0-2500Hz----------\n');
fprintf(fid,'\t\t-----------Magnitude response: Monotonic-----\n\n\');
fprintf(fid,'\n float num_bw1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_bw1);
fprintf(fid,'\nfloat den_bw1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_bw1);

fprintf(fid,'\n\n\n\t\t-----------Pass band range: 0-8000Hz----------\n');


fprintf(fid,'\t\t-----------Magnitude response: Monotonic-----\n\n');
fprintf(fid,'\nfloat num_bw2[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_bw2);
fprintf(fid,'\nfloat den_bw2[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_bw2);

fclose(fid);
winopen('IIR_LP_BW.txt');

fid=fopen('IIR_LP_CHEB Type1.txt','wt');
fprintf(fid,'\t\t-----------Pass band range: 2500Hz----------\n');
fprintf(fid,'\t\t-----------Magnitude response: Rippled (3dB) -----\n\n\');
fprintf(fid,'\nfloat num_cb1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_cb1);
fprintf(fid,'\nfloat den_cb1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_cb1);
fprintf(fid,'\n\n\n\t\t-----------Pass band range: 8000Hz----------\n');
fprintf(fid,'\t\t-----------Magnitude response: Rippled (3dB)-----\n\n');
fprintf(fid,'\nfloat num_cb2[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_cb2);
63
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

fprintf(fid,'\nfloat den_cb2[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_cb2);
fclose(fid);
winopen('IIR_LP_CHEB Type1.txt');

%%%%%%%%%%%%%%%%%%
figure(1);
[h,w]=freqz(num_bw1,den_bw1);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb1,den_cb1);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response of Low pass IIR filters (Fc=2500Hz)');

figure(2);
[h,w]=freqz(num_bw2,den_bw2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb2,den_cb2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1 (Ripple: 3dB)');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response in the passband');
axis([0 12000 -20 20]);

IIR_CHEB_LP FILTER CO-EFFICIENTS:

64
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Co- Fc=2500Hz Fc=800Hz Fc=8000Hz


Effic
ients Floating Point Fixed Point Floating Point Fixed Point Floating Point Fixed Point
Values Values Values(Q15)
Values(Q15) Values Values(Q15)

B0 0.044408 1455 0.005147 168 0.354544 11617

B1 0.088815 1455[B1/2] 0.010295 168[B1/2] 0.709088 11617[B1/2]

B2 0.044408 1455 0.005147 168 0.354544 11617

A0 1.000000 32767 1.000000 32767 1.000000 32767

A1 -1.412427 -23140[A1/2] -1.844881 - 0.530009 8683[A1/2]


30225[A1/2]

A2 0.663336 21735 0.873965 28637 0.473218 15506

Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
IIR_BUTTERWORTH_LP FILTER CO-EFFICIENTS:

Co- Fc=2500Hz Fc=800Hz Fc=8000Hz


Effic
ients Floating Point Fixed Point Floating Point Fixed Point Floating Point Fixed Point
Values Values
Values(Q15) Values(Q15) Values Values(Q15)

B0 0.072231 2366 0.009526 312 0.465153 15241

B1 0.144462 2366[B1/2] 0.019052 312[B1/2] 0.930306 15241[B1/2]

B2 0.072231 2366 0.009526 312 0.465153 15241

A0 1.000000 32767 1.000000 32767 1.000000 32767

A1 -1.109229 -18179[A1/2] -1.705552, - 0.620204 10161[A1/2]


27943[A1/2]

A2 0.398152 13046 0.743655 24367 0.240408 7877

Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
IIR_CHEB_HP FILTER CO-EFFICIENTS:

65
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Co- Fc=2500Hz Fc=4000Hz Fc=7000Hz


Effic
ients Floating Point Fixed Point Floating Point Fixed Point Floating Point Fixed Point
Values Values
Values(Q15) Values(Q15 Values Values(Q15)
)

B0 0.388513 12730 0.282850 9268 0.117279 3842

B1 -0.777027 -12730[B1/2] -0.565700 -9268[B1/2] -0.234557 -3842[B1/2]

B2 0.388513 12730 0.282850 9268 0.117279 3842

A0 1.000000 32767 1.000000 32767 1.000000 32767

A1 -1.118450 -18324[A1/2] -0.451410 -7395[A1/2] 0.754476 12360[A1/2]

A2 0.645091 21137 0.560534 18367 0.588691 19289

Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
IIR_BUTTERWORTH_HP FILTER CO-EFFICIENTS:

Co- Fc=2500Hz Fc=4000Hz Fc=7000Hz


Effic
ients Floating Point Fixed Point Floating Point Fixed Point Floating Point Fixed Point
Values Values
Values(Q15) Values(Q15 Values Values(Q15)
)

B0 0.626845 20539 0.465153 15241 0.220195 7215

B1 -1.253691 -20539[B1/2] -0.930306 - -0.440389 -7215[B1/2]


15241[B1/2]

B2 0.626845 20539 0.465153 15241 0.220195 7215

A0 1.000000 32767 1.000000 32767 1.000000 32767

A1 -1.109229 -18173[A1/2] -0.620204 - 0.307566 5039[A1/2}


10161[A1/2]

A2 0.398152 13046 0.240408 7877 0.188345 6171

Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.

66
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

‘C’ PROGRAM TO IMPLEMENT IIR FILTER


/* IIR.c
* Created on: 15-Nov-2022
* Author: sultan.m */

#include "L138_LCDK_aic3106_init.h"

const signed int h[] =


{
//12730,-12730,12730,32767,-18324,21137 /*HP 2500 */
312,312,312,32767,-27943,24367 /*LP 800 */
//1455,1455,1455,32767,-23140,21735 /*LP 2500 */
//9268,-9268,9268,32767,-7395,18367 /*HP 4000*/
//7215,-7215,7215,32767,5039,6171, /*HP 7000*/
};

interrupt void interrupt4(void)


{
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 */
long temp=0;

temp = input_right_sample(); // input from ADC; /* Copy input to temp */

x[0] = (signed int) temp; /* Copy input to x[stages][0] */

temp = ( (long)h[0] * x[0]) ; /* B0 * x(n) */


temp += ( (long)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (long)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (long)h[2] * x[2]); /* B2 * x(n-2) */
temp -= ( (long)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (long)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (long)h[5] * y[2]); /* A2 * y(n-2) */
/* Divide temp by coefficients[A0] */
temp >>= 15;
if ( temp > 32767 )
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}
y[0] = (short int) ( 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 */


output_right_sample((short)(temp)); // output to DAC
return;

int main(void)
{
L138_initialise_intr(FS_24000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
67
while(1);

} // end of main()
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

PROCEDURE:

 After successful generation of .out file connect target to host PC

 Connect signal generator to LINE INPUT with 1Vp-p Sine Wave frequency is set according to
filter co-efficient

 Connect CRO to LINE OUT with volt/div at 1 and time/div at 5msec

68
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Adaptive Filters
An adaptive filter is a system with a linear filter that has a transfer function controlled by variable parameters and a
means to adjust those parameters according to an optimization algorithm. Because of the complexity of the
optimization algorithms, almost all adaptive filters are digital filters. Adaptive filters are required for some
applications because some parameters of the desired processing operation (for instance, the locations of reflective
surfaces in a reverberant space) are not known in advance or are changing. The closed loop adaptive filter uses
feedback in the form of an error signal to refine its transfer function.

Generally speaking, the closed loop adaptive process involves the use of a cost function, which is a criterion for
optimum performance of the filter, to feed an algorithm, which determines how to modify filter transfer function to
minimize the cost on the next iteration. The most common cost function is the mean square of the error signal.

As the power of digital signal processors has increased, adaptive filters have become much more common and are
now routinely used in devices such as mobile phones and other communication devices, camcorders and digital
cameras, and medical monitoring equipment.

This example cancel an undesired noise signal using a desired signal(input to right channel a sine wave of 500Hz)
and a reference noise signal generated using a Math Library function[sin(2500)Hz].

Figure shows the program in block diagram form. Within the program, a primary noise signal correlated with the
reference noise signal input on the right channel is formed by passing the reference noise through an FIR filter. The
primary noise signal is added to the desired signal input on the right channel.

As adaptation takes place, the output on the right channel of LINE OUT should gradually change from noisy signal
to desired signal only. You may need to adjust the volume at which you play the file speechnoise.wav. If the input
signals are too quiet, then the adaptation may be very slow.

69
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

/* Adaptive FIR filter for noise cancellation


* Created on: 13-Aug-2023
* Author: sultan.m */

#include "L138_LCDK_aic3106_init.h"
#include<math.h>

#define beta 1E-15 //rate of convergence


#define N 30 //# of weights (coefficients)
#define REF_NOISE_FREQ 2500 // Reference Noise sin(2500)
float w[N]; //buffer weights of adapt filter
float delay[N]; //input buffer to adapt filter
short output; //overall output

void main()
{
int j,T;
for (T = 0; T < 30; T++)
{
w[T] = 0; //init buffer for weights
delay[T] = 0; //init buffer for delay samples
}

L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}

interrupt void interrupt4(void) //ISR


{
short i,j;
static short buffercount=0; //init count of # out samples
float dplusn[128]=0, desired=0, yn, E=0; //output
filter/"error" signal
float refnoise[128]; // stores noise samples

for(buffercount=0;buffercount<128;buffercount++)
{
refnoise[buffercount]=30000*sin(2*3.14*REF_NOISE_FREQ*buffercount/8000);
desired = (float)input_right_sample(); // desired Signal sin(500)
dplusn[buffercount] = desired+refnoise[buffercount]; //desired+noise
delay[0] = refnoise[buffercount]; //sin(500Hz) input to adapt FIR

yn = 0; //init output of adapt filter


for (i = 0; i < N; i++) //to calculate out of adapt FIR
yn += (w[i] * delay[i]); //output of adaptive filter

E = dplusn[buffercount] - yn; //"error" signal=(d+n)-yn

for (i = N-1; i >= 0; i--) //to update weights and delays


{
w[i] = w[i] + beta*E*delay[i]; //update weights
delay[i] = delay[i-1]; //update delay samples
}
output = ((short)E); //"error" signal overall output

output_right_sample(output); //overall output result


}
return; //return from ISR
Procedure
}

70
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 Connect Desired signal to LINE INPUT and connect LINE OUT TO CRO

 Connect target to host PC run the program observe the output on CRO

Noisy Output for few seconds

Output Signal adapted to Desired Signal

71
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

DTMF
Dual-tone multi-frequency (DTMF) is an international signaling standard for telephone digits. These signals are
used in touch-tone telephone call signaling as well as many other areas such as interactive control applications,
telephone banking, and pager systems.

A DTMF signal consists of two superimposed sinusoidal waveforms whose frequencies are chosen from a set of
eight standardized frequencies. These frequencies were chosen in Bell Laboratories, where DTMF signaling system
was originally proposed as an alternative to pulse dialing system in telephony.

72
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

// L138_sineDTMF_intr.c
//
#include "L138_LCDK_aic3106_init.h"
#include <math.h>
#define PI 3.14159265358979
#define TABLESIZE 512 // size of look up table
#define SAMPLING_FREQ 16000
#define STEP_770 (float)(770 * TABLESIZE)/SAMPLING_FREQ
#define STEP_1336 (float)(1336 * TABLESIZE)/SAMPLING_FREQ
#define STEP_697 (float)(697 * TABLESIZE)/SAMPLING_FREQ
#define STEP_852 (float)(852 * TABLESIZE)/SAMPLING_FREQ
#define STEP_941 (float)(941 * TABLESIZE)/SAMPLING_FREQ
#define STEP_1209 (float)(1209 * TABLESIZE)/SAMPLING_FREQ
#define STEP_1477 (float)(1477 * TABLESIZE)/SAMPLING_FREQ
#define STEP_1633 (float)(1633 * TABLESIZE)/SAMPLING_FREQ
int16_t sine_table[TABLESIZE];
float loopindexlow = 0.0;
float loopindexhigh = 0.0;
int16_t i;
interrupt void interrupt4(void) // interrupt service routine
{
output_left_sample(sine_table[(int16_t)loopindexlow] +
sine_table[(int16_t)loopindexhigh]);
loopindexlow += STEP_770;
if (loopindexlow > (float)TABLESIZE)
loopindexlow -= (float)TABLESIZE;
loopindexhigh += STEP_1477;
if (loopindexhigh > (float)TABLESIZE)
loopindexhigh -= (float)TABLESIZE;
return;
}
int main(void)
{

L138_initialise_intr(FS_16000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_MIC_INPUT)
;
for (i=0 ; i< TABLESIZE ; i++)
sine_table[i] = (short)(10000.0*sin(2*PI*i/TABLESIZE));
while(1);
}

Procedure:
 After successful generation of .out file connect the kit

 Connect mobile phone to LINE INPUT using 3.5mm stereo Jack

 Connect CRO to LINE OUT

 Press any key in phone and observe corresponding frequency in CRO


73
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Generation of real time Signals (Sine, Square & ramp)


Sine wave

// L138_sine_intr.c
//

#include "L138_LCDK_aic3106_init.h"
#include "math.h"

#define SAMPLING_FREQ 8000


#define PI 3.14159265358979

float frequency = 1000.0;


float amplitude = 30000.0;
float theta_increment;
float theta = 0.0;

interrupt void interrupt4(void) // interrupt service routine


{
theta_increment = 2*PI*frequency/SAMPLING_FREQ;
theta += theta_increment;
if (theta > 2*PI) theta -= 2*PI;
output_right_sample((int16_t)(amplitude*sin(theta)));
return;
}

int main(void)
{

L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}

74
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Square wave Generation

// L138_squarewave_intr.c
//

#include "L138_LCDK_aic3106_init.h"
#define LOOPLENGTH 64

int16_t square_table[LOOPLENGTH] =
{10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000,
10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000,
10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000,
10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000,
-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,
-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,
-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,
-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000};

int16_t loopindex = 0;

interrupt void interrupt4(void) // interrupt service routine


{
output_right_sample(square_table[loopindex++]);
if (loopindex >= LOOPLENGTH)
loopindex = 0;
return;
}

int main(void)
{

L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}

75
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Ramp Wave Generation

// L138_ramp_intr.c
//

#include "L138_LCDK_aic3106_init.h"
#define LOOPLENGTH 64

int16_t output = 0;

interrupt void interrupt4(void) // interrupt service routine


{
output_right_sample(output); // output to L DAC
output += 2000; // increment output value
if (output >= 30000) // if peak is reached
output = -30000; // reinitialize
return;
}

int main(void)
{

L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}

Procedure
 After successful generation of .out file connect kit to host PC and run program

 Connect Line out to CRO to observe Waves

 To vary frequency and amplitude in sine wave change the value of Frequency and amplitude

 To vary amplitude of Square wave change the value of lookup table and to vary frequency change
sampling frequency

 To vary amplitude of Ramp wave change the value of peak amplitude and to vary frequency
change the value of sampling frequency

76
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Generation of AM signal
// L138_am_poll.c
//

#include "L138_LCDK_aic3106_init.h"

short amp = 20; //index for modulation

int main(void)
{
int16_t baseband[20]={1000,951,809,587,309,0,-309,
-587,-809,-951,-1000,-951,-809,
-587,-309,0,309,587,809,951}; // base band signal
int16_t carrier[20] ={1000,0,-1000,0,1000,0,-1000,
0,1000,0,-1000,0,1000,0,-1000,
0,1000,0,-1000,0}; // 2 kHz
int16_t output[20];
int16_t k;

L138_initialise_poll(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);

while(1)
{
for (k=0; k<20; k++)
{
output[k]= carrier[k] + ((amp*baseband[k]*carrier[k]/10)>>12);
output_right_sample(20*output[k]);
}
}
}

Procedure:
 Here ISR is executing through Polling method so add vectors_poll.asm instead of vectors_intr.asm

 After successful generation of .out file connect target to Host PC and run program

 Connect LINE OUT to CRO to observe AM wave

 Carrier frequency: Carrier holds 20 samples of 5 cycles of a sinusoidal carrier signal with a
frequency of 5 Fs/20 = 2 KHz

77
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

IMAGE PROCESSING WITH LIBRARY FUNCTIONS:


Create a project:

1. Goto File ->new->CCS project and enter the details as below.In “Advanced Settings” choose the Linker
command file: as “linker_dsp.cmd” (Browse from ‘supporting files’ folder given at the time of installation)

Adding the files:

2. Right click on project name-> Add files from source file folder and add below files
 ‘IMAGEMAIN.c’
 ‘IMG_conv_3x3_i8_c8s_c.c’
 ‘IMG_sobel_3x3_8_c.c’and
 ‘wolf.c’

3. Build and debug the project.

4. Before running, create breakpoints after each line starting from 78th line.

5. Every time you change the breakpoint, restart the program and Resume it.

6. Also refresh the image to see the change.


78
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

7. Plot image by Tools-> Image Analyzer and follow the below details:

Plot for input image:

Plot for output image:

79
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Generating FIR coefficient Using MatLab


 Start MATLAB
 Enter "fdatool" in command window of MATLAB
 Select Type of Response and Design Method
 Specify the order (user Define)
 Keep Sampling frequency Fs as 48000 (same as mentioned in C Code for FIR), Keep Cut-off Frequency
(User Define) twice less than sampling Frequency

 C
l
i
c
k

o
n

D
e
s
i
g
n

F
i
l
t
e
r
,

t
o

s
e
e

Designed Filter response.

80
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 Now it’s time to get filter coefficients. For that click on Targets‐ > Generate C Header

 Once Done Click on Generate to generate Co-efficient for Filter it will be saved in .h format use notepad or
WordPad to open and past co-efficient in C Code

81
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Generating IIR coefficient Using MatLab


 Start MATLAB
 Select Workspace where you need to store Co-efficient

 H
e
r
e
w
e
h
a
ve Selected iir folder from desktop
 Enter "fdatool" in command window of MATLAB
 Design Filter with respect to your requirement

 Click on Design Filter to see the filter output


 C
li
c
k
o
n
fil
e
a
n
d
se
le
ct Export

82
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 E
x
p
o
r
t

S
O
S

a
nd Gain

 Come back to Matlab Command prompt select New Script type the Script for IIR filter (Provided in IIR
folder) save it in same workspace with L138_iirsos_coeffs.m, run the script to check error

83
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

 Once done type L138_iirsos_coeffs(SOS,G)


 It will ask the name for coefficients once you type name and enter it will generate coefficient in same
workspace you can copy value of generated coefficient to “elliptic.cof” and add it in project.

84
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

General Procedure for working with Assembly Projects Using


C6748LCDK:
Creating a New Project:
Project -> New CCS Project.

Selecting Project template


Select empty project in project template as we add assembly source code externally,
And click Finish

Create a New Source File(Assembly .asm file)

Give a name to source file with an .asm extension and click finish

85
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M

Save, build and debug it


Once it is debugged it will enter into debug perspective there will be a Registers, to view the value of select Core
registers as shown below

Set a Break Point at line4 as shown below and Perform single Step Debugging to execute
program line by line

86

You might also like