DSP LCDK USER_MANUAL_V3
DSP LCDK USER_MANUAL_V3
1
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
CONTENTS
2
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
TMS320C6748 LCDK
Kit Contents:
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
4
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
Memory
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)
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
NR2. Choose the location for the workspace, where your project will be saved.
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
9
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
NR5. BUILD
Build the program to check your code.
Go to
If your code doesn’t have any errors and warnings, a message will be printed in the console window that
“**** Build Finished ****”
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.
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
#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.
12
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
Picture
Start Address: m
Click: Ok
13
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
#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:
Where: n=4, k=4. ; If n & k are not equal pad with zero’s
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
Buffer size: 10
Start Address: y
Click: Ok
18
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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:
19
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
#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.
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
Twiddle Factor
Note that
22
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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.
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
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
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
#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:
27
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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
#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
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
}
{
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
#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.)
N 1
S ( ) FT ( R( )) lim
N
N 1
Rˆ ( )e j
1
R( ) FT 1 ( S ( )) S ( )e d
j
2
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
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
lower_leg = upper_leg+leg_diff;
Procedure:
42
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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.
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
// L138_loop_intr.c
//
#include "L138_LCDK_aic3106_init.h"
int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}
R3. Now add the following library files and supporting files of codec to your project.
44
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
1. Supporting files\evmomapl138_bsl.lib
R4. Right click on the project name and choose “Show Build Settings..” -> Build-> C6000 Compiler->
Include Options -> Click “Add” as shown in the figure.
45
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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
// 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;
int main(void)
{
int i;
Procedure:
After successful generation of .out file connect the Target to Host PC run program
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;
int main(void)
{
int i;
Procedure:
Follow the same procedure as ECO program
48
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
Following are the steps to design linear phase FIR filters Using Windowing Method.
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)
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.
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.
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
% FIR Low pass filters using rectangular, triangular and kaiser windows
% sampling rate - 8000
order = 30;
cf--> contains set of cut-off frequencies[Wc ]
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
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
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
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
Start
Initialize Counter = 0
Initialize Output = 0 , i = 0
Output += coeff[N-i]*val[i]
No
Is the loop
Cnt = order
Output += coeff[0]*data
int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
} // end of main()
PROCEDURE:
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
(Fc=1000Hz)
59
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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.
Start
x[-1]=x[0]
62
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
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);
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]);
64
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
IIR_BUTTERWORTH_LP FILTER CO-EFFICIENTS:
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
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
IIR_BUTTERWORTH_HP FILTER CO-EFFICIENTS:
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
66
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
#include "L138_LCDK_aic3106_init.h"
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:
Connect signal generator to LINE INPUT with 1Vp-p Sine Wave frequency is set according to
filter co-efficient
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
#include "L138_LCDK_aic3106_init.h"
#include<math.h>
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);
}
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
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
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
// L138_sine_intr.c
//
#include "L138_LCDK_aic3106_init.h"
#include "math.h"
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
// 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;
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
// L138_ramp_intr.c
//
#include "L138_LCDK_aic3106_init.h"
#define LOOPLENGTH 64
int16_t output = 0;
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
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"
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
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
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)
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’
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.
7. Plot image by Tools-> Image Analyzer and follow the below details:
79
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
C
l
i
c
k
o
n
D
e
s
i
g
n
F
i
l
t
e
r
,
t
o
s
e
e
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
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
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
84
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
Give a name to source file with an .asm extension and click finish
85
STARCOM INFORMATION TECH LTD DSP|EMBEDDED|T&M
Set a Break Point at line4 as shown below and Perform single Step Debugging to execute
program line by line
86