-
Notifications
You must be signed in to change notification settings - Fork 4
/
FFT_extract.c
59 lines (43 loc) · 1.18 KB
/
FFT_extract.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
#include <stdio.h>
#include <stdlib.h>
#define FFT_SIZE 1024
#define BIN_AMOUNT (FFT_SIZE / 2)
int main(int argc, char **argv) {
char defaultInputName[] = "fft.raw";
char defaultOutputName[] = "fft.csv";
char *inputName, *outputName;
if (argc >= 2) {
inputName = argv[1];
} else {
printf("[INFO] No input file specified. Using %s.\n", defaultInputName);
inputName = defaultInputName;
}
if (argc >= 3) {
outputName = argv[2];
} else {
printf("[INFO] No output file specified. Using %s.\n", defaultOutputName);
outputName = defaultOutputName;
}
FILE *input = fopen(inputName, "rb");
if (input == NULL) {
printf("[ERROR] Can't open %s.\n", inputName);
exit(EXIT_FAILURE);
}
FILE *output = fopen(outputName, "w");
if (output == NULL) {
printf("[ERROR] Can't open %s.\n", outputName);
exit(EXIT_FAILURE);
}
printf("Converting RAW FFT data to tab separated values.\n");
float buffer[BIN_AMOUNT];
int n;
while ((n = fread(&buffer[0], sizeof(float), BIN_AMOUNT, input)) > 0) {
int i;
for (i = 0; i < n; i++) {
fprintf(output, "%.6f;", buffer[i]);
}
fprintf(output, "\n");
}
printf("Conversion finished.\n");
return EXIT_SUCCESS;
}