Digital Signal Processing Reference
In-Depth Information
// Dotp4.c Multiplies two arrays, each array with 4 numbers
int dotp(short *a,short *b,int ncount);//function prototype
#include <stdio.h> //for printf
#include "dotp4.h" //header file with data
#define count 4 //# data in each array
short x[count] = {x_array}; //declaration of 1st array
short y[count] = {y_array}; //declaration of 2nd array
main()
{
int result = 0;
//result sum of products
result = dotp(x, y, count); //call dotp function
printf("result = %d (decimal) \n", result); //print result
}
int dotp(short *a,short *b,int ncount) //dot product function
{
int sum = 0;
//init sum
int i;
for (i = 0; i < ncount; i++)
sum += a[i] * b[i];
//sum of products
return(sum);
//return sum as result
}
FIGURE 1.11. Sum-of-products program using C code ( dotp4.c ).
// dotp4.h Header file with two arrays of numbers
#define x_array 1,2,3,4
#define y_array 0,2,4,6
FIGURE 1.12. Header file with two arrays each with four numbers ( dotp4.h ).
become more familiar with the tools. We invoke C compiler optimization to see how
performance or execution speed can be drastically increased.
The C source file dotp4.c in Figure 1.11 takes the sum of products of two arrays,
each with four numbers, contained in the header file dotp4.h in Figure 1.12. The
first array contains the four numbers 1, 2, 3, and 4, and the second array contains
the four numbers 0, 2, 4, and 6. The sum of products is (1
¥
0)
+
(2
¥
2)
+
(3
¥
4)
+
(4
40.
The program can be readily modified to handle a larger set of data. No real-time
implementation is used in this example, and no real-time I/O support files are
needed. The support functions for interrupts are not needed here.
Create this project as dotp4 and add the following files to the project (see
Example 1.1):
¥
6)
=
Search WWH ::




Custom Search