forked from grahamwhaley/DSPham
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ik8yfw.cpp
67 lines (55 loc) · 1.58 KB
/
ik8yfw.cpp
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
/**
******************************************************************************
* @file main.c
* @author Giuseppe Callipo - IK8YFW - [email protected]
* @version V1.0.0
* @date 22-04-2018
* @brief IO Routine
*
*
* NOTE: This file is part of RadioDSP project.
* See main.c file for additional project informations.
*
* Code taken from github.com/gcallipo/RadioDSP-Stm32f103/src/RadioDSP_Fast/src
* License was CC
******************************************************************************/
#include <Audio.h>
#include <arm_math.h>
#include <arm_const_structs.h>
#include "global.h"
#include "ik8yfw.h"
// Pass these in to the functions.
// Simply global here to keep the code together.
uint16_t fnr_level = 2; //1-3
uint16_t fnra_level = 5; //4-6
volatile float outwork_fn = 0;
static float buffer[MAX_FILTER_BUF];
// Variable noise filter (Exponential Smooting Moving Filter) : n: 3 (max) - 1 (min)
float fnrFilter_n(float inwork, uint16_t n)
{
float coeff;
if (n==1) coeff = 0.5;
if (n==2) coeff = 0.3;
if (n==3) coeff = 0.1;
outwork_fn += (inwork - outwork_fn) * coeff;
return outwork_fn;
}
// Variable noise filter (Average Smooting Moving Filter) : n: 6 (max) - 4 (min)
float fnrFilter_n_Average(float inwork ,uint16_t n)
{
int idx_max_buf;
if (n==4) idx_max_buf = 8;
if (n==5) idx_max_buf = 16;
if (n==6) idx_max_buf = 24;
int i;
float out = 0;
for (i = (idx_max_buf-1); i > 0; i--)
{
buffer[i] = buffer[i-1];
out+=buffer[i];
}
buffer[0] = inwork;
out+=inwork;
out=(out/idx_max_buf)*0.8;
return out;
}