ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_fird_s16_ansi.c File Reference
#include "dsps_fir.h"
Include dependency graph for dsps_fird_s16_ansi.c:

Go to the source code of this file.

Functions

int32_t dsps_fird_s16_ansi (fir_s16_t *fir, const int16_t *input, int16_t *output, int32_t len)
 16 bit signed fixed point Decimation FIR filter

Function Documentation

◆ dsps_fird_s16_ansi()

int32_t dsps_fird_s16_ansi ( fir_s16_t * fir,
const int16_t * input,
int16_t * output,
int32_t len )

16 bit signed fixed point Decimation FIR filter

Function implements FIR filter with decimation The extension (_ansi) uses ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Parameters
firpointer to fir filter structure, that must be initialized before
inputinput array
outputarray with the result of the FIR filter
lenlength of the result array
Returns
: function returns the number of samples stored in the output array depends on the previous state value could be [0..len/decimation]

Definition at line 9 of file dsps_fird_s16_ansi.c.

10{
11 int32_t result = 0;
12 int32_t input_pos = 0;
13 long long rounding = 0;
14 const int32_t final_shift = fir->shift - 15;
15
16 rounding = (long long)(fir->rounding_val);
17
18 if (fir->shift >= 0) {
19 rounding = (rounding >> fir->shift) & 0xFFFFFFFFFF; // 40-bit mask
20 } else {
21 rounding = (rounding << (-fir->shift)) & 0xFFFFFFFFFF; // 40-bit mask
22 }
23
24 // len is already a length of the *output array, calculated as (length of the input array / decimation)
25 for (int i = 0; i < len; i++) {
26
27 for (int j = 0; j < fir->decim - fir->d_pos; j++) {
28
29 if (fir->pos >= fir->coeffs_len) {
30 fir->pos = 0;
31 }
32 fir->delay[fir->pos++] = input[input_pos++];
33 }
34 fir->d_pos = 0;
35
36 long long acc = rounding;
37 int16_t coeff_pos = fir->coeffs_len - 1;
38
39 for (int n = fir->pos; n < fir->coeffs_len ; n++) {
40 acc += (int32_t)fir->coeffs[coeff_pos--] * (int32_t)fir->delay[n];
41 }
42 for (int n = 0; n < fir->pos ; n++) {
43 acc += (int32_t)fir->coeffs[coeff_pos--] * (int32_t)fir->delay[n];
44 }
45
46 if (final_shift > 0) {
47 output[result++] = (int16_t)(acc << final_shift);
48 } else {
49 output[result++] = (int16_t)(acc >> (-final_shift));
50 }
51
52 }
53 return result;
54}
int16_t shift
Definition dsps_fir.h:61
int16_t * coeffs
Definition dsps_fir.h:55
int32_t rounding_val
Definition dsps_fir.h:63
int16_t * delay
Definition dsps_fir.h:56
int16_t decim
Definition dsps_fir.h:59
int16_t pos
Definition dsps_fir.h:58
int16_t d_pos
Definition dsps_fir.h:60
int16_t coeffs_len
Definition dsps_fir.h:57
const int n
Definition test_mmult.c:17

References fir_s16_s::coeffs, fir_s16_s::coeffs_len, fir_s16_s::d_pos, fir_s16_s::decim, fir_s16_s::delay, n, fir_s16_s::pos, fir_s16_s::rounding_val, and fir_s16_s::shift.