954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I-Q demod algorithm?

I'm not a c-programmer, rather a guy who inherited a system that previously had an I/Q demodulation in a gate array, need to move it into c-code. I have 1024 sample buffer that was synchronously digitized with x4 clock, so samples are alternately +I, +Q, -I, -Q,....... Need a snippet of code that flips signs of alternate I's and Q's so they are all positive, then sums the I's and Q's. I know this is trivial for a c-programmer, but not so for a non-programmer. Can anyone point me to an example, please?

petethepop
Newbie Poster
3 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

How about using abs to get the absolute value? Perhaps post an attempt.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

yes, thanks, abs gives 1024 samples of interleaved I and Q. Now I need the simple chunk of code that sums alternate samples to Isum and Qsum

petethepop
Newbie Poster
3 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   unsigned long Isum = 0, Qsum = 0;
   int buffer[1024];
   size_t i;
   /*
    * Fill the buffer with values between -100 and 100
    * (you can probably skip this).
    */
   srand(time(NULL));
   for ( i = 0; i < sizeof buffer / sizeof *buffer; ++i )
   {
      buffer[i] = rand() % 200 - 100;
   }
   /*
    * Calculate sums.
    */
   for ( i = 0; i < sizeof buffer / sizeof *buffer; ++i )
   {
      if ( i % 2 )  /* odd */
      {
         Qsum += abs(buffer[i]);
      }
      else          /* even */
      {
         Isum += abs(buffer[i]);
      }
   }
   printf("Isum = %lu, Qsum = %lu\n", Isum, Qsum);
   return 0;
}

/* my output
Isum = 26194, Qsum = 24823
*/
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Dave,

Good help. Many thanks. Will pass it on when I can.

Pete

petethepop
Newbie Poster
3 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You