forked from noqsi/WWVB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuneup.c
70 lines (55 loc) · 1.08 KB
/
tuneup.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
/* $Id: tuneup.c,v 1.4 2009-07-15 19:39:33 jpd Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include "param.h"
#include <math.h>
#define RESAMP_HZ 50
#define RESAMP (SAMPLE_HZ/SAMPLES_PER_BIN/RESAMP_HZ)
#define PWRSUM 20
float resamp_pwr( void )
{
int i, q, k;
short ib[ 2*RESAMP*sizeof( short) ];
if( read( 0, ib, sizeof ib ) <= 0 ) {
perror( "tuneup" );
exit( 1 );
}
i = q = 0;
for( k = 0; k < RESAMP; k += 2 ) {
i += ib[ k ];
q += ib[ k + 1 ];
}
return ((float) i) * ((float) i) + ((float) q) * ((float) q);
}
float sum_pwr( void )
{
int i;
float p;
for( i = 0; i < PWRSUM; i += 1 ) p += resamp_pwr();
return p;
}
int main(int argc,char *argv[])
{
for(;;) {
if( printf( "%f\n", log(sum_pwr())) <= 0 ) {
perror( "tuneup" );
exit( 1 );
}
}
}
/*
* $Log: tuneup.c,v $
* Revision 1.4 2009-07-15 19:39:33 jpd
* Tuneup timing.
*
* Revision 1.3 2009-06-22 16:33:32 jpd
* Fix tuneup cadence.
*
* Revision 1.2 2009-06-22 00:35:38 jpd
* First light.
*
* Revision 1.1 2009-06-21 22:04:57 jpd
* Share parameters.
* Tuneup filter.
*
*/