• No results found

185848895-Dsp-Lab-Manual.doc

N/A
N/A
Protected

Academic year: 2021

Share "185848895-Dsp-Lab-Manual.doc"

Copied!
49
0
0

Loading.... (view fulltext now)

Full text

(1)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

Course : B.Tech. (ECE)

Year/Semester:III/VI

Session: 2008-09

Digital Signal Processing Lab (TEC-652)

L T P

0 0 2

S. No.

NAME OF THE EXPERIMENT

1.

Sampling & Waveform Generation.

2.

Quantization

3.

PCM Encoding

4.

Delta Modulation

5.

Digital Modulation Schemes (ASK, PSK, FSK)

6.

Error Correcting Codes

7.

DFT Computation.

8.

Fast Fourier Transform.

9.

FIR Filter implementation.

10.

IIR Filter implementation.

11.

DSP Processor Implementation

(2)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

List of Equipment for

Digital Signal Processing Lab (TEC-652)

S.No.

Equipment

Qty(N

os.)

Functional Status

Working Non-Working

1

TMS320C6713 DSK

development board

10

10

NIL

2

External 5VDC power supply

10

10

NIL

3

IEEE 1284 compliant

male-to-female cable

10

10

NIL

4

233MHz or Higher

Pentium-Compatible CPU

15

15

NIL

5

Monitor

15

15

NIL

6

Frequency Generator

2

2

NIL

7

CRO

2

2

NIL

(3)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

List of Consumables for

Digital Signal Processing Lab (TEC-652)

(4)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Course : B.Tech. (ECE)

Year/Semester:III/VI

Section:C1/C2

List of Students of EC VI Semester for the Session 2008-09

S.No. Roll No. Name Group C1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

(5)

36 37 38 39 Group C2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

(6)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-1

Object: Sampling and Waveform Generation.

Equipment Used: 6713 DSK Board, IEEE 1284 compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory/Formula Used: In signal processing, sampling is the reduction of a continuous signal to

a discrete signal. A common example is the conversion of a sound wave (a continuous-time signal) to a sequence of samples (a discrete-time signal).

Let x(t) be a continuous signal which is to be sampled, and that sampling is performed by measuring the value of the continuous signal every T seconds. Thus, the sampled signal x[n] given by

x[n] = x(nT), with n = 0, 1, 2, 3, ...

The sampling frequency or sampling rate fs is defined as the number of samples obtained in one

second, or fs = 1/T. The sampling rate is measured in hertz or in samples per second.

Code:

For waveform generation:

#include<stdio.h> #include<math.h> #include<stdlib.h> float x[700]; void main() { float A,F,Fs; int i,choice,k,n;

printf(" Generation of discrete time signals \n"); printf("\nEnter the frequency of analog signal F = "); scanf("%f",&F); //frequency of the signal printf("Enter the sampling frequency Fs = ");

scanf("%f",&Fs); //sampling frequency printf("\nEnter your choice");

printf("\ncosine wave (Enter 1)"); //cosine wave printf("\nsine wave (Enter 2)"); //sine wave printf("\nsquare wave (Enter 3)"); //square wave

(7)

printf("\nexponential signal (Enter 4)"); //exponential signal scanf("%d",&choice);

i = 640; //640 samples of the signal will be generated A = 1.0; //maximum amplitude of the signals is 1 switch(choice)

{

case 1 : for(n = 0; n < i; n++) // cosine wave

x[n] = A * cos( 2 * 3.1415927 * F * (n/Fs)); break;

case 2 : for(n = 0; n < i; n++) // sine wave

x[n] = A * sin( 2 * 3.1415927 * F * (n/Fs)); break;

case 3 : k = 0; // square wave do

{

for( n = (k*Fs)/(2*F); n < ((k+1)*Fs)/(2*F); n++) { // positive half cycle of aquare wave

x[n] = A; if(n>i)break; }

for(n = ((k+1)*Fs)/(2*F); n < ((k+2)*Fs)/(2*F); n++) { // negative half cycle of aquare wave

x[n] = -A; if(n>i) break; }

k = k+2; // this count is modified for next cycle } while(n<i);

break;

case 4 : for(n = 0; n < i; n++) // exponential signal x[n] = A * exp( -(n/Fs)); break; } } For Sampling: #include "samplecfg.h" #include "C:\CCStudio_v3.1\C6000\dsk6713\include\dsk6713.h" #include "C:\CCStudio_v3.1\C6000\dsk6713\include\dsk6713_aic23.h" #define N 33 short antialiasing_filter(short*,short*); short reconstruction_filter(short*,short*); int flag=0,antialiasing=0,recon=0;

(8)

short h[33]={-31,43,69,-58,-178,42,379,81,-670,-426,1006, 1172,-1326,-2857,1554,10206,14739,10206,1554,-2857, -1326,1172,1006,-426,-670,81,379,42,-178,-58,69,43,-31}; short inp_buffer[N],out_buffer[N],ant_out[N],out_sample; short left_output,right_output,l_input,r_input,i,flag0=0,flg=0; DSK6713_AIC23_Config config = { \

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \ 0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\ 0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \ 0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \ 0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \ 0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \ 0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \ 0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \ 0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \ 0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \ };

void main() {

DSK6713_AIC23_CodecHandle hCodec;

Uint32 l_input, r_input,l_output, r_output;

/* Initialize the board support library, must be called first */ DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);

while(1)

{ /* Read a sample to the left channel */

while (!DSK6713_AIC23_read(hCodec, &l_input)); /* Read a sample to the right channel */

while (!DSK6713_AIC23_read(hCodec, &r_input)); /*******processing********/

(9)

out_sample=0; if(flg==0) flg=1; else { if(antialiasing==1) out_sample=antialiasing_filter(inp_buffer,h); else out_sample=r_input; flg=0; } for(i=N-1;i>0;i--) inp_buffer[i]=inp_buffer[i-1]; out_buffer[0]=out_sample; if(recon==1) out_sample=reconstruction_filter(out_buffer,h); for(i=N-1;i>0;i--) out_buffer[i]=out_buffer[i-1]; l_output=out_sample; r_output=out_sample;

/* Send a sample to the left channel */

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

while (!DSK6713_AIC23_write(hCodec, r_output)); }

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec); }

short antialiasing_filter(short *x,short *h) {

short j,val; long int sum=0; for(j=0;j<N;j++)

sum += (long int)x[j]*(long int)h[j]; sum=sum>>15;

val=(short)sum; return(val); }

(10)

short reconstruction_filter(short *x,short *h) {

short j,val; long int sum=0; for(j=0;j<N;j++)

sum += (long int)x[j]*(long int)h[j]; sum=sum>>15;

val=(short)sum; return(val); }

Method of Experiment:

For waveform generation:

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

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

 Create the source file i.e. program for waveform generation in C language.  Add the source files to the project using ‘Project—add files to project’ pull

down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(xyz.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

Select view ― graph ― time and frequency.

For sampling of waveform:

 Connect CRO to the Socket Provided for LINE OUT.  Connect a Signal Generator to the LINE IN Socket.

 Switch on the Signal Generator with a sine wave of frequency 500 Hz. and Vp-p=1.5v.

 Now Switch on the DSK and Bring Up Code Composer Studio on the PC.  Create a new project with name sample.pjt.

 From the File Menu → new → DSP/BIOS Configuration →select “dsk6713.cdb” and save it as “sample.cdb”

Add “sample.cdb” to the current project.

Add the given “codec.c” file to the current project which has the main function and calls all the other necessary routines.

(11)

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

Copy files “dsk6713.h” and “dsk6713_aic23.h” from

C:\CCStudio\C6000\dsk6713\include and paste it in current project.  Build, Load and Run the program.

 You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec configuration.

 You can also pass an audio input and hear the output signal through the speakers.

 You can also vary the sampling frequency using the DSK6713_AIC23_setFreq Function in the “codec.c” file and repeat the above steps.

Result:The output waveform can be seen on the monitor and sampling can be viewed on CRO

after performing the experiment.

Precautions:

1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: Students have now understood the basic concept of sampling and

(12)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-2

Object: Quantization

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory/Formula Used: With the adjective "digital" we indicate those systems that work on

signals that are represented by numbers, with the (finite) precision that computing systems allow. Up to now we have considered discrete-time and discrete-space signals as if they were collections of infinite-precision numbers, or real numbers. Unfortunately, computers only allow to represent finite subsets of rational numbers. This means that our signals are subject to quantization.

For our purposes, the most interesting quantization is the linear one, which is usually occurring in the process of conversion of an analog signal into the digital domain. If the memory word dedicated to storing a number is made of b bits, then the range of such number is discretized into 2b quantization levels. Any value that is found between two quantization levels can be

approximated by truncation or rounding to the closest value. The Figure 1 shows an example of quantization with representation on 3 bits in two's complement.

Figure 1: Sampling and quantization of an analog signal

The approximation introduced by quantization manifests itself as a noise, called quantization

(13)

de-correlated with the signal, but in reality it is perceptually tied to the signal itself, in such an extent that quantization can be perceived as an effect.

Code:

#include "quancfg.h"

#include "E:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713.h" #include "E:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713_aic23.h" //extern signed int FILTER(signed int );

DSK6713_AIC23_Config config = { \

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \ 0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\ 0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \ 0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \ 0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \ 0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \ 0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \ 0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \ 0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \ 0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \ };

/*

* main() - Main code routine, initializes BSL and generates tone */

Uint32 l_input, r_input,l_output, r_output; void main() { DSK6713_AIC23_CodecHandle hCodec;

/* Initialize the board support library, must be called first */ DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);

while(1)

(14)

while (!DSK6713_AIC23_read(hCodec, &l_input)); /* Read a sample to the right channel */

while (!DSK6713_AIC23_read(hCodec, &r_input)); l_output= quan(l_input);

r_output= l_output;

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

while (!DSK6713_AIC23_write(hCodec, r_output)); }

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec); }

int quan(Uint32 sin_out) { float sin_pos[100],sin_neg[100],pos_out[100],neg_out[100]; float quant_out[100]; int i; for(i=0;i<100;i++) { sin_pos[i] = sin_out ; sin_neg[i] = sin_out ; if (sin_pos[i] < 1) { pos_out[i] = 0; } else if (sin_pos[i] < 3) { pos_out[i] = 2; } else if (sin_pos[i] < 5) { pos_out[i] = 4; } else if (sin_pos[i] < 7) { pos_out[i] =6; }

(15)

else if (sin_pos[i] < 9) { pos_out[i] = 8; } else if (sin_pos[i] < 10) { pos_out[i] = 10; } else { pos_out[i] = 0; } if ( sin_neg[i] > -1) { neg_out[i] = -1 ; } else if ( sin_neg[i] > -3) { neg_out[i] = -2; } else if ( sin_neg[i] > -5) { neg_out[i] = -4; } else if ( sin_neg[i] > -7) { neg_out[i] =-6; } else if ( sin_neg[i] > -9) { neg_out[i] = -8; } else if ( sin_neg[i] > -10) { neg_out[i] = -10; } else { neg_out[i] = 0; }

quant_out[i] = pos_out[i] + neg_out[i]; }

(16)

Method of Experiment:

 Connect CRO to the Socket Provided for LINE OUT.  Connect a Signal Generator to the LINE IN Socket.

 Switch on the Signal Generator with a sine wave of frequency 500 Hz. and Vp-p=1.5v.

 Now Switch on the DSK and Bring Up Code Composer Studio on the PC.  Create a new project with name quant.pjt.

 From the File Menu → new → DSP/BIOS Configuration →select “dsk6713.cdb” and save it as “quant.cdb”

Add “quant.cdb” to the current project.

Add the given “codec.c” file to the current project which has the main function and calls all the other necessary routines.

Add the library file “dsk6713bsl.lib” to the current project

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

Copy files “dsk6713.h” and “dsk6713_aic23.h” from

C:\CCStudio\C6000\dsk6713\include and paste it in current project.  Build, Load and Run the program.

 You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec configuration.

 You can also pass an audio input and hear the output signal through the speakers.

 You can also vary the sampling frequency using the DSK6713_AIC23_setFreq Function in the “codec.c” file and repeat the above steps.

Result: Quantized waveform obtained on CRO. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: Students have now understood the basic concept of quantization

(17)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-3

Object: PCM Encoding

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory/Formula Used: Pulse-code modulation (PCM) is a digital representation of an analog

signal where the magnitude of the signal is sampled regularly at uniform intervals, then quantized to a series of symbols in a digital (usually binary) code.

Here is one example of sine wave shown in figure. The sine wave is sampled at regular intervals, For each sample, one of the available values is chosen by some algorithm in this case, the ceiling function is used. This produces a fully discrete representation of the input signal that can be easily encoded as digital data for storage or manipulation. For the sine wave example at right, we can verify that the quantized values at the sampling moments are 9, 11, 12, 13, 14, 14, 15, 15, 15, 14, etc. Encoding these values as binary numbers would result in the following set of nibbles: 1001, 1011, 1100, 1101, 1110, 1110, 1111, 1111, 1111, 1110, etc. These digital values could then be further processed or analyzed by a purpose-specific digital signal processor or general purpose CPU.

There are many ways to implement a real device that performs this task. In real systems, such a device is commonly implemented on a single Integrated Development Environment generally referred to as an ADC (analog-to-digital converter). These devices will produce on their output a binary representation of the input whenever they are triggered by a clock signal, generated by DSP processor means 225MHz.

(18)

Code:

#include <stdio.h> #include <stdlib.h> #include <math.h>

double quantize(double value,double delta) { int q = value/delta; if ((value-delta*q)<=(delta * (q + 1)-value)) return delta * q; else return delta * (q + 1); }

void quantize_vector(double s[],double x[],double dither[],double delta,int n) {

int i;

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

s[i] = quantize(x[i]+dither[i],delta)-dither[i]; }

void print_vector(double x[],int n) { int i; for (i=0;i<n;i++) printf("%.2f",x[i]); printf("\n"); }

void print_bits(char x[],int n) { int i; for (i = 0; i < n; i++) printf("%c", x[i] ? '1' : '0'); printf("\n"); } double sqr(double x) { return x * x; }

double distance(double y[],double dither[],double delta,int n) { int i; double sum=0.0; for (i=0;i<n;i++) sum +=sqr(y[i]-(quantize(y[i]+dither[i],delta)-dither[i])); return sum; }

int decode_vector(double y[],double **dither,double delta,int l) {

(19)

return (distance(y,dither[0],delta,l) < distance(y,dither[1],delta,l)) ? 0 : 1; }

int main(int argc,char *argv[]) { double *s,*x,*y; double delta,delta2; double **dither; int n; int i; int nbits;

char *bits, *bits2; int l; srand(1234); delta=10.0; delta2=delta/2.0; nbits=10000; bits=malloc(nbits*sizeof(char)); bits2=malloc(nbits * sizeof(char)); for (i=0;i<nbits;i++) { bits[i]=(rand() > RAND_MAX / 2) ? 0 : 1; bits2[i]=0; } printf("original bits\n"); print_bits(bits, nbits); l = 140;

dither = malloc(2 * sizeof(double *)); dither[0] = malloc(l * sizeof(double)); dither[1] = malloc(l * sizeof(double)); for (i = 0; i < l; i++) {

dither[0][i] = (rand() / (double) RAND_MAX) * delta - delta2; if (dither[0][i] < 0.0)

dither[1][i] = dither[0][i] + delta2; else

dither[1][i] = dither[0][i] - delta2; } printf("dither 0\n"); print_vector(dither[0], l); printf("dither 1\n"); print_vector(dither[1], l); n = l * nbits; s = malloc(n * sizeof(double)); x = malloc(n * sizeof(double)); y = malloc(n * sizeof(double)); for (i = 0; i < n; i++) {

(20)

x[i] = (rand() / (double) RAND_MAX) * 255.0; s[i] = 0.0; y[i] = 0.0; } printf("original\n"); print_vector(x, n); for (i = 0; i < nbits; i++) {

int bit = bits[i];

quantize_vector(s + l*i, x + l*i, dither[bit], delta, l); }

printf("watermarked\n"); print_vector(s, n); for (i = 0; i < n; i++) {

y[i] = s[i] + 5 * ((rand() / (double) RAND_MAX) - 0.5); }

printf("attacked\n"); print_vector(y, n); for (i=0;i<n;i++) {

if (i>200 && i<300) y[i] = 0;

}

printf("zeroed\n"); print_vector(y, n); for (i = 0; i < nbits; i++) {

bits2[i] = decode_vector(y + l*i, dither, delta, l); }

printf("decoded bits\n"); print_bits(bits2, nbits); for (i=0;i<nbits;i++) if (bits[i] != bits2[i]) printf("error bit #%d\n", i); exit(0);

}

Method of Experiment:

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

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

(21)

Add the source files to the project using ‘Project—add files to project’ pull down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(pcm.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

Select view ― graph ― time and frequency.

Result: The encoded data can be seen on the monitor and inferences will be drawn from that. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: Students have now came to known the different types of encoding

(22)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-4

Object: Delta Modulation

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory/Formula Used: Delta modulation (DM or Δ-modulation) is an analog-to-digital and

digital-to-analog signal conversion technique used for transmission of voice information where quality is not of primary importance. DM is the simplest form of differential pulse-code modulation (DPCM) where the difference between successive samples is encoded into n-bit data streams. In delta modulation, the transmitted data is reduced to a 1-bit data stream.

Its main features are:

 the analog signal is approximated with a series of segments

 each segment of the approximated signal is compared to the original analog wave to determine the increase or decrease in relative amplitude

 the decision process for establishing the state of successive bits is determined by this comparison

 only the change of information is sent, that is, only an increase or decrease of the signal amplitude from the previous sample is sent whereas a no-change condition causes the modulated signal to remain at the same 0 or 1 state of the previous sample.

To achieve high signal-to-noise ratio, delta modulation must use oversampling techniques, that is, the analog signal is sampled at a rate several times higher than the Nyquist rate.

Rather than quantizing the absolute value of the input analog waveform, delta modulation quantizes the difference between the current and the previous step, as shown in the block diagram in Figure

(23)

The modulator is made by a quantizer which converts the difference between the input signal and the average of the previous steps. In its simplest form, the quantizer can be realized with a comparator referenced to 0 (two levels quantizer), whose output is 1 or 0 if the input signal is positive or negative. The demodulator is simply an integrator (like the one in the feedback loop) whose output rises or falls with each 1 or 0 received. The integrator itself constitutes a low-pass filter. Code: /*Fc=30hz Fm=10hz Carrier Gain=10 Modulation Index =3;*/ #include<stdio.h> #include<math.h> float X1[50],X2[50],X3[50]; main() { int i,j,k,fc,Gain,fm; float Beta;

printf( " Enter the value of Carrier frequency \n"); scanf("%d",&fc);

printf(" enter the value of Gain\n"); scanf("%d",&Gain);

printf("Enter the value of modulation Frequency\n"); scanf("%d",&fm);

printf("Enter the value of Modulation index\n"); scanf("%f",&Beta); printf("carrier signal \n"); for(i=0;i<=50;i++) { X1[i]= Gain*cos(2*3.14*fc*i/100); printf("%f \t", X1[i]); }

printf("\n \n sinusoidal Signal\n\n"); for(j=0;j<=50;j++)

{

X2[j]= Beta*sin(2*3.14*fm*j/100); printf("%f\t ",X2[j]);

(24)

printf("\n \n Frequency Modulated Signal\n\n"); for(k=0;k<=50;k++) { X3[k]=X1[i]*cos((2*3.14*fc*k/100) +Beta*sin(2*3.14*fm*k/100)); printf("%f \t",X3[k]); }} Method of Experiment:

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

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

 Create the source file i.e. program for delta modulation in C language.

Add the source files to the project using ‘Project—add files to project’ pull down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(xyz.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

Select view ― graph ― time and frequency.

Result: The delta modulated signal can be seen on the monitor for necessary parameters

calculation to be known.

Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies:Delta modulated signal advantages in DSP application understood

(25)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-5

Object: Digital Modulation Schemes (ASK, FSK)

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory/Formula Used: In digital modulation, an analog carrier signal is modulated by a digital

bit stream. Digital modulation methods can be considered as digital-to-analog conversion, and the corresponding demodulation or detection as analog-to-digital conversion. The changes in the carrier signal are chosen from a finite number of M alternative symbols (the modulation alphabet).

Fundamental digital modulation methods

These are the most fundamental digital modulation techniques:  In the case of PSK, a finite number of phases are used.  In the case of FSK, a finite number of frequencies are used.  In the case of ASK, a finite number of amplitudes are used.

 In the case of QAM, a finite number of at least two phases, and at least two amplitudes are used.

In QAM, an inphase signal (the I signal, for example a cosine waveform) and a quadrature phase signal (the Q signal, for example a sine wave) are amplitude modulated with a finite number of amplitudes, and summed. It can be seen as a two-channel system, each channel using ASK. The resulting signal is equivalent to a combination of PSK and ASK.

In all of the above methods, each of these phases, frequencies or amplitudes are assigned a unique pattern of binary bits. Usually, each phase, frequency or amplitude encodes an equal number of bits. This number of bits comprises the symbol that is represented by the particular phase.

If the alphabet consists of M = 2N alternative symbols, each symbol represents a message

consisting of N bits. If the symbol rate (also known as the baud rate) is fS symbols/second (or

(26)

For example, with an alphabet consisting of 16 alternative symbols, each symbol represents 4 bits. Thus, the data rate is four times the baud rate.

In the case of PSK, ASK or QAM, where the carrier frequency of the modulated signal is constant, the modulation alphabet is often conveniently represented on a constellation diagram, showing the amplitude of the I signal at the x-axis, and the amplitude of the Q signal at the y-axis, for each symbol.

Code:

Code for ASK

#include<stdio.h> #include<string.h> #include<math.h> void freq_10( void ); void freq_0( void ); float c[1000]; int k=0; main() { int i, length; char b[10];

puts("\n Enter the value for ASK in 1's and 0's\n"); gets(b); length = strlen(b); for(i=0;i<length;i++) { if (b[i]=='1') freq_10(); else freq_0(); } } void freq_10 () { int j; for(j=k;j<(k+100);j++) { c[j]= sin(2*3.14*10*j/200); printf("\n%dj\t%dj\t\t%.3fc\n",j,k,c[j]); } k=j; } void freq_0 () { int j; for(j=k;j<(k+100);j++)

(27)

{ c[j]= 0; printf("\n%d\t %d\t\t%.3f\n",j,k,c[j]); } k=j; } Code for FSK #include<stdio.h> #include<string.h> #include<math.h> void freq_10( void ); void freq_5( void ); float c[1000]; int k=0; main() { int i, length; char b[10];

puts("\n Enter the value for FSK in 1's and 0's\n"); gets(b); length = strlen(b); for(i=0;i<length;i++) { if (b[i]=='1') freq_10(); else freq_5(); } } void freq_10 () { int j; for(j=k;j<(k+100);j++) { c[j]= sin(2*3.14*10*j/500); printf("\n%d\t%d\t\t%.3f\n",j,k,c[j]); } k=j; } void freq_5 () { int j; for(j=k;j<(k+100);j++) {

(28)

c[j]= sin(2*3.14*5*j/500); printf("\n%d\t %d\t\t%.3f\n",j,k,c[j]); } k=j; } Method of Experiment:

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

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

 Create the source file i.e. program for any modulation technique (ASK, FSK) in C language.

Add the source files to the project using ‘Project—add files to project’ pull down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(xyz.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

Select view ― graph ― time and frequency.

Result: Waveforms for ASK and FSK are shown on CRO. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: Student will came to know the advantages of different digital

(29)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-6

Object: Error Correcting Codes

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply.

Theory/Formula Used: A cyclic redundancy check (CRC) is a type of function that takes as

input a data stream of unlimited length and produces as output a value of a certain fixed size. The term CRC is often used to denote either the function or the function's output. A CRC can be used in the same way as a checksum to detect accidental alteration of data during transmission or storage. For example:

Note that 2x becomes zero in the above equation because addition of coefficients is performed modulo 2

Multiplication is similar:

We can also divide polynomials mod 2 and find the quotient and remainder. For example, suppose we're dividing x3 + x2 + x by x + 1. We would find that

Code:

/* DESCRIPTION * * *

* Program for the error detection *

* using the TMS320C6713 DSK. * *

(30)

* *

* Enter the data in the form of string *

*

*

* input --> Input data string * * data --> Output data string */

/**********************************************************************/ #include<stdio.h> #include<string.h> int i,frame_length,polynomial_degree,dividend[100],remainder[100]; int temp_var1=0,data[100]; void main() { char input[100]; int polynomial[10],frame_pointer=0,temp_var=0,remainder_length=0;

/****************Input data string***************************************/ printf(" Enter the Data [Bits string]::"); //Enter in the form of bit string gets(input); frame_length=strlen(input)-1; for(i=0;i<strlen(input);i++) { if(input[i]=='1') data[i]=1; else data[i]=0; }

/************Enter the Polynomial or divisor string **************************/ printf("Enter the CRC Polynomial/divisor::"); //Enter the polynomial or divisor string gets(input); polynomial_degree=strlen(input)-1; for(i=0;i<strlen(input);i++) { if(input[i]=='1') polynomial[i]=1; else polynomial[i]=0; }

/************For Cyclic Redundancy check*********************************/ for(i=frame_length+1;i<=frame_length+polynomial_degree;i++) data[i]=0; for(i=0;i<=polynomial_degree;i++) dividend[i]=data[i]; frame_pointer=polynomial_degree+1; remainder_length=polynomial_degree; while(remainder_length==polynomial_degree)

(31)

{ for(i=0;i<=polynomial_degree;i++) { if(dividend[i]==polynomial[i]) remainder[i]=0; else remainder[i]=1; } for(temp_var=-1,i=0;i<=polynomial_degree;i++) { if(remainder[i]==1 || temp_var>-1) dividend[++temp_var]=remainder[i]; } if(temp_var<polynomial_degree) { if(frame_pointer<=(polynomial_degree+frame_length)) { temp_var1=temp_var; for(i=0;i<(polynomial_degree-temp_var1);i++) { if(frame_pointer<=(polynomial_degree+frame_length)) dividend[++temp_var]=data[frame_pointer++]; else { remainder_length=temp_var; break; } } } else remainder_length=temp_var; } } if(remainder_length==-1) for(i=1;i<=polynomial_degree;i++) data[frame_length+i]=0; else { for(i=(polynomial_degree-remainder_length);i>1;i--) data[++frame_length]=0; for(i=0;i<=remainder_length;i++) data[++frame_length]=dividend[i]; }

printf("<!! The CRC status !! >"); for(i=0;i<=frame_length;i++) printf("%d",data[i]);

}

(32)

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

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

 Create the source file i.e. program for “error correction” in C language.

Add the source files to the project using ‘Project—add files to project’ pull down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(crc.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

Select view ― graph ― time and frequency.

Result: To verify the CRC status, Observe the output string, view the output window in the CCS

IDE.

Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: The student came to know that how the error correcting codes are

(33)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-7

Object: DFT Computation.

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply.

Theory/Formula Used:

In mathematics, the discrete Fourier transform (DFT) is one of the specific forms of Fourier analysis. As such, it transforms one function into another, which is called the frequency domain representation, or simply the DFT, of the original function (which is often a function in the time domain). But the DFT requires an input function that is discrete and whose non-zero values have a limited (finite) duration. Such inputs are often created by sampling a continuous function, like a person's voice. And unlike the discrete-time Fourier transform (DTFT), it only evaluates enough frequency components to reconstruct the finite segment that was analyzed. Its inverse transform cannot reproduce the entire time domain, unless the input happens to be periodic (forever). Therefore it is often said that the DFT is a transform for Fourier analysis of finite-domain discrete-time functions.

Discrete Fourier Transform (DFT) is an operation to evaluate the FT of the sampled signal s(n) = s(nT) where T is sampling time with a finite number of samples (say ). It is defined as

Code:

#include <stdio.h> #include <math.h>

void dft(short *x, short k, int *out); //function prototype

#define N 8 //number of data values float pi = 3.1416;

short x[N] = {1000,707,0,-707,-1000,-707,0,707}; //1-cycle cosine //short x[N]={0,602,974,974,602,0,-602,-974,-974,-602,

(34)

// 0,602,974,974,602,0,-602,-974,-974,-602};//2-cycles sine int out[2] = {0,0}; //init Re and Im results

void dft(short *x, short k, int *out) //DFT function {

int sumRe = 0, sumIm = 0; //init real/imag components float cs = 0, sn = 0; //init cosine/sine components int i = 0;

for (i = 0; i < N; i++) //for N-point DFT {

cs = cos(2*pi*(k)*i/N); //real component sn = sin(2*pi*(k)*i/N); //imaginary component sumRe = sumRe + x[i]*cs; //sum of real components sumIm = sumIm - x[i]*sn; //sum of imaginary components }

out[0] = sumRe; //sum of real components out[1] = sumIm; //sum of imaginary components } void main() { int j; for (j = 0; j < N; j++) {

dft(x,j,out); //call DFT function }

}

Method of Experiment:

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

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

 Create the source file i.e. program for “dft” in C language.

Add the source files to the project using ‘Project—add files to project’ pull down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(dft.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

(35)

Result:The DFT of the any arbitrary sequence has been obtained in the form of waveform. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: DFT computation concept will be more elaborated through this

(36)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-8

Object: Fast Fourier Transform.

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply.

Theory/Formula Used : A fast Fourier transform (FFT) is an efficient algorithm to compute

the discrete Fourier transform (DFT) and its inverse. FFTs are of great importance to a wide variety of applications, from digital signal processing and solving partial differential equations to algorithms for quick multiplication of large integers. This article describes the algorithms, of which there are many; see discrete Fourier transform for properties and applications of the transform.

Let x0, ...., xN-1 be complex numbers. The DFT is defined by the formula

Evaluating these sums directly would take O(N 2) arithmetical operations. An FFT is an

algorithm to compute the same result in only O(N log N) operations. In general, such algorithms depend upon the factorization of N, but (contrary to popular misconception) there are FFTs with O(N log N) complexity for all N, even for prime N.

Many FFT algorithms only depend on the fact that is an Nth primitive root of unity, and thus can be applied to analogous transforms over any finite field, such as number-theoretic

transforms.

Since the inverse DFT is the same as the DFT, but with the opposite sign in the exponent and a 1/N factor, any FFT algorithm can easily be adapted for it as well.

Code:

/********************************************************************* * DESCRIPTION *

* Number of points for FFT (PTS) 256 * * * iobuffer --> input signal * * sample --> output of FFT function (don't use on graph window) * x1 --> use in graph window

**********************************************************************/ //FFT256c.c FFT implementation calling a C-coded FFT function

#include <math.h>

(37)

#define PI 3.14159265358979

typedef struct {float real,imag;} COMPLEX;

void FFT(COMPLEX *Y, int n); //FFT prototype float iobuffer[PTS]; //as input and output buffer float x1[PTS]; //intermediate buffer

short i; //general purpose index variable short buffercount = 0; //number of new samples in iobuffer short flag = 0; //set to 1 by ISR when iobuffer full COMPLEX w[PTS]; //twiddle constants stored in w

COMPLEX samples[PTS]; //primary working buffer main()

{

for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w {

w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants }

for (i = 0 ; i < PTS ; i++) //swap buffers {

iobuffer[i] = sin(2*PI*30*i/PTS);/*10- > freq,100 -> sampling freq*/ samples[i].real=0.0;

samples[i].imag=0.0; }

for (i = 0 ; i < PTS ; i++) //swap buffers {

samples[i].real=iobuffer[i]; //buffer with new data

/* iobuffer[i] = x1[i]; //processed frame to iobuffer*/ }

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

samples[i].imag = 0.0; //imag components = 0 FFT(samples,PTS); //call function FFT.c for (i = 0 ; i < PTS ; i++) //compute magnitude {

x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag);///32; }

} //end of main

#define PTS 256 //# of points for FFT

(38)

{

COMPLEX temp1,temp2; //temporary storage variables int i,j,k; //loop counter variables

int upper_leg, lower_leg; //index of upper/lower butterfly leg int leg_diff; //difference between upper/lower leg int num_stages = 0; //number of FFT stages (iterations) int index, step; //index/step through twiddle constant i = 1; //log(base2) of N points= # of stages do

{

num_stages +=1; i = i*2;

}while (i!=N);

leg_diff = N/2; //difference between upper&lower legs

step = (PTS*2)/N; //step between values in twiddle.h // 512 for (i = 0;i < num_stages; i++) //for N-point FFT

{

index = 0;

for (j = 0; j < leg_diff; j++) {

for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) {

lower_leg = upper_leg+leg_diff;

temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real -temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag +temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index += step; } leg_diff = leg_diff/2; step *= 2; } j = 0;

for (i = 1; i < (N-1); i++) //bit reversal for resequencing data {

k = N/2; while (k <= j) {

(39)

k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; } Method of Experiment:

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

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

 Create the source file i.e. program for “fft” in C language.

Add the source files to the project using ‘Project—add files to project’ pull down menu.

Add the linker command file hello.cmd .

(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)

Add the run time support library file rts6700.lib

(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

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

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

 Load the program(fft.out) in program memory of DSP chip using the File-load program. pull down menu.

 To View output graphically

Select view ― graph ― time and frequency.

Result:The graph has been viewed on the monitor. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: Students have understood the importance of FFT and procedure to

(40)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-9

Object: FIR Filter implementation.

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory: In signal processing, a filter removes unwanted parts of the signal, such as random

noise, or extracts the useful parts of the signal, such as the components lying within a certain frequency range.

A finite impulse response (FIR) filter is a filter structure that can be used to implement almost any sort of frequency response digitally. An FIR filter is usually implemented by using a series of delays, multipliers, and adders to create the filter's output. Figure 1 shows the basic block diagram for an FIR filter of length N. The delays result in operating on prior input samples. The hk values are the coefficients used for multiplication, so that the output at time n is the

summation of all the delayed samples multiplied by the appropriate coefficients.

Figure 1. The logical structure of an FIR filter

The process of selecting the filter's length and coefficients is called filter design. The goal is to set those parameters such that certain desired stopband and passband parameters will result from running the filter. FIR, Finite Impulse Response, filters are one of the primary types of filters used in Digital Signal Processing. FIR filters are said to be finite because they do not have any feedback. Therefore, if you send an impulse through the system (a single spike) then the output will invariably become zero as soon as the impulse runs through the filter.

There are a few terms used to describe the behavior and performance of FIR filter including the following:

Filter Coefficients - The set of constants, also called tap weights, used to multiply against

delayed sample values. For an FIR filter, the filter coefficients are, by definition, the impulse response of the filter.

Impulse Response – A filter’s time domain output sequence when the input is an impulse.

An impulse is a single unity-valued sample followed and preceded by zero-valued samples. For an FIR filter the impulse response of a FIR filter is the set of filter coefficients.

(41)

Tap – The number of FIR taps, typically N, tells us a couple things about the filter. Most

importantly it tells us the amount of memory needed, the number of calculations required, and the amount of "filtering" that it can do. Basically, the more taps in a filter results in better stopband attenuation (less of the part we want filtered out), less rippling (less variations in the passband), and steeper rolloff (a shorter transition between the passband and the stopband).

Multiply-Accumulate (MAC) – In the context of FIR Filters, a "MAC" is the operation of

multiplying a coefficient by the corresponding delayed data sample and accumulating the result. There is usually one MAC per tap.

There are a couple different basic filter responses. Each will have a unique frequency response based on its cut-off frequency, the number of taps used, its roll off, and amount of ripple. The various attributes describing a filter may be seen in the following diagram:

Figure 2: This figure demonstrates an FIR low pass filter with 40 taps.

Reducing the number of taps used in the filter will reduce the number of calculations to process in the signal, however, the quality of the filtering will suffer. Rippling will become more sever, the rolloff will be less steep, and the passband will be less accurate. This may be seen in the following diagram where fewer number of taps were used.

(42)

All filters may be categorized by the section of the frequency spectrum that they alter. The following figures depict some of the basic types of digital filters:

Figure 4: High pass filters remove low frequency content.

Figure 5: Bandpass filters allow a section in the middle of the spectrum to remain.

(43)

Code: #include "FIRcfg.h" #include "dsk6713.h" #include "dsk6713_aic23.h" float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,0.011139,0.010502, -0.000000,-0.018003,-0.033416,-0.031505,0.000000,0.063010,0.144802,0.220534,0.262448, 0.220534,0.144802,0.063010,0.000000,-0.031505,-0.033416,-0.018003,-0.000000,0.010502, 0.011139,0.005728,0.000000,-0.002423,-0.001591,0.000000}; static short in_buffer[100];

DSK6713_AIC23_Config config = { \

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \ 0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\ 0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \ 0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \ 0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \ 0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \ 0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \ 0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \ 0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \ 0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \ };

/* main() - Main code routine, initializes BSL and generates tone */ void main()

{

DSK6713_AIC23_CodecHandle hCodec;

Uint32 l_input, r_input,l_output, r_output;

/* Initialize the board support library, must be called first */ DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 1); while(1)

{ /* Read a sample to the left channel */

while (!DSK6713_AIC23_read(hCodec, &l_input)); while (!DSK6713_AIC23_read(hCodec, &r_input));

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

(44)

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

while (!DSK6713_AIC23_write(hCodec, r_output)); }

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec); }

signed int FIR_FILTER(float * h, signed int x) {

int i=0;

signed long output=0;

in_buffer[0] = x; /* new input at buffer[0] */ for(i=30;i>0;i--)

in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */ for(i=0;i<32;i++)

output = output + h[i] * in_buffer[i]; return(output);

}

Method of Experiment:

 Connect CRO to the Socket Provided for LINE OUT.  Connect a Signal Generator to the LINE IN Socket.

 Switch on the Signal Generator with a sine wave of frequency 500 Hz. and Vp-p=1.5v.

 Now Switch on the DSK and Bring Up Code Composer Studio on the PC.  Create a new project with name fir.pjt.

 From the File Menu → new → DSP/BIOS Configuration →select “dsk6713.cdb” and save it as “fir.cdb”.

 Add “fir.cdb” to the current project.

 Add the given “codec.c” file to the current project which has the main function and calls all the other necessary routines.

 Add the library file “dsk6713bsl.lib” to the current project

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

 Copy files “dsk6713.h” and “dsk6713_aic23.h” from

C:\CCStudio\C6000\dsk6713\include and paste it in current project.  Build, Load and Run the program.

(45)

 You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec configuration.

 You can also pass an audio input and hear the output signal through the speakers.  You can also vary the sampling frequency using the DSK6713_AIC23_setFreq

Function in the “codec.c” file and repeat the above steps.

Result: Filteration has been observed through the head-phone. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: This practical helps in designing of FIR filter of desired

(46)

DEPTT. OF ELECTRONICS AND COMMUNICATION ENGG.

2008-09

Digital Signal Processing Lab (TEC-652) Experiment No.-10

Object: IIR Filter implementation

Equipment Used: 6713 DSK Board, IEEE 1284, compliant male- to-female cable, computer

system, power supply, CRO, Function Generator, stereo jacks.

Theory/Formula Used:

Infinite impulse response (IIR) is a property of signal processing systems. Systems with that property are known as IIR systems or when dealing with electronic filter systems as IIR filters. They have an impulse response function which is non-zero over an infinite length of time. This is in contrast to finite impulse response filters (FIR) which have fixed-duration impulse responses. The simplest analog IIR filter is an RC filter made up of a single resistor (R) feeding into a node shared with a single capacitor (C). This filter has an exponential impulse response characterized by an RC time constant.

IIR filters may be implemented as either analog or digital filters. In digital IIR filters, the output feedback is immediately apparent in the equations defining the output. Note that unlike with FIR filters, in designing IIR filters it is necessary to carefully consider "time zero" case in which the outputs of the filter have not yet been clearly defined.

Design of digital IIR filters is heavily dependent on that of their analog counterparts because there are plenty of resources, works and straightforward design methods concerning analog feedback filter design while there are hardly any for digital IIR filters. As a result, mostly, if a digital IIR filter is going to be implemented, first, an analog filter (e.g. Chebyshev filter, Butterworth filter, Elliptic filter) is designed and then it is converted to digital by applying discretization techniques such as Bilinear transform or Impulse invariance.

In practice, electrical engineers find IIR filters to be fast and cheap, but with poorer bandpass filtering and stability characteristics than FIR filters.

Code:

#include "IIRcfg.h" #include "dsk6713.h" #include "dsk6713_aic23.h" const signed int filter_Coeff[] = {

(47)

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

/* Codec configuration settings */ DSK6713_AIC23_Config config = { \

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \ 0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\ 0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \ 0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \ 0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \ 0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \ 0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \ 0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \ 0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \ 0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \ };

/* main() - Main code routine, initializes BSL and generates tone */ void main()

{

DSK6713_AIC23_CodecHandle hCodec; int l_input, r_input, l_output, r_output;

/* Initialize the board support library, must be called first */ DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3); while(1)

{ /* Read a sample to the left channel */

while (!DSK6713_AIC23_read(hCodec, &l_input)); /* Read a sample to the right channel */

while (!DSK6713_AIC23_read(hCodec, &r_input)); l_output=IIR_FILTER(&filter_Coeff ,l_input); r_output=l_output;

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

(48)

while (!DSK6713_AIC23_write(hCodec, r_output)); }

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec); }

signed int IIR_FILTER(const signed int * h, signed int x1) {

static signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be static */ static signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be static */ int temp=0;

temp = (short int)x1; /* Copy input to temp */

x[0] = (signed int) temp; /* Copy input to x[stages][0] */ temp = ( (int)h[0] * x[0]) ; /* B0 * x(n) */ temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */ temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */ temp += ( (int)h[2] * x[2]); /* B2 * x(n-2) */

temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */ temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */ temp -= ( (int)h[5] * y[2]); /* A2 * y(n-2) */

/* Divide temp by coefficients[A0] */ temp >>= 15; if ( temp > 32767 ) { temp = 32767; } else if ( temp < -32767) { temp = -32767; } y[0] = temp ;

/* Shuffle values along one place for next time */ y[2] = y[1]; /* y(n-2) = y(n-1) */

y[1] = y[0]; /* y(n-1) = y(n) */ x[2] = x[1]; /* x(n-2) = x(n-1) */ x[1] = x[0]; /* x(n-1) = x(n) */

/* temp is used as input next time through */ return (temp<<2);

(49)

Method of Experiment:

 Connect CRO to the Socket Provided for LINE OUT.  Connect a Signal Generator to the LINE IN Socket.

 Switch on the Signal Generator with a sine wave of frequency 500 Hz. and Vp-p=1.5v.

 Now Switch on the DSK and Bring Up Code Composer Studio on the PC.  Create a new project with name iir.pjt.

 From the File Menu → new → DSP/BIOS Configuration →select “dsk6713.cdb” and save it as “iir.cdb”.

 Add “iir.cdb” to the current project.

 Add the given “codec.c” file to the current project which has the main function and calls all the other necessary routines.

 Add the library file “dsk6713bsl.lib” to the current project

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

 Copy files “dsk6713.h” and “dsk6713_aic23.h” from

C:\CCStudio\C6000\dsk6713\include and paste it in current project.  Build, Load and Run the program.

 You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec configuration.

 You can also pass an audio input and hear the output signal through the speakers.  You can also vary the sampling frequency using the DSK6713_AIC23_setFreq

Function in the “codec.c” file and repeat the above steps.

Observations: Filtration has been observed through head-phone. Precautions: 1) Connect the wire properly

2) Power cable should be connected after the connection of data cable in the DSK board.

Importance/Competencies: This practical helps in designing of IIR filter of desired

References

Related documents

To actualize this vision, we adopt a layered approach: Web services provide the base layer of executable functionalities; a SWS broker and ontologies support the gradual

0900-0950 Room utilized by LE/CI Track during this session Room utilized by LE/CI Track during this session Room utilized by DIB Track during this session Room utilized

Despite the recent publication of clinical veterinary studies examining the use of NGAL concentration to diagnose AKI and chronic renal disease, no one has described

Applications of Fourier transform ion cyclotron resonance (FT-ICR) and orbitrap based high resolution mass spectrometry in metabolomics and lipidomics. LC–MS-based holistic metabolic

National Conference on Technical Vocational Education, Training and Skills Development: A Roadmap for Empowerment (Dec. 2008): Ministry of Human Resource Development, Department

The purpose of this dissertation is to develop active catalysts and proper electrode structures to improve the current density and selectivity to certain products, thereby

In order to make the best of FLACS capabilities, GEXCON Software is actively supporting FLACS users from the first introduction to FLACS software, to the advanced use of the code