Sei sulla pagina 1di 11

Lab 1 Cover Sheet

Name 1:Loveena Harchandani


Course: EGCP-548

Name 2:Khaja Furquan Ahmed


Date: 07/10/2015

Grading Criteria:
Problem
Problem 1:
Problem 2:
Problem 3:
Total:

Earned
Points

Possible
Points
6
8
8
22

Report Submission Instructions:


Please, upload your lab report to TITANIum. No paper submissions.
This is a group lab. Two people per group. A group can use the same
report but both members are required to upload report to TITANium.

1/11

1. (6 Points) Write a Matlab script that calculates the samples for the
sine_table to generate a cosine with a frequency of 666.66Hz. Update the
C6713_Sine_Poll_Example program such that it generates this 666.66 Hz
cosine signal. Verify your output using Visual Analyzer by plotting the
generated cosine in both time and frequency domains. Use a sampling
frequency of 8 kHz and a gain of 5. Provide your Matlab and CCS
(main.c) code as text and screenshots of Visual Analyzer. You must label
your screenshots and code to receive full credit.
Solution:
F=666.66khz
1
Matlab Script:
t=
0

30

60

90 120 150 180 210 240 270 300 330

>> round(cos(deg2rad(t))*1000)
ans =
Columns 1 through 8
1000

866

500

-500

-866

-1000

-866

Columns 9 through 12
-500

500

866

Sine_pole_example updated according to the specified values:


Main.c
#include <stdio.h>
#include "C6713dskinit.h"
#include "dsk6713_dip.h"
file for DSK DIP Switches
#include "dsk6713_led.h"
file for DSK LEDs
Uint32 fs = DSK6713_AIC23_FREQ_8KHZ;
sampling rate
short loop = 0;
// Table index

// Support
// Support
// Set

2/11

short gain = 5;
Gain factor
short cosine_table[12]={1000,866,500,0,-500,-866,-1000,-866,500,0,500,866}; // cos values
void main() {
comm_poll();
DSK, codec, McBSP
DSK6713_LED_init();
LED from BSL
DSK6713_DIP_init();
DIP from BSL

//

// Init
// Init
// Init

// Main loop
while(1) {
if(DSK6713_DIP_get(0) == 0) {
// =0 if switch #0
pressed
DSK6713_LED_on(0);
// Turn LED #0
ON
output_sample(cosine_table[loop]*gain);
// Output every Ts
(SW0 on)
if (++loop > 11) loop = 0;
// Check for end of
table
}
else
{
DSK6713_LED_off(0);
// LED
#0 off
}
// End of
while (1)
}
}
Screenshots of virtual analyser:

3/11

4/11

2. (8 Points) Write a polling-based program so that once dip switch #3 is


pressed, LED #3 turns on and a 666.66 Hz cosine is generated for
approximately 5 seconds. Explain how you did this. Again, use a sampling
frequency of 8 kHz and a gain of 5. Provide your CCS code (main.c) as
text. You must label your screenshots and code to receive full credit.
Solution:
Main.c:

#include <stdio.h>
#include "C6713dskinit.h"
#include "dsk6713_dip.h"
DIP Switches
#include "dsk6713_led.h"
LEDs

// Support file for DSK


// Support file for DSK

Uint32 fs = DSK6713_AIC23_FREQ_8KHZ;
// Set sampling rate
short loop = 0;
// Table index
short gain = 5;
//
Gain factor
short cosine_table[12]={1000,866,500,0,-500,-866,-1000,-866,500,0,500,866}; // cos values
void main() {
comm_poll();
McBSP
DSK6713_LED_init();
BSL
DSK6713_DIP_init();
BSL
int i;
int flag = 0;
// Main loop
while(1)
{
if(DSK6713_DIP_get(3) == 0)
pressed
{
if ( flag == 0 )
{
DSK6713_LED_on(3);
for(i=0;i<=40000;i++)
{

// Init DSK, codec,


// Init LED from
// Init DIP from

// =0 if switch #3

// Turn LED #0 ON

5/11

output_sample(cosine_table[loop]*gain);

// Output every Ts

(SW0 on)
if (++loop > 11)

// Check for end of

table
loop = 0;
}
flag = 1;
}
else
{
DSK6713_LED_off(3);
}
}
else
{
DSK6713_LED_off(3);
flag = 0;
}
}
}

// LED #0 off

// LED #0 off
// End of while (1)

Screenshot of the output when the switch is on:

Screenshot after 5 seconds approximately:

6/11

Explanation:
Given sampling frequency = 8khz
Therefore, sampling rate = 8000 samples/sec
Therefore, inorder to output a cosine wave for five seconds, we need 8000 *5
samples for 5 seconds = 40000 samples.
Therefore in the code, we initialize a for loop to output the cosine wave for
40000 samples. This for loop goes on till 40000 samples and then turns off
the led, also the cosine wave disappears approximately after 5 seconds.
Also, we initialize a flag to keep a track of dip switch and led so that the real
time process is achieved successfully.

7/11

3. (8 Points) Write a program using the dot product to multiply two arrays,
each containing the five numbers 1, 2, 3, 4, and 5 (i.e., 1 2 + 22 + 32 + 42
+ 52). Verify your result using the Expression window and printing it
using fprintf within CCS in the Console window. Provide your CCS code
(main.c) as text and a screenshot of the debug window after execution.
HINT: you will have to use a breakpoint and stepping to see the value of
result in the Expression window. You must label your screenshots and
code to receive full credit.
Solution:
Dotp4.h
#define x_array 1,2,3,4,5
#define y_array 1,2,3,4,5

main.c
#include <stdio.h>
#include "dotp4.h"
#define count 5

// For fprintf
// Header file with data
// # data in each array
8/11

int dotp(short *a,short *b,int ncount);


short x[count] = {x_array};
array
short y[count] = {y_array};
array

// Function prototype
// Declaration of 1st
// Declaration of 2nd

main() {
int result = 0;
// Result sum of
products
result = dotp(x, y, count);
// Call dotp function
fprintf(stderr, "result = %d (decimal) \n", result);
// Print result
}
// Dot product function
int dotp(short *a,short *b,int ncount) {
int sum = 0;
int i;
for (i = 0; i < ncount; i++)
sum += a[i] * b[i];
return(sum);
}

// Init sum
// Sum of products
// Return sum as result

Result in the expression window:

9/11

Console window:

Debug window after execution:

10/11

11/11

Potrebbero piacerti anche