diff --git a/.gitignore b/.gitignore index 8a75201..d192aa6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.raw *.py +*.csv diff --git a/fft-beacon-finder/.gitignore b/fft-beacon-finder/.gitignore new file mode 100644 index 0000000..aca7194 --- /dev/null +++ b/fft-beacon-finder/.gitignore @@ -0,0 +1,2 @@ +finder +!plot.py diff --git a/fft-beacon-finder/finder.c b/fft-beacon-finder/finder.c new file mode 100644 index 0000000..1c4490a --- /dev/null +++ b/fft-beacon-finder/finder.c @@ -0,0 +1,67 @@ +#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; +} diff --git a/fft-beacon-finder/plot.py b/fft-beacon-finder/plot.py new file mode 100644 index 0000000..ba68c91 --- /dev/null +++ b/fft-beacon-finder/plot.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +from numpy import genfromtxt +import matplotlib +import matplotlib.pyplot as plt + +def main(): + data = genfromtxt('output.csv', delimiter=';') + + fig, ax = plt.subplots() + im = ax.imshow(data) + plt.show() + + +if __name__ == '__main__': + main()