-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathvfo.c
59 lines (48 loc) · 1.24 KB
/
vfo.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
#include <math.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <linux/types.h>
#include <complex.h>
#include <fftw3.h>
#include <unistd.h>
#include "sdr.h"
//we define one more than needed to cover the boundary of quadrature
static int phase_table[MAX_PHASE_COUNT];
int sampling_freq = 96000;
void vfo_init_phase_table(){
for (int i = 0; i < MAX_PHASE_COUNT; i++){
double d = (M_PI/2) * ((double)i)/((double)MAX_PHASE_COUNT);
phase_table[i] = (int)(sin(d) * 1073741824.0);
}
}
void vfo_start(struct vfo *v, int frequency_hz, int start_phase){
v->phase_increment = (frequency_hz * 65536) / sampling_freq;
v->phase = start_phase;
v->freq_hz = frequency_hz;
}
int vfo_read(struct vfo *v){
int i = 0;
if (v->phase < 16384)
i = phase_table[v->phase];
else if (v->phase < 32768)
i = phase_table[32767 - v->phase];
else if (v->phase < 49152)
i = -phase_table[v->phase - 32768];
else
i = -phase_table[65535- v->phase];
//increment the phase and modulo-65536
v->phase += v->phase_increment;
v->phase &= 0xffff;
return i;
}
/*
void main(int argc, char **argv){
struct vfo v;
vfo_init_phase_table();
vfo_start(&v, 1000, 0);
for (int i = 0; i < 100; i++)
printf("%d ", vfo_read(&v));
}
*/