Subversion Repositories dashGPS

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------
  2.  * Project:      CMSIS DSP Library
  3.  * Title:        arm_cmplx_conj_q31.c
  4.  * Description:  Q31 complex conjugate
  5.  *
  6.  * $Date:        27. January 2017
  7.  * $Revision:    V.1.5.1
  8.  *
  9.  * Target Processor: Cortex-M cores
  10.  * -------------------------------------------------------------------- */
  11. /*
  12.  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
  13.  *
  14.  * SPDX-License-Identifier: Apache-2.0
  15.  *
  16.  * Licensed under the Apache License, Version 2.0 (the License); you may
  17.  * not use this file except in compliance with the License.
  18.  * You may obtain a copy of the License at
  19.  *
  20.  * www.apache.org/licenses/LICENSE-2.0
  21.  *
  22.  * Unless required by applicable law or agreed to in writing, software
  23.  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25.  * See the License for the specific language governing permissions and
  26.  * limitations under the License.
  27.  */
  28.  
  29. #include "arm_math.h"
  30.  
  31. /**
  32.  * @ingroup groupCmplxMath
  33.  */
  34.  
  35. /**
  36.  * @addtogroup cmplx_conj
  37.  * @{
  38.  */
  39.  
  40. /**
  41.  * @brief  Q31 complex conjugate.
  42.  * @param  *pSrc points to the input vector
  43.  * @param  *pDst points to the output vector
  44.  * @param  numSamples number of complex samples in each vector
  45.  * @return none.
  46.  *
  47.  * <b>Scaling and Overflow Behavior:</b>
  48.  * \par
  49.  * The function uses saturating arithmetic.
  50.  * The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value 0x7FFFFFFF.
  51.  */
  52.  
  53. void arm_cmplx_conj_q31(
  54.   q31_t * pSrc,
  55.   q31_t * pDst,
  56.   uint32_t numSamples)
  57. {
  58.   uint32_t blkCnt;                               /* loop counter */
  59.   q31_t in;                                      /* Input value */
  60.  
  61. #if defined (ARM_MATH_DSP)
  62.  
  63.   /* Run the below code for Cortex-M4 and Cortex-M3 */
  64.   q31_t inR1, inR2, inR3, inR4;                  /* Temporary real variables */
  65.   q31_t inI1, inI2, inI3, inI4;                  /* Temporary imaginary variables */
  66.  
  67.   /*loop Unrolling */
  68.   blkCnt = numSamples >> 2U;
  69.  
  70.   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
  71.    ** a second loop below computes the remaining 1 to 3 samples. */
  72.   while (blkCnt > 0U)
  73.   {
  74.     /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  75.     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  76.     /* Saturated to 0x7fffffff if the input is -1(0x80000000) */
  77.     /* read real input sample */
  78.     inR1 = pSrc[0];
  79.     /* store real input sample */
  80.     pDst[0] = inR1;
  81.  
  82.     /* read imaginary input sample */
  83.     inI1 = pSrc[1];
  84.  
  85.     /* read real input sample */
  86.     inR2 = pSrc[2];
  87.     /* store real input sample */
  88.     pDst[2] = inR2;
  89.  
  90.     /* read imaginary input sample */
  91.     inI2 = pSrc[3];
  92.  
  93.     /* negate imaginary input sample */
  94.     inI1 = __QSUB(0, inI1);
  95.  
  96.     /* read real input sample */
  97.     inR3 = pSrc[4];
  98.     /* store real input sample */
  99.     pDst[4] = inR3;
  100.  
  101.     /* read imaginary input sample */
  102.     inI3 = pSrc[5];
  103.  
  104.     /* negate imaginary input sample */
  105.     inI2 = __QSUB(0, inI2);
  106.  
  107.     /* read real input sample */
  108.     inR4 = pSrc[6];
  109.     /* store real input sample */
  110.     pDst[6] = inR4;
  111.  
  112.     /* negate imaginary input sample */
  113.     inI3 = __QSUB(0, inI3);
  114.  
  115.     /* store imaginary input sample */
  116.     inI4 = pSrc[7];
  117.  
  118.     /* store imaginary input samples */
  119.     pDst[1] = inI1;
  120.  
  121.     /* negate imaginary input sample */
  122.     inI4 = __QSUB(0, inI4);
  123.  
  124.     /* store imaginary input samples */
  125.     pDst[3] = inI2;
  126.  
  127.     /* increment source pointer by 8 to proecess next samples */
  128.     pSrc += 8U;
  129.  
  130.     /* store imaginary input samples */
  131.     pDst[5] = inI3;
  132.     pDst[7] = inI4;
  133.  
  134.     /* increment destination pointer by 8 to process next samples */
  135.     pDst += 8U;
  136.  
  137.     /* Decrement the loop counter */
  138.     blkCnt--;
  139.   }
  140.  
  141.   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  142.    ** No loop unrolling is used. */
  143.   blkCnt = numSamples % 0x4U;
  144.  
  145. #else
  146.  
  147.   /* Run the below code for Cortex-M0 */
  148.   blkCnt = numSamples;
  149.  
  150.  
  151. #endif /* #if defined (ARM_MATH_DSP) */
  152.  
  153.   while (blkCnt > 0U)
  154.   {
  155.     /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  156.     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  157.     /* Saturated to 0x7fffffff if the input is -1(0x80000000) */
  158.     *pDst++ = *pSrc++;
  159.     in = *pSrc++;
  160.     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  161.  
  162.     /* Decrement the loop counter */
  163.     blkCnt--;
  164.   }
  165. }
  166.  
  167. /**
  168.  * @} end of cmplx_conj group
  169.  */
  170.