Digital Signal Processing Reference
In-Depth Information
{
offset = 2*PI*f0/fs;
//set offset value
angle = angle + offset;
//previous angle plus offset
if (angle > 2*PI)
//reset angle if > 2*PI
angle -= 2*PI;
//angle = angle - 2*PI
sine_value=(short)amplitude*sin(angle); //calculate
current output sample
output_sample(sine_value); //output each sine value
return;
//return from interrupt
}
void main()
{
comm_intr();
//init DSK, codec, SP0 for
interrupts
while(1);
//wait for an interrupt to
occur
}
In order to efficiently analyze the code, we will break it up into three
sections, namely section one (lines 1 through 8), section two (lines 9 through
20), and section three (lines 22 through 26). Generally, the section containing
the main() function, section three in this case, will always come last. In C,
the function main() is always the starting point of the program. The linker
knows to look for this function to begin execution. Therefore, a C program
without a main() function is meaningless.
Step 2: Analyzing the Code
The first section of code (lines 1 through 8) is used for preprocessor directives
and the definition of global variables. In C, the # sign signifies a preprocessor
directive. In this lab, we will primarily use only two preprocessor directives,
namely #include and #define . In line 1, the preprocessor directive, #include
<math.h> , tells the preprocessor to insert the code stored in the header file
math.h into the first lines of the code sine gen.c before the compiler compiles
the file. Including this header file allows us to call mathematical functions
such as sin( ¢ ), cos( ¢ ), tan( ¢ ), etc. as well as functions for logarithms, expo-
nentials, and hyperbolic functions. This header file is required for the sin( ¢ )
function line 17. To see a full list of functions available with math.h , use the
Search WWH ::




Custom Search