Digital Signal Processing Reference
In-Depth Information
multiply/accumulate, which is useful in a number of applications requiring
digital filtering, correlation, and spectrum analysis.
Step 1: Creating the Header and C Code Files
Create a header file with the following listing and save it as dotp5.h .
//dotp5.h Header file with two arrays of numbers
#define x_array 1, 2, 3, 4,1
#define y_array 0, 2, 4, 6, 1
Create a C code file with the following listing and save it as dotp5.c
//dotp5.c Multiplies two arrays, each with 5 numbers
int dotp(short *a, short*b, int ncount); //function
prototype
# include <stdio.h>
//for printf
# include “dotp5.h”
//data file of numbers
# define count 5
//# of data in each array
short x[count] = {x_array};
//declare 1st array
short y[count] = {y_array};
//declare 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
}
The C source file dotp5.c takes the sum of product of two arrays, each
with five numbers, contained in the header file dotp5.h . The support func-
tions for interrupts are not needed here. The vector file used is less extensive.
 
Search WWH ::




Custom Search