-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSodar.c
122 lines (89 loc) · 2.2 KB
/
TestSodar.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* TestSodar.c
*
* Created on: 28 Dec 2017
* Author: aron
*/
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <fftw3.h>
#include "Sodar.h"
#include "sodar_fft.h"
#define BUFFSIZE 2048
extern double testData[40960][2];
static void testEndian();
extern int32_t getBufferVal(char *src, int offset, int channel, int channels);
int testDatacolumn = sizeof(testData[0])/sizeof(testData[0][0]);
int testDatarow = sizeof(testData) / sizeof(testData[0]);
int main()
{
int i;
int j;
double re1[BUFFSIZE];
double re2[BUFFSIZE];
double im1[BUFFSIZE];
double im2[BUFFSIZE];
double raw[2][BUFFSIZE];
Results results;
double sintheta;
double theta;
testEndian();
FftHnd *fftHnd = initialiseFFT(BUFFSIZE);
for (j = 0;j < testDatarow/BUFFSIZE;j++)
{
// Do first channel
for (i = 0; i < BUFFSIZE;i++)
{
fftHnd->input_buffer[i] = testData[i+j*BUFFSIZE][0];
raw[0][i] = fftHnd->input_buffer[i];
}
FFT_c(fftHnd);
for (i = 0; i < BUFFSIZE;i++)
{
re1[i] = fftHnd->output_buffer[i][0];
im1[i] = fftHnd->output_buffer[i][1];
}
// next do other channel.
for (i = 0; i < BUFFSIZE;i++)
{
fftHnd->input_buffer[i] = testData[i+j*BUFFSIZE][1];
raw[1][i] = fftHnd->input_buffer[i];
}
FFT_c(fftHnd);
for (i = 0; i < BUFFSIZE;i++)
{
re2[i] = fftHnd->output_buffer[i][0];
im2[i] = fftHnd->output_buffer[i][1];
}
estimatePhaseShift3(&raw[0][0],&raw[1][0], BUFFSIZE, &results);
printf("Index %d, Best Fit Index %f, Correlation %f, CorrelationStd %f, Std %f\n",results.offset,results.bestFitIndex, results.correlation, results.correlationStd,results.sx);
if (results.correlation > 0.95 && results.correlationStd > 0.1)
{
// sintheta = 1000*(results.offset * SPEED_OF_SOUND_MS/44000.0)/70.0;
if (sintheta >= 1)
{
theta = 90.0;
} else
if (sintheta <= -1)
{
theta = -90.0;
} else
{
theta = asin(sintheta) * 360.0/(2.0*M_PI);
}
}
}
terminateFFT(fftHnd);
}
char test[] = {0x00,0xC4,0xFF,0xFF,0x00,0x88,0xFF,0xFF};
void testEndian()
{
int32_t v1 = getBufferVal(test,0,0,2);
int32_t v2 = getBufferVal(test,0,1,2);
if (v1 != -15360 || v2 != -30720)
{
fprintf(stderr,
"Endian test failed\n");
}
}