1 / 42

“Sine Waves ”

“Sine Waves ”. Texas Instruments University Programme Teaching Materials. Sine Waves. Introduction. DSP can be used to generate sine waves Sine waves can be used in audio to: Generate musical tones and complex waveforms Generate tones for touch phones (DTMF)

quasar
Download Presentation

“Sine Waves ”

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. “Sine Waves” Texas Instruments University Programme Teaching Materials

  2. Sine Waves

  3. Introduction • DSP can be used to generate sine waves • Sine waves can be used in audio to: • Generate musical tones and complex waveforms • Generate tones for touch phones (DTMF) • Modulate audio signals (alien voices) • Control audio effects (chorus/phasing/flanging).

  4. Objectives • To generate sine waves from 10Hz to 16000Hz. • To introduce the Texas Instruments library of DSP functions DSPLIB.

  5. Knowledge Required • Some understanding of fixed-point and floating-point numbers is required. • Details of two useful articles from www.cnx.org are given in the References Section.

  6. Sine Wave and FFT • A sine wave is a pure tone. It only contains one frequency:

  7. Complex Waveform and FFT • A complex waveform has several frequency components:

  8. Generating Sine Waves • There are 3 main ways to generate sine waves: • Look-up Table • Recursive Equation • Taylor Expansion.

  9. Look-up Table • This is the simplest way to generate a sine wave. • Put known values into a table: • Values are read using an offset e.g. sinetable[3];

  10. About Look-up Tables • Advantages: • Fast to implement • Values are always accurate • Disadvantages: • Can only be used for exact divisions of sampling frequency.

  11. Recursive Equation • Uses the following mathematical equation: • The next sine output is derived from the previous values • We shall look at this in more detail in Chapter 7, Infinite Impulse Response (IIR) filters.

  12. Taylor Series • A sine function can be implemented as a geometric series: where x is the input in radians. • This method is used by the Texas Instruments DSP Library DSPLIB.

  13. About Taylor Series • Advantages: • Can generate any frequency • Disadvantages: • Not as accurate as look-up table because there are rounding errors • Care needs to be taken to avoid overflow during multiplications.

  14. C Code Implementation

  15. Sine Function in C • As standard, C comes with the function sin(x) in “math.h”. • This uses floating-point maths. • It is not efficient for real-time applications. • A better way is to use DSPLIB.

  16. Introducing DSPLIB

  17. About DSPLIB • Texas Instruments provides a library containing a whole range of useful functions used in DSP: • Fast Fourier Transform (FFT) • Sine, Cosine and Tangent • Exponentials and logs. • Each function is optimised for the processor, in this case the TMS320C55xx.

  18. DSP LIB Headers • When using DSPLIB, you need to add the two following #include statements to your code:

  19. DSPLIB Library • The library file 55xdsph.lib must be present in the build. DSPLIB for TMS320C5505 USB Stick.

  20. DSPLIB Sine Function • Is written in TMS320C55xx assembly language. • The function takes 3 parameters: • Parameter 1. Address of location containing the frequency • Parameter 2. Address of location to store calculated sine • Parameter 3. Always 1.

  21. Scaling the sine() function • Need to convert frequency in Hz to value for sine() function. • Use a scaling factor of 22368.

  22. Magic Numbers • Where did the magic number 22368 come from? • The TMS320C5505 is a 16-bit fixed-point processor that uses: • 32767 to represent 1.000 • –32767 to represent –1.000 • Here 22368 represents 0.682 decimal. • We shall now look at how this magic number was obtained.

  23. DSPLIB sine() function • The DSPLIB function sine() calculates the sine of an angle. • The input to the function is a fixed-point number that represents an angle: • 0 => 0o • 16383 => 90o • 32767 => 180o • 2 * 32767 => 360o

  24. Sine 90o • To generate a waveform using 4 values we use: • sin 0o • sin 90o • sin 180o • sin 270o. • If Fs = 48000 Hz, the frequency generated will be: • 48000/4 = 12000 Hz.

  25. Sine 45o • To generate a waveform using 8 value use: • sin 0o • sin 45o • sin 90o • sin 135o etc. • If Fs = 48000 Hz, the frequency generated will be: • 48000/8 = 6000 Hz.

  26. Generate 1 Hz Sine Wave • To generate a 1 Hz sine wave we work backwards: • 48000/value = 1 Hz • value = 1/48000 • There corresponding angle will be: • 360o/48000 = 0.0075o • To implement a 1 Hz sine wave we use: • 0o, 0.0075o, 0.015o, 0.0225o, 0.030o etc.

  27. Fixed-Point Implementation • For 1 Hz we require each angle to be multiples of: • 360o/48000 = 0.0075o • For 1 Hz using fixed-point using DSPLIB we require: • 2 * 32767 / 48000

  28. Scaling Factor • We can use the value for 1 Hz as a scaling factor to calculate other frequencies: • SCALING FACTOR = 360o/48000 = 0.0075o • For 2 Hz: • 2 * SCALING FACTOR = 2 * 360o/48000 = 0.015o • For 10 Hz: • 10 * SCALING FACTOR = 10 * 360o/48000 = 0.075o

  29. Scaling Factor Calculation • The fixed-point scaling factor is: • In fixed-point maths, to divide by 48000 is awkward • However, to divide by 32768 is easy because 32768 = 215 • Example: To divide 3FFFFFFFh by 32768d shift right 15 places. Result = 7FFFh • In C code, divide by 32768 is implemented as >> 15.

  30. Scaling Factor Calculation • The fixed-point scaling factor is derived as follows: • The divide by 32768 is implemented as >>15 • Here 2/32768 is implemented as >>14. • The scaling factor used is therefore 22368.

  31. Introduction to Laboratory

  32. USB Stick Setup TMS320C5505 USB to PC USB Stick Headphones

  33. Installing the Application • Use the code given in Application 4, Sine Waves • Follow the steps previously given in Chapter 1 to set up the new project.

  34. Create New Project

  35. Files Used in Project

  36. Console • Sampling frequency and Gain are shown in the Console window.

  37. Experiments

  38. Change the Headphone Volume • Reduce gain from 10000 to 5000.

  39. Change the Frequencies • Rather than 200 Hz and 500 Hz, use two musical notes: A = 440 Hz C = 523 Hz

  40. Change the Sampling Frequency • Change the sampling frequency to 24000 Hz. • The output frequencies will have changed. • You will need to alter the scaling factor in sinewaves.c

  41. Questions • What are 3 ways to generate sine waves? • Which method is best suited to the TMS320C5505 USB Stick? • What are 3 applications of sine waves?

  42. References • TMS320C55xx DSP Library Programmer’s Reference. SPRU 422. • Digital Signal Processing with C and the TMS320C30 by Rulph Chassaing. ISBN 0-471-55780-3. • www.cnx.org Fixed Point Arithmetic and Format (m10919) by Hyeokho Choi. • www.cnx.org Fixed Point Arithmetic (m11054) by Hyeokho Choi.

More Related