This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Generating sine wave in CCS

Hi,

I have been working the device DSK6713. I would like tot know , how to generate a sine wave of required frequency and amplitude on CCS. I tried to pregenerate the sine wave values using Matlab and add that to table. But i couldn't figure out how to convert the matlab values to CCS. SO is there any way we can produce the sine wave

these are the MATLAB Values i got,

Columns 1 through 9

0 0.5878 0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511

Columns 10 through 18

-0.5878 0.0000 0.5878 0.9511 0.9511 0.5878 0.0000 -0.5878 -0.9511

Columns 19 through 27

-0.9511 -0.5878 0.0000 0.5878 0.9511 0.9511 0.5878 -0.0000 -0.5878

Columns 28 through 36

-0.9511 -0.9511 -0.5878 -0.0000 0.5878 0.9511 0.9511 0.5878 -0.0000

Columns 37 through 45

-0.5878 -0.9511 -0.9511 -0.5878 0.0000 0.5878 0.9511 0.9511 0.5878

Columns 46 through 54

-0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0.0000 0.5878 0.9511 0.9511

Columns 55 through 63

0.5878 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878 -0.0000 0.5878 0.9511

Columns 64 through 72

0.9511 0.5878 0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0.0000 0.5878

Columns 73 through 81

0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0.0000

Columns 82 through 90

0.5878 0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878

Columns 91 through 99

0.0000 0.5878 0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511

Columns 100 through 108

-0.5878 0.0000 0.5878 0.9511 0.9511 0.5878 0.0000 -0.5878 -0.9511

Columns 109 through 117

-0.9511 -0.5878 0.0000 0.5878 0.9511 0.9511 0.5878 0.0000 -0.5878

Columns 118 through 126

-0.9511 -0.9511 -0.5878 -0.0000 0.5878 0.9511 0.9511 0.5878 0.0000

Columns 127 through 135

-0.5878 -0.9511 -0.9511 -0.5878 -0.0000 0.5878 0.9511 0.9511 0.5878

Columns 136 through 144

-0.0000 -0.5878 -0.9511 -0.9511 -0.5878 -0.0000 0.5878 0.9511 0.9511

Columns 145 through 153

0.5878 0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0.0000 0.5878 0.9511

Columns 154 through 162

0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0.0000 0.5878

Columns 163 through 171

0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0.0000

Columns 172 through 180

0.5878 0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878

Columns 181 through 189

0.0000 0.5878 0.9511 0.9511 0.5878 -0.0000 -0.5878 -0.9511 -0.9511

Columns 190 through 198

-0.5878 -0.0000 0.5878 0.9511 0.9511 0.5878 0.0000 -0.5878 -0.9511

Columns 199 through 201

-0.9511 -0.5878 0.0000

  • Hi Venkat,

    Thanks for your post.

    If you are facing problem related to matlab, then i will suggest you post your query on appropriate matlab forum.

    As per your requirement, we have a Tone example code which uses AIC23 codec BSL to generate a 1KHz sine wave. Data used by sine wave will be pre-calculated and would be feed in the form of an array. The codec operates at 48KHz by default.
    You can download BSL example projects for C6713 from Spectrum Digital's website from the below mentioned link,
    c6000.spectrumdigital.com/.../revc
  • I do have the pre-calculated values for 1Khz. How do we calculate the values for other frequencies?
  • Can i have a update on this?
  • Venkat,

    I think we are waiting for you to get the Tone example that Arvind referenced. If you have any questions on that example, please let us know.

    There is no difference between the sine wave samples for one frequency or another if you can adjust the sample rate. You could use the same ones as you show above, and you only need 10 of them since those repeat throughout your Matlab array.

    Regards,
    RandyP
  • I would need to generate a frequency of 606hz. But this device operates only at 8K,16K,48K,64K and 128K sampling rate. Not sure how to generate a frequency of 606hz, which is kind difficult using the table. So is there any other way we can generate a sine wave with direct input of frequency.
  • Hi Navaneeth Karthikeyan and Venkat,

    Will you please clear your idea/goal which you are trying to achieve by changing the frequency. The example code which i referred you to use as an reference, would be the good way to get going and have an idea how to generate a sine wave.
  • Venkat,

    Use the sin() function and scale the output to give you a good number to output. The value of sin(x) is what you are looking for, so all you have to solve for is x, given time=t which is a function of linear sample time steps and frequency=f which is 606Hz in your case.

    Can you figure the formula for x?

    Regards,
    RandyP
  • We did use your code as a reference. But using your code as reference, we are unable to generate the required frequency (606 Hz).
    and we are doing few research on the sounds , so we had to produce sound at required frequencies using this device.
  • HI Randy,

    I tried using the sin() function -( Sin(2*pi*i)) , where i is an array type. But couldn't get the sine wave out of it. Could you see if you can generate a sine wave using this function. Would be of great help. This would be the last stage of my project. 

  • Venkat,

    What do you mean by "i is an array type"? That does not match anything I would think of.

    A variable 'i' is usually a counter and is of some integer type, not an 'array type'. But in this case, if i is any integer value then 2*pi*i will be a multiple of 2pi. You do not need a function call to tell you what the sine of 2pi is, since it is always 0.

    What I want to happen here is for you to meet your real goal, which would appear to be learning how to write DSP code. Hopefully, I can at least guide you in that process if you have the patience to work with me. But writing your project would not accomplish your goal, only learning to write your project will accomplish that. To wit,

    On a piece of paper, draw a horizontal x-axis line across the page and a vertical y-axis line on the left side. The x-axis represents increasing time, or for a sine wave it also represents phase for a particular frequency. The y-axis is the amplitude, either positive or negative. Then draw one cycle of a sine wave from left to right. The x-intercept at the far right is at the 2*pi point.

    What is that 2*pi point equivalent to in microseconds or milliseconds for the frequency that you want to generate? With that, you now have a time scale.

    Do you know your sample frequency, the rate at which the outputs will be presented to the DAC? Using the time scale established by the step above, mark all or some of the points in time when you will be outputting a sample of your waveform.

    The sample points will be evenly spaced, but they will probably not line up perfectly with the 1*pi and 2*pi points. We make them line up for our examples to make it easier.

    As I said in my previous post on July 6, but in different words, you need to determine an equation to figure out the x-axis value for the sample points, with the result being the angle from 0 to 2*pi. What would you suggest for that equation?

    Regards,
    RandyP