Project Ne10
An Open Optimized Software Library Project for the ARM Architecture
NE10_fir_init.c
1 /*
2  * Copyright 2012-15 ARM Limited and Contributors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ARM Limited nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <string.h>
29 
30 #include "NE10_types.h"
31 
53 ne10_result_t ne10_fir_init_float (ne10_fir_instance_f32_t * S,
54  ne10_uint16_t numTaps,
55  ne10_float32_t * pCoeffs,
56  ne10_float32_t * pState,
57  ne10_uint32_t blockSize)
58 {
59  /* Assign filter taps */
60  S->numTaps = numTaps;
61 
62  /* Assign coefficient pointer */
63  S->pCoeffs = pCoeffs;
64 
65  /* Clear state buffer and the size of state buffer is (blockSize + numTaps - 1) */
66  memset (pState, 0, (numTaps + (blockSize - 1u)) * sizeof (ne10_float32_t));
67 
68  /* Assign state pointer */
69  S->pState = pState;
70  return NE10_OK;
71 }
72 
96 ne10_result_t ne10_fir_decimate_init_float (
98  ne10_uint16_t numTaps,
99  ne10_uint8_t M,
100  ne10_float32_t * pCoeffs,
101  ne10_float32_t * pState,
102  ne10_uint32_t blockSize)
103 {
104  ne10_result_t status;
105 
106  /* The size of the input block must be a multiple of the decimation factor */
107  if ( (blockSize % M) != 0u)
108  {
109  /* Set status as NE10_ERR */
110  status = NE10_ERR;
111  }
112  else
113  {
114  /* Assign filter taps */
115  S->numTaps = numTaps;
116 
117  /* Assign coefficient pointer */
118  S->pCoeffs = pCoeffs;
119 
120  /* Clear state buffer and size is always (blockSize + numTaps - 1) */
121  memset (pState, 0, (numTaps + (blockSize - 1u)) * sizeof (ne10_float32_t));
122 
123  /* Assign state pointer */
124  S->pState = pState;
125 
126  /* Assign Decimation Factor */
127  S->M = M;
128 
129  status = NE10_OK;
130  }
131 
132  return (status);
133 
134 }
135 
160 ne10_result_t ne10_fir_interpolate_init_float (
162  ne10_uint8_t L,
163  ne10_uint16_t numTaps,
164  ne10_float32_t * pCoeffs,
165  ne10_float32_t * pState,
166  ne10_uint32_t blockSize)
167 {
168  ne10_result_t status;
169 
170  /* The filter length must be a multiple of the interpolation factor */
171  if ( (numTaps % L) != 0u)
172  {
173  /* Set status as NE10_ERR */
174  status = NE10_ERR;
175  }
176  else
177  {
178 
179  /* Assign coefficient pointer */
180  S->pCoeffs = pCoeffs;
181 
182  /* Assign Interpolation factor */
183  S->L = L;
184 
185  /* Assign polyPhaseLength */
186  S->phaseLength = numTaps / L;
187 
188  /* Clear state buffer and size of state array is always phaseLength + blockSize - 1 */
189  memset (pState, 0,
190  (blockSize +
191  ( (ne10_uint32_t) S->phaseLength - 1u)) * sizeof (ne10_float32_t));
192 
193  /* Assign state pointer */
194  S->pState = pState;
195 
196  status = NE10_OK;
197  }
198 
199  return (status);
200 
201 }
202 
212 ne10_result_t ne10_fir_lattice_init_float (
214  ne10_uint16_t numStages,
215  ne10_float32_t * pCoeffs,
216  ne10_float32_t * pState)
217 {
218  /* Assign filter taps */
219  S->numStages = numStages;
220 
221  /* Assign coefficient pointer */
222  S->pCoeffs = pCoeffs;
223 
224  /* Clear state buffer and size is always numStages */
225  memset (pState, 0, (numStages) * sizeof (ne10_float32_t));
226 
227  /* Assign state pointer */
228  S->pState = pState;
229 
230  return NE10_OK;
231 }
232 
254 ne10_result_t ne10_fir_sparse_init_float (
256  ne10_uint16_t numTaps,
257  ne10_float32_t * pCoeffs,
258  ne10_float32_t * pState,
259  ne10_int32_t * pTapDelay,
260  ne10_uint16_t maxDelay,
261  ne10_uint32_t blockSize)
262 {
263  /* Assign filter taps */
264  S->numTaps = numTaps;
265 
266  /* Assign coefficient pointer */
267  S->pCoeffs = pCoeffs;
268 
269  /* Assign TapDelay pointer */
270  S->pTapDelay = pTapDelay;
271 
272  /* Assign MaxDelay */
273  S->maxDelay = maxDelay;
274 
275  /* reset the stateIndex to 0 */
276  S->stateIndex = 0u;
277 
278  /* Clear state buffer and size is always maxDelay + blockSize */
279  memset (pState, 0, (maxDelay + blockSize) * sizeof (ne10_float32_t));
280 
281  /* Assign state pointer */
282  S->pState = pState;
283 
284  return NE10_OK;
285 }
286 
287 
ne10_float32_t * pCoeffs
Points to the coefficient array.
Definition: NE10_types.h:388
Instance structure for the floating-point FIR Sparse filter.
Definition: NE10_types.h:406
ne10_uint16_t numTaps
Length of the filter.
Definition: NE10_types.h:387
ne10_float32_t * pCoeffs
Points to the coefficient array.
Definition: NE10_types.h:378
ne10_uint16_t phaseLength
Length of each polyphase filter component.
Definition: NE10_types.h:398
ne10_float32_t * pState
Points to the state variable array.
Definition: NE10_types.h:410
ne10_uint16_t numTaps
Length of the filter.
Definition: NE10_types.h:366
Instance structure for the floating-point FIR Interpolation.
Definition: NE10_types.h:395
ne10_float32_t * pState
Points to the state variable array.
Definition: NE10_types.h:377
Instance structure for the floating-point FIR filter.
Definition: NE10_types.h:364
ne10_uint8_t L
Interpolation Factor.
Definition: NE10_types.h:397
ne10_float32_t * pState
Points to the state variable array.
Definition: NE10_types.h:389
ne10_float32_t * pCoeffs
Points to the coefficient array.
Definition: NE10_types.h:399
ne10_float32_t * pCoeffs
Points to the coefficient array.
Definition: NE10_types.h:368
ne10_float32_t * pState
Points to the state variable array.
Definition: NE10_types.h:367
Instance structure for the floating point FIR Lattice filter.
Definition: NE10_types.h:374
ne10_float32_t * pCoeffs
Points to the coefficient array.
Definition: NE10_types.h:411
Instance structure for the floating-point FIR Decimation.
Definition: NE10_types.h:384
ne10_uint16_t numTaps
Length of the filter.
Definition: NE10_types.h:408
ne10_uint16_t numStages
numStages of the of lattice filter.
Definition: NE10_types.h:376
ne10_uint16_t maxDelay
the largest number of delay line values .
Definition: NE10_types.h:412
ne10_float32_t * pState
Points to the state variable array.
Definition: NE10_types.h:400
ne10_int32_t * pTapDelay
Pointer to the array containing positions of the non-zero tap values.
Definition: NE10_types.h:413
ne10_uint8_t M
Decimation Factor.
Definition: NE10_types.h:386
ne10_uint16_t stateIndex
Index pointer for the state buffer .
Definition: NE10_types.h:409