Sie sind auf Seite 1von 8

Digital Signal Processing Lab Report # 6

Introduction to DSP using DSK-C6713

Group Members Umar Usman Saad Sarwar 2009-NUST-BE-BICSE-233 2009-NUST-BE-BICSE-176

Introduction
The hardware experiments in the DSP lab are carried out on the Texas Instruments TMS320C6713 DSP Starter Kit (DSK), based on the TMS320C6713 floating point DSP running at 225 MHz. The basic clock cycle instruction time is 1/(225 MHz)= 4.44 nanoseconds. During each clock cycle, up to eight instructions can be carried out in parallel, achieving up to 8225 = 1800 million instructions per second (MIPS). All features of the DSK are managed by the CCS, which is a complete integrated development environment (IDE) that includes an optimizing C/C++ compiler, assembler, linker, debugger, and program loader. The CCS communicates with the DSK via a USB connection to a PC.

Task 1:- Sine Led Code Lab Objectives:


After familiaring our self with the DSK board and CCS compiler, we will have to change the Sine_Led code given in our lab task to generate the following sinusoidal signals: A 4kHz and 1KHz Sinusoid Take two sinusoid of 1KHz and 4KHz, add the two sinusoids together and generate a sinusoid that will be the sum of these two sinusoids. The 1KHz sinusoid should have a gain 1 and 4 KHz sinusoid should have a gain 2

Thought Process in modifying the code


We have been given the sine_led code in which our fs= 32Khz and no. of samples = 8; which implies that the signal would have 4KHz frequency. We had to modify this code to produce a 4KHz and 1KHz signals and in the latter part, we would assign 1KHz sinusoid a gain equal to 1 and 4 KHz sinusoid a gain equal to 2 and produce a sinusoid that will be the sum of these two sinusoids. The input signal is calculated by dividing the sampling frequency over the no. of samples to get the desired input frequency. For example, to generate a 500Hz signal by using fc = 16KHz, we would have to make an array having 32 samples which would be calculated by plugging in values into the equation sin( n(360/32) ) where n varies from 0 to 31. As now our resultant array is equidistant in the radians axis, we can get the required 500Hz signal. Similarly, in order to generate 1KHz and 4KHz signals using fc = 16KHz, we take the no. of samples as 16 and 4 respectively.

C Code for Lab Tasks:


#include "dsk6713.h" #include "dsk6713_aic23.h" //support file for codec,DSK Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; //set sampling rate short loop = 0; short loop1 = 0; //table index short gain = 1; short gain1 = 2; //gain factor short sine_table1k[16]={0,382,707,923,1000,923,707,382,0,-382,-707,923,-1000,-923,-707,-382}; short sine_table4k[4]={0,1000,0,-1000}; //short sine_table1k[16]={0,500,866,1000,866,500,0,-500,-866,-1000,866,-500}; //short sine_table500k[6]={0,866,866,0,-866,-866}; void main() { comm_poll(); //initDSK,codec,McBSP DSK6713_LED_init(); //init LED from BSL DSK6713_DIP_init(); //init DIP from BSL while(1) //infinite loop { if(DSK6713_DIP_get(0)==0) //=0 if DIP switch #0 { DSK6713_LED_on(0) ; //turn LED #0 ON output_sample((sine_table4k[loop1]*gain) +( sine_table1k[loop]*gain1));//output for on-time sec if (loop < 15) ++loop; //check for end of table else loop=0 ; if (loop1 < 3) ++loop; //check for end of table else loop1 = 0; //reinit loop index } else DSK6713_LED_off(0); //turn LED off if not pressed } //end of while (1) infinite loop } //end of main

Task 2:- Generation of a concatenated signal; having 1 kHz, 3kHz and 1 kHz signals as the input for the first 3 seconds Lab Objective:
In this task, our aim was to produce a 1KHz and 3KHz signals, then we would have to concatenate them in such a manner that for the 1st second,1KHz signal is at the output, for the 2nd second, 3KHz signal is at the output and for the 3rd second, again 1KHz signal is at the output.

Thought Process in modifying the code


To accomplish this task, we used the same code in the generation of the two signals at frequencies 1KHz and 4KHz by putting the no. of samples equal to 24 and 8 for the fc =24KHz by employing the use of the formula Required Frequency = (Sampling Frequency/ No. of samples). We then employed the use of a count variable to populate our out_buffer array with the desired input frequencies i.ie for for fs < 24KHz, we populate the out_buffer array with the 1KHz signal and for 24KHz<fs < 48KHz , we populate the out_buffer array with the 3KHz signal and finally for 48KHz<fs < 72KHz , we populate the out_buffer array again with the 1KHz signal. We have chosen the intervals as our sampling period in the below code is 24KHz. Note that we didnt use loops to accomplish this task as our code has fc = 24KHZ and after every t= 1/24000 second, our code is again executed thus giving us a look that already an in-built loop is in execution.

C Code for Lab Tasks:


#include "dsk6713_aic23.h"//support file for codec,DSK Uint32 fs=DSK6713_AIC23_FREQ_24KHZ; //set sampling rate int loop=0; //table index short gain=100; //gain factor short sine_table24[24]={0,2588,5000,7071,8660,9659,10000,9659, 8660,7071,5000,2588, 0,-2588,-5000,-7071,-8660,-9659,-10000,-9659,8660,-7071,-5000,-2588}; //sine values short sine_table8[8]={0,7071,10000,7071,0,-7071,-10000,-7071}; short out_buffer[72000]; //output buffer buffer const shortBUFFERLENGTH=72000; int i=0,count =0; int j=0; int k=0; interrupt voidc_int11()//interrupt service routine //size of buffer

{ output_sample(sine_table8[loop]*gain); //output sine values if (count<24000) { out_buffer[i] = sine_table24[loop]*gain; output_sample(out_buffer[i]); i++; count++; //increment buffer count if(i==BUFFERLENGTH) i=0; //if @ bottom reinitialize counter if (loop < 23) ++loop; //check for end of table else loop = 0; } if (count>= 24000 && count<48000) { out_buffer[i] = sine_table8[loop]*gain; output_sample(out_buffer[i]); i++; count++; //increment buffer count if(i==BUFFERLENGTH) i=0; //if @ bottom reinitialize count if (loop < 7) ++loop; //check for end of table else loop = 0; } if (count>= 48000 && count<72000) { out_buffer[i] = sine_table24[loop]*gain; output_sample(out_buffer[i]); count++; i++; //increment buffer count if(i==BUFFERLENGTH) i=0; //if @ bottom reinit count if (loop < 23) ++loop; //check for end of table else loop = 0; } //reinit table index return; //return from interrupt } void main() { comm_intr();//init DSK, codec, McBSP while(1); //infinite loop

Task 3:- Viewing the effects of aliasing. Lab Objective:


The aim of this lab task was to demonstrate the effects of aliasing arising from improper sampling. A given analog signal x(t) is sampled at a rate fs, where fs satisfies the Nyquists criteria. If we sample the given signal with f< fs, then our concatenated signal would witness aliasing effect and the two different tones would be merged together to generate a single tone at out output.

Thought Process in modifying the code


Aliasing in DSP kit does not occurs because of an anti-aliasing filter present in it. To view the effect of aliasing, we decimate the signal i.e. we down sample it. If the codec sampling rate is set to 24 kHz and every four out of five samples are dropped, the effective sampling rate will be 6 kHz, with a Nyquist interval of [3, 3] kHz. A sinusoid whose frequency is outside the decimated Nyquist interval [3, 3] kHz, but inside the true Nyquist interval [6, 6] kHz, will not be cut off by the anti aliasing filter and will be aliased. To achieve aliasing as discussed above, we simply have to multiply our signal at 24KHz frequency with a pulse train in which we drop every four out of five samples as represented by pulses array in our given C code. In this manner, we down sample our signal so that the signal does not follow the Nyquists criteria and we can hear the effect of aliasing by having a single tone as our output. Note; that in order to achieve aliasing, we have two different arrays sine_table and sine_table1 having 24 samples each; meaning both are operating as 1KHz signals.

C Code for Lab Tasks:


#include "dsk6713_aic23.h" //support file for codec,DSK Uint32 fs=DSK6713_AIC23_FREQ_24KHZ; //set sampling rate int loop = 0; short gain = 10; short sine_table[24]={0,259,500,707,866,966,1000,966,866,707,500,259,0,259,-500,-707,-866,-966,-1000,-966,-866,-707,-500,-259};//sine values short sine_table1[24]={0,707,1000,707,0,-707,-1000,707,0,707,1000,707,0,-707,-1000,-707,0,707,1000,707,0,-707,-1000,707}; //gain factor //table index

short pulse[24]={0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0};//pulse values int out_buffer[72]; //output buffer

long count = 0;

//for buffer count

interrupt void c_int11() {

//interrupt service routine

if(count < 24000) { output_sample(sine_table[loop]*gain*pulse[loop]); //output sine values out_buffer[loop] = sine_table[loop]*gain*pulse[loop]; count++; if (loop < 23) ++loop; else {loop = 0;} } //check for end of table

if(count >= 24000 && count < 48000) { output_sample(sine_table1[loop]*gain*pulse[loop]); //output sine values out_buffer[loop+23] = sine_table1[loop]*gain*pulse[loop]; count++; if (loop < 23) ++loop; //check for end of table

else {loop = 0;} } if(count >= 48000 && count < 72000) { output_sample(sine_table[loop]*gain*pulse[loop]); //output sine values out_buffer[loop+23+24] = sine_table[loop]*gain*pulse[loop]; count++; if (loop < 23) ++loop; else {loop = 0;} } if(count == 72000) count = 0; //return from interrupt } //check for end of table

void main() { comm_intr(); while(1); } //init DSK, codec, McBSP //infinite loop

Das könnte Ihnen auch gefallen