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.

design code program

i need to create a AM coding but that coding need to have a signal generator to vary the frequency manually.

Sine wave = a*sin (2* PI * (sample/cycle))

how to put that signal generator equation to AM coding below 

or have to edit the AM coding to make that coding can vary the frequency manually

Please help me !!!

//AM.c 
 
#include "DSK6713_AIC23.h" //codec-dsk support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
short amp = 1; //index for modulation
void main()
{
 short baseband[20]={1000,951,809,587,309,0,-309,-587,-809,-951,-1000,-951,-809,-587,-309,0,309,587,809,951}; //400-Hz baseband
 short carrier[20] ={1000,0,-1000,0,1000,0,-1000,0,1000,0,-1000,0,1000,0,-1000,0,1000,0,-1000,0}; //2-kHz carrier 
 short output[20];
 short k;
 comm_poll();                            //init DSK, codec, McBSP
 while(1)                                //infinite loop
  {
   for (k=0; k<20; k++)
    {
     output[k]= carrier[k] + ((amp*baseband[k]*carrier[k]/10)>>12);
     output_sample(20*output[k]);        //scale output
    }
  }
}

  • Henry,

    You should explain again more exactly what you want to do. You say to vary the frequency, but there is mentioned in your code the following:

    • 8KHz sampling frequency
    • 400Hz baseband frequency sine wave data
    • 2kHz carrier triangle wave data
    • short amp, index for modulation

    Whatever it is that you want to vary, yes, you will have to edit the program to include that variable frequency component.

    Since your program seems to be timed by the AIC23 sampling rate, all other frequency components will be relative to that sampling rate. You have already figured this out as shown by your baseband and carrier data values and comments.

    What you want to do may not be trivial, so it may require some major changes to your program. But, I am not sure what it is you will want to do.

    Regards,
    RandyP

  • Sorry i'm beginner and thank for the reply...

    i only want to edit this AM coding so it can  vary the frequency manually...

    The AM coding is original coding, i need to edit or modify the original AM coding and make it can vary the frequency manually...

    Can help me...

  • Henry,

    Why are you doing this project? What is the application?

    Which frequency do you want to vary?

    Regards,
    RandyP

  • Thank again...

    My lecturer give me that project, since this AM coding is using table for carrier and baseband signals

    short baseband[20]={1000,951,809,587,309,0,-309,-587,-809,-951,-1000,-951,-809,-587,-309,0,309,587,809,951}; //400-Hz baseband

    short carrier[20] ={1000,0,-1000,0,1000,0,-1000,0,1000,0,-1000,0,1000,0,-1000,0,1000,0,-1000,0}; //2-kHz carrier 

    so my lecturer said need to re-design this AM coding without the table, and create a signal generator or function that can vary the frequency randomly to repteresent the table.

    Thank for helping me 

  • Henry,

    From my pleasant experience with skilled lecturers, assignments like this will be building on the information covered in the most recent lectures. Looking back through your notes from the recent lectures, you should find examples of programming techniques that may fit your assignment.

    Because I have asked twice about which of the several frequencies you want to vary, and we have not found a way to make that important point clear, I will need to let someone else try to help you after this post. My apologies for not being able to figure that out.

    Some closing questions follow. Answering these may help to lead you to the solution you need.

    Which frequency needs to be varied?
    How were the values in the baseband array calculated?
    If the values in the baseband array needed to be initialized in the program at run-time instead of with constants at compile-time, how would you do that?
    If the length of the baseband array were increased to 200, how could you use only the first 20 values?
    If you filled the baseband array with values from a different frequency, how many values would you need to use?
    If the number of values in the baseband array that you need to use is different from the number of values in the carrier array, how could you correctly read the values from the two arrays for your AM coding?

    These questions may be helpful, or they may not, depending on which frequency need to be varied. If they are helpful, please post your solution here for others in the future. If they are not helpful, please ask additional questions here so someone else may be able to help you.

    Regards,
    RandyP

  • ok...thank for your information...

    My lecturer want me to do the project is using AM coding to build a SSB modulator and demodulator...before that my lecturer want me edit or modify the AM coding to make the frequency in the coding can vary or tune by user...

    about the Which frequency needs to be varied, my lecturer not mention it because he said the frequency is obtain by that formula  f = fs / sample and apply that formula into the coding so the user can vary any frequency they want...

    Thank