• No results found

Sampling and Reconstruction

while 1 begin forever loop

13 c6x_daq ( ’ SwapFrame ’ , data ) ; % send / receive data

% data = data * 10; % add gain

15 end

To keep the number of samples acquired down, this demonstration uses a relatively low 8 kHz sample frequency for the DSK’s onboard codec (TLV320AIC23), even though the codec itself is capable of much higher speeds. Most other programs in this book use a sample frequency of 48 kHz.

To verify that the data stream is actually being transferred through MATLAB, you can activate line 14 in the forever loop by removing the comment symbol (%). This adds gain to the signal.

2.5 DSK Implementation in C

The files necessary to run this application are in the ccs\MyTalkThrough directory of Chap-ter 2 on the CD-ROM that accompanies this book. The primary file of inChap-terest is ISRs.c, which contains the interrupt service routines. This file includes the necessary variable dec-larations and performs a swap of the left and right channel data. This swap of left and right channel data is used so that you actually have a few lines of code to view.

The code listings are given below.

Listing 2.3: Talk-through declarations.

1#define LEFT 0

#define RIGHT 1

3

f l o a t temp ;

An explanation of Listing 2.3 follows.

1. (Lines 1–2): Define LEFT and RIGHT for user convenience.

2. (Line 4): Declares a temporary variable that is used to allow for channel swapping.

28 CHAPTER 2. SAMPLING AND RECONSTRUCTION Listing 2.4: Talk-through code to swap left and right channels.

/* I added my routine here */

2

temp=CodecData . channel [ RIGHT ] ; // R to temp

4 CodecData . channel [ RIGHT ]= CodecData . channel [ LEFT ] ; // L to R

CodecData . channel [ LEFT ]= temp ; // temp to L

6

/* end of my routine */

An explanation of Listing 2.4 follows.

1. (Line 3): Assigns the right channel data to the variable temp.

2. (Line 4): Assigns the left channel data to the right channel.

3. (Line 5): Assigns temp to the left channel.

Note that if you are using a C6713 DSK, the board’s input circuitry contains a voltage divider that reduces the input voltage level by a factor of 2 (i.e., a−6 dB change in voltage).

To counteract this signal level decrease, the DSK_Support.c file (in the common_code direc-tory on the book’s CD-ROM) automatically inserts +6 dB of input gain whenever the C6713 DSK is selected. This voltage divider is not present on the OMAP-L138 Experimenter Kit.

Now that you understand the code. . .

Go ahead and copy all of the files into a separate directory to preserve the originals. Open the project in Code Composer Studio (CCS) and select “Rebuild All.” Once the build is complete, select “Load Program” to load the binary code into the DSK and then click on

“Run.” Your talk-through system should now be running on the DSK. Remember, the codecs for the DSKs do not contain audio power amplifiers to drive the connected loads.

For the best results, use amplified speakers with your DSK (e.g., powered speakers used with PCs), headphones, or earbuds to hear the audio output.11

2.6 Follow-On Challenges

Consider extending what you have learned, using the C compiler and the DSK.

1. Experiment with scaling the output values (multiplying the input value, e.g., by 0.3, 1.6, and so on. . . ) that you pass to the DAC. Are there limits associated with this scaling?

2. Implement your own program for spectral inversion on the DSK.

3. Change the sign bit of every sample that you pass to the DACs. Describe the effect of this sign bit change on how the output signal sounds.

4. Modify your talk-through code to output only the left or right channel value.

5. Modify your talk-through code to combine the left and right channel inputs and send the result to both the left and right channel outputs. Are there any limitations associated with combining the left and right channels?

11The OMAP-L138 Experimenter Kit only provides a line output, not a separate headphone output.

Since impedance and efficiency of headphones (and earbuds) varies, the performance using a line output with these devices will also vary.

2.7. PROBLEMS 29 6. Reduce the number of bits used by the DAC by using only the 8 most significant bits

(MSBs). Can you hear the difference when only the 8 MSBs are used?

7. Reduce the number of bits used by the DAC by using only the 4 most significant bits (MSBs). Can you hear the difference when only the 4 MSBs are used?

8. Reduce the number of bits used by the DAC by using only the 2 most significant bits (MSBs). Can you hear the difference when only the 2 MSBs are used?

9. Reduce the number of bits used by the DAC by using only the most significant bit (MSB). Can you hear the difference when only the MSB is used?

2.7 Problems

1. Given a sample frequency of Fs= 48 kHz, what is the highest input frequency that, in theory, can be sampled without aliasing?

2. Suppose an input signal with a significant frequency component at 30 kHz was sampled at a frequency of Fs= 48 kHz, in a simple “talk-through” configuration. Assume no anti-aliasing filter is present. At what frequency would the original 30 kHz component appear at the output of the “talk-through” configuration?

3. An input signal ranges in amplitude from +1 V to−1 V, which matches the dynamic range of the ADC being used. No clipping of the input signal occurs. If each sample is uniformly quantized to 16 bits, what is the approximate resolution (also called the LSB voltage), in volts, of this ADC?

4. An input signal ranges in amplitude from +1 V to−1 V, which matches the dynamic range of the ADC being used. No clipping of the input signal occurs, and the signal amplitude is equally likely across the full dynamic range of the ADC. If each sample is uniformly quantized to 16 bits, what is the approximate signal to quantization noise ratio (SQNR) in dB? Assume no noise shaping or other advanced techniques are being used in the ADC design.

5. It was mentioned earlier in the chapter that changing the sign of every other sample of an input signal is equivalent to modulating the input signal by a sinusoid with a frequency of one-half the sample frequency. Explain why this is true.

This page intentionally left blank This page intentionally left blank

Chapter 3