forked from Tsukihime/OpenExpertSDR
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnoiseblanker.c
91 lines (77 loc) · 2.5 KB
/
noiseblanker.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* noiseblanker.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2004, 2005, 2006 by Frank Brickle, AB2KT and Bob McGwier, N4HY
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The authors can be reached by email at
or
or by paper mail at
The DTTS Microwave Society
6 Kathleen Place
Bridgewater, NJ 08807
*/
#include <common.h>
NB
new_noiseblanker(CXB sigbuf, REAL threshold)
{
NB nb = (NB)safealloc(1, sizeof(nbstate), "new nbstate");
nb->sigbuf = sigbuf;
nb->threshold = threshold;
nb->average_mag = 1.0;
nb->hangtime = 0;
nb->sigindex = 0;
nb->delayindex = 2;
memset(nb->delay, 0, 8 * sizeof(COMPLEX));
return (nb);
}
void
del_nb(NB nb)
{
if(nb)
{
safefree((char *)nb);
}
}
void
noiseblanker(NB nb)
{
int i;
for (i = 0; i < CXBsize(nb->sigbuf); i++)
{
REAL cmag = Cmag(CXBdata(nb->sigbuf, i));
nb->delay[nb->sigindex] = CXBdata(nb->sigbuf, i);
nb->average_mag = (REAL)(0.999 * (nb->average_mag) + 0.001 * cmag);
if((nb->hangtime == 0) && (cmag > (nb->threshold * nb->average_mag))) nb->hangtime = 7;
if(nb->hangtime > 0)
{
CXBdata(nb->sigbuf, i) = Cmplx(0.0, 0.0);
nb->hangtime--;
} else CXBdata(nb->sigbuf, i) = nb->delay[nb->delayindex];
nb->sigindex = (nb->sigindex + 7) & 7;
nb->delayindex = (nb->delayindex + 7) & 7;
}
}
void
SDROMnoiseblanker(NB nb)
{
int i;
for (i = 0; i < CXBsize(nb->sigbuf); i++)
{
REAL cmag = Cmag(CXBdata(nb->sigbuf, i));
nb->average_sig = Cadd(Cscl(nb->average_sig, 0.75),
Cscl(CXBdata(nb->sigbuf, i), 0.25));
nb->average_mag = (REAL)(0.999 * (nb->average_mag) + 0.001 * cmag);
if(cmag > (nb->threshold * nb->average_mag)) CXBdata(nb->sigbuf, i) = nb->average_sig;
}
}