Digital Signal Processing Reference
In-Depth Information
7.2.5
Experimenting with the 'C6711 DSK as a Real-Time Signal Source
Exercise 3: This experiment tests the 'C6711 DSK as a real-time signal
source and consists of a series of four steps. Please follow the instructions
carefully to complete the experiment.
In many of the communication systems that we design, we want to be able
to generate a sinusoid with arbitrary frequency
fo
. In Exercise 2, we generated
the sinusoid
x
(
t
) = sin(2
fot
)
,
where
fo
= 1kHz. In real-time digital systems,
this requires
samples
of the signal
x
(
t
) to be sent to the codec at a fixed rate.
In the case of the on-board codec, samples are being sent at rate
fs
= 8 kHz
(
Ts
= 0.125ms).
In C code, we generate samples of
x
(
t
), namely
x
[
n
] =
x
(
nts
) = sin(2
π
nfo/fs
),
where
fs
=1/
ts,
which is defined only for integer values of
n
. Here, the
argument of the sine function
π
nfo
/
fs
is a linear function that can be
easily updated at each sample point. Specifically, at the time instance
n
+ 1,
the argument becomes
θ
[
n
] = 2
π
θ
[
n
+=
12
]
π
(
n
+
1
)
fo
fs
=
θ
[ ]
n
+
2
π
fo
fs
(7.1)
which is the previous argument plus the offset 2
fo/fs
. This makes it possible
to generate any sinusoid whose frequency is
fo <
3.6 kHz. You may have
expected the maximum frequency to be
fs =
2 = 4kHz, but the codec requires
oversampling.
π
Step 1: Code Analysis and Modification
In this step, we analyze the source code in
Sine_gen.c
to see exactly how
this 1 kHz sine wave was generated. Note that in C (or more precisely C++)
that text following // on any line is regarded as a comment and is ignored,
when the program is compiled. A listing of
Sine_gen.c
is given below.
//Sine_gen.c C program file to generate sine wave
#include <math.h> //needed for sin() function
#define PI=3.14159265359 //define the constant PI
float f0=1000; //sinusoid frequency
short fs=8000; //sampling frequency of codec
float angle=0; //angle in radians
float offset; //offset value for next sample
short sine_value; //value sent to codec
short amplitude = 20000; //gain factor
interrupt void c_int11()
//interrupt service routine