Src/radar_dsp.c
//do fft on each row of data

do fft on each row of data
do fft on each row of data
float dofft(uint16_t** data, uint8v2_t data_size){
	uint8_t sweeps = data_size.x1;
	uint8_t bins = data_size.x2;
	float scales[bins];
	int16_t real[sweeps];
	int16_t imag[sweeps];
	for(uint16_t i = 0; i<bins; i++){
		for (uint16_t j = 0; j < sweeps; j++) {
		  real[j] = data[j][i];
		}
		for (uint16_t j = 0; j < sweeps; j++) {
		  imag[j] = 0;
		}
		scales[i] = fftRangeScaling(real, sweeps);
		fftWindowing(real, sweeps, FFT_FORWARD);
		fftCompute(real, imag, sweeps, FFT_FORWARD);
		fftComplexToMagnitude(real, imag, sweeps);
		for (uint16_t j = 0; j < sweeps/2; j++) {
		  data[j][i] = real[j];
		}
		for (uint16_t j = sweeps/2; j < sweeps; j++) {
		  data[j][i] = 0;
		}
	}
	float min_scale = scales[0];
	for(uint16_t i =1; i<bins; i++){
		if (scales[i] < min_scale){
			min_scale = scales[i];		
		}
	}
	for(uint16_t i =0; i<bins; i++){
		float scaling_factor = min_scale/scales[i]; 
		for(uint16_t j = 0; j < sweeps/2; j++){
			data[j][i] *= scaling_factor;
		}
	}
	return min_scale;
}
float dofft ( uint16_t * * data , uint8v2_t data_size ) { uint8_t sweeps = data_size . x1 ; uint8_t bins = data_size . x2 ; float scales [ bins ] ; int16_t real [ sweeps ] ; int16_t imag [ sweeps ] ; for ( uint16_t i = 0 ; i < bins ; i ++ ) { for ( uint16_t j = 0 ; j < sweeps ; j ++ ) { real [ j ] = data [ j ] [ i ] ; } for ( uint16_t j = 0 ; j < sweeps ; j ++ ) { imag [ j ] = 0 ; } scales [ i ] = fftRangeScaling ( real , sweeps ) ; fftWindowing ( real , sweeps , FFT_FORWARD ) ; fftCompute ( real , imag , sweeps , FFT_FORWARD ) ; fftComplexToMagnitude ( real , imag , sweeps ) ; for ( uint16_t j = 0 ; j < sweeps / 2 ; j ++ ) { data [ j ] [ i ] = real [ j ] ; } for ( uint16_t j = sweeps / 2 ; j < sweeps ; j ++ ) { data [ j ] [ i ] = 0 ; } } float min_scale = scales [ 0 ] ; for ( uint16_t i = 1 ; i < bins ; i ++ ) { if ( scales [ i ] < min_scale ) { min_scale = scales [ i ] ; } } for ( uint16_t i = 0 ; i < bins ; i ++ ) { float scaling_factor = min_scale / scales [ i ] ; for ( uint16_t j = 0 ; j < sweeps / 2 ; j ++ ) { data [ j ] [ i ] *= scaling_factor ; } } return min_scale ; }
do fft on each row of data
do fft on each row of data
//note that this method of copying data to another array to do the FFT becomes less relatively memory efficient the fewer distance bins you have.
 //set real componet of FFT to data
 //set imaginary componet of FFT to zero
 //Compute FFT
 //load data back in to data array
 //set real componet of FFT to data
 //the data has been normalised in each row but to make meaningful comparisons we need in normalised across the entire array, we shall do this now
 //we will normalise by scaling everything realtive to the smallest scaling
 //first to find it
 //now just multiply each row by the relevant scaling factor
