Digital Signal Processing Reference
In-Depth Information
conditions, determine the frequency generated. They are scaled for a fixed-point
implementation. Using the difference equation
() =
(
) --
(
)
y n
Ay n
-
1
y n
2
the output at time n
=
0 is
() = () - () =-
(
)
(
) +
(
) =
y
0
y
1
y
2
2
cos
ww
T T
sin
sin
2
w
T
0
// two_tones.c Generates/adds two tones using difference equations
#include "DSK6713_AIC23.h" //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
short sinegen(void); //for generating tone
short output; //for output
short sinegen_buffer[256]; //buffer for output data
const short bufferlength = 256; //buffer size for plot with CCS
short i = 0; //buffer count index
short y1[3] = {0,-15137,-11585}; //y1(0),y1(-1),y1(-2) for 1.5kHz
const short A1 = 12540; //A1 = 2coswT scaled by 2^14
short y2[3] = {0,-16384,0}; //y2(0),y2(-1),y2(-2) for 2kHz
const short A2 = 0; //A2 = 2coswT scaled by 2^14
interrupt void c_int11()
//ISR
{
output = sinegen(); //out from tone generation function
sinegen_buffer[i] = output; //output into buffer
output_sample(output); //output result
i++; //increment buffer count
if (i == bufferlength) i = 0;
//if buffer count=size of buffer
return;
//return to main
}
short sinegen()
//function to generate tone
{
y1[0] =((y1[1]*A1)>>14)-y1[2];
//y1(n)= A1*y1(n-1)-y1(n-2)
y1[2] = y1[1];
//update y1(n-2)
y1[1] = y1[0];
//update y1(n-1)
y2[0] =((y2[1]*A2)>>14)-y2[2];
//y2(n)= A2*y2(n-1)-y2(n-2)
y2[2] = y2[1];
//update y2(n-2)
y2[1] = y2[0];
//update y2(n-1)
return (y1[0] + y2[0]);
//add the two tones
}
void main()
{
comm_intr();
//init DSK, codec, McBSP
while(1);
//infinite loop
}
FIGURE 5.19. Program to generate and add two tones ( two_tones.c ).
Search WWH ::




Custom Search