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?

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

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

#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,

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

Pete

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.