Joep D / CMSIS_DSP_5

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_offset_f32.c Source File

arm_offset_f32.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_offset_f32.c
00004  * Description:  Floating-point vector offset
00005  *
00006  * $Date:        27. January 2017
00007  * $Revision:    V.1.5.1
00008  *
00009  * Target Processor: Cortex-M cores
00010  * -------------------------------------------------------------------- */
00011 /*
00012  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
00013  *
00014  * SPDX-License-Identifier: Apache-2.0
00015  *
00016  * Licensed under the Apache License, Version 2.0 (the License); you may
00017  * not use this file except in compliance with the License.
00018  * You may obtain a copy of the License at
00019  *
00020  * www.apache.org/licenses/LICENSE-2.0
00021  *
00022  * Unless required by applicable law or agreed to in writing, software
00023  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00024  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00025  * See the License for the specific language governing permissions and
00026  * limitations under the License.
00027  */
00028 
00029 #include "arm_math.h"
00030 
00031 /**
00032  * @ingroup groupMath
00033  */
00034 
00035 /**
00036  * @defgroup offset Vector Offset
00037  *
00038  * Adds a constant offset to each element of a vector.
00039  *
00040  * <pre>
00041  *     pDst[n] = pSrc[n] + offset,   0 <= n < blockSize.
00042  * </pre>
00043  *
00044  * The functions support in-place computation allowing the source and
00045  * destination pointers to reference the same memory buffer.
00046  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
00047  */
00048 
00049 /**
00050  * @addtogroup offset
00051  * @{
00052  */
00053 
00054 /**
00055  * @brief  Adds a constant offset to a floating-point vector.
00056  * @param[in]  *pSrc points to the input vector
00057  * @param[in]  offset is the offset to be added
00058  * @param[out]  *pDst points to the output vector
00059  * @param[in]  blockSize number of samples in the vector
00060  * @return none.
00061  */
00062 
00063 
00064 void arm_offset_f32(
00065   float32_t * pSrc,
00066   float32_t offset,
00067   float32_t * pDst,
00068   uint32_t blockSize)
00069 {
00070   uint32_t blkCnt;                               /* loop counter */
00071 
00072 #if defined (ARM_MATH_DSP)
00073 
00074 /* Run the below code for Cortex-M4 and Cortex-M3 */
00075   float32_t in1, in2, in3, in4;
00076 
00077   /*loop Unrolling */
00078   blkCnt = blockSize >> 2U;
00079 
00080   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
00081    ** a second loop below computes the remaining 1 to 3 samples. */
00082   while (blkCnt > 0U)
00083   {
00084     /* C = A + offset */
00085     /* Add offset and then store the results in the destination buffer. */
00086     /* read samples from source */
00087     in1 = *pSrc;
00088     in2 = *(pSrc + 1);
00089 
00090     /* add offset to input */
00091     in1 = in1 + offset;
00092 
00093     /* read samples from source */
00094     in3 = *(pSrc + 2);
00095 
00096     /* add offset to input */
00097     in2 = in2 + offset;
00098 
00099     /* read samples from source */
00100     in4 = *(pSrc + 3);
00101 
00102     /* add offset to input */
00103     in3 = in3 + offset;
00104 
00105     /* store result to destination */
00106     *pDst = in1;
00107 
00108     /* add offset to input */
00109     in4 = in4 + offset;
00110 
00111     /* store result to destination */
00112     *(pDst + 1) = in2;
00113 
00114     /* store result to destination */
00115     *(pDst + 2) = in3;
00116 
00117     /* store result to destination */
00118     *(pDst + 3) = in4;
00119 
00120     /* update pointers to process next samples */
00121     pSrc += 4U;
00122     pDst += 4U;
00123 
00124     /* Decrement the loop counter */
00125     blkCnt--;
00126   }
00127 
00128   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
00129    ** No loop unrolling is used. */
00130   blkCnt = blockSize % 0x4U;
00131 
00132 #else
00133 
00134   /* Run the below code for Cortex-M0 */
00135 
00136   /* Initialize blkCnt with number of samples */
00137   blkCnt = blockSize;
00138 
00139 #endif /* #if defined (ARM_MATH_DSP) */
00140 
00141   while (blkCnt > 0U)
00142   {
00143     /* C = A + offset */
00144     /* Add offset and then store the result in the destination buffer. */
00145     *pDst++ = (*pSrc++) + offset;
00146 
00147     /* Decrement the loop counter */
00148     blkCnt--;
00149   }
00150 }
00151 
00152 /**
00153  * @} end of offset group
00154  */