#include #include #include #include #include const float SAMPLINGRATE = 1000000.0; const float FFT_LEN = 256; int main() { FILE* output = fopen("output.csv", "w"); FILE* input = fopen("input.raw", "r"); float complex * fft_in = (float complex*) malloc(FFT_LEN * sizeof(float complex)); float complex * fft_out = (float complex*) malloc(FFT_LEN * sizeof(float complex)); // create FFT plan fftplan fft = fft_create_plan(FFT_LEN, fft_in, fft_out, LIQUID_FFT_FORWARD, 0); int pos = 0; float in[2]; while(fread(in, sizeof(float), 2, input) == 2) { fft_in[pos] = (in[1] + I * in[0]); pos += 1; if(pos == FFT_LEN) { pos = 0; fft_execute(fft); float fft_min = cabsf(fft_out[0]); float fft_max = cabsf(fft_out[0]); for(int i = 0; i < FFT_LEN; i++) { float mag = cabsf(fft_out[i]); if(mag < fft_min) { fft_min = mag; } if(mag > fft_max) { fft_max = mag; } } //printf("Min: %f Max: %f\n", fft_min, fft_max); for(int i = FFT_LEN / 2; i < FFT_LEN; i++) { float mag = cabsf(fft_out[i]); mag = (mag - fft_min) / (fft_max - fft_min); fprintf(output, "%f;", mag); } for(int i = 0; i < FFT_LEN / 2; i++) { float mag = cabsf(fft_out[i]); mag = (mag - fft_min) / (fft_max - fft_min); fprintf(output, "%f;", mag); } fprintf(output, "\n"); } } fft_destroy_plan(fft); free(fft_in); free(fft_out); fclose(output); fclose(input); return 0; }