added phase calculation (dummy, always return 0) in imagery2abs. Added FFT_Re, FFT_Im dumping to the output file. Possible issue: phase of simple sin is -1.
This commit is contained in:
18
C/FP_math.c
18
C/FP_math.c
@ -10,21 +10,25 @@
|
||||
#include "FFT_FP_realisation.h"
|
||||
|
||||
|
||||
void imagery2abs(int64_t* inp, uint32_t inp_L, int64_t *out){
|
||||
void imagery2abs(int64_t* inp, uint32_t inp_L, int64_t *out_abs, int64_t *out_phase){
|
||||
printf("+++++++++++++++++++++\n");
|
||||
printf("calculating abs^2\n");
|
||||
for (uint32_t i = 0; i < inp_L; ++i){
|
||||
int64_t re = inp[i*2];
|
||||
int64_t im = inp[i*2 +1];
|
||||
int64_t val = (re * re + im * im) / FP_acc;
|
||||
printf("%lld\n", (long long)val);
|
||||
out[i] = val;
|
||||
int64_t phase = 0;
|
||||
printf("%lld, %ldd\n", (long long)val, (long long) phase);
|
||||
out_abs[i] = val;
|
||||
out_phase[i] = phase;
|
||||
|
||||
}
|
||||
}
|
||||
void data_generator(int64_t* X, int64_t* Y, uint32_t N){
|
||||
for (int i = 0; i < N; ++i){
|
||||
X[i] = (int64_t)i;
|
||||
Y[i] = lround(sin(((double)i)*2.0* PI/(N/10))*FP_acc);
|
||||
Y[i] += lround(cos(((double)i)*2.0* PI/(N/20))*FP_acc);
|
||||
Y[i] += 1*FP_acc;
|
||||
}
|
||||
}
|
||||
@ -35,6 +39,8 @@ void main(){
|
||||
int64_t data_Y[DATA_L] = {0,};
|
||||
int64_t data_res_FFT_imag[DATA_L*2] = {0,};
|
||||
int64_t data_res_FFT_abs[DATA_L] = {0,};
|
||||
int64_t data_res_FFT_phase[DATA_L] = {0,};
|
||||
|
||||
|
||||
fft_fp_prepare();
|
||||
|
||||
@ -44,13 +50,13 @@ void main(){
|
||||
FFT_fp(data_Y, DATA_L, data_res_FFT_imag);
|
||||
|
||||
|
||||
imagery2abs(data_res_FFT_imag, DATA_L, data_res_FFT_abs);
|
||||
imagery2abs(data_res_FFT_imag, DATA_L, data_res_FFT_abs, data_res_FFT_phase);
|
||||
|
||||
FILE *logfile_ptr;
|
||||
logfile_ptr = fopen(logfilename, "w");
|
||||
fprintf(logfile_ptr, "X, Y, FFT\n");
|
||||
fprintf(logfile_ptr, "X, Y, FFT_val, FFT_phase, FFT_Re, FFT_Im\n");
|
||||
for (uint32_t i = 0; i < DATA_L; ++i){
|
||||
fprintf(logfile_ptr, "%lld, %lg, %lg \n", (long long)data_X[i], ((double)data_Y[i])/(double)FP_acc , (double)data_res_FFT_abs[i]/(double)FP_acc);
|
||||
fprintf(logfile_ptr, "%lld, %lg, %lg, %lg, %lg, %lg\n", (long long)data_X[i], ((double)data_Y[i])/(double)FP_acc , (double)data_res_FFT_abs[i]/(double)FP_acc, (double)data_res_FFT_phase[i]/(double)FP_acc, (double)data_res_FFT_imag[2*i]/(double)FP_acc, (double)data_res_FFT_imag[2*i +1]/(double)FP_acc );
|
||||
}
|
||||
fclose(logfile_ptr);
|
||||
}
|
||||
|
||||
BIN
C/FP_math.o
BIN
C/FP_math.o
Binary file not shown.
Reference in New Issue
Block a user