Documente Academic
Documente Profesional
Documente Cultură
Grading Criteria:
Problem
Problem 1:
Problem 2:
Problem 3:
Total:
Earned
Points
Possible
Points
6
8
8
22
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
>> round(cos(deg2rad(t))*1000)
ans =
Columns 1 through 8
1000
866
500
-500
-866
-1000
-866
Columns 9 through 12
-500
500
866
// 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
#include <stdio.h>
#include "C6713dskinit.h"
#include "dsk6713_dip.h"
DIP Switches
#include "dsk6713_led.h"
LEDs
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++)
{
// =0 if switch #3
// Turn LED #0 ON
5/11
output_sample(cosine_table[loop]*gain);
// Output every Ts
(SW0 on)
if (++loop > 11)
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)
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
// 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
9/11
Console window:
10/11
11/11