The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Thu Jun 21 11:56:27 2018 +0000
Revision:
3:4098b9d3d571
Parent:
1:24714b45cd1b
headers is a folder not a library

Who changed what in which revision?

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