Digital Signal Processing Reference
In-Depth Information
// SinegenDE.c Generates a sinewave using a difference equation
#include "dsk6713_aic23.h" //codec-DSK file support
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
short y[3] = {0,16384,0}; //y(0),y(1),y(2)
const short A = 0; //A = 2*coswT * 2^14
int n = 2;
interrupt void c_int11() //ISR
{
y[n] = ((A*y[n-1])>>14) - y[n-2]; //y(n)=Ay(n-1)-y(n-2)
y[n-2] = y[n-1]; //update y(n-2)
y[n-1] = y[n]; //update y(n-1)
output_sample(y[n]); //output result
return;
//return to main
}
void main()
{
comm_intr();
//init DSK, codec, McBSP
while(1);
//infinite loop
}
FIGURE 5.21. Program to generate a sine wave using a difference equation
( sinegenDE.c ).
Example 5.4: Generation of a Swept Sinusoid Using a
Difference Equation ( sweepDE )
Figure 5.22 shows a listing of the program sweepDE.c , which generates a sinusoidal
signal, sweeping in frequency. The program implements the difference equation
() =
(
) --
(
)
y n
Ay n
-
1
y n
2
where A
=
2cos(
w
T ) and the two initial conditions are y (
-
1)
=
sin (
w
T ) and
y (
T ). Example 5.2 illustrates the generation of a sine wave using this
difference equation, and Example 2.15 implements a swept sinusoid using an 8000-
point lookup table.
An initial signal frequency is set in the program at 500 Hz. The signal's frequency
is incremented by 10 Hz until a set maximum frequency of 3500 Hz is reached. The
duration of the sinusoidal signal at each frequency generated is set with 200 and can
be reduced for a faster sweep.
With an initial frequency of 500 Hz, the constants A = 30,274 , y (0)
-
2)
=-
sin (2
w
=
0, y (
-
1)
=-
11,585 (see Example 5.2). For each frequency (510, 520,...)
the function coeff_gen is called to calculate a new set of constants A , y ( n
6270 and y (
-
2)
=-
-
1),
y ( n
2) to implement the difference equation. A slider can be used to control
the swept signal, such as the step or incremental frequency and the duration of the
sinusoidal signal at each incremental frequency.
-
Search WWH ::




Custom Search