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.

Sine Wave invertion

I have this code for simple sine wave generation. But i am trying to invert the phase of the input.

Can some  guide how to invert the phase of the input.

#include "tonecfg.h"

#include "dsk6713.h"
#include "dsk6713_aic23.h"

/* Length of sine wave table */


#define SINE_TABLE_SIZE 48

/* Codec configuration settings */


DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};

/* Pre-generated sine wave data, 16-bit signed samples */


Int16 sinetable[SINE_TABLE_SIZE] = {
0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};


/*
* main() - Main code routine, initializes BSL and generates tone
*/

void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Int16 msec, sample;

/* Initialize the board support library, must be called first */
DSK6713_init();

/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

/* Generate a 1KHz sine wave for 5 seconds */
for (msec = 0; msec < 5000; msec++)
{
for (sample = 0; sample < SINE_TABLE_SIZE; sample++)
{
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, sinetable[sample]));

/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, sinetable[sample]));
}
}

/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}

  • Navaneeth,

    From where did you get this source code?
    Why do you think this code will generate a sine wave?
    Why do you want to invert it?

    Have you looked at whether you can just write a '-' minus sign in front of the data to invert it? That is what you would do with floating point numbers.

    But this looks link it uses integers, Int16 in particular. Is there a reason you chose Int16?

    You probably need to go back over the material on fixed point representation of numbers that you might have covered in some of your classes back at school. That understanding of what the fixed-point numbers mean may be critical to how to do something as fancy as numerical inversion. I could not find any TI-based training materials on it, so you may have to go back through your own notes. Sorry.

    Regards,
    RandyP
  • I got his code from TI along with my DSK Kit. I want to invert the phase of the sine wave, because that's the requirement.
    and i did use the minus(-) sign , but it gives a non uniform wave.
  • Navaneeth,

    Can you clarify "that's the requirement", please. Without understanding the end goal, it is difficult to help you achieve that goal. Other than being an example to get you started, this code has no real application that I know of.

    What is your understanding of how the numbers are created in the sinetable and how they are used?
    What do they represent numerically?
    How do fixed-point numbers like those become a uniform wave at the output?

    How are you observing your output, to see the uniform and non-uniform waves?

    Regards,
    RandyP
  • by inverting the wave exactly out of of phase with the input to cancel out the original signal.
    My understanding is the codec is reading the hexadecimal values and DSP is reading the binary values of them, Correct me if i am wrong.
    I have observing the output using oscilloscope.
  • Navaneeth,

    Sorry if this sounds rude, but you seem to be leaving some things out of your clarification. You could cancel out the original signal by setting all the values in sinetable to 0. And the code does nothing that would cancel out anything if you inverted the waveform. If you are trying to keep it simple for the TI guy, maybe you should go into a little more detail, please.

    The DSP is reading the values from sinetable and is writing those values to the codec. The codec is a slave, so it does not read anything, but it has values written to it.

    What do the values in sinetable correspond to on the oscilloscope screen? The first value is 0x0000; what does that correspond to on the oscilloscope screen? What about the next value, 0x10b4? And the largest value, and the smallest value, and so on?

    If you filled sinetable with all 0x0000, what would you get? Or with 0x10b4, what would you get?

    I am trying to understand what inversion will mean in this case. And I am trying to find out what you understand about using the DSP and the codec.

    You may benefit from reading the "Fixed-Point Arithmetic" section of the application note SPRA588. Sorry, but the instructors I used to turn to are not available to give me newer material to offer to you.

    Regards,
    RandyP

  • Okay basically i am trying to read the noise through the mic, invert the signal and send the inverted signal to cancel out the noise.
    Its like sending a anti-noise. So before i start inverting real time signal, i have been trying to invert the basic sine wave.
  • Navaneeth,

    You will need to get the datasheet for the codec to see what values it generates from the mic inputs, with the purpose of understanding how the outside analog signal is mapped onto the 16-bit binary number that the DSP reads. You will want to understand the same for the output side, how the 16-bit value that the DSP writes will be translated to an analog value at the output.

    To start with, you will need to learn for the output side what the answers are to the sinetable questions I asked in my previous reply. You have to understand those issues to be able to do anything with math with fixed-point numbers. That app note may help.

    When you know what output voltage will be generated by the digital number of 0x0000, you will be closer to ready to answer those questions.

    Regards,
    RandyP