Digital Signal Processing Reference
In-Depth Information
// Sinegen_table.c Generates sinusoid with generated values
#include "DSK6713_AIC23.h" //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
#include <math.h>
#define table_size (short)10
//set table size
short sine_table[table_size];
//sine table array
int i;
interrupt void c_int11()
//interrupt service routine
{
output_sample(sine_table[i]);
//output each sine value
if (i < table_size - 1) ++i;
//incr index until end of table
else i = 0;
//reinit index if end of table
return;
//return from interrupt
}
void main()
{
float pi=3.14159;
for(i = 0; i < table_size; i++)
sine_table[i] = 10000*sin(2.0*pi*i/table_size); //scaled values
i = 0;
comm_intr();
//init DSK, codec, McBSP
while(1);
//infinite loop
}
FIGURE 2.19. Sine-wave generation program using the table generated within a program
( sinegen_table.c ).
Example 2.13: Sine Generation with a Table Created by
MATLAB ( sin1500MATL )
This example illustrates the generation of a sinusoid using a lookup table created
with MATLAB. Figure 2.20 shows a listing of the MATLAB program sin1500.m ,
which generates a file with 128 data points over 24 cycles. The sine-wave frequency
generated is
(
) (
) =
f
=
number of cycles
number of points
1500
Hz
s
Run sin1500.m within MATLAB and verify the header file sin1500.h with 128
points, as shown in Figure 2.21. Different numbers of points representing sinusoidal
signals of different frequencies can readily be obtained with minor changes in the
MATLAB program sin1500.m .
Figure 2.22 shows a listing of the C source file sin1500MATL.c , which imple-
ments this project in real time. This program includes the header file generated by
MATLAB. See also Example 2.12, which generates the table within the main C
source program in lieu of using MATLAB.
Search WWH ::




Custom Search