-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIR_Filter.c
executable file
·67 lines (55 loc) · 3.17 KB
/
FIR_Filter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "arm_math.h"
#include "stm32f4xx.h"
#include "defines.h"
#define BLOCK_SIZE 32
#define NUM_TAPS 31
const float32_t firCoeffs32_10k[NUM_TAPS] = {
-0.000867416331376402f, -0.00281346593729113f, 0.00268838255809662f, 0.00544340365669604f, -0.00648925602912664f,
-0.00892739279100665f, 0.0135227005092023f, 0.0129797497634584f, -0.0258415605324788f, -0.0171068973346708f,
0.0479881217664920f, 0.0206937262136956f, -0.0959611744262382f, -0.0231400422609313f, 0.314797786653009f,
0.524008789018353f, 0.314797786653009f, -0.0231400422609313f, -0.0959611744262382f, 0.0206937262136956f,
0.0479881217664920f, -0.0171068973346708f, -0.0258415605324788f, 0.0129797497634584f, 0.0135227005092023f,
-0.00892739279100665f, -0.00648925602912664f, 0.00544340365669604f, 0.00268838255809662f, -0.00281346593729113f,
-0.000867416331376402f
};
const float32_t firCoeffs32_30k[NUM_TAPS] = {
0.000881544236361683f,0.00279681008727858f,0.00481723056165078f,0.00541707353345437f,0.00284481990282610f,
-0.00382857451602248f,-0.0135727606449136f,-0.0228082492747443f,-0.0259193537781556f,-0.0169988733389352f,
0.00766360204532679f,0.0473447358286823f,0.0959949505201271f,0.143348215512277f,0.177867444334464f,
0.190512695268353f,0.177867444334464f,0.143348215512277f,0.0959949505201271f,0.0473447358286823f,
0.00766360204532679f,-0.0169988733389352f,-0.0259193537781556f,-0.0228082492747443f,-0.0135727606449136f,
-0.00382857451602248f,0.00284481990282610f,0.00541707353345437f,0.00481723056165078f,0.00279681008727858f,
0.000881544236361683f
};
const float32_t firCoeffs32_60k[NUM_TAPS] = {
-0.002476070511941722f,-0.003994435788253404f,-0.005431530485995430f,-0.006227893854242941f,-0.005678741646165756f,
-0.003038496044311324f, 0.002337180334418086f, 0.010836610922048622f, 0.022456665834928214f, 0.036719262997815375f,
0.052665231905480461f, 0.068937004737742183f, 0.083943609212946496f, 0.096083376662691525f, 0.103985896274988873f,
0.106728515599183560f, 0.103985896274988873f, 0.096083376662691525f, 0.083943609212946496f, 0.068937004737742183f,
0.052665231905480461f, 0.036719262997815375f, 0.022456665834928214f, 0.010836610922048622f, 0.002337180334418086f,
-0.003038496044311324f,-0.005678741646165756f,-0.006227893854242941f,-0.005431530485995430f,-0.003994435788253404f,
-0.002476070511941722f
};
uint32_t blockSize = BLOCK_SIZE;
uint32_t numBlocks = FFT_LENGTH/BLOCK_SIZE;
float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1];
float32_t inputF32[FFT_LENGTH], outputF32[FFT_LENGTH];
float32_t *firCoeffs32;
int Fir_Filter_Toggle = 0;
void Fir_Filter(int Coeff_Num, int16_t * data)
{
arm_fir_instance_f32 S;
int i;
if(Coeff_Num==1) firCoeffs32 = &firCoeffs32_10k[0];
if(Coeff_Num==2) firCoeffs32 = &firCoeffs32_30k[0];
if(Coeff_Num==2) firCoeffs32 = &firCoeffs32_60k[0];
for(i=0;i<FFT_LENGTH;i++)
inputF32[i] = (float32_t) (data[i]);
arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize);
for(i=0; i < numBlocks; i++)
{
arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
}
for(i=0;i<FFT_LENGTH;i++)
data[i] = (int16_t)outputF32[i];
}